import * as React from 'react'; import { classify } from '../helpers/classify'; import { BreakpointClasses, breakpoints } from '../helpers/breakpoints'; import { computeClass } from '../helpers/computeClass'; const radiuses = ['sm', 'md', 'lg', 'full'] as const; type RADIUS = keyof { [key in typeof radiuses[number]]: string }; const RADIUS: { [key: string]: string; } = {}; const RADIUSES: BreakpointClasses = { default: {}, sm: {}, md: {}, lg: {}, xl: {}, }; radiuses.forEach((radius) => { const prefix = 'rounded'; RADIUS[radius] = `${prefix}-${radius}`; breakpoints.forEach((breakpoint) => { RADIUSES[breakpoint][radius] = `${breakpoint}:${prefix}-${radius}`; }); }); interface Props { backgroundColor?: React.HTMLAttributes['className'] | string; textColor?: React.HTMLAttributes['className'] | string; borderColor?: React.HTMLAttributes['className'] | string; borderWidth?: number; cornerRadius?: | RADIUS | { default?: RADIUS; sm?: RADIUS; md?: RADIUS; lg?: RADIUS; xl?: RADIUS; }; className?: React.HTMLAttributes['className']; style?: React.HTMLAttributes['style']; } const Box: React.FC = ({ backgroundColor, textColor, borderColor, borderWidth, cornerRadius, className, style, children, }) => { const computedClasses: (string | undefined)[] = [ !backgroundColor?.includes('#') ? backgroundColor : undefined, !textColor?.includes('#') ? textColor : undefined, !borderColor?.includes('#') ? borderColor : undefined, computeClass(cornerRadius, RADIUS, RADIUSES), ]; return (
{children}
); }; export default Box;