useVariant

Commons
stable

Resolves a component variant value into a BEM modifier class. Accepts either a props object implementing IVariantProps or a direct reactive ref to the variant string. Returns a single computed array of class strings for binding.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

Interfaces consommées

IVariantProps

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

props
requis
{ variant?: string } | Ref<string | undefined>
Either the component props object (reads `props.variant`) or a bare reactive ref / computed to the variant string. The composable detects which form is passed via `isRef`.
name
string
getCurrentInstanceName()
The BEM block prefix. Defaults to the current component name (e.g. `origam-btn`). The class produced will be `{name}--variant-{variant}`.

API

Valeurs de retour

Propriétés et méthodes exposées par l'objet retourné par le composable.

variantClasses
Array containing `{name}--variant-{variant}` when a variant is set, empty array otherwise. Bind to the component root via `:class`.

Usage

Exemples

Extraits de code prêts à coller.

Component with variant prop

vue

Passing a raw ref

vue