Ir al contenido
Español
Barra dock viene con Pro. La vista previa aparece al desbloquearlo.

Cómo funciona

Only transform changes, so the root keeps its size. Each icon scales by 1 + (magnify - 1) × a raised-cosine bell of its distance from the pointer, then shifts sideways so gaps stay equal and the row spreads symmetrically. Values are written by a requestAnimationFrame loop into CSS variables without React renders, and approach their targets with a 70ms time constant, so following and settling are continuous.

Úsalo para

  • Shortcut rows at the bottom of an internal workspace or dashboard: 5 to 8 frequent actions where icons are recognizable.
  • Floating toolbars in creative tools that benefit from a playful feel.
  • App or social link rows on portfolios and landing pages.

Busca otra opción cuando

  • Mobile: touch has no hover, so use a bottom tab bar.
  • More than 8 or 9 entries: the row grows noticeably wide, use a grouped sidebar.
  • Dense tables and forms: overflowing icons cover content above, use a plain icon button group.
  • No space above, or a parent with overflow: hidden and too little padding: the enlarged icons and labels get clipped.

Uso

import { useState } from 'react'
import { DockBar } from './DockBar.jsx'

export function Workspace() {
  const [page, setPage] = useState('orders')
  const entry = (key, label, icon) => ({
    key,
    label,
    icon, // an SVG with stroke="currentColor" so the color follows the state
    active: page === key,
    onClick: () => setPage(key),
  })
  return (
    // Leave at least size * (magnify - 1) + 40px above for the enlarged icons and labels
    <div style={{ paddingTop: 72 }}>
      <DockBar
        aria-label="Shortcuts"
        magnify={1.6}
        range={120}
        size={44}
        items={[
          entry('orders', 'Orders', <OrderIcon />),
          entry('chats', 'Chats', <ChatIcon />),
          entry('customers', 'Customers', <UserIcon />),
          { key: 'docs', label: 'Help docs', icon: <BookIcon />, href: '/docs' },
        ]}
      />
    </div>
  )
}

Propiedades

PropiedadTipoPor defectoQué hace
items{ key, label, icon, onClick?, href?, active? }[]—The icons. label is both the hover label and the accessible name; href renders an <a>, otherwise a <button>; active shows a small dot underneath.
magnifynumber1.6Scale of the icon right under the pointer; 1 means no magnifying.
rangenumber120Influence radius in px: icons farther from the pointer are not enlarged. About 2.5 to 3 times the icon size works well.
sizenumber44Base icon size in px; the icon artwork takes half of it.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root, such as aria-label, className and style. Use --ds-dock-shadow to override the shelf shadow.

Accesibilidad

  • The root is role="toolbar" (pass an aria-label) and the row is one Tab stop: Left and Right move between icons with wrap-around, Home and End jump to the ends.
  • Each icon is a real <button> or <a> with an aria-label; the current one has aria-current; the visual name label is aria-hidden.
  • Keyboard focus (:focus-visible) magnifies the icon and its neighbours and shows the label and a focus ring; focus from a mouse click does not.
  • With reduced motion there is no magnifying or shifting (no animation loop, transform off in CSS), only the hover and focus highlight and the label.
  • Touch devices get a plain row of buttons with no magnifying; icons are 44×44 by default.

Movimiento

Scale and shift chase their targets with a 70ms time constant (about 200ms to settle); settling starts 80ms after the pointer leaves. The label enters in 160ms ease-out (fade and 4px up) and leaves in 100ms ease-in; pressing scales an icon to 0.86 in 100ms.

Añádelo a tu proyecto

Los miembros Pro copian un prompt y su agente de programación instala el código, igual que con los gratuitos.

DockBar.jsxdock-bar.csstokens.cssREADME.md

Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

Navegación