Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui/react/components/layout): Box 컴포넌트 추가 #253

Merged
merged 4 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions packages/ui/react/src/components/layout/box.css.ts
Original file line number Diff line number Diff line change
@@ -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<typeof boxEnumVariants>,
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<keyof typeof boxDynamicVariants, number | string>
>;
55 changes: 55 additions & 0 deletions packages/ui/react/src/components/layout/box.tsx
Original file line number Diff line number Diff line change
@@ -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<BoxProps, 'div'>(
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 (
<Slot
{...restProps}
ref={forwardedRef}
className={cx(
'favolink-box',
styles.boxEnumVariants({
position,
overflow,
overflowX,
overflowY,
flexShrink,
flexGrow,
}),
className,
)}
>
{asChild ? children : <Tag>{children}</Tag>}
</Slot>
);
},
);
1 change: 1 addition & 0 deletions packages/ui/react/src/components/layout/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Loading