Skip to content

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.config preset 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:

sh
pnpm create nuxt my-app-ui
sh
npm create nuxt@latest my-app-ui
sh
yarn create nuxt my-app-ui
sh
bun create nuxt my-app-ui

Then install the layer:

sh
pnpm add @n5i/ui
sh
npm install @n5i/ui
sh
yarn add @n5i/ui
sh
bun add @n5i/ui

Extend it in nuxt.config.ts. App UIs run in the browser only, so turn off server-side rendering:

ts
// nuxt.config.ts
export default defineNuxtConfig({
  extends: ["@n5i/ui"],
  ssr: false,
});

Tell the dashboard who you are:

ts
// 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:

OptionDefaultDescription
enabledtrueConnect to the dashboard when running in an iframe.
themetrueApply the dashboard's theme tokens and colour mode.
localetrueFollow the dashboard's language. Needs @nuxtjs/i18n with that locale.
syncPathtrueReport 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:

ts
// nuxt.config.ts
export default defineNuxtConfig({
  extends: ["@n5i/ui"],
  ssr: false,
  n5iUi: { css: false },
  css: ["~/assets/css/main.css"],
});
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.

ts
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" });
MemberDescription
stateReactive state: protocol, capabilities, contentOnly, locale, colorMode, theme, host, ...
readyPromise that resolves after the handshake.
embedded, contentOnlyComputed 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.
bridgeThe 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:

PurposeTailwind classes (examples)Tokens
Surfacesbg-surface, bg-surface-raised, bg-surface-sunken--nv-bg, --nv-surface, --nv-surface-hover, --nv-surface-raised, --nv-surface-sunken, --nv-sidebar
Texttext-ink, text-ink-muted, text-ink-toned--nv-ink, --nv-ink-muted, --nv-ink-toned
Bordersborder-border--nv-border, --nv-border-control
Primarybg-primary-soft, text-primary-soft-ink--nv-primary, --nv-primary-hover, --nv-on-primary, --nv-primary-soft, --nv-primary-soft-ink
Statusbg-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 ​

ComponentPropsSlots
NPageHeadertitle, descriptiontitle, description, actions
NStatusBadgestatus (success, warning, danger, info, neutral), labeldefault
NCopyFieldvalue, label, monospace; emits copied
NEmptyStatetitle, description, icontitle, description, actions
NConfirmDialogtitle, description, confirmLabel, cancelLabel, danger, loading, v-model:open; emits confirm, canceldefault

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.

Free and open-source software under the GNU AGPL 3.0 or later.