Navbars JS behaviour

Dock navbar

The macOS-style dock at the bottom of the stage: items magnify on a gaussian curve as the mouse approaches and nudge their neighbours, a tooltip rises above, the dot indicator parks under the active item, and a click changes destination.

Documentation

Real scenarios

The component as it is used in a product — not a specimen grid.

Sweep the pointer across the dock

Tiles magnify on a gaussian curve — the one under the cursor peaking at 1.55×, neighbours swelling politely — the tooltip rises above hover and focus, and the dot parks under the running app. Click to switch; the heading follows.

Follow-the-sun operations across every region you ship to.

Deploys this week218
p95 latency214ms
Error budget left87%
Rollout eu-de-2 finished4 min ago
Latency spike in ap-se-1 resolved22 min ago
Priya rotated on-call for Toronto1 h ago

The scale, pinned

Idle, the polite neighbour at 1.3× and the tile under the cursor at 1.55× — the running app keeps its sky gradient and dot.

var(--dkn-s) = 1
var(--dkn-s) = 1.3
var(--dkn-s) = 1.55

Important props

Important props
Prop Type Default What it does
magnification scale '1 → 1.55×' The peak magnification under the cursor; it decays exponentially with distance.
spread px '64' The gaussian radius; near neighbours swell a little too.
tooltip placement 'above · hover & focus' The label rises above the item on hover and keyboard focus.
indicator string 'dot' The small dot under the running item — the host dock convention.
badge dot|count 'count' The corner counter on the inbox item; unread count.

Snippet

{{-- resources/views/components/dock-navbar.blade.php — the macOS-style dock --}}
<div class="dkn" x-data="{
    active: 'overview',
    move(e) {
        this.$refs.dock.querySelectorAll('.dkn-item').forEach(el => {
            const r = el.getBoundingClientRect();
            const d = Math.abs(e.clientX - (r.left + r.width / 2));
            const s = 1 + .55 * Math.exp(-.5 * (d / 64) ** 2);
            el.style.setProperty('--dkn-s', s.toFixed(3));
        });
    },
    reset() {
        this.$refs.dock.querySelectorAll('.dkn-item').forEach(el => el.style.setProperty('--dkn-s', 1));
    },
}">
    <nav class="dkn-bar" x-ref="dock" aria-label="App navigation"
         x-on:pointermove="move($event)" x-on:pointerleave="reset()">
        <button type="button" class="dkn-item" data-tip="Overview" x-bind:data-active="active === 'overview'"
                x-on:click="active = 'overview'"><span class="dkn-box"><svg>…</svg></span></button>
        <button type="button" class="dkn-item" data-tip="Analytics" x-bind:data-active="active === 'analytics'"
                x-on:click="active = 'analytics'"><span class="dkn-box"><svg>…</svg></span></button>
        <button type="button" class="dkn-item" data-tip="Inbox, 3 unread" x-bind:data-active="active === 'inbox'"
                x-on:click="active = 'inbox'">
            <span class="dkn-box"><svg>…</svg><i class="dkn-badge">3</i></span>
        </button>
    </nav>
</div>

<style>
.dkn-bar { position: absolute; inset-block-end: .8rem; inset-inline: 0; z-index: 6;
           display: flex; justify-content: center; align-items: flex-end; gap: .5rem; }
