@nibcss/vue
Every export of the Vue bindings: the Nib plugin, v-nib, $nib, useNib, useNibRuntime and SSR collection.
Exports#
Export | Signature | What it is |
|---|---|---|
|
| the plugin: one runtime, the directive, the provide |
|
| a reactive class string |
|
| the runtime provided by the plugin |
|
| the directive — applies classes straight to the element |
|
| a class string inside a template, no setup needed |
| the collected CSS, for a custom SSR setup | |
| class | re-exported, for a deliberately separate instance |
$nib is declared on ComponentCustomProperties, so it type-checks in a template with no extra
setup.
The plugin#
app.use(Nib, nibConfig); // config
app.use(Nib, { runtime: existing }); // or a runtime you own (SSR, tests)useNib takes three shapes#
const a = useNib("p=16px"); // a constant
const b = useNib(attrRef); // a ref
const c = useNib(() => `p=${pad.value}px; bgc=$color.surface`); // a getterThe directive vs the composable#
<!-- v-nib: applies classes to this element, re-applied when the value changes -->
<div v-nib="`p=${pad}px`">…</div>
<!-- useNib: a string you can pass anywhere, including into a child component -->
<Child :class="box" />SSR#
const rt = new NibRuntime({ watch: false, ...config });
const app = createSSRApp(App).use(Nib, { runtime: rt });
const body = await renderToString(app);
const head = `<style id="nib">${collectNibStyles(rt)}</style>`;