Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | 1x 1x 1x 1x 1x | import { compact, getSlotRecipes, memo, splitProps } from '../helpers.mjs';
import { cva } from './cva.mjs';
import { cx } from './cx.mjs';
export function sva(config) {
const slots = Object.entries(getSlotRecipes(config)).map(([slot, slotCva]) => [slot, cva(slotCva)])
const defaultVariants = config.defaultVariants ?? {}
const classNameMap = slots.reduce((acc, [slot, cvaFn]) => {
if (config.className) acc[slot] = cvaFn.config.className
return acc
}, {})
function svaFn(props) {
const result = slots.map(([slot, cvaFn]) => [slot, cx(cvaFn(props), classNameMap[slot])])
return Object.fromEntries(result)
}
function raw(props) {
const result = slots.map(([slot, cvaFn]) => [slot, cvaFn.raw(props)])
return Object.fromEntries(result)
}
const variants = config.variants ?? {};
const variantKeys = Object.keys(variants);
function splitVariantProps(props) {
return splitProps(props, variantKeys);
}
const getVariantProps = (variants) => ({ ...defaultVariants, ...compact(variants) })
const variantMap = Object.fromEntries(
Object.entries(variants).map(([key, value]) => [key, Object.keys(value)])
);
return Object.assign(memo(svaFn), {
__cva__: false,
raw,
config,
variantMap,
variantKeys,
classNameMap,
splitVariantProps,
getVariantProps,
})
} |