(config)
| 3 | import { cx } from './cx.mjs'; |
| 4 | |
| 5 | export function sva(config) { |
| 6 | const slots = Object.entries(getSlotRecipes(config)).map(([slot, slotCva]) => [slot, cva(slotCva)]) |
| 7 | const defaultVariants = config.defaultVariants ?? {} |
| 8 | |
| 9 | const classNameMap = slots.reduce((acc, [slot, cvaFn]) => { |
| 10 | if (config.className) acc[slot] = cvaFn.config.className |
| 11 | return acc |
| 12 | }, {}) |
| 13 | |
| 14 | function svaFn(props) { |
| 15 | const result = slots.map(([slot, cvaFn]) => [slot, cx(cvaFn(props), classNameMap[slot])]) |
| 16 | return Object.fromEntries(result) |
| 17 | } |
| 18 | |
| 19 | function raw(props) { |
| 20 | const result = slots.map(([slot, cvaFn]) => [slot, cvaFn.raw(props)]) |
| 21 | return Object.fromEntries(result) |
| 22 | } |
| 23 | |
| 24 | const variants = config.variants ?? {}; |
| 25 | const variantKeys = Object.keys(variants); |
| 26 | |
| 27 | function splitVariantProps(props) { |
| 28 | return splitProps(props, variantKeys); |
| 29 | } |
| 30 | const getVariantProps = (variants) => ({ ...defaultVariants, ...compact(variants) }) |
| 31 | |
| 32 | const variantMap = Object.fromEntries( |
| 33 | Object.entries(variants).map(([key, value]) => [key, Object.keys(value)]) |
| 34 | ); |
| 35 | |
| 36 | return Object.assign(memo(svaFn), { |
| 37 | __cva__: false, |
| 38 | raw, |
| 39 | config, |
| 40 | variantMap, |
| 41 | variantKeys, |
| 42 | classNameMap, |
| 43 | splitVariantProps, |
| 44 | getVariantProps, |
| 45 | }) |
| 46 | } |
nothing calls this directly
no test coverage detected