( componentName: ComponentType, props: Omit<ComponentProps<ComponentType>, "children">, )
| 8 | * Centralizes the common pattern used by the Kuma React wrappers. |
| 9 | */ |
| 10 | export function resolveMergedBoxProps< |
| 11 | ComponentType extends keyof typeof componentList, |
| 12 | >( |
| 13 | componentName: ComponentType, |
| 14 | props: Omit<ComponentProps<ComponentType>, "children">, |
| 15 | ): BoxProps { |
| 16 | type ComponentName = Parameters<typeof theme.getVariants>[0]; |
| 17 | const variantData = theme.getVariants(componentName as ComponentName); |
| 18 | const variants = variantData?.variants; |
| 19 | |
| 20 | // Variant is already typed as string literal union or undefined from ComponentProps |
| 21 | const variantKey = props.variant; |
| 22 | const variantProps: Partial<BoxProps> = |
| 23 | variantKey && |
| 24 | variants && |
| 25 | typeof variantKey === "string" && |
| 26 | variantKey in variants |
| 27 | ? (variants[variantKey] as Partial<BoxProps>) |
| 28 | : {}; |
| 29 | |
| 30 | return { |
| 31 | ...variantProps, |
| 32 | ...props, |
| 33 | IS_KUMA_DEFAULT: true, |
| 34 | }; |
| 35 | } |
no test coverage detected