Usage
sva
Learn how to style your components with sva functions.
You can import sva functions from jade-garden/sva.
sva
Implementation of the slots variants authority (sva) function using the default class merging function (cx).
Parameters
The
metaConfig parameter is intended for UI/UX library authors to generate JSDoc and CSS Comments when used with unplugin-jade-garden.styleConfig:base: the base classes for each slotPartial<typeof slots[number], ClassValue>.slots: an array of slots for the componentstring[].variants: variants allow you to create multiple versions of the same component.compoundVariants: compound variants allow you to apply classes to multiple variants at once.compoundSlots: compound slots allow you to apply classes to multiple slots at once.defaultVariants: default variants allow you to set default variants for a component.
metaConfig:deprecated: adds adeprecatedtag and a description ifdeprecatedis a stringstring | boolean.description: adds adescriptiontagstring.name: adds anametagstring.see: adds aseetagstring.
Examples
basic.ts
import { sva } from "jade-garden/sva";
const card = sva({
base: {
description: "text-md font-medium",
infoWrapper: "font-medium",
name: "text-sm text-sky-500 dark:text-sky-400",
role: "text-sm text-slate-700 dark:text-slate-500"
},
slots: ["base", "avatar", "wrapper", "description", "infoWrapper", "name", "role"]
});
const { base, avatar, wrapper, description, infoWrapper, name, role } = card();
createSVA
Creates a slots variants authority (sva) function with a custom merge function.
Parameters
createOptions:mergeFn: The optional function to merge class names, defaults tocx(MergeFn).prefix: The prefix for the class name. Applied whenuseStylesheetis set totrue.useStylesheet: Determines if the component returns classes for a stylesheet or not. Iftruethe class name generated is a combination ofbaseandvariantkeys.
Examples
sva.ts
import { cn, createSVA, type MergeFn } from "jade-garden";
import { twMerge } from "tailwind-merge";
import { alert } from "./alert.ts";
const svaCN = createSVA({ mergeFn: cn });
const alertCN = svaCN(alert.styleConfig)({ variant: "outlined" });
const sva = createSVA({
prefix: "jg",
useStylesheet: true
});
const alertDefault = sva(alert.styleConfig)({ severity: "success" });
const svaTM = createSVA({ mergeFn: twMerge as MergeFn });
const alertTM = svaTM(alert.styleConfig)({ size: "xs" });