Building with @n5i/ui
@n5i/ui is a Nuxt layer for app UIs. It is the same layer the dashboard is built on, so app UIs built with it look and behave like the rest of the dashboard. It provides:
- Nuxt UI 4 with Tailwind CSS 4 and
@tailwindcss/typography. Don't install Nuxt UI separately. - n5i's design tokens, as CSS variables and Tailwind colours.
- An
app.configpreset with n5i's colours and component styles. useHost(), which connects to the dashboard with the app bridge and applies its theme, colour mode and language automatically.- Components for common page elements.
Setup
If you don't have a Nuxt app yet, create one:
pnpm create nuxt my-app-uinpm create nuxt@latest my-app-uiyarn create nuxt my-app-uibun create nuxt my-app-uiThen install the layer:
pnpm add @n5i/uinpm install @n5i/uiyarn add @n5i/uibun add @n5i/uiExtend it in nuxt.config.ts. App UIs run in the browser only, so turn off server-side rendering:
// nuxt.config.ts
export default defineNuxtConfig({
extends: ["@n5i/ui"],
ssr: false,
});Tell the dashboard who you are:
// app/app.config.ts
export default defineAppConfig({
n5iUi: {
host: { app: { name: "My app", version: "1.0.0" } },
},
});The package's source is in the n5i dashboard repository under packages/ui.
Options
n5iUi.host in app.config.ts:
| Option | Default | Description |
|---|---|---|
enabled | true | Connect to the dashboard when running in an iframe. |
theme | true | Apply the dashboard's theme tokens and colour mode. |
locale | true | Follow the dashboard's language. Needs @nuxtjs/i18n with that locale. |
syncPath | true | Report client-side navigation to the dashboard. |
app | {} | name and version sent in the handshake. |
Your own Tailwind entry
The layer adds its own Tailwind CSS entry. To add Tailwind plugins or directives, turn it off and import the layer's CSS from your own entry:
// nuxt.config.ts
export default defineNuxtConfig({
extends: ["@n5i/ui"],
ssr: false,
n5iUi: { css: false },
css: ["~/assets/css/main.css"],
});/* app/assets/css/main.css */
@import "@n5i/ui/css/main.css";
@plugin "@tailwindcss/forms";In the dashboard
When the app loads, the layer sends hello to the dashboard right away, then applies the dashboard's tokens, colour mode, high contrast setting and locale, and reports client-side navigation with syncPath. You don't need to write any code for this.
The dashboard shows the app as a page (full width, transparent background), so build pages with a page header and cards, not a full-screen card.
Outside the dashboard (for example when you open the app's domain directly), the bridge stays inactive and the app uses its own theme.
useHost()
useHost() gives access to the dashboard. It is client-only.
const host = useHost();
// Waits for the handshake; cached until shortly before it expires
const jwt = await host.getJwt();
const peers = await $fetch("/api/peers", {
headers: { Authorization: `Bearer ${jwt}` },
});
host.breadcrumb([{ label: "Peers" }]);
host.toast({ title: "Peer added", color: "success" });| Member | Description |
|---|---|
state | Reactive state: protocol, capabilities, contentOnly, locale, colorMode, theme, host, ... |
ready | Promise that resolves after the handshake. |
embedded, contentOnly | Computed booleans. |
has(capability) | Whether the dashboard supports a capability. |
getJwt(), requestSession() | Credentials for the app's API. Both wait for the handshake. |
syncPath(), navigate(), breadcrumb(), toast(), openHostPage() | See the client methods. |
bridge | The underlying app bridge client. |
Design tokens
All colours derive from two palettes: brand (the primary colour, --color-brand-50 to --color-brand-950) and Nuxt UI's neutral. On top of them, the layer defines semantic --nv-* tokens, which are also available as Tailwind colours:
| Purpose | Tailwind classes (examples) | Tokens |
|---|---|---|
| Surfaces | bg-surface, bg-surface-raised, bg-surface-sunken | --nv-bg, --nv-surface, --nv-surface-hover, --nv-surface-raised, --nv-surface-sunken, --nv-sidebar |
| Text | text-ink, text-ink-muted, text-ink-toned | --nv-ink, --nv-ink-muted, --nv-ink-toned |
| Borders | border-border | --nv-border, --nv-border-control |
| Primary | bg-primary-soft, text-primary-soft-ink | --nv-primary, --nv-primary-hover, --nv-on-primary, --nv-primary-soft, --nv-primary-soft-ink |
| Status | bg-success-soft, text-success-ink | --nv-{success,warning,danger,info}-{ink,soft,dot} |
Use these instead of fixed colours, so your UI follows the dashboard's theme, dark mode and high contrast mode. For high contrast, the layer sets the .high-contrast class on <body> and provides a contrast: Tailwind variant.
To change the look of the layer itself, for example in a distribution's theme, extend @n5i/ui and override --color-brand-* and any --nv-* token in CSS (in :root and .dark) and ui.colors in app.config. App UIs in the dashboard receive the dashboard's resolved token values at runtime.
Components
| Component | Props | Slots |
|---|---|---|
NPageHeader | title, description | title, description, actions |
NStatusBadge | status (success, warning, danger, info, neutral), label | default |
NCopyField | value, label, monospace; emits copied | |
NEmptyState | title, description, icon | title, description, actions |
NConfirmDialog | title, description, confirmLabel, cancelLabel, danger, loading, v-model:open; emits confirm, cancel | default |
All Nuxt UI components (UButton, UCard, UTable, ...) are available as well.
Strings
The components' built-in strings are available in English, German and French. They use the app's @nuxtjs/i18n locale if there is one. To change a string, define the message n5iUi.<key> in your app's translations.