{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "split-view",
  "title": "Split View",
  "author": "Ballmac <https://ui.ballmac.com>",
  "description": "A master and detail layout with a keyboard-resizable divider. Panes sit side by side in wide containers and stack with a Back button in narrow ones.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils",
    "https://ui.ballmac.com/r/i18n.json",
    "https://ui.ballmac.com/r/direction.json"
  ],
  "files": [
    {
      "path": "registry/ballmac/components/split-view.tsx",
      "content": "// Ballmac UI: Split View. https://ui.ballmac.com/components/split-view\n\"use client\";\n\nimport * as React from \"react\";\nimport { ArrowLeft } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\nimport { useMessages } from \"@/lib/ballmac/i18n\";\nimport { useDirection } from \"@/lib/ballmac/direction\";\n\ntype SplitViewContextValue = {\n  detailOpen: boolean;\n  setDetailOpen: (open: boolean) => void;\n};\nconst SplitViewContext = React.createContext<SplitViewContextValue | null>(null);\n\n/** Read or change whether the detail pane is showing on narrow screens. */\nfunction useSplitView() {\n  const context = React.useContext(SplitViewContext);\n  if (!context) throw new Error(\"useSplitView must be used inside <SplitView>\");\n  return context;\n}\n\ntype SplitViewProps = React.ComponentProps<\"div\"> & {\n  /** Controlled: show the detail pane when the container is narrow. */\n  detailOpen?: boolean;\n  /** Initial state when uncontrolled. */\n  defaultDetailOpen?: boolean;\n  /** Called when the detail pane opens or closes on narrow screens. */\n  onDetailOpenChange?: (open: boolean) => void;\n  /** Initial width of the list pane in pixels when both panes show. */\n  listWidth?: number;\n  /** Smallest width the list pane can be dragged to. */\n  minListWidth?: number;\n  /** Largest width the list pane can be dragged to. */\n  maxListWidth?: number;\n};\n\n/**\n * A master and detail layout (mail, files, settings). Both panes show side by side when the container is wide;\n * below ~40rem it shows one at a time with a Back button. The divider resizes with the mouse, touch or arrow keys.\n */\nfunction SplitView({\n  detailOpen: detailOpenProp,\n  defaultDetailOpen = false,\n  onDetailOpenChange,\n  listWidth = 300,\n  minListWidth = 220,\n  maxListWidth = 520,\n  className,\n  style,\n  children,\n  ...props\n}: SplitViewProps) {\n  const dir = useDirection()\n  const msg = useMessages()\n  const [inner, setInner] = React.useState(defaultDetailOpen);\n  const detailOpen = detailOpenProp ?? inner;\n  const setDetailOpen = React.useCallback(\n    (open: boolean) => {\n      if (detailOpenProp === undefined) setInner(open);\n      onDetailOpenChange?.(open);\n    },\n    [detailOpenProp, onDetailOpenChange],\n  );\n  const [width, setWidth] = React.useState(listWidth);\n  const clamp = React.useCallback((w: number) => Math.min(maxListWidth, Math.max(minListWidth, w)), [minListWidth, maxListWidth]);\n  const value = React.useMemo(() => ({ detailOpen, setDetailOpen }), [detailOpen, setDetailOpen]);\n  const drag = React.useRef<{ x: number; w: number } | null>(null);\n  return (\n    <SplitViewContext.Provider value={value}>\n      <div\n        data-slot=\"split-view\"\n        data-detail-open={detailOpen || undefined}\n        className={cn(\"@container/split group/split h-full min-h-0 w-full overflow-hidden\", className)}\n        {...props}\n      >\n        <div\n          style={{ \"--split-list-w\": `${width}px`, ...style } as React.CSSProperties}\n          className=\"grid h-full min-h-0 w-full grid-cols-1 @2xl/split:grid-cols-[var(--split-list-w)_auto_minmax(0,1fr)]\"\n        >\n          {children}\n          <div\n            role=\"separator\"\n            aria-orientation=\"vertical\"\n            aria-label={msg(\"split-view.resizeList\", \"Resize list\")}\n            aria-valuemin={minListWidth}\n            aria-valuemax={maxListWidth}\n            aria-valuenow={width}\n            tabIndex={0}\n            data-slot=\"split-view-divider\"\n            onPointerDown={(event) => {\n              event.currentTarget.setPointerCapture(event.pointerId);\n              drag.current = { x: event.clientX, w: width };\n            }}\n            onPointerMove={(event) => {\n              if (drag.current) setWidth(clamp(drag.current.w + (dir === \"rtl\" ? -1 : 1) * (event.clientX - drag.current.x)));\n            }}\n            onPointerUp={() => (drag.current = null)}\n            onKeyDown={(event) => {\n              const step = event.shiftKey ? 64 : 16;\n              if (event.key === \"ArrowLeft\") setWidth((w) => clamp(w + (dir === \"rtl\" ? step : -step)));\n              else if (event.key === \"ArrowRight\") setWidth((w) => clamp(w + (dir === \"rtl\" ? -step : step)));\n              else if (event.key === \"Home\") setWidth(minListWidth);\n              else if (event.key === \"End\") setWidth(maxListWidth);\n              else return;\n              event.preventDefault();\n            }}\n            className=\"group/divider relative col-start-2 row-start-1 hidden w-px cursor-col-resize touch-none bg-border outline-none transition-colors after:absolute after:inset-y-0 after:-inset-x-1.5 hover:bg-ring/60 focus-visible:bg-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 @2xl/split:block motion-reduce:transition-none\"\n          />\n        </div>\n      </div>\n    </SplitViewContext.Provider>\n  );\n}\n\ntype SplitViewPaneProps = React.ComponentProps<\"section\"> & {\n  /** Accessible name of the pane. */\n  label?: string;\n};\n\n/** The list (master) pane. Hidden on narrow containers while the detail pane is open. */\nfunction SplitViewList({ label, className, ...props }: SplitViewPaneProps) {\n  const msg = useMessages()\n  label ??= msg(\"split-view.label\", \"List\")\n  return (\n    <section\n      aria-label={label}\n      data-slot=\"split-view-list\"\n      className={cn(\n        \"col-start-1 row-start-1 min-h-0 min-w-0 overflow-y-auto @max-2xl/split:group-data-[detail-open]/split:hidden\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\n/** The detail pane. Hidden on narrow containers until something is opened. */\nfunction SplitViewDetail({ label, className, ...props }: SplitViewPaneProps) {\n  const msg = useMessages()\n  label ??= msg(\"split-view.label2\", \"Detail\")\n  return (\n    <section\n      aria-label={label}\n      data-slot=\"split-view-detail\"\n      className={cn(\n        \"col-start-1 row-start-1 hidden min-h-0 min-w-0 overflow-y-auto group-data-[detail-open]/split:block @2xl/split:col-start-3 @2xl/split:block\",\n        className,\n      )}\n      {...props}\n    />\n  );\n}\n\ntype SplitViewBackProps = React.ComponentProps<\"button\">;\n/** Returns to the list on narrow containers. Not rendered visibly when both panes are showing. */\nfunction SplitViewBack({ className, children = \"Back\", onClick, ...props }: SplitViewBackProps) {\n  const { setDetailOpen } = useSplitView();\n  return (\n    <button\n      type=\"button\"\n      data-slot=\"split-view-back\"\n      onClick={(event) => {\n        onClick?.(event);\n        setDetailOpen(false);\n      }}\n      className={cn(\n        \"inline-flex h-8 items-center gap-1.5 rounded-md px-2 text-sm font-medium text-muted-foreground outline-none transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:ring-[3px] focus-visible:ring-ring/50 @2xl/split:hidden\",\n        className,\n      )}\n      {...props}\n    >\n      <ArrowLeft aria-hidden=\"true\" className=\"size-4 rtl:rotate-180\" />\n      {children}\n    </button>\n  );\n}\n\nexport {\n  SplitView,\n  SplitViewList,\n  SplitViewDetail,\n  SplitViewBack,\n  useSplitView,\n  type SplitViewProps,\n  type SplitViewPaneProps,\n  type SplitViewBackProps,\n};\n",
      "type": "registry:ui",
      "target": "@components/ballmac/split-view.tsx"
    }
  ],
  "meta": {
    "schema": 1,
    "tier": "free",
    "tags": [
      "master detail",
      "split",
      "list",
      "responsive"
    ],
    "version": "1.0.0",
    "updated": "2026-09-30",
    "ai": {
      "summary": "SplitView > SplitViewList, SplitViewDetail and SplitViewBack. Use useSplitView().setDetailOpen(true) when an item is chosen. Responds to its own width, not the screen's.",
      "whenToUse": [
        "Mail, files and settings screens",
        "Any list that opens a detail"
      ],
      "whenNotToUse": [
        "User-arranged dock panels; use resizable",
        "Overlay details; use sheet or drawer"
      ],
      "composesWith": [
        "resizable",
        "scroll-area",
        "sidebar"
      ],
      "a11y": [
        {
          "keys": "ArrowLeft / ArrowRight",
          "action": "Resize the list from the divider; Shift for larger steps; Home and End for the limits"
        },
        {
          "keys": "Tab",
          "action": "Back button appears only when panes stack"
        },
        {
          "keys": "Screen readers",
          "action": "Panes are labelled regions; the divider is a separator with value bounds"
        }
      ],
      "customization": [
        "listWidth, minListWidth, maxListWidth",
        "controlled detailOpen",
        "container-query breakpoint"
      ]
    },
    "examples": [
      "split-view-demo",
      "split-view-states"
    ],
    "url": "https://ui.ballmac.com/components/split-view"
  },
  "categories": [
    "layout"
  ],
  "type": "registry:ui"
}