.dkn-item { position: relative; border: 0; background: none; padding: 0; cursor: pointer; }
.dkn-box { display: grid; place-items: center; inline-size: calc(2.5rem * var(--dkn-s, 1));
           block-size: calc(2.5rem * var(--dkn-s, 1)); border-radius: .65rem;
           background: linear-gradient(160deg, #6366f1, #8b5cf6); color: #fff;
           transition: inline-size .12s ease-out, block-size .12s ease-out; }
.dkn-item::before { content: attr(data-tip); position: absolute; inset-block-end: calc(100% + .45rem);
           left: 50%; translate: -50% 0; padding: .3rem .55rem; border-radius: .45rem;
           background: #0f172a; color: #fff; font-size: .7rem; white-space: nowrap;
           opacity: 0; visibility: hidden; transition: opacity .15s, inset-block-end .15s; }
.dkn-item:hover::before, .dkn-item:focus-visible::before { opacity: 1; visibility: visible; inset-block-end: calc(100% + .6rem); }
.dkn-item::after { content: ''; position: absolute; inset-block-end: -.5rem; left: 50%; translate: -50% 0;
           inline-size: .3rem; block-size: .3rem; border-radius: 50%; background: currentColor;
           opacity: 0; }
.dkn-item[data-active='true']::after { opacity: 1; }
</style>
// app/Pages/Console.jsx — Inertia (React) page; renders the React
// snippet below unchanged, with Inertia's Link wired into the provider.
import { Link } from '@inertiajs/react';
import { NabuXUIProvider } from '@nabuxai/ui-react';
import DockNavbar from '@/components/DockNavbar';

export default function Console() {
  return (
    <NabuXUIProvider locale="en" linkComponent={Link}>
      <DockNavbar />
    </NabuXUIProvider>
  );
}
// DockNavbar.jsx — gaussian magnification, tooltips and the active dot
import { useRef, useState } from 'react';
import '@nabuxai/ui-core/css';

const ITEMS = [
  { id: 'overview', label: 'Overview', glyph: '⌂' },
  { id: 'analytics', label: 'Analytics', glyph: '▤' },
  { id: 'team', label: 'Team', glyph: '☺' },
  { id: 'inbox', label: 'Inbox · 3 unread', glyph: '✉' },
  { id: 'settings', label: 'Settings', glyph: '⚙' },
];

export default function DockNavbar() {
  const [active, setActive] = useState('overview');
  const itemRefs = useRef({});
  const [scales, setScales] = useState({});

  // Gaussian falloff from the cursor — the closer, the bigger.
  const move = (e) => {
    const next = {};
    for (const it of ITEMS) {
      const el = itemRefs.current[it.id];
      if (!el) continue;
      const r = el.getBoundingClientRect();
      const d = Math.abs(e.clientX - (r.left + r.width / 2));
      next[it.id] = 1 + 0.55 * Math.exp(-0.5 * (d / 64) ** 2);
    }
    setScales(next);
  };
  const reset = () => setScales({});

  return (
    <>
      <style>{`
        .dkn-bar { position: absolute; inset-block-end: .8rem; inset-inline: 0; z-index: 6;
                   display: flex; justify-content: center; align-items: flex-end; gap: .5rem;
                   font: 500 14px/1 Inter, sans-serif; }
        .dkn-item { position: relative; border: 0; background: none; padding: 0; cursor: pointer; color: #334155; }
        .dkn-box { display: grid; place-items: center; inline-size: calc(2.5rem * var(--dkn-s, 1));
                   block-size: calc(2.5rem * var(--dkn-s, 1)); border-radius: .65rem; color: #fff;
                   background: linear-gradient(160deg, #6366f1, #8b5cf6);
                   transition: inline-size .12s ease-out, block-size .12s ease-out; }
        .dkn-item[data-active='true'] .dkn-box { background: linear-gradient(160deg, #0ea5e9, #6366f1); }
        .dkn-item::before { content: attr(data-tip); position: absolute; inset-block-end: calc(100% + .45rem);
                   left: 50%; translate: -50% 0; padding: .3rem .55rem; border-radius: .45rem;
                   background: #0f172a; color: #fff; font-size: .7rem; white-space: nowrap;
                   opacity: 0; visibility: hidden; transition: opacity .15s, inset-block-end .15s; }
        .dkn-item:hover::before, .dkn-item:focus-visible::before { opacity: 1; visibility: visible; }
        .dkn-item::after { content: ''; position: absolute; inset-block-end: -.5rem; left: 50%;
                   translate: -50% 0; inline-size: .3rem; block-size: .3rem; border-radius: 50%;
                   background: currentColor; opacity: 0; }
        .dkn-item[data-active='true']::after { opacity: 1; }
      `}</style>
      <nav className="dkn-bar" aria-label="App navigation" onPointerMove={move} onPointerLeave={reset}>
        {ITEMS.map((it) => (
          <button key={it.id} type="button" className="dkn-item" data-tip={it.label}
                  data-active={active === it.id} aria-pressed={active === it.id}
                  ref={(el) => { itemRefs.current[it.id] = el; }}
                  style={{ '--dkn-s': scales[it.id] ?? 1 }}
                  onClick={() => setActive(it.id)}>
            <span className="dkn-box" aria-hidden="true">{it.glyph}</span>
            <span className="dkn-sr">{it.label}</span>
          </button>
        ))}
      </nav>
    </>
  );
}
<!-- DockNavbar.vue — gaussian magnification, tooltips and the active dot -->
<script setup lang="ts">
import { ref } from 'vue';
import '@nabuxai/ui-core/css';

const ITEMS = [
  { id: 'overview', label: 'Overview', glyph: '⌂' },
  { id: 'analytics', label: 'Analytics', glyph: '▤' },
  { id: 'team', label: 'Team', glyph: '☺' },
  { id: 'inbox', label: 'Inbox · 3 unread', glyph: '✉' },
  { id: 'settings', label: 'Settings', glyph: '⚙' },
];
const active = ref('overview');
const itemEls = ref<Record<string, HTMLElement>>({});
const scales = ref<Record<string, number>>({});

// Gaussian falloff from the cursor — the closer, the bigger.
function move(e: PointerEvent) {
  const next: Record<string, number> = {};
  for (const it of ITEMS) {
    const el = itemEls.value[it.id];
    if (!el) continue;
    const r = el.getBoundingClientRect();
    const d = Math.abs(e.clientX - (r.left + r.width / 2));
    next[it.id] = 1 + 0.55 * Math.exp(-0.5 * (d / 64) ** 2);
  }
  scales.value = next;
}
function reset() { scales.value = {}; }
</script>

<template>
  <nav class="dkn-bar" aria-label="App navigation" @pointermove="move" @pointerleave="reset">
    <button v-for="it in ITEMS" :key="it.id" type="button" class="dkn-item" :data-tip="it.label"
            :data-active="active === it.id" :aria-pressed="active === it.id"
            :ref="(el: any) => { if (el) itemEls[it.id] = el }"
            :style="{ '--dkn-s': scales[it.id] ?? 1 }"
            @click="active = it.id">
      <span class="dkn-box" aria-hidden="true">{{ it.glyph }}</span>
      <span class="dkn-sr">{{ it.label }}</span>
    </button>
  </nav>
</template>

<style scoped>
.dkn-bar { position: absolute; inset-block-end: .8rem; inset-inline: 0; z-index: 6;
           display: flex; justify-content: center; align-items: flex-end; gap: .5rem;
           font: 500 14px/1 Inter, sans-serif; }
.dkn-item { position: relative; border: 0; background: none; padding: 0; cursor: pointer; color: #334155; }
.dkn-box { display: grid; place-items: center; inline-size: calc(2.5rem * var(--dkn-s, 1));
           block-size: calc(2.5rem * var(--dkn-s, 1)); border-radius: .65rem; color: #fff;
           background: linear-gradient(160deg, #6366f1, #8b5cf6);
           transition: inline-size .12s ease-out, block-size .12s ease-out; }
.dkn-item[data-active='true'] .dkn-box { background: linear-gradient(160deg, #0ea5e9, #6366f1); }
.dkn-item::before { content: attr(data-tip); position: absolute; inset-block-end: calc(100% + .45rem);
           left: 50%; translate: -50% 0; padding: .3rem .55rem; border-radius: .45rem;
           background: #0f172a; color: #fff; font-size: .7rem; white-space: nowrap;
           opacity: 0; visibility: hidden; transition: opacity .15s, inset-block-end .15s; }
.dkn-item:hover::before, .dkn-item:focus-visible::before { opacity: 1; visibility: visible; }
.dkn-item::after { content: ''; position: absolute; inset-block-end: -.5rem; left: 50%;
           translate: -50% 0; inline-size: .3rem; block-size: .3rem; border-radius: 50%;
           background: currentColor; opacity: 0; }
.dkn-item[data-active='true']::after { opacity: 1; }
</style>
<!-- DockNavbar.svelte — gaussian magnification, tooltips and the active dot -->
<script lang="ts">
  import '@nabuxai/ui-core/css';

  const ITEMS = [
    { id: 'overview', label: 'Overview', glyph: '⌂' },
    { id: 'analytics', label: 'Analytics', glyph: '▤' },
    { id: 'team', label: 'Team', glyph: '☺' },
    { id: 'inbox', label: 'Inbox · 3 unread', glyph: '✉' },
    { id: 'settings', label: 'Settings', glyph: '⚙' },
  ];
  let active = $state('overview');
  let itemEls = $state<Record<string, HTMLElement>>({});
  let scales = $state<Record<string, number>>({});

  // Gaussian falloff from the cursor — the closer, the bigger.
  function move(e: PointerEvent) {
    const next: Record<string, number> = {};
    for (const it of ITEMS) {
      const el = itemEls[it.id];
      if (!el) continue;
      const r = el.getBoundingClientRect();
      const d = Math.abs(e.clientX - (r.left + r.width / 2));
      next[it.id] = 1 + 0.55 * Math.exp(-0.5 * (d / 64) ** 2);
    }
    scales = next;
  }
  function reset() { scales = {}; }
</script>

<nav class="dkn-bar" aria-label="App navigation" onpointermove={move} onpointerleave={reset}>
  {#each ITEMS as it (it.id)}
    <button type="button" class="dkn-item" data-tip={it.label}
            data-active={active === it.id} aria-pressed={active === it.id}
            bind:this={itemEls[it.id]}
            style={`--dkn-s: ${scales[it.id] ?? 1}`}
            onclick={() => (active = it.id)}>
      <span class="dkn-box" aria-hidden="true">{it.glyph}</span>
      <span class="dkn-sr">{it.label}</span>
    </button>
  {/each}
</nav>

<style>
.dkn-bar { position: absolute; inset-block-end: .8rem; inset-inline: 0; z-index: 6;
           display: flex; justify-content: center; align-items: flex-end; gap: .5rem;
           font: 500 14px/1 Inter, sans-serif; }
.dkn-item { position: relative; border: 0; background: none; padding: 0; cursor: pointer; color: #334155; }
.dkn-box { display: grid; place-items: center; inline-size: calc(2.5rem * var(--dkn-s, 1));
           block-size: calc(2.5rem * var(--dkn-s, 1)); border-radius: .65rem; color: #fff;
           background: linear-gradient(160deg, #6366f1, #8b5cf6);
           transition: inline-size .12s ease-out, block-size .12s ease-out; }
.dkn-item[data-active='true'] .dkn-box { background: linear-gradient(160deg, #0ea5e9, #6366f1); }
.dkn-item::before { content: attr(data-tip); position: absolute; inset-block-end: calc(100% + .45rem);
           left: 50%; translate: -50% 0; padding: .3rem .55rem; border-radius: .45rem;
           background: #0f172a; color: #fff; font-size: .7rem; white-space: nowrap;
           opacity: 0; visibility: hidden; transition: opacity .15s, inset-block-end .15s; }
.dkn-item:hover::before, .dkn-item:focus-visible::before { opacity: 1; visibility: visible; }
.dkn-item::after { content: ''; position: absolute; inset-block-end: -.5rem; left: 50%;
           translate: -50% 0; inline-size: .3rem; block-size: .3rem; border-radius: 50%;
           background: currentColor; opacity: 0; }
.dkn-item[data-active='true']::after { opacity: 1; }
</style>