API Reference

Here's the API reference for the unocss-variants exported types and functions.

uv

import { 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>>

Options

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>;
}

extend

description: 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.

base

description: This property allows you to define the base styles for the component.

type: ClassValue

default: undefined

slots

description: 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.

variants

description: 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.

defaultVariants

description: 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.

compoundVariants

description: 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.

compoundSlots

description: 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.

Types

ClassValue

type ClassValue = string | Array<string> | null | undefined | Array<ClassValue>;

ClassProp

type ClassProp<V extends unknown = ClassValue>
  = | {
    class: V;
    className?: never;
  }
  | { class?: never; className: V }
  | { class?: never; className?: never };

UVReturnType

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>>;
}