Source

adminjs-design-system/src/atoms/box/box.tsx

  1. import styled from 'styled-components'
  2. import {
  3. space, SpaceProps, color, layout,
  4. LayoutProps, flexbox, FlexboxProps, border, BorderProps,
  5. position, PositionProps, variant,
  6. shadow, ShadowProps,
  7. } from 'styled-system'
  8. import { ColorProps } from '../../utils/color-props'
  9. import { cssClass } from '../../utils/css-class'
  10. const variants = variant({
  11. variants: {
  12. grey: {
  13. flexGrow: 1,
  14. bg: 'bg',
  15. py: 'xl',
  16. px: ['0', 'xl'],
  17. className: cssClass(['Box', 'Box_Grey']),
  18. },
  19. white: {
  20. px: ['default', 'xxl'],
  21. py: 'xxl',
  22. bg: 'white',
  23. className: cssClass(['Box', 'Box_White']),
  24. },
  25. card: {
  26. p: 'xxl',
  27. bg: 'white',
  28. className: cssClass(['Box', 'Box_Card']),
  29. boxShadow: 'card',
  30. },
  31. },
  32. })
  33. type FlexboxFlexProp = boolean | FlexboxProps['flex']
  34. /**
  35. * @load ./box-props.doc.md
  36. * @memberof Box
  37. * @alias BoxProps
  38. * @property {string} [...] Other props from {@link SpaceProps}, {@link ColorProps},
  39. * {@link LayoutProps}, {@link FlexboxProps},
  40. * {@link PositionProps} and {@link BorderProps}.
  41. */
  42. export type BoxProps = SpaceProps & ColorProps & LayoutProps &
  43. Omit<FlexboxProps, 'flex'> & BorderProps & PositionProps & ShadowProps & {
  44. /** If box should be rendered as flex. You can pass boolean or FlexboxProps['flex'] */
  45. flex?: FlexboxFlexProp;
  46. /** Box variants */
  47. variant?: 'grey' | 'white' | 'card';
  48. /** If set to true it makes css changes as 500ms transitions */
  49. animate?: boolean;
  50. /** Optional class name passed down to the wrapper */
  51. className?: string;
  52. }
  53. /**
  54. * @load ./box.doc.md
  55. * @hideconstructor
  56. * @component
  57. * @subcategory Atoms
  58. * @section design-system
  59. * @see BoxProps
  60. * @see {@link https://storybook.adminjs.co/?path=/story/designsystem-atoms-box--simple-white-gray-wrapper StoryBook}
  61. */
  62. const Box = styled.section<BoxProps>`
  63. box-sizing: border-box;
  64. min-width: 0;
  65. ${({ flex }): string => (flex && typeof flex === 'boolean' ? 'display: flex;' : '')}
  66. font-family: ${({ theme }): string => theme.font};
  67. line-height: ${({ theme }): string => theme.lineHeights.default};
  68. font-size: ${({ theme }): string => theme.fontSizes.default};
  69. font-weight: normal;
  70. ${({ animate }): string => (animate ? 'transition: all 500ms;' : '')};
  71. ${space};
  72. ${color};
  73. ${layout};
  74. ${flexbox};
  75. ${border};
  76. ${shadow};
  77. ${position};
  78. ${variants};
  79. `
  80. Box.defaultProps = {
  81. className: cssClass('Box'),
  82. }
  83. export { Box }
  84. export default Box