From bce353bfc66a9cf7ead48dc5567237d3288803e6 Mon Sep 17 00:00:00 2001 From: Wonsuk Choi Date: Fri, 19 Jul 2024 15:06:10 +0900 Subject: [PATCH] =?UTF-8?q?feat(ui/react):=20extractProps=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/ui/react/src/extract-props.ts | 53 -------------------------- 1 file changed, 53 deletions(-) delete mode 100644 packages/ui/react/src/extract-props.ts diff --git a/packages/ui/react/src/extract-props.ts b/packages/ui/react/src/extract-props.ts deleted file mode 100644 index 9bbb32e..0000000 --- a/packages/ui/react/src/extract-props.ts +++ /dev/null @@ -1,53 +0,0 @@ -import { mergeStyles } from '@favolink-ui/utils'; -import { type createVar } from '@vanilla-extract/css'; -import { assignInlineVars } from '@vanilla-extract/dynamic'; -import { type CSSProperties } from 'react'; -import { type FlexStyleProps } from './styles'; - -export function extractProps< - Props extends { - className?: string; - style?: CSSProperties; - [key: string]: any; - }, - CSSVarFuntion extends ReturnType, - Styles extends ReturnType, ->( - props: Props, - vars: Record, - ...styleProps: Record[] -) { - const { style, ...restProps } = props; - const copiedRestProps = { ...restProps }; - const copiedVars = { ...vars }; - const allStyleProps = mergeStyles(...styleProps); - const willAssignInlineStyle = {} as Record; - - for (const styleProp in allStyleProps) { - if (styleProp in copiedRestProps) { - delete copiedRestProps[styleProp]; - - const regex = new RegExp(`\\w*${styleProp}\\w*`, 'i'); - - for (const _var in copiedVars) { - if (regex.test(copiedVars[_var] as CSSVarFuntion)) { - delete copiedVars[_var]; - - willAssignInlineStyle[vars[_var] as CSSVarFuntion] = props[ - styleProp - ] as string; - - break; - } - } - } - } - - return { - ...(copiedRestProps as Omit), - style: { - ...assignInlineVars(willAssignInlineStyle), - ...style, - } as CSSProperties & Styles, - }; -}