-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui/components/layout): flex, box 컴포넌트에 변경사항 적용
- Loading branch information
Showing
2 changed files
with
57 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,47 @@ | ||
import { assignInlineVars } from '@vanilla-extract/dynamic'; | ||
import { Box, type BoxProps } from './box'; | ||
import * as styles from './flex.css'; | ||
import { forwardRef } from '../../system'; | ||
import { cx, mergeStyles, px } from '../../utils'; | ||
import { extractFlexProps } from './extract-flex-props'; | ||
import { extractLayoutProps } from './extract-layout-props'; | ||
import type * as Styles from './flex.css'; | ||
import type * as CommonStyles from './layout.css'; | ||
import { | ||
type HTMLFavolinkPropsWithout, | ||
type RemovedProps, | ||
Slot, | ||
forwardRef, | ||
} from '../../system'; | ||
import { cx } from '../../utils'; | ||
import { type MarginVariants, extractMarginProps } from '../margin'; | ||
|
||
export type FlexProps = BoxProps & | ||
styles.FlexDynamicVariants & | ||
styles.FlexEnumVariants; | ||
type FlexDivProps = HTMLFavolinkPropsWithout<'div', RemovedProps> & { | ||
as?: 'div'; | ||
}; | ||
|
||
export const Flex = forwardRef<FlexProps, typeof Box>( | ||
type FlexSpanProps = HTMLFavolinkPropsWithout<'span', RemovedProps> & { | ||
as: 'span'; | ||
}; | ||
|
||
export type FlexProps = CommonStyles.LayoutVariants & | ||
MarginVariants & | ||
Styles.FlexVariants & | ||
(FlexDivProps | FlexSpanProps); | ||
|
||
export const Flex = forwardRef<FlexProps, 'div'>( | ||
function Flex(props, forwardedRef) { | ||
const { | ||
as: Tag = 'div', | ||
asChild, | ||
className, | ||
style, | ||
display, | ||
direction, | ||
align, | ||
justify, | ||
wrap, | ||
gap, | ||
gapX, | ||
gapY, | ||
children, | ||
...restProps | ||
} = props; | ||
} = extractMarginProps(extractFlexProps(extractLayoutProps(props))); | ||
|
||
return ( | ||
<Box | ||
<Slot | ||
{...restProps} | ||
ref={forwardedRef} | ||
className={cx( | ||
'favolink-flex', | ||
gap && styles.gap, | ||
gapX && styles.gapX, | ||
gapY && styles.gapY, | ||
styles.flexEnumVariants({ display, direction, align, justify, wrap }), | ||
className, | ||
)} | ||
style={mergeStyles( | ||
assignInlineVars({ | ||
[styles.dynamicVars.gap]: px(gap), | ||
[styles.dynamicVars.gapX]: px(gapX), | ||
[styles.dynamicVars.gapY]: px(gapY), | ||
}), | ||
style, | ||
)} | ||
/> | ||
className={cx('favolink-flex', className)} | ||
> | ||
{asChild ? children : <Tag>{children}</Tag>} | ||
</Slot> | ||
); | ||
}, | ||
); |