Skip to content
npm ↗ GitHub ↗

Documentation

02/Structure

Navbar

Fixed bar with logo, menu with submenus (hover and click), search, theme toggle and call to action.

Full

Submenus use the same component as the dropdown. With data-cb-dropdown-hover they also open on mouse hover on devices that support it.

HTML
<header class="cb-nav static">
  <div class="cb-nav__inner">
    <a href="#" class="cb-logo"><span class="cb-logo__mark" aria-hidden="true">A</span>Acme</a>
    <nav aria-label="Principal">
      <ul class="cb-nav__menu">
        <li class="cb-nav__item"><a class="cb-nav__link" href="#" aria-current="page">Inicio</a></li>
        <li class="cb-nav__item cb-dropdown" data-cb-dropdown data-cb-dropdown-hover>
          <button class="cb-nav__link" type="button" data-cb-dropdown-trigger>Productos <svg class="cb-nav__chevron" viewBox="0 0 10 10" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M2 3.5 5 6.5 8 3.5"/></svg></button>
          <div class="cb-dropdown__panel cb-dropdown__panel--wide">
            <a class="cb-dropdown__item cb-dropdown__item--rich" href="#"><span class="cb-dropdown__num">01</span><span><strong class="cb-dropdown__title">Facturación</strong><span class="cb-dropdown__desc">Emite y controla tus documentos.</span></span></a>
            <a class="cb-dropdown__item cb-dropdown__item--rich" href="#"><span class="cb-dropdown__num">02</span><span><strong class="cb-dropdown__title">Inventario</strong><span class="cb-dropdown__desc">Existencias en tiempo real.</span></span></a>
          </div>
        </li>
        <li class="cb-nav__item"><a class="cb-nav__link" href="#">Precios</a></li>
      </ul>
    </nav>
    <div class="cb-nav__actions">
      <button class="cb-search-btn" type="button" aria-label="Buscar"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="11" cy="11" r="7"/><path d="m20 20-3.5-3.5"/></svg><span class="cb-search-btn__text">Buscar</span><kbd data-cb-kbd-mod="K">⌘K</kbd></button>
      <button class="cb-icon-btn" type="button" data-cb-theme-toggle aria-label="Cambiar tema"><svg class="cb-theme-toggle__moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><path d="M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z"/></svg><svg class="cb-theme-toggle__sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true"><circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/></svg></button>
      <a href="#" class="cb-btn cb-btn--primary cb-nav__collapse-sm">Empezar ↗</a>
    </div>
  </div>
</header>

Classes and modifiers

ClassDescription
.cb-navFixed top bar with a translucent background and blur.
.cb-nav__innerRow with the container's maximum width and 64px height.
.cb-logo, .cb-logo__markLogo with a square mark in the accent color.
.cb-nav__menuList of links. Hidden below 960px.
.cb-nav__item, .cb-nav__linkMenu item and its link or button. aria-current="page" marks it as active.
.cb-nav__chevronArrow that rotates when the submenu is open.
.cb-nav__actionsGroup of actions aligned to the right.
.cb-nav__collapseHidden below 960px.
.cb-nav__collapse-smHidden below 600px.
.cb-nav__burgerMobile menu button, visible only below 960px.
.cb-search-btnSearch button with a keyboard shortcut.
.cb-theme-toggle__sun, .cb-theme-toggle__moonIcons that swap automatically depending on the mode.

data-cb-* attributes

AttributeDescription
data-cb-dropdownTurns the li into a submenu.
data-cb-dropdown-hoverOpens the submenu on hover on devices with a mouse.
data-cb-theme-toggleSwitches between light and dark and saves the choice.
data-cb-kbd-mod="K"Shows ⌘K on Mac and Ctrl K elsewhere.

JavaScript

EventWhen it fires
cb:open / cb:closeOn the submenu's li when it opens or closes.
cb:themeOn document when the mode changes. detail.theme and detail.resolved.

Accessibility

  • Submenus are buttons with aria-expanded and aria-controls; Esc closes them and returns focus.
  • Down arrow on the button opens the submenu and focuses the first link.
  • The theme button needs an aria-label; icons use aria-hidden.