{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dock",
  "type": "registry:ui",
  "title": "Dock",
  "description": "A layout of main content with a panel docked beside it that stays while the person works: the panel can be resized with a splitter, collapsed to a slim bar, and on narrow containers gives way to a bar at the bottom.",
  "categories": [
    "ui"
  ],
  "dependencies": [],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/direction",
    "@rivier-ui/use-controllable-state",
    "@rivier-ui/use-size"
  ],
  "files": [
    {
      "path": "registry/ui/dock.tsx",
      "type": "registry:ui",
      "target": "components/ui/dock.tsx",
      "content": "\"use client\";\n/**\n * @name dock\n * @category ui\n * @description A layout of main content with a panel docked beside it that stays while the person works: the panel can be resized with a splitter, collapsed to a slim bar, and on narrow containers gives way to a bar at the bottom.\n * @when A working surface that belongs beside the content and is not modal: a plan next to a conversation, an inspector next to a canvas, details next to a list. For a panel that covers the page for a moment use sheet; for two fixed columns with no resizing use split. Write the parts in reading order: DockMain, DockResizer, DockPanel for a panel at the end; DockPanel, DockResizer, DockMain with side=\"start\". Below 42rem of its own width (another width with `stackBelow`) the panel and splitter are hidden and DockBar shows at the bottom: open the panel's content in a bottom-sheet from `onOpenStacked`. Where the content ends in a region that must stay lowest (a composer), put a second DockBar inside DockMain above that region with `show=\"stacked\"`, and give the one after the panel `show=\"collapsed\"`. Give the Dock a height (it fills its parent).\n * @example\n * <Dock defaultSize={32} minSize={24} maxSize={50} className=\"h-[32rem]\">\n *   <DockMain>…the conversation…</DockMain>\n *   <DockResizer aria-label=\"Resize the plan\" />\n *   <DockPanel aria-label=\"Plan\">\n *     <DockCollapse aria-label=\"Hide the plan\"><PanelRightClose /></DockCollapse>\n *     …the plan…\n *   </DockPanel>\n *   <DockBar onOpenStacked={() => setSheetOpen(true)}>Plan · 3 stops</DockBar>\n * </Dock>\n *\n * // Controlled, in pixels, at the start\n * <Dock side=\"start\" unit=\"px\" size={width} onSizeChange={setWidth} minSize={240} maxSize={480} collapsed={hidden} onCollapsedChange={setHidden}>…</Dock>\n *\n * // Stacks below 56rem; on a narrow dock the bar sits above the composer, not under it\n * <Dock stackBelow={56} className=\"h-[32rem]\">\n *   <DockMain className=\"flex flex-col\">\n *     <div className=\"min-h-0 flex-1 overflow-y-auto\">…the conversation…</div>\n *     <DockBar show=\"stacked\" onOpenStacked={() => setSheetOpen(true)}>Plan · 3 stops</DockBar>\n *     <footer>…the composer…</footer>\n *   </DockMain>\n *   <DockResizer aria-label=\"Resize the plan\" />\n *   <DockPanel aria-label=\"Plan\">…</DockPanel>\n *   <DockBar show=\"collapsed\">Plan · 3 stops</DockBar>\n * </Dock>\n */\nimport { createContext, use, useEffect, useId, useRef, type ComponentProps, type CSSProperties, type KeyboardEvent, type PointerEvent } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { inlineStep, isRtl } from \"@/lib/direction\";\nimport { useControllableState } from \"@/lib/use-controllable-state\";\nimport { useSize } from \"@/lib/use-size\";\n\n/** The container width, in rem, below which the panel no longer sits beside the content unless `stackBelow` says otherwise (Tailwind's @2xl). */\nconst STACK_BELOW_REM = 42;\n\n/**\n * How the dock decides between side by side and stacked. \"auto\": the stylesheet does, with a container\n * query at 42rem, so it is right before any script runs. \"side\" and \"stacked\": the dock measured itself\n * against another `stackBelow`, which a container query cannot read from a property.\n */\ntype DockLayout = \"auto\" | \"side\" | \"stacked\";\n\ntype DockSide = \"start\" | \"end\";\ntype FocusTarget = \"bar\" | \"panel\" | \"resizer\";\n\ntype DockContextValue = {\n  side: DockSide;\n  unit: \"%\" | \"px\";\n  size: number;\n  minSize: number;\n  maxSize: number;\n  step: number;\n  /** Sets the size, kept within the limits. */\n  resize: (size: number) => void;\n  resetSize: () => void;\n  collapsed: boolean;\n  /**\n   * Collapses or restores, then moves focus to what replaces the control that was used. `from` is where\n   * a collapse came from, so that restoring from the bar returns there.\n   */\n  setCollapsed: (collapsed: boolean, focus?: FocusTarget | \"back\", from?: FocusTarget) => void;\n  /** True when the dock is too narrow for the panel to sit beside the content. */\n  stacked: boolean;\n  panelId: string;\n};\n\nconst DockContext = createContext<DockContextValue | null>(null);\n\n/** The dock's state, for a part of your own: `stacked`, `collapsed`, `setCollapsed`, `size`, `resize`. */\nexport function useDock(part = \"useDock\"): DockContextValue {\n  const context = use(DockContext);\n  if (!context) throw new Error(`<${part}> must be used inside <Dock>.`);\n  return context;\n}\n\nexport type DockProps = ComponentProps<\"div\"> & {\n  /** The edge the panel is on: \"end\" (default) or \"start\". Both follow the reading direction. */\n  side?: DockSide;\n  /** What `size`, `minSize` and `maxSize` are measured in: \"%\" of the dock's width (default) or \"px\". */\n  unit?: \"%\" | \"px\";\n  /** The controlled size of the panel. */\n  size?: number;\n  /** The size of the panel when uncontrolled, and what a double-click on the splitter goes back to. Default 32 (%) or 320 (px). */\n  defaultSize?: number;\n  onSizeChange?: (size: number) => void;\n  minSize?: number;\n  maxSize?: number;\n  /** What one arrow key on the splitter adds or takes away. Default 2 (%) or 16 (px). */\n  step?: number;\n  collapsed?: boolean;\n  defaultCollapsed?: boolean;\n  onCollapsedChange?: (collapsed: boolean) => void;\n  /**\n   * The width of the dock itself, in rem, below which the panel gives way to the bar. Default 42. With the\n   * default the stylesheet decides (a container query); with another width the dock measures itself, so\n   * until it has (on the server, and for the first frame) it is laid out as for 42.\n   */\n  stackBelow?: number;\n};\n\n/**\n * The layout. Resizing sets one CSS variable that the panel's width reads, as the pointer moves: it is\n * layout, not an animation, and nothing transitions.\n */\nexport function Dock({\n  className,\n  style,\n  children,\n  side = \"end\",\n  unit = \"%\",\n  size,\n  defaultSize,\n  onSizeChange,\n  minSize,\n  maxSize,\n  step,\n  collapsed,\n  defaultCollapsed = false,\n  onCollapsedChange,\n  stackBelow = STACK_BELOW_REM,\n  ...props\n}: DockProps) {\n  const percent = unit === \"%\";\n  const initial = defaultSize ?? (percent ? 32 : 320);\n  const min = minSize ?? (percent ? 20 : 240);\n  const max = maxSize ?? (percent ? 50 : 560);\n  const [current, setCurrent] = useControllableState({ value: size, defaultValue: initial, onChange: onSizeChange });\n  const [isCollapsed, setIsCollapsed] = useControllableState({ value: collapsed, defaultValue: defaultCollapsed, onChange: onCollapsedChange });\n  const panelId = useId();\n  const root = useRef<HTMLDivElement>(null);\n  const returnTo = useRef<FocusTarget>(\"panel\");\n  const pendingFocus = useRef<FocusTarget | \"back\" | null>(null);\n  const { ref: measure, width } = useSize<HTMLDivElement>();\n\n  // Focus follows a collapse or a restore: the control that was used is hidden by it.\n  useEffect(() => {\n    const target = pendingFocus.current === \"back\" ? returnTo.current : pendingFocus.current;\n    pendingFocus.current = null;\n    if (!target) return;\n    // There may be two bars (one for each layout): the one that is shown takes focus.\n    const parts = [...(root.current?.querySelectorAll<HTMLElement>(`[data-slot=dock-${target}]`) ?? [])];\n    (parts.find((part) => part.getClientRects().length > 0) ?? parts[0])?.focus();\n  }, [isCollapsed]);\n\n  const stacked = width > 0 && width < stackBelow * 16;\n  const layout: DockLayout = stackBelow === STACK_BELOW_REM || width === 0 ? \"auto\" : stacked ? \"stacked\" : \"side\";\n\n  const clamp = (value: number): number => Math.round(Math.min(max, Math.max(min, value)) * 100) / 100;\n\n  return (\n    <DockContext\n      value={{\n        side,\n        unit,\n        size: clamp(current),\n        minSize: min,\n        maxSize: max,\n        step: step ?? (percent ? 2 : 16),\n        resize: (next) => setCurrent(clamp(next)),\n        resetSize: () => setCurrent(clamp(initial)),\n        collapsed: isCollapsed,\n        setCollapsed: (next, focus, from) => {\n          if (next !== isCollapsed) pendingFocus.current = focus ?? null;\n          if (from) returnTo.current = from;\n          setIsCollapsed(next);\n        },\n        stacked,\n        panelId,\n      }}\n    >\n      <div\n        ref={(node) => {\n          root.current = node;\n          measure(node);\n        }}\n        data-slot=\"dock\"\n        data-side={side}\n        data-layout={layout}\n        data-collapsed={isCollapsed ? \"\" : undefined}\n        className={cn(\"group/dock @container/dock h-full min-h-0 w-full min-w-0\", className)}\n        style={{ \"--dock-size\": `${clamp(current)}${unit}`, ...style } as CSSProperties}\n        {...props}\n      >\n        <div data-slot=\"dock-layout\" className=\"flex h-full min-h-0 w-full flex-col group-data-[layout=side]/dock:flex-row @2xl/dock:group-data-[layout=auto]/dock:flex-row\">\n          {children}\n        </div>\n      </div>\n    </DockContext>\n  );\n}\n\n/** The content the panel is docked beside. It takes the room the panel leaves. */\nexport function DockMain({ className, ...props }: ComponentProps<\"div\">) {\n  return <div data-slot=\"dock-main\" className={cn(\"min-h-0 min-w-0 flex-1\", className)} {...props} />;\n}\n\nexport type DockPanelProps = ComponentProps<\"aside\">;\n\n/**\n * The panel: a complementary landmark, so give it an `aria-label` (or `aria-labelledby`) that says what it\n * holds. Hidden while collapsed and on narrow containers.\n */\nexport function DockPanel({ className, ...props }: DockPanelProps) {\n  const { panelId } = useDock(\"DockPanel\");\n  return (\n    <aside\n      id={panelId}\n      tabIndex={-1}\n      data-slot=\"dock-panel\"\n      className={cn(\n        \"hidden min-h-0 min-w-0 shrink-0 grow-0 basis-(--dock-size) flex-col overflow-hidden outline-none group-data-[collapsed]/dock:hidden! group-data-[layout=side]/dock:flex @2xl/dock:group-data-[layout=auto]/dock:flex\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type DockResizerProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  /** What a screen reader says for a size. Default: \"32%\" or \"320 pixels\". Translate it with the interface. */\n  valueText?: (size: number, unit: \"%\" | \"px\") => string;\n};\n\n/**\n * The splitter between the content and the panel (the window splitter pattern). Left and Right arrows move\n * it by a step, the way the arrow points in either reading direction; Home makes the panel as small as it\n * may be and End as large; Enter collapses the panel (Enter on the bar that replaces it restores it and\n * returns here). Drag it with a pointer or a finger: the target is wider than the line. A double-click\n * goes back to the default size. Its name (\"Resize the panel\") is an `aria-label`: translate it.\n */\nexport function DockResizer({\n  className,\n  valueText = (size, unit) => (unit === \"%\" ? `${Math.round(size)}%` : `${Math.round(size)} pixels`),\n  \"aria-label\": ariaLabel = \"Resize the panel\",\n  onKeyDown,\n  onPointerDown,\n  onDoubleClick,\n  ...props\n}: DockResizerProps) {\n  const dock = useDock(\"DockResizer\");\n  const { side, unit, size, minSize, maxSize, step, resize } = dock;\n\n  const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n    onKeyDown?.(event);\n    if (event.defaultPrevented) return;\n    // A key that points towards the content makes the panel larger.\n    const towardsEnd = inlineStep(event.key, event.currentTarget);\n    if (towardsEnd !== 0) {\n      event.preventDefault();\n      resize(size + (side === \"end\" ? -towardsEnd : towardsEnd) * step);\n    } else if (event.key === \"Home\") {\n      event.preventDefault();\n      resize(minSize);\n    } else if (event.key === \"End\") {\n      event.preventDefault();\n      resize(maxSize);\n    } else if (event.key === \"Enter\") {\n      event.preventDefault();\n      dock.setCollapsed(true, \"bar\", \"resizer\");\n    }\n  };\n\n  const sizeAt = (handle: HTMLElement, clientX: number): number | null => {\n    const node = handle.closest(\"[data-slot=dock]\");\n    if (!node) return null;\n    const rect = node.getBoundingClientRect();\n    if (rect.width === 0) return null;\n    // The panel is on the right when it is at the end of a left-to-right line, or at the start of a right-to-left one.\n    const onRight = (side === \"end\") !== isRtl(node);\n    const pixels = onRight ? rect.right - clientX : clientX - rect.left;\n    return unit === \"%\" ? (pixels / rect.width) * 100 : pixels;\n  };\n\n  const handlePointerDown = (event: PointerEvent<HTMLDivElement>): void => {\n    onPointerDown?.(event);\n    if (event.defaultPrevented || event.button !== 0) return;\n    event.preventDefault();\n    event.currentTarget.focus();\n    event.currentTarget.setPointerCapture(event.pointerId);\n  };\n\n  return (\n    <div\n      role=\"separator\"\n      tabIndex={0}\n      data-slot=\"dock-resizer\"\n      aria-label={ariaLabel}\n      aria-orientation=\"vertical\"\n      aria-controls={dock.panelId}\n      aria-valuenow={Math.round(size)}\n      aria-valuemin={Math.round(minSize)}\n      aria-valuemax={Math.round(maxSize)}\n      aria-valuetext={valueText(size, unit)}\n      onKeyDown={handleKeyDown}\n      onPointerDown={handlePointerDown}\n      onPointerMove={(event) => {\n        if (!event.currentTarget.hasPointerCapture(event.pointerId)) return;\n        const next = sizeAt(event.currentTarget, event.clientX);\n        if (next !== null) resize(next);\n      }}\n      onPointerUp={(event) => event.currentTarget.releasePointerCapture(event.pointerId)}\n      onDoubleClick={(event) => {\n        onDoubleClick?.(event);\n        if (!event.defaultPrevented) dock.resetSize();\n      }}\n      className={cn(\n        \"relative z-10 hidden w-px shrink-0 cursor-col-resize touch-none bg-border-strong select-none group-data-[collapsed]/dock:hidden! before:absolute before:inset-y-0 before:-inset-x-[1.5px] before:my-auto before:h-8 before:rounded-full before:bg-border-strong after:absolute after:inset-y-0 after:-inset-x-3 hover:before:bg-foreground focus-visible:before:bg-foreground pointer-coarse:after:-inset-x-5 group-data-[layout=side]/dock:block @2xl/dock:group-data-[layout=auto]/dock:block\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type DockCollapseProps = Omit<ComponentProps<\"button\">, \"type\">;\n\n/**\n * A button that collapses the panel (or restores it, when placed outside the panel). Give it an\n * `aria-label` or text that says what it hides. Focus moves to the bar when the panel goes.\n */\nexport function DockCollapse({ className, onClick, ...props }: DockCollapseProps) {\n  const dock = useDock(\"DockCollapse\");\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"dock-collapse\"\n      aria-expanded={!dock.collapsed}\n      aria-controls={dock.panelId}\n      onClick={(event) => {\n        onClick?.(event);\n        if (event.defaultPrevented) return;\n        dock.setCollapsed(!dock.collapsed, dock.collapsed ? \"panel\" : \"bar\", \"panel\");\n      }}\n      className={cn(\n        \"inline-flex size-(--control-h) shrink-0 items-center justify-center rounded-control text-muted-foreground transition-[background-color,color] duration-instant ease-out hover:bg-accent hover:text-foreground motion-reduce:transition-none [&_svg]:size-4 rtl:[&_svg]:-scale-x-100\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\nexport type DockBarProps = Omit<ComponentProps<\"button\">, \"type\"> & {\n  /**\n   * Called when the bar is pressed while the dock is too narrow for the panel to sit beside the content:\n   * open the panel's content another way (a bottom-sheet). On a wide dock the bar restores the panel itself.\n   */\n  onOpenStacked?: () => void;\n  /**\n   * When this bar is there. \"both\" (default): across the bottom on a narrow dock, and as the slim strip\n   * where the panel was on a wide one. \"stacked\": only on a narrow dock, and then wherever it is written, so\n   * it can sit inside DockMain above a region that must stay lowest (a composer). \"collapsed\": only as the\n   * strip of a wide dock. Use the last two as a pair.\n   */\n  show?: \"both\" | \"stacked\" | \"collapsed\";\n};\n\n/**\n * The collapsed form of the panel: one button that says what is in the panel (its children: \"Plan · 3\n * stops\") and brings it back. On a wide dock it shows only while the panel is collapsed, as a slim strip\n * where the panel was; on a narrow one it is always there, across the bottom, or with `show=\"stacked\"`\n * wherever it is written inside DockMain.\n */\nexport function DockBar({ className, onClick, onOpenStacked, show = \"both\", children, ...props }: DockBarProps) {\n  const dock = useDock(\"DockBar\");\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"dock-bar\"\n      data-show={show}\n      aria-expanded={dock.stacked ? undefined : false}\n      aria-controls={dock.stacked ? undefined : dock.panelId}\n      aria-haspopup={dock.stacked ? \"dialog\" : undefined}\n      onClick={(event) => {\n        onClick?.(event);\n        if (event.defaultPrevented) return;\n        if (dock.stacked) onOpenStacked?.();\n        else dock.setCollapsed(false, \"back\");\n      }}\n      className={cn(\n        \"h-control-lg w-full shrink-0 items-center gap-2 border-t border-border bg-card px-4 text-start text-sm font-medium text-card-foreground transition-colors duration-instant ease-out hover:bg-accent motion-reduce:transition-none [&_svg]:size-4 [&_svg]:shrink-0\",\n        // On a narrow dock: there, unless it is only the strip of a wide one.\n        show === \"collapsed\" ? \"hidden\" : \"flex\",\n        // On a wide dock it is gone, whichever way the width was decided…\n        \"group-data-[layout=side]/dock:hidden @2xl/dock:group-data-[layout=auto]/dock:hidden\",\n        // …and comes back as the strip where the panel was, while the panel is collapsed.\n        show !== \"stacked\" && [\n          \"group-data-[layout=side]/dock:h-full group-data-[layout=side]/dock:w-(--control-h-lg) group-data-[layout=side]/dock:justify-start group-data-[layout=side]/dock:border-t-0 group-data-[layout=side]/dock:px-0 group-data-[layout=side]/dock:py-4 group-data-[layout=side]/dock:[writing-mode:vertical-rl] group-data-[layout=side]/dock:group-data-[collapsed]/dock:flex group-data-[layout=side]/dock:group-data-[side=end]/dock:border-s group-data-[layout=side]/dock:group-data-[side=start]/dock:order-first group-data-[layout=side]/dock:group-data-[side=start]/dock:border-e\",\n          \"@2xl/dock:group-data-[layout=auto]/dock:h-full @2xl/dock:group-data-[layout=auto]/dock:w-(--control-h-lg) @2xl/dock:group-data-[layout=auto]/dock:justify-start @2xl/dock:group-data-[layout=auto]/dock:border-t-0 @2xl/dock:group-data-[layout=auto]/dock:px-0 @2xl/dock:group-data-[layout=auto]/dock:py-4 @2xl/dock:group-data-[layout=auto]/dock:[writing-mode:vertical-rl] @2xl/dock:group-data-[layout=auto]/dock:group-data-[collapsed]/dock:flex @2xl/dock:group-data-[layout=auto]/dock:group-data-[side=end]/dock:border-s @2xl/dock:group-data-[layout=auto]/dock:group-data-[side=start]/dock:order-first @2xl/dock:group-data-[layout=auto]/dock:group-data-[side=start]/dock:border-e\",\n        ],\n        className,\n      )}\n      {...props}\n    >\n      {children}\n    </button>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "A working surface that belongs beside the content and is not modal: a plan next to a conversation, an inspector next to a canvas, details next to a list. For a panel that covers the page for a moment use sheet; for two fixed columns with no resizing use split. Write the parts in reading order: DockMain, DockResizer, DockPanel for a panel at the end; DockPanel, DockResizer, DockMain with side=\"start\". Below 42rem of its own width (another width with `stackBelow`) the panel and splitter are hidden and DockBar shows at the bottom: open the panel's content in a bottom-sheet from `onOpenStacked`. Where the content ends in a region that must stay lowest (a composer), put a second DockBar inside DockMain above that region with `show=\"stacked\"`, and give the one after the panel `show=\"collapsed\"`. Give the Dock a height (it fills its parent).",
    "example": "<Dock defaultSize={32} minSize={24} maxSize={50} className=\"h-[32rem]\">\n  <DockMain>…the conversation…</DockMain>\n  <DockResizer aria-label=\"Resize the plan\" />\n  <DockPanel aria-label=\"Plan\">\n    <DockCollapse aria-label=\"Hide the plan\"><PanelRightClose /></DockCollapse>\n    …the plan…\n  </DockPanel>\n  <DockBar onOpenStacked={() => setSheetOpen(true)}>Plan · 3 stops</DockBar>\n</Dock>\n\n// Controlled, in pixels, at the start\n<Dock side=\"start\" unit=\"px\" size={width} onSizeChange={setWidth} minSize={240} maxSize={480} collapsed={hidden} onCollapsedChange={setHidden}>…</Dock>\n\n// Stacks below 56rem; on a narrow dock the bar sits above the composer, not under it\n<Dock stackBelow={56} className=\"h-[32rem]\">\n  <DockMain className=\"flex flex-col\">\n    <div className=\"min-h-0 flex-1 overflow-y-auto\">…the conversation…</div>\n    <DockBar show=\"stacked\" onOpenStacked={() => setSheetOpen(true)}>Plan · 3 stops</DockBar>\n    <footer>…the composer…</footer>\n  </DockMain>\n  <DockResizer aria-label=\"Resize the plan\" />\n  <DockPanel aria-label=\"Plan\">…</DockPanel>\n  <DockBar show=\"collapsed\">Plan · 3 stops</DockBar>\n</Dock>",
    "client": true
  }
}
