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
Full TypeScript signature sourced from the composable file.
Consumed interfaces
IVariantProps
API
Parameters
Input parameters accepted by this composable.
- propsrequired{ 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`.
- namestringgetCurrentInstanceName()
- The BEM block prefix. Defaults to the current component name (e.g. `origam-btn`). The class produced will be `{name}--variant-{variant}`.
API
Return values
Properties and methods exposed by the composable return object.
- variantClasses
- Array containing `{name}--variant-{variant}` when a variant is set, empty array otherwise. Bind to the component root via `:class`.
Usage
Examples
Ready-to-paste usage snippets.
Component with variant prop
Passing a raw ref