Component styling engine
useUI
useUI is the internal styling engine that every Vueless component uses to turn its configuration into per-element class and attribute bindings. You'll reach for it when building your own components or copies of existing ones.
It merges a component's configuration from four layers, in ascending priority:
The component's
defaultConfig.The global config from
vueless.config.{js,ts}(vuelessConfig.components[componentName]).The instance's
:config="{ ... }"prop.The element's
class="..."attribute.
It resolves CVA-style configs into class strings based on props and variants, applies dynamic color theming, handles the {>key} "extends" and {ComponentName} nested-component patterns, and exposes a reactive attribute object per config key.
<script setup>
import { useUI } from "vueless";
import defaultConfig from "./config.ts";
const props = defineProps(["color", "size", "config", "dataTest"]);
const { config, getDataTest, wrapperAttrs, buttonAttrs } = useUI(defaultConfig);
</script>
<template>
<div v-bind="wrapperAttrs">
<button v-bind="buttonAttrs" :data-test="getDataTest('submit')">
<slot />
</button>
</div>
</template>Signature:
defaultConfig— the component's default config object, keyed by element name (each value is a class string, a CVA object, or a nested-component config). The first key is treated as the top-level element unless overridden.mutatedProps— optional ref/getter of computed prop overrides (e.g. a derivedcolor) folded into CVA resolution.topLevelClassKey— optional key that should receive the rootclassand passthrough attrs; defaults to the first key ofdefaultConfig.
Returns:
config
Ref<ComponentConfigFull>
The fully merged, reactive config for the component.
getDataTest
(suffix?: string) => string | null
Builds a data-test value from the component's dataTest prop; null when none is set.
…{key}Attrs
Ref<KeyAttrs>
One reactive attrs object per config key (e.g. wrapperAttrs, buttonAttrs), with the computed class, nested config, and merged default attrs. Spread onto elements with v-bind.
Last updated