@nibcss/react
Every export of the React bindings: NibProvider, useNib, nib, useNibRuntime, NibStyles and collectNibStyles.
Exports#
Export | Signature | What it is |
|---|---|---|
|
| starts (or adopts) the page's runtime and provides it |
|
| a class string, memoised per render |
|
| the non-hook variant, for handlers and helpers |
|
| the runtime itself |
|
| the collected CSS as a |
|
| the same CSS as a string |
| class | re-exported, for a deliberately separate instance |
nib and data-nib are declared on React's HTMLAttributes, so <div nib="…"> type-checks with
no extra setup.
NibProvider#
// with a config — the documented path
<NibProvider {...nibConfig}>
<App />
</NibProvider>
// with a runtime you own — SSR, tests, a scoped widget
<NibProvider runtime={rt}>
<App />
</NibProvider>useNib#
const box = useNib(`p=${pad}px; bdrd=$radius.md; bgc=$color.surface`);
return <div className={box}>…</div>;The class is generated during render, so the element is styled on its first paint — no one-frame delay, nothing to clean up. Memoised on the attribute string, so an unchanged value costs nothing.
nib() outside a component#
import { nib } from "@nibcss/react";
function highlight(runtime: NibRuntime, level: "warn" | "error") {
return nib(runtime, level === "error" ? "cl=#b91c1c; ftw=700" : "cl=#b45309");
}SSR#
const rt = new NibRuntime({ watch: false, ...config });
const body = renderToString(<NibProvider runtime={rt}><App /></NibProvider>);
const head = `<style id="nib">${collectNibStyles(rt)}</style>`;