|
| 1 | +import type { ComponentProps, FC } from 'react'; |
| 2 | +import { createVariants } from '../../utils'; |
| 3 | +import styles from './Grid.module.css'; |
| 4 | + |
| 5 | +const variants = createVariants(styles); |
| 6 | + |
| 7 | +type Props = ComponentProps<'div'> & { |
| 8 | + columns?: number; |
| 9 | + rows?: number; |
| 10 | + alignItems?: 'stretch' | 'start' | 'end' | 'center'; |
| 11 | + justifyItems?: 'stretch' | 'start' | 'end' | 'center'; |
| 12 | + gap?: number; |
| 13 | + width?: number | string; |
| 14 | + height?: number | string; |
| 15 | + padding?: { top: number; right: number; bottom: number; left: number }; |
| 16 | + margin?: { top: number; right: number; bottom: number; left: number }; |
| 17 | + background?: string; |
| 18 | +}; |
| 19 | + |
| 20 | +export const Grid: FC<Props> = ({ |
| 21 | + className, |
| 22 | + columns, |
| 23 | + rows, |
| 24 | + alignItems, |
| 25 | + justifyItems, |
| 26 | + gap, |
| 27 | + width, |
| 28 | + height, |
| 29 | + padding, |
| 30 | + margin, |
| 31 | + background, |
| 32 | + ...props |
| 33 | +}) => ( |
| 34 | + <div |
| 35 | + className={variants('grid', { |
| 36 | + className, |
| 37 | + alignItems, |
| 38 | + justifyItems, |
| 39 | + ...(background?.startsWith('#') ? {} : { background }), |
| 40 | + })} |
| 41 | + style={{ |
| 42 | + gridTemplateColumns: `repeat(${columns}, 1fr)`, |
| 43 | + gridTemplateRows: `repeat(${rows}, 1fr)`, |
| 44 | + gap, |
| 45 | + width, |
| 46 | + height, |
| 47 | + paddingTop: padding?.top, |
| 48 | + paddingBottom: padding?.bottom, |
| 49 | + paddingLeft: padding?.left, |
| 50 | + paddingRight: padding?.right, |
| 51 | + marginTop: margin?.top, |
| 52 | + marginBottom: margin?.bottom, |
| 53 | + marginLeft: margin?.left, |
| 54 | + marginRight: margin?.right, |
| 55 | + ...(background?.startsWith('#') ? { background } : {}), |
| 56 | + }} |
| 57 | + {...props} |
| 58 | + /> |
| 59 | +); |
0 commit comments