preview.jsx 1.0 KB

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