diff --git a/packages/ui/react/src/components/layout/box.css.ts b/packages/ui/react/src/components/layout/box.css.ts new file mode 100644 index 0000000..10810a4 --- /dev/null +++ b/packages/ui/react/src/components/layout/box.css.ts @@ -0,0 +1,113 @@ +import { type RecipeVariants, recipe } from '@vanilla-extract/recipes'; +import { dynamicStyles, dynamicVars, enumStyles } from '../../styles/utils'; + +const { position, overflow, overflowX, overflowY, flexShrink, flexGrow } = + enumStyles; + +export const boxEnumVariants = recipe({ + variants: { + position, + overflow, + overflowX, + overflowY, + flexShrink, + flexGrow, + }, +}); + +export type BoxEnumVariants = Exclude< + RecipeVariants, + undefined +>; + +const { + paddingVar, + paddingBottomVar, + paddingLeftVar, + paddingRightVar, + paddingTopVar, + paddingXVar, + paddingYVar, + widthVar, + minWidthVar, + maxWidthVar, + heightVar, + minHeightVar, + maxHeightVar, + insetVar, + topVar, + bottomVar, + leftVar, + rightVar, + flexBasisVar, +} = dynamicVars; + +export const boxDynamicVariantVars = { + paddingVar, + paddingBottomVar, + paddingLeftVar, + paddingRightVar, + paddingTopVar, + paddingXVar, + paddingYVar, + widthVar, + minWidthVar, + maxWidthVar, + heightVar, + minHeightVar, + maxHeightVar, + insetVar, + topVar, + bottomVar, + leftVar, + rightVar, + flexBasisVar, +}; + +export const { + padding, + paddingBottom, + paddingLeft, + paddingRight, + paddingTop, + paddingX, + paddingY, + width, + minWidth, + maxWidth, + height, + minHeight, + maxHeight, + inset, + top, + bottom, + left, + right, + flexBasis, +} = dynamicStyles; + +export const boxDynamicVariants = { + padding, + paddingBottom, + paddingLeft, + paddingRight, + paddingTop, + paddingX, + paddingY, + width, + minWidth, + maxWidth, + height, + minHeight, + maxHeight, + inset, + top, + bottom, + left, + right, + flexBasis, +}; + +export type BoxDynamicVariants = Partial< + Record +>; diff --git a/packages/ui/react/src/components/layout/box.tsx b/packages/ui/react/src/components/layout/box.tsx new file mode 100644 index 0000000..4f700c9 --- /dev/null +++ b/packages/ui/react/src/components/layout/box.tsx @@ -0,0 +1,55 @@ +import { type HTMLFavolinkProps, Slot, forwardRef } from '@favolink-ui/system'; +import { cx } from '@favolink-ui/utils'; +import * as styles from './box.css'; +import { extractDynamicProps } from '../../styles'; + +type BoxDivProps = HTMLFavolinkProps<'div'> & { as?: 'div' }; + +type BoxSpanProps = HTMLFavolinkProps<'span'> & { as: 'span' }; + +export type BoxProps = styles.BoxDynamicVariants & + styles.BoxEnumVariants & + (BoxDivProps | BoxSpanProps); + +export const Box = forwardRef( + function Box(props, forwardedRef) { + const { + as: Tag = 'div', + asChild, + children, + className, + position, + overflow, + overflowX, + overflowY, + flexShrink, + flexGrow, + ...restProps + } = extractDynamicProps( + props, + styles.boxDynamicVariantVars, + styles.boxDynamicVariants, + ); + + return ( + + {asChild ? children : {children}} + + ); + }, +); diff --git a/packages/ui/react/src/components/layout/index.ts b/packages/ui/react/src/components/layout/index.ts index 0fd178f..5c35e3d 100644 --- a/packages/ui/react/src/components/layout/index.ts +++ b/packages/ui/react/src/components/layout/index.ts @@ -4,4 +4,5 @@ export { type CSSPropertyValue, } from './create-css-property-style-variants'; +export { Box, type BoxProps } from './box'; export { Flex, type FlexProps } from './flex';