import { get } from '@vtex/admin-ui-util' import type { StyleProp } from './types' export function style(csx: StyleProp): StyleProp { return csx } export function styleVariants(variants: VariantDef) { return function variantFn(rules: VariantsCall) { const css: StyleProp = {} for (const key in rules) { Object.assign(css, get(variants, `${key}.${get(rules, key)}`, {})) } return style(css) } } export type VariantDef = { [k in keyof V]: { [b in keyof V[k]]: StyleProp } } export type InferVariant = T extends 'true' | 'false' ? boolean : T export type VariantsCall = { [k in keyof V]?: InferVariant } /** * Get variant parameters as props * @example * const variants = styleVariants({}) * type Props = VariantProps */ export type VariantProps any> = Parameters[0] /** * Enhance component props with variants * @example * interface Props {} * const variants = styleVariants({}) * type ComponentProps = PropsWithVariants */ export type PropsWithVariants

any> = P & VariantProps