{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"nav-list","type":"registry:ui","title":"Nav list","description":"A sidebar's list of destinations, with sections, the current page and locked rows that say why.","categories":["disclosure"],"dependencies":["motion"],"registryDependencies":["https://ui.teamofsilicons.com/r/silicon-motion-tokens.json","https://ui.teamofsilicons.com/r/badge.json"],"files":[{"path":"registry/components/nav-list/nav-list.tsx","type":"registry:component","target":"@components/silicon-ui/nav-list/nav-list.tsx","content":"\"use client\";\n\nimport { createContext, useCallback, useContext, useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from \"react\";\nimport type { MouseEvent, ReactNode, Ref } from \"react\";\nimport { FluidHoverHighlight, useFluidHover } from \"../lib/fluid-hover\";\nimport { MenuHighlight } from \"../lib/menu-highlight\";\nimport { SiliconLink } from \"../lib/silicon-provider\";\nimport { Badge } from \"../badge/badge\";\nimport styles from \"./nav-list.module.css\";\n\ntype Box = { top: number; height: number; danger: boolean; glide: boolean };\nconst ITEM = \"[data-nav-item]\";\nconst boxOf = (item: HTMLElement): Omit<Box, \"glide\"> => ({ top: item.offsetTop, height: item.offsetHeight, danger: false });\n\n/** What NavList's onNavigate receives: the chosen row's href, or none for an action row. */\nexport interface NavChoice { href?: string }\n\n/** Lets NavItem reach its list without prop drilling: the active marker's position, and reporting a choice. */\nconst NavContext = createContext<{ activeChanged: () => void; navigate: (choice: NavChoice) => void } | null>(null);\n\nexport interface NavListProps {\n  /** Names the navigation for screen readers, such as \"Main\" or \"Settings\". */\n  label: string;\n  /** NavItem and NavSection elements, in order. */\n  children: ReactNode;\n  /** Placement only (width, margins, grid area); the rows' look comes from the component. */\n  className?: string;\n  /** The `<nav>` element. */\n  ref?: Ref<HTMLElement>;\n  /**\n   * Called when any row is chosen (click, Enter or Space; link and action rows), before it navigates or acts. A notification,\n   * such as closing a phone sheet: it cannot cancel. Locked rows and modified clicks (a new tab or window) do not call it.\n   */\n  onNavigate?: (choice: NavChoice) => void;\n}\n\n/**\n * A sidebar's list of destinations: a `<nav>` with a list of NavItem rows, optionally grouped by NavSection. The row nearest\n * the pointer is lit (fluid hover), and the current page's marker glides when the page changes.\n */\nexport function NavList({ label, children, className, ref, onNavigate }: NavListProps) {\n  const root = useRef<HTMLElement | null>(null);\n  const [active, setActive] = useState<Box | null>(null);\n  // The row nearest the pointer is lit, gaps included, and a click in a gap follows the row (lib/fluid-hover).\n  const hover = useFluidHover(root, { items: ITEM });\n  // The latest handler, read at choice time, so a new function each render never changes the context.\n  const navigateHandler = useRef(onNavigate);\n  useEffect(() => { navigateHandler.current = onNavigate; });\n\n  const setRoot = useCallback((node: HTMLElement | null) => {\n    root.current = node;\n    if (typeof ref === \"function\") return ref(node);\n    if (ref) ref.current = node;\n  }, [ref]);\n\n  // The active marker follows the item with aria-current. It glides only when the page changes, never on first paint.\n  const measureActive = useCallback(() => {\n    const item = root.current?.querySelector<HTMLElement>(`${ITEM}[aria-current=\"page\"]`);\n    setActive(current => {\n      if (!item) return null;\n      const next = boxOf(item);\n      return current && current.top === next.top && current.height === next.height ? current : { ...next, glide: current !== null };\n    });\n  }, []);\n  useLayoutEffect(() => {\n    measureActive();\n    const node = root.current;\n    if (!node || typeof ResizeObserver === \"undefined\") return;\n    // A resize (a late font, a collapsing section) moves the marker at once; only a page change glides.\n    const observer = new ResizeObserver(() => {\n      const item = node.querySelector<HTMLElement>(`${ITEM}[aria-current=\"page\"]`);\n      setActive(current => {\n        if (!item) return null;\n        const next = boxOf(item);\n        return current && current.top === next.top && current.height === next.height ? current : { ...next, glide: false };\n      });\n    });\n    observer.observe(node);\n    return () => observer.disconnect();\n  }, [measureActive]);\n\n  const context = useMemo(() => ({ activeChanged: measureActive, navigate: (choice: NavChoice) => navigateHandler.current?.(choice) }), [measureActive]);\n  return (\n    <NavContext.Provider value={context}>\n      <nav ref={setRoot} aria-label={label} className={[styles.list, className].filter(Boolean).join(\" \")} {...hover.handlers}>\n        {/* The current page's marker paints over the hover fill, so hovering the current row never lightens it. */}\n        <FluidHoverHighlight hover={hover} className={styles.highlight} />\n        <MenuHighlight state={active} className={styles.active} />\n        <ul className={styles.items}>{children}</ul>\n      </nav>\n    </NavContext.Provider>\n  );\n}\n\nexport interface NavSectionProps {\n  /** The section's heading, such as \"Workspace\". */\n  label: string;\n  /** The section's NavItem rows. */\n  children: ReactNode;\n}\n\n/** A labelled group of NavItem rows inside a NavList. */\nexport function NavSection({ label, children }: NavSectionProps) {\n  const id = useId();\n  return (\n    <li className={styles.section}>\n      <div id={id} className={styles.sectionLabel}>{label}</div>\n      <ul className={styles.items} aria-labelledby={id}>{children}</ul>\n    </li>\n  );\n}\n\ninterface NavItemBase {\n  /** The row's label. */\n  children: ReactNode;\n  /** A 16px icon before the label. */\n  icon?: ReactNode;\n  /** The current page: sets aria-current=\"page\" and the active marker. */\n  active?: boolean;\n  /** Turns the row off. It stays focusable (aria-disabled) so keyboard users can reach it and hear why. */\n  disabled?: boolean;\n  /** Why the row is off, such as \"Pro\". Shown as a badge and read as the row's description. Only shown when disabled. */\n  reason?: string;\n  /** Content at the row's end, such as a count or an avatar. Hidden while a reason shows. */\n  trailing?: ReactNode;\n  /**\n   * Called each time the pointer enters the row or it receives focus, before it is chosen: start loading the destination\n   * (prefetch). It can fire more than once, so keep it idempotent. Not called while disabled.\n   */\n  onIntent?: () => void;\n  /** Placement only; the row's look comes from the component. */\n  className?: string;\n}\n\nexport type NavItemProps = NavItemBase & (\n  | { /** A destination, rendered with the SiliconProvider's link. */ href: string; onSelect?: never }\n  | { href?: never; /** An action, such as opening search. */ onSelect: () => void }\n);\n\n/** One row of a NavList: a link by `href`, or an action by `onSelect`. */\nexport function NavItem({ children, icon, active = false, disabled = false, reason, trailing, onIntent, className, href, onSelect }: NavItemProps) {\n  const nav = useContext(NavContext);\n  const reasonId = useId();\n  const showReason = disabled && reason;\n  useLayoutEffect(() => { nav?.activeChanged(); }, [active, nav]);\n\n  const content = <>\n    {icon ? <span className={styles.icon} aria-hidden=\"true\">{icon}</span> : null}\n    <span className={styles.label}>{children}</span>\n    {/* Hidden from the name and read once, as the description (aria-describedby reads hidden text). */}\n    {showReason ? <Badge id={reasonId} size=\"sm\" className={styles.reason} aria-hidden=\"true\">{reason}</Badge>\n      : trailing ? <span className={styles.trailing}>{trailing}</span> : null}\n  </>;\n  const shared = {\n    className: [styles.item, className].filter(Boolean).join(\" \"),\n    \"data-nav-item\": \"\",\n    \"aria-current\": active ? \"page\" as const : undefined,\n    \"aria-disabled\": disabled || undefined,\n    \"aria-describedby\": showReason ? reasonId : undefined,\n  };\n\n  if (disabled) {\n    // No href and no action: it can be focused and read, but not followed.\n    return <li><span {...shared} role={href ? \"link\" : \"button\"} tabIndex={0} onClick={(event: MouseEvent<HTMLElement>) => event.preventDefault()}>{content}</span></li>;\n  }\n  const intent = onIntent ? { onPointerEnter: onIntent, onFocus: onIntent } : {};\n  if (href !== undefined) {\n    // A modified click opens a new tab or window, so this page stays where it is: no choice to report.\n    const onClick = (event: MouseEvent<HTMLAnchorElement>) => { if (event.button === 0 && !event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) nav?.navigate({ href }); };\n    return <li><SiliconLink {...shared} {...intent} href={href} onClick={onClick}>{content}</SiliconLink></li>;\n  }\n  return <li><button {...shared} {...intent} type=\"button\" onClick={() => { nav?.navigate({}); onSelect?.(); }}>{content}</button></li>;\n}\n\nexport default NavList;\n"},{"path":"registry/components/nav-list/nav-list.module.css","type":"registry:component","target":"@components/silicon-ui/nav-list/nav-list.module.css","content":"/* The list is the positioning box for both markers, so rows measure their offsetTop against it. Place it on --background or\n   --surface; on a --surface-muted panel the hover fill has nothing to show against. */\n.list { position: relative; display: block; font-family: var(--font-body); letter-spacing: var(--tracking-body); }\n.items { display: grid; gap: var(--space-hair); margin: 0; padding: 0; list-style: none; }\n.section + .section, .items > li + .section { margin-top: var(--space-group); }\n.sectionLabel { padding: var(--space-tight) var(--space-related); color: var(--text-muted); font-size: var(--text-xs); font-weight: 500; line-height: var(--leading-body); }\n\n/* Two markers under the rows: the current page (stronger), and the pointer's hover, which glides between rows. */\n.active, .highlight { position: absolute; top: 0; right: 0; left: 0; border-radius: var(--radius-control); corner-shape: var(--corner-shape); pointer-events: none; }\n.active { background: var(--surface-pressed); }\n.highlight { background: var(--surface-muted); }\n\n.item { position: relative; display: flex; box-sizing: border-box; width: 100%; min-height: 2rem; align-items: center; gap: var(--space-related); margin: 0; padding: 0 var(--space-related); border: 0; border-radius: var(--radius-control); corner-shape: var(--corner-shape); background: transparent; color: var(--text-secondary); font: inherit; font-size: var(--text-sm); line-height: var(--leading-body); text-align: left; text-decoration: none; cursor: pointer; -webkit-tap-highlight-color: transparent; transition: color var(--duration-fast) var(--ease-standard); }\n.item:hover, .item:focus-visible, .item[aria-current=\"page\"] { color: var(--foreground); }\n.item[aria-current=\"page\"] { font-weight: 500; }\n.item[aria-disabled=\"true\"] { color: var(--text-muted); cursor: not-allowed; }\n.icon { display: inline-flex; flex: none; color: var(--text-secondary); }\n.icon svg { width: 16px; height: 16px; }\n.item[aria-current=\"page\"] .icon, .item:hover .icon { color: var(--foreground); }\n.item[aria-disabled=\"true\"] .icon { color: var(--text-muted); }\n.label { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n.trailing { display: inline-flex; flex: none; align-items: center; color: var(--text-muted); font-size: var(--text-xs); font-variant-numeric: tabular-nums; }\n.reason { flex: none; }\n\n@media (prefers-reduced-motion: reduce) { .item { transition: none; } }\n"},{"path":"lib/menu-highlight.tsx","type":"registry:lib","target":"@components/silicon-ui/lib/menu-highlight.tsx","content":"\"use client\";\n\nimport { useRef } from \"react\";\nimport type { FocusEvent, MouseEvent } from \"react\";\nimport { motion, useReducedMotion } from \"motion/react\";\nimport { FluidHoverHighlight, useFluidHover, type FluidRect } from \"./fluid-hover\";\nimport { motionTokens } from \"./motion-tokens\";\n\n/** A fluid hover highlight in a menu: where it sits, whether it travels, its pointer session, and its tone. */\ntype FluidHighlight = { rect: FluidRect | null; glide: boolean; session: number; danger: boolean };\n/** A marker positioned by top and height only (a list's current-page marker). */\ntype BarHighlight = { top: number; height: number; danger: boolean; glide: boolean };\n\nconst ITEMS = '[role=\"menuitem\"], [role=\"menuitemcheckbox\"], [role=\"menuitemradio\"], [role=\"option\"]';\n\n/**\n * Fluid hover for a Radix menu or listbox (lib/fluid-hover): the item nearest the pointer is lit, gaps and padding\n * included, a click in a gap picks the lit item, and the keyboard moves the highlight with Radix's focus, without travel.\n * Spread `contentProps` on the content, call `reset` when it opens, and render `<MenuHighlight state={highlight} … />`\n * as its first child. Items mark a destructive tone with `data-tone=\"danger\"`.\n */\nexport function useMenuHighlight(itemSelector = ITEMS) {\n  // The content element is taken from its own events, so the hook never competes with the content's ref.\n  const content = useRef<HTMLElement | null>(null);\n  const hover = useFluidHover(content, { items: itemSelector });\n  const own = (event: { currentTarget: EventTarget }) => { content.current = event.currentTarget as HTMLElement; };\n  const { handlers } = hover;\n  const highlight: FluidHighlight = { rect: hover.rect, glide: hover.glide, session: hover.session, danger: hover.item?.dataset.tone === \"danger\" };\n  return {\n    highlight,\n    reset: hover.reset,\n    contentProps: {\n      onMouseEnter: (event: MouseEvent<HTMLElement>) => { own(event); handlers.onMouseEnter(); },\n      onMouseMove: (event: MouseEvent<HTMLElement>) => { own(event); handlers.onMouseMove(event); },\n      onMouseLeave: handlers.onMouseLeave,\n      onKeyDownCapture: handlers.onKeyDownCapture,\n      onFocus: (event: FocusEvent<HTMLElement>) => { own(event); handlers.onFocus(event); },\n      onBlur: handlers.onBlur,\n      onClick: (event: MouseEvent<HTMLElement>) => { own(event); handlers.onClick(event); },\n    },\n  };\n}\n\n/** The highlight itself: the fluid hover highlight, or a marker that moves by top and height (a current-page marker). */\nexport function MenuHighlight({ state, className }: { state: FluidHighlight | BarHighlight | null; className?: string }) {\n  if (state && \"session\" in state) return <FluidHoverHighlight hover={state} className={className} tone={state.danger ? \"danger\" : undefined} />;\n  return <BarMarker state={state} className={className} />;\n}\n\nfunction BarMarker({ state, className }: { state: BarHighlight | null; className?: string }) {\n  const reduced = useReducedMotion();\n  return <motion.span className={className} data-tone={state?.danger ? \"danger\" : undefined} aria-hidden=\"true\" initial={false}\n    animate={state ? { y: state.top, height: state.height, opacity: 1 } : { opacity: 0 }}\n    transition={{ default: state?.glide && !reduced ? motionTokens.spring.fast : { duration: 0 }, opacity: { duration: reduced ? 0 : motionTokens.duration.fast } }} />;\n}\n"},{"path":"lib/fluid-hover.tsx","type":"registry:lib","target":"@components/silicon-ui/lib/fluid-hover.tsx","content":"\"use client\";\n\n/**\n * Fluid hover: in a set of items (a menu, a list, tabs, a grid), the item nearest the pointer is lit, even while the\n * pointer is in a gap, the padding or past the last item, and one highlight springs between items. A click in a gap goes\n * to the lit item, so what is lit is what a click hits. A new pointer entry fades the highlight in where it lands instead\n * of sliding it over from the last item. The keyboard moves it without travel, and reduced motion keeps the fade but\n * drops the travel.\n *\n *   const list = useRef<HTMLUListElement>(null);\n *   const hover = useFluidHover(list, { items: \"[data-item]\" });\n *   <ul ref={list} className={styles.list} {...hover.handlers}>      // .list { position: relative }\n *     <FluidHoverHighlight hover={hover} className={styles.highlight} />\n *     …items…\n *   </ul>\n *\n * Adapted from Fluid Functionalism's use-fluid-hover and fluid-hover-highlight by Micka Touillaud (MIT),\n * https://github.com/mickadesign/fluid-functionalism. Items are found by a selector instead of registering themselves,\n * so a component adopts it without changing its items.\n */\nimport { useEffect, useEffectEvent, useRef, useState } from \"react\";\nimport type { FocusEvent, MouseEvent, PointerEvent, RefObject } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"motion/react\";\nimport { motionTokens } from \"./motion-tokens\";\n\n/** An item's box in the container's own layout space (unaffected by transforms or scrolling). */\nexport interface FluidRect { top: number; left: number; width: number; height: number }\n\nexport interface FluidHoverState {\n  /** Where the highlight sits, or null when nothing is lit. */\n  rect: FluidRect | null;\n  /** The lit item. */\n  item: HTMLElement | null;\n  /** False when the highlight should jump (keyboard, a resize) rather than travel. */\n  glide: boolean;\n  /** Steps on each new pointer entry, so the highlight fades in where it lands. */\n  session: number;\n}\n\nexport interface FluidHoverOptions {\n  /** Selector for the items inside the container. */\n  items: string;\n  /** \"y\" for lists (default), \"x\" for a row of tabs, \"xy\" for grids. */\n  axis?: \"x\" | \"y\" | \"xy\";\n  /** Items the highlight skips (and a gap click never activates). Defaults to disabled or aria-disabled items. */\n  isItemDisabled?: (item: HTMLElement) => boolean;\n  /** \"skip\" (default) lights the nearest enabled item even over a disabled one; \"clear\" lights nothing over a disabled item (a calendar's unavailable days). */\n  disabled?: \"skip\" | \"clear\";\n  /** Route a click in a gap to the lit item. On by default; turn it off where empty space should stay inert. */\n  gapClick?: boolean;\n  /** Light the item that receives keyboard focus. On by default. */\n  followFocus?: boolean;\n}\n\nconst defaultDisabled = (item: HTMLElement) =>\n  item.matches(\":disabled, [aria-disabled='true'], [data-disabled]\");\n\n/** Controls that sit between items keep their own clicks. */\nconst CONTROL = \"input, textarea, select, button, a, summary, [contenteditable], [role='textbox'], [role='searchbox'], [role='button']\";\n\n/** The item's box relative to the container, summing offsets through positioned ancestors in between. */\nexport function rectOf(item: HTMLElement, container: HTMLElement): FluidRect {\n  let top = item.offsetTop, left = item.offsetLeft;\n  let parent = item.offsetParent as HTMLElement | null;\n  while (parent && parent !== container && container.contains(parent)) {\n    top += parent.offsetTop + parent.clientTop;\n    left += parent.offsetLeft + parent.clientLeft;\n    parent = parent.offsetParent as HTMLElement | null;\n  }\n  return { top, left, width: item.offsetWidth, height: item.offsetHeight };\n}\n\n/**\n * The item the pointer is inside, or else the one whose edge is nearest along the axis (both axes for a grid). Edges, not\n * centres, so a gap next to a wide item still lights the item the pointer is closer to.\n */\nexport function pickNearest(items: HTMLElement[], x: number, y: number, axis: \"x\" | \"y\" | \"xy\"): HTMLElement | null {\n  let nearest: HTMLElement | null = null, best = Infinity;\n  for (const item of items) {\n    const r = item.getBoundingClientRect();\n    if (!r.width && !r.height) continue;\n    if (x >= r.left && x <= r.right && y >= r.top && y <= r.bottom) return item;\n    const dx = Math.max(r.left - x, 0, x - r.right), dy = Math.max(r.top - y, 0, y - r.bottom);\n    const distance = axis === \"x\" ? dx : axis === \"y\" ? dy : Math.hypot(dx, dy);\n    if (distance < best) { best = distance; nearest = item; }\n  }\n  return nearest;\n}\n\n/** Hands a gap click to the item as a real mouse click (detail, modifiers and coordinates kept), so the item reads it as a pointer press, not a keyboard one. */\nfunction forwardClick(item: HTMLElement, event: MouseEvent<HTMLElement>) {\n  const { detail, clientX, clientY, screenX, screenY, ctrlKey, shiftKey, altKey, metaKey, button, buttons } = event;\n  item.dispatchEvent(new globalThis.MouseEvent(\"click\", { bubbles: true, cancelable: true, composed: true, view: window, detail, clientX, clientY, screenX, screenY, ctrlKey, shiftKey, altKey, metaKey, button, buttons }));\n}\n\n/** Whether an event happened inside the element whose handler hears it, not in a portalled child (a submenu, a tooltip). */\nconst isOwn = (event: { currentTarget: EventTarget; target: EventTarget }) =>\n  !(event.currentTarget instanceof Node) || !(event.target instanceof Node) || event.currentTarget.contains(event.target);\n\nexport function useFluidHover<T extends HTMLElement>(container: RefObject<T | null>, options: FluidHoverOptions) {\n  const { items: selector, axis = \"y\", isItemDisabled = defaultDisabled, disabled = \"skip\", gapClick = true, followFocus = true } = options;\n  const [state, setState] = useState<FluidHoverState>({ rect: null, item: null, glide: false, session: 0 });\n  const current = useRef(state);\n  const pointer = useRef(false);\n  const entering = useRef(false);\n  const frame = useRef(0);\n\n  function commit(next: FluidHoverState) {\n    const prev = current.current;\n    if (prev.item === next.item && prev.session === next.session && sameRect(prev.rect, next.rect)) return;\n    current.current = next;\n    setState(next);\n  }\n\n  function light(item: HTMLElement | null, glide: boolean) {\n    const root = container.current;\n    if (!root || !item) return commit({ ...current.current, rect: null, item: null, glide });\n    let session = current.current.session;\n    if (entering.current) { entering.current = false; session += 1; }\n    commit({ rect: rectOf(item, root), item, glide: glide && session === current.current.session, session });\n  }\n\n  const enabledItems = () => {\n    const root = container.current;\n    return root ? [...root.querySelectorAll<HTMLElement>(selector)].filter(item => !isItemDisabled(item)) : [];\n  };\n\n  // The lit item can move under a still highlight (a resize, content above it changing): follow it without travel.\n  const follow = useEffectEvent(() => { const { item } = current.current; if (item?.isConnected) light(item, false); });\n  useEffect(() => {\n    const root = container.current;\n    if (!root || typeof ResizeObserver === \"undefined\") return;\n    const observer = new ResizeObserver(() => follow());\n    observer.observe(root);\n    return () => observer.disconnect();\n  }, [container]);\n  useEffect(() => () => cancelAnimationFrame(frame.current), []);\n\n  const handlers = {\n    onMouseEnter: () => { entering.current = true; },\n    onMouseMove: (event: MouseEvent<T>) => {\n      if (!isOwn(event)) return;\n      pointer.current = true;\n      const { clientX, clientY } = event;\n      cancelAnimationFrame(frame.current);\n      frame.current = requestAnimationFrame(() => {\n        const over = disabled === \"clear\" ? document.elementFromPoint(clientX, clientY)?.closest<HTMLElement>(selector) : null;\n        light(over && isItemDisabled(over) ? null : pickNearest(enabledItems(), clientX, clientY, axis), true);\n      });\n    },\n    onMouseLeave: () => { cancelAnimationFrame(frame.current); entering.current = false; light(null, false); },\n    onKeyDownCapture: () => { pointer.current = false; },\n    onFocus: (event: FocusEvent<T>) => {\n      if (!followFocus || pointer.current || !isOwn(event)) return;\n      const item = event.target instanceof HTMLElement ? event.target.closest<HTMLElement>(selector) : null;\n      if (item && container.current?.contains(item) && !isItemDisabled(item)) light(item, false);\n    },\n    onBlur: (event: FocusEvent<T>) => {\n      if (!pointer.current && !event.currentTarget.contains(event.relatedTarget as Node | null)) light(null, false);\n    },\n    onClick: (event: MouseEvent<T>) => {\n      if (!gapClick || !isOwn(event)) return;\n      const target = event.target as Element;\n      if (!target.isConnected || target.closest(selector) || target.closest(CONTROL)) return;\n      const { item } = current.current;\n      if (item?.isConnected && !isItemDisabled(item)) forwardClick(item, event);\n    },\n  };\n\n  /** Clears the highlight at once, such as when a menu opens again. */\n  const reset = () => { cancelAnimationFrame(frame.current); entering.current = true; light(null, false); };\n\n  return { ...state, handlers, reset, light };\n}\n\nexport interface NearestItemOptions extends Omit<FluidHoverOptions, \"followFocus\"> {\n  /** Called with the nearest enabled item as the mouse moves over the container. */\n  onPick: (item: HTMLElement) => void;\n}\n\n/**\n * Fluid hover's picking without its highlight, for a list that already keeps its own active item and highlight (a listbox\n * with aria-activedescendant, a roving list): the mouse picks the nearest enabled item, gaps and padding included, and a\n * click in a gap goes to that item. Spread the result on the container.\n */\n// A hook only so callbacks that touch refs can be passed during render; it keeps no state.\nexport function useNearestItem<T extends HTMLElement>({ items: selector, axis = \"y\", isItemDisabled = defaultDisabled, gapClick = true, onPick }: NearestItemOptions) {\n  const nearest = (event: MouseEvent<T>) => {\n    if (!isOwn(event)) return null;\n    const items = [...event.currentTarget.querySelectorAll<HTMLElement>(selector)].filter(item => !isItemDisabled(item));\n    return pickNearest(items, event.clientX, event.clientY, axis);\n  };\n  return {\n    onPointerMove: (event: PointerEvent<T>) => { if (event.pointerType !== \"mouse\") return; const item = nearest(event); if (item) onPick(item); },\n    onClick: (event: MouseEvent<T>) => {\n      if (!gapClick) return;\n      const target = event.target as Element;\n      if (!target.isConnected || target.closest(selector) || target.closest(CONTROL)) return;\n      const item = nearest(event);\n      if (item) forwardClick(item, event);\n    },\n  };\n}\n\nconst sameRect = (a: FluidRect | null, b: FluidRect | null) =>\n  a === b || (!!a && !!b && a.top === b.top && a.left === b.left && a.width === b.width && a.height === b.height);\n\nexport interface FluidHoverHighlightProps {\n  /** The state from useFluidHover (or any { rect, glide, session }). */\n  hover: Pick<FluidHoverState, \"rect\" | \"glide\" | \"session\">;\n  /** Radius, fill, z-index. The container must be position: relative; the highlight is placed at its top-left corner. */\n  className?: string;\n  /** Extra attributes for styling, such as data-tone. */\n  tone?: string;\n}\n\n/** The one highlight a fluid hover set renders: it springs between items on transforms, and fades in and out. */\nexport function FluidHoverHighlight({ hover, className, tone }: FluidHoverHighlightProps) {\n  const reduced = useReducedMotion() ?? false;\n  const { rect, glide, session } = hover;\n  const place = rect ? { x: rect.left, y: rect.top, width: rect.width, height: rect.height } : undefined;\n  return (\n    <AnimatePresence initial={false}>\n      {place ? (\n        <motion.span key={session} className={className} data-tone={tone} aria-hidden=\"true\"\n          style={{ position: \"absolute\", top: 0, left: 0, pointerEvents: \"none\" }}\n          initial={{ opacity: 0, ...place }}\n          animate={{ opacity: 1, ...place }}\n          exit={{ opacity: 0, transition: motionTokens.spring.fast.exit }}\n          transition={{ default: glide && !reduced ? motionTokens.spring.fast : { duration: 0 }, opacity: { duration: motionTokens.duration.fast } }} />\n      ) : null}\n    </AnimatePresence>\n  );\n}\n"},{"path":"lib/silicon-provider.tsx","type":"registry:lib","target":"@components/silicon-ui/lib/silicon-provider.tsx","content":"\"use client\";\n\n/**\n * Lets an app swap the link and image elements Silicon UI components render.\n *\n * Without a provider, Silicon UI renders a plain `<a>` and `<img>`, so components work in any React app (Vite, Remix, Astro,\n * plain React). Wrap the app once to use your framework's or your own components instead:\n *\n *   import Link from \"next/link\";\n *   import Image from \"next/image\";\n *   import { SiliconProvider } from \"@/components/silicon-ui/lib/silicon-provider\";\n *\n *   <SiliconProvider link={Link} image={Image}>{children}</SiliconProvider>\n *\n * Any component that accepts these props works, such as a locale-aware Link from next-intl or a React Router Link\n * wrapped to map `href` to `to`.\n */\nimport { createContext, createElement, useContext, useMemo, type AnchorHTMLAttributes, type ComponentType, type ImgHTMLAttributes, type ReactNode, type Ref } from \"react\";\n\n/** The props Silicon UI passes to a link: an href plus ordinary anchor attributes. */\nexport interface SiliconLinkProps extends AnchorHTMLAttributes<HTMLAnchorElement> {\n  href: string;\n  ref?: Ref<HTMLAnchorElement>;\n}\n\n/**\n * The props Silicon UI passes to an image. A subset of next/image's props, so next/image can be passed as is: either `fill`\n * (cover the positioned parent) or `width` and `height`, plus `sizes` and `priority` as hints.\n */\nexport interface SiliconImageProps extends Omit<ImgHTMLAttributes<HTMLImageElement>, \"src\" | \"alt\" | \"width\" | \"height\" | \"loading\" | \"srcSet\"> {\n  src: string;\n  alt: string;\n  width?: number;\n  height?: number;\n  /** Fills the nearest positioned parent, like next/image's `fill`. */\n  fill?: boolean;\n  /** Loads the image eagerly with high priority, like next/image's `priority`. */\n  priority?: boolean;\n  loading?: \"eager\" | \"lazy\";\n  ref?: Ref<HTMLImageElement>;\n}\n\nexport type SiliconLinkComponent = ComponentType<SiliconLinkProps>;\nexport type SiliconImageComponent = ComponentType<SiliconImageProps>;\n\n/** The default link: a plain anchor. */\nexport function SiliconAnchor(props: SiliconLinkProps) {\n  return <a {...props} />;\n}\n\nconst fillStyle = { position: \"absolute\", inset: 0, width: \"100%\", height: \"100%\" } as const;\n\n/** The default image: a plain, lazily decoded `<img>` that understands `fill` and `priority`. */\nexport function SiliconImg({ alt, fill, priority, loading, style, ...props }: SiliconImageProps) {\n  // eslint-disable-next-line @next/next/no-img-element -- the framework-free default; pass next/image through SiliconProvider instead.\n  return <img alt={alt} decoding=\"async\" {...props} loading={loading ?? (priority ? \"eager\" : \"lazy\")} fetchPriority={priority ? \"high\" : props.fetchPriority} style={fill ? { ...fillStyle, ...style } : style} />;\n}\n\ninterface SiliconComponents {\n  link: SiliconLinkComponent;\n  image: SiliconImageComponent;\n}\n\nconst SiliconContext = createContext<SiliconComponents>({ link: SiliconAnchor, image: SiliconImg });\n\nexport interface SiliconProviderProps {\n  /** The link component Silicon UI renders for navigation, such as next/link or your own wrapped Link. Defaults to `<a>`. */\n  link?: SiliconLinkComponent;\n  /** The image component Silicon UI renders for photos, such as next/image. Defaults to `<img>`. */\n  image?: SiliconImageComponent;\n  children: ReactNode;\n}\n\n/** Sets the link and image components for every Silicon UI component inside it. Nested providers inherit what they do not set. */\nexport function SiliconProvider({ link, image, children }: SiliconProviderProps) {\n  const parent = useContext(SiliconContext);\n  const value = useMemo(() => ({ link: link ?? parent.link, image: image ?? parent.image }), [link, image, parent]);\n  return <SiliconContext.Provider value={value}>{children}</SiliconContext.Provider>;\n}\n\n/** The link component from the nearest SiliconProvider, or a plain anchor. */\nexport const useArcLink = () => useContext(SiliconContext).link;\n/** The image component from the nearest SiliconProvider, or a plain img. */\nexport const useArcImage = () => useContext(SiliconContext).image;\n\n/** What Silicon UI components render for a link: the provider's link component, or a plain anchor. */\nexport function SiliconLink(props: SiliconLinkProps) {\n  return createElement(useArcLink(), props);\n}\n\n/** What Silicon UI components render for an image: the provider's image component, or a plain img. */\nexport function SiliconImage(props: SiliconImageProps) {\n  return createElement(useArcImage(), props);\n}\n"}],"docs":"Docs and live preview: https://ui.teamofsilicons.com/nav-list","meta":{"tier":"free","kind":"component","docs":"https://ui.teamofsilicons.com/nav-list","markdown":"https://ui.teamofsilicons.com/nav-list.md","tags":["navigation","sidebar"],"status":"experimental"}}