preview.jsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import styled from '@emotion/styled'
  2. import React, { useRef } from 'react'
  3. import useResizeObserver from 'use-resize-observer'
  4. import { GlobalStyle } from '../src/shared/components/GlobalStyle'
  5. const Wrapper = styled.div`
  6. padding: 10px;
  7. height: calc(100vh - 20px);
  8. & > * + * {
  9. margin-left: 15px;
  10. }
  11. `
  12. const StylesWrapperDecorator = (styleFn) => {
  13. const ref = useRef(null)
  14. const { width, height } = useResizeObserver({ ref })
  15. return (
  16. <Wrapper ref={ref}>
  17. <div style={{ position: 'absolute', fontSize: '12px', right: '4px', top: '4px' }}>
  18. {width}px x {height}px
  19. </div>
  20. <GlobalStyle />
  21. {styleFn()}
  22. </Wrapper>
  23. )
  24. }
  25. export const decorators = [StylesWrapperDecorator]
  26. export const parameters = {
  27. actions: { argTypesRegex: '^on[A-Z].*' },
  28. backgrounds: {
  29. default: 'black',
  30. values: [
  31. {
  32. name: 'black',
  33. value: '#000000',
  34. },
  35. {
  36. name: 'gray',
  37. value: '#272D33',
  38. },
  39. ],
  40. },
  41. options: {
  42. storySort: (a, b) => (a[1].kind === b[1].kind ? 0 : a[1].id.localeCompare(b[1].id, undefined, { numeric: true })),
  43. },
  44. }