Zubra UI
Code for
GitHub

nav-bar

The bar across the top of a site: the brand, the main links, and actions such as Sign in. The current page's link is marked aria-current="page". When the bar is too narrow for the links (its own width, not the screen's), they fold behind a Menu button. links is [{ label, href, current? }].

Sign in

This one has no events: it shows what it's given.

Source: nav-bar.zb, and its registry item.

Install

Compiled (any project)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/nav-bar.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/nav-bar.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/nav-bar.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/nav-bar.json
One file, no dependencies (5.2 KB gzipped)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/nav-bar.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/nav-bar.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/nav-bar.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/element/nav-bar.json
.zb source (to edit it with Zubra)
npx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/nav-bar.jsonpnpm dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/nav-bar.jsonyarn dlx shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/nav-bar.jsonbunx --bun shadcn@latest add https://zubra-js.github.io/zubra-ui/r/src/nav-bar.json
No build: a script tag, straight from this site
HTML
<link rel="stylesheet" href="https://zubra-js.github.io/zubra-ui/themes/default.css">
<script type="module" src="https://zubra-js.github.io/zubra-ui/cdn/nav-bar.js"></script>

The compiled install writes src/components/zubra/nav-bar.js and the theme, and adds @zubra/runtime to your dependencies. The one-file install writes the same path as a plain custom element that needs nothing installed (or download it and load it with a <script type="module">); it's smaller on a page with one to three components, the shared runtime with more.

Usage

index.html
<nav-bar brand="Bakehouse" href="#home">
  <action-button slot="actions" variant="outline" href="#signin">Sign in</action-button>
</nav-bar>

<script type="module">
  import './components/zubra/nav-bar.js';
  import './components/zubra/action-button.js';

  const element = document.querySelector('nav-bar');
  element.links = [
    { label: 'Recipes', href: '#recipes', current: true },
    { label: 'Classes', href: '#classes' },
    { label: 'Shop', href: '#shop' },
    { label: 'About', href: '#about' },
  ];
</script>
Example.jsx
import './components/zubra/nav-bar.js';
import './components/zubra/action-button.js';

const links = [
  { label: 'Recipes', href: '#recipes', current: true },
  { label: 'Classes', href: '#classes' },
  { label: 'Shop', href: '#shop' },
  { label: 'About', href: '#about' },
];

export function NavBarExample() {
  return (
    <nav-bar brand="Bakehouse" href="#home" links={links}>
      <action-button slot="actions" variant="outline" href="#signin">Sign in</action-button>
    </nav-bar>
  );
}
Example.vue
<script setup>
import './components/zubra/nav-bar.js';
import './components/zubra/action-button.js';
const links = [
  { label: 'Recipes', href: '#recipes', current: true },
  { label: 'Classes', href: '#classes' },
  { label: 'Shop', href: '#shop' },
  { label: 'About', href: '#about' },
];
</script>

<template>
  <nav-bar brand="Bakehouse" href="#home" :links.prop="links">
    <action-button slot="actions" variant="outline" href="#signin">Sign in</action-button>
  </nav-bar>
</template>

<!-- vite.config.js: vue({ template: { compilerOptions: { isCustomElement: (tag) => tag.includes('-') } } }) -->
Example.svelte
<script>
  import './components/zubra/nav-bar.js';
  import './components/zubra/action-button.js';
  const links = [
    { label: 'Recipes', href: '#recipes', current: true },
    { label: 'Classes', href: '#classes' },
    { label: 'Shop', href: '#shop' },
    { label: 'About', href: '#about' },
  ];
</script>

<nav-bar brand="Bakehouse" href="#home" {links}>
  <action-button slot="actions" variant="outline" href="#signin">Sign in</action-button>
</nav-bar>
example.component.ts
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import './components/zubra/nav-bar.js';
import './components/zubra/action-button.js';

@Component({
  selector: 'app-nav-bar-example',
  schemas: [CUSTOM_ELEMENTS_SCHEMA],
  template: `
    <nav-bar brand="Bakehouse" href="#home" [links]="links">
      <action-button slot="actions" variant="outline" href="#signin">Sign in</action-button>
    </nav-bar>
  `,
})
export class NavBarExample {
  links = [
    { label: 'Recipes', href: '#recipes', current: true },
    { label: 'Classes', href: '#classes' },
    { label: 'Shop', href: '#shop' },
    { label: 'About', href: '#about' },
  ];
}

API

Properties (each is also an HTML attribute of the same name, unless marked)
PropertyTypeDefault
brandstring""
hrefstring"/"
labelstring"Main"
Slots
SlotFor
actionsButtons or links at the end.
brandThe logo or name (defaults to brand, linked to href).

Size

1.4 KB gzipped for the component, plus the runtime, which every Zubra component on a page shares (up to 22.1 KB, all of it). On its own, with the parts of the runtime it uses, it's 18.2 KB.

Theme

Every component reads shadcn/ui's CSS variables, so any shadcn theme works. Pick a look or a colour, or paste a theme's CSS.

Look: colours, fonts, corners and motion

Accent colour