preview.jsx 923 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import styled from '@emotion/styled'
  2. import { useRef } from 'react'
  3. import useResizeObserver from 'use-resize-observer'
  4. import { GlobalStyles } from '@/styles'
  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, box: 'border-box' })
  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. <GlobalStyles />
  21. {styleFn()}
  22. </Wrapper>
  23. )
  24. }
  25. export const decorators = [StylesWrapperDecorator]
  26. export const parameters = {
  27. actions: { argTypesRegex: '^on[A-Z].*' },
  28. options: {
  29. storySort: (a, b) => (a[1].kind === b[1].kind ? 0 : a[1].id.localeCompare(b[1].id, undefined, { numeric: true })),
  30. },
  31. }