uvimport { uv } from 'unocss-variants'
const element = uv(options, config)
// call the element function to get the class names
element({'...'}) // => string
// call the element function with slots to get the class names
const { slot1, slot2 } = element({...}) // => Record<Function, Function>
slot1({}) // => string
// access to the returned object
element.base // => string
element.slots // => Record<string, string>
element.variants // => Record<string, string>
element.variantKeys // => string[]
element.defaultVariants // => Record<string, string>
element.compoundVariants // => Array<Record<string, string>>
element.compoundSlots // => Array<Record<string, string>>
The options argument is an object with the following properties:
interface UvOptions {
extend?: UvReturnType | undefined;
base?: ClassValue;
slots?: Record<string, ClassValue>;
variants?: Record<string, Record<string, ClassValue>>;
defaultVariants?: Record<string, ClassValue>;
compoundVariants?: Array<Record<string, string> & ClassProp>;
compoundSlots?: Array<Record<string, string> & ClassProp>;
}
extenddescription: This property allows you to extend the base styles, slots, variants,
defaultVariants and compoundVariants from another component.
type: UVReturnType | undefined
default: undefined
To learn more about Components composition, check out this page.
basedescription: This property allows you to define the base styles for the component.
type: ClassValue
default: undefined
slotsdescription: This property allows you to define the slots for the component.
type: Record<string, ClassValue> | undefined
default: {}
To learn more about slots and how to use them, check out the Slots page.
variantsdescription: This property allows you to define the variants for the component.
type: Record<string, Record<string, ClassValue>> | undefined
default: {}
To learn more about variants and how to use them, check out the Variants page.
defaultVariantsdescription: This property allows you to define the default variants for the component.
type: Record<string, ClassValue> | undefined
default: {}
To learn more about default variants and how to use them, check out the Default Variants page.
compoundVariantsdescription: This property allows you to define the compound variants for the component.
type: Array<Record<string, string> & ClassProp> | undefined
default: []
To learn more about compound variants and how to use them, check out the Compound Variants page.
compoundSlotsdescription: This property allows you to define the compound slots for the component.
type: Array<Record<string, string> & ClassProp> | undefined
default: []
To learn more about compound slots and how to use them, check out the Compound Slots page.
type ClassValue = string | Array<string> | null | undefined | Array<ClassValue>;
type ClassProp<V extends unknown = ClassValue>
= | {
class: V;
className?: never;
}
| { class?: never; className: V }
| { class?: never; className?: never };
interface UVReturnType {
base?: string;
extend?: UVReturnType;
slots?: Record<string, string>;
variants?: Record<string, string>;
variantKeys?: Array<string>;
defaultVariants?: Record<string, string>;
compoundVariants?: Array<Record<string, string>>;
}