{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "resizable",
  "type": "registry:ui",
  "title": "Resizable",
  "description": "Panels side by side (or stacked) with a handle between each pair that is dragged, or moved with the arrow keys, to share the space differently; Home and End go to the limits and Enter folds a panel away and back: the WAI-ARIA window splitter pattern.",
  "categories": [
    "ui"
  ],
  "dependencies": [],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/cn",
    "@rivier-ui/direction",
    "@rivier-ui/use-controllable-state"
  ],
  "files": [
    {
      "path": "registry/ui/resizable.tsx",
      "type": "registry:ui",
      "target": "components/ui/resizable.tsx",
      "content": "\"use client\";\n/**\n * @name resizable\n * @category ui\n * @description Panels side by side (or stacked) with a handle between each pair that is dragged, or moved with the arrow keys, to share the space differently; Home and End go to the limits and Enter folds a panel away and back: the WAI-ARIA window splitter pattern.\n * @when Layouts whose parts the person sizes: a list beside a detail view, an editor beside its preview, a map beside its table. For a panel docked beside the whole page use dock; for two fixed columns use split.\n * @example\n * <ResizablePanelGroup defaultSizes={[30, 70]} aria-label=\"Mail\">\n *   <ResizablePanel minSize={20} id=\"folders\">Folders</ResizablePanel>\n *   <ResizableHandle aria-label=\"Resize the folders\" />\n *   <ResizablePanel id=\"messages\">Messages</ResizablePanel>\n * </ResizablePanelGroup>\n */\nimport { Children, cloneElement, createContext, isValidElement, use, useRef, type ComponentProps, type KeyboardEvent, type PointerEvent, type ReactElement, type RefObject } from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { useControllableState } from \"@/lib/use-controllable-state\";\nimport { isRtl } from \"@/lib/direction\";\n\ntype GroupContext = {\n  direction: \"horizontal\" | \"vertical\";\n  sizes: readonly number[];\n  setSizes: (next: readonly number[]) => void;\n  limits: { min: number; max: number }[];\n  ids: (string | undefined)[];\n  group: RefObject<HTMLDivElement | null>;\n  step: number;\n};\n\nconst Context = createContext<GroupContext | null>(null);\n\nexport type ResizablePanelGroupProps = Omit<ComponentProps<\"div\">, \"defaultValue\"> & {\n  direction?: \"horizontal\" | \"vertical\";\n  /** Each panel's share in percent, in order. Controlled with `onSizesChange`. */\n  sizes?: readonly number[];\n  defaultSizes?: readonly number[];\n  onSizesChange?: (sizes: readonly number[]) => void;\n  /** What an arrow key moves a handle by, in percent. Default 5. */\n  step?: number;\n};\n\n/** Panels and handles, alternating, as its direct children. */\nexport function ResizablePanelGroup({ direction = \"horizontal\", sizes: sizesProp, defaultSizes, onSizesChange, step = 5, className, children, ...props }: ResizablePanelGroupProps) {\n  const items = Children.toArray(children).filter(isValidElement) as ReactElement<Record<string, unknown>>[];\n  const panels = items.filter((child) => child.type === ResizablePanel);\n  const even = panels.map(() => 100 / Math.max(1, panels.length));\n  const [sizes, setSizes] = useControllableState<readonly number[]>({ value: sizesProp, defaultValue: defaultSizes ?? even, onChange: onSizesChange });\n  const group = useRef<HTMLDivElement>(null);\n  const limits = panels.map((panel) => ({ min: Number(panel.props[\"minSize\"] ?? 10), max: Number(panel.props[\"maxSize\"] ?? 90) }));\n  const ids = panels.map((panel) => panel.props[\"id\"] as string | undefined);\n  let panelIndex = 0;\n  let handleIndex = 0;\n  return (\n    <Context value={{ direction, sizes, setSizes, limits, ids, group, step }}>\n      <div ref={group} data-slot=\"resizable-panel-group\" data-direction={direction} className={cn(\"flex size-full min-h-0 min-w-0\", direction === \"vertical\" && \"flex-col\", className)} {...props}>\n        {items.map((child) => {\n          if (child.type === ResizablePanel) return cloneElement(child, { key: `p${panelIndex}`, index: panelIndex++ });\n          if (child.type === ResizableHandle) return cloneElement(child, { key: `h${handleIndex}`, index: handleIndex++ });\n          return child;\n        })}\n      </div>\n    </Context>\n  );\n}\n\nexport type ResizablePanelProps = ComponentProps<\"div\"> & {\n  /** The smallest share in percent. Default 10. */\n  minSize?: number;\n  /** The largest share in percent. Default 90. */\n  maxSize?: number;\n  /** Set by the group. */\n  index?: number;\n};\n\n// minSize and maxSize are read by the group from the element's props; here they are only marked on the panel.\nexport function ResizablePanel({ className, style, index = 0, minSize, maxSize, ...props }: ResizablePanelProps) {\n  const context = use(Context);\n  const size = context?.sizes[index] ?? 50;\n  return <div data-slot=\"resizable-panel\" data-min-size={minSize} data-max-size={maxSize} className={cn(\"min-h-0 min-w-0 overflow-auto\", className)} style={{ flexBasis: 0, flexGrow: size, flexShrink: 1, ...style }} {...props} />;\n}\n\nexport type ResizableHandleProps = Omit<ComponentProps<\"div\">, \"children\"> & {\n  /** Set by the group. */\n  index?: number;\n  /** Shown as a small grip in the middle of the line. Default true. */\n  withGrip?: boolean;\n};\n\n/** The splitter between panel `index` and the next. Name it with `aria-label`: \"Resize the folders\". */\nexport function ResizableHandle({ className, index = 0, withGrip = true, ...props }: ResizableHandleProps) {\n  const context = use(Context);\n  const before = useRef<number | null>(null);\n  if (!context) throw new Error(\"ResizableHandle must be inside a ResizablePanelGroup.\");\n  const { direction, sizes, setSizes, limits, ids, group, step } = context;\n  const a = sizes[index] ?? 50;\n  const b = sizes[index + 1] ?? 50;\n  const pair = a + b;\n  const low = Math.max(limits[index]?.min ?? 10, pair - (limits[index + 1]?.max ?? 90));\n  const high = Math.min(limits[index]?.max ?? 90, pair - (limits[index + 1]?.min ?? 10));\n  const place = (value: number): void => {\n    const next = Math.max(low, Math.min(high, value));\n    setSizes(sizes.map((size, i) => (i === index ? next : i === index + 1 ? pair - next : size)));\n  };\n  const onKeyDown = (event: KeyboardEvent<HTMLDivElement>): void => {\n    const sign = direction === \"horizontal\" && isRtl(event.currentTarget) ? -1 : 1;\n    const grow = direction === \"horizontal\" ? \"ArrowRight\" : \"ArrowDown\";\n    const shrink = direction === \"horizontal\" ? \"ArrowLeft\" : \"ArrowUp\";\n    if (event.key === grow) place(a + step * sign);\n    else if (event.key === shrink) place(a - step * sign);\n    else if (event.key === \"Home\") place(low);\n    else if (event.key === \"End\") place(high);\n    else if (event.key === \"Enter\") {\n      // Fold the first panel to its smallest and back to where it was.\n      if (a > low + 0.5) {\n        before.current = a;\n        place(low);\n      } else place(before.current ?? pair / 2);\n    } else return;\n    event.preventDefault();\n  };\n  const onPointerDown = (event: PointerEvent<HTMLDivElement>): void => {\n    const box = group.current?.getBoundingClientRect();\n    if (!box) return;\n    event.currentTarget.setPointerCapture(event.pointerId);\n    const total = direction === \"horizontal\" ? box.width : box.height;\n    const start = direction === \"horizontal\" ? event.clientX : event.clientY;\n    const sign = direction === \"horizontal\" && isRtl(event.currentTarget) ? -1 : 1;\n    const origin = a;\n    const move = (e: globalThis.PointerEvent): void => place(origin + (((direction === \"horizontal\" ? e.clientX : e.clientY) - start) / total) * 100 * sign);\n    const up = (): void => {\n      window.removeEventListener(\"pointermove\", move);\n      window.removeEventListener(\"pointerup\", up);\n    };\n    window.addEventListener(\"pointermove\", move);\n    window.addEventListener(\"pointerup\", up);\n  };\n  return (\n    <div\n      data-slot=\"resizable-handle\"\n      role=\"separator\"\n      tabIndex={0}\n      aria-orientation={direction === \"horizontal\" ? \"vertical\" : \"horizontal\"}\n      aria-valuenow={Math.round(a)}\n      aria-valuemin={Math.round(low)}\n      aria-valuemax={Math.round(high)}\n      aria-controls={ids[index]}\n      onKeyDown={onKeyDown}\n      onPointerDown={onPointerDown}\n      className={cn(\n        \"group/handle relative flex shrink-0 touch-none items-center justify-center bg-border select-none\",\n        direction === \"horizontal\"\n          ? \"w-px cursor-col-resize before:absolute before:inset-y-0 before:-inset-x-2 before:content-['']\"\n          : \"h-px cursor-row-resize before:absolute before:inset-x-0 before:-inset-y-2 before:content-['']\",\n        className,\n      )}\n      {...props}\n    >\n      {withGrip ? <span aria-hidden=\"true\" className={cn(\"z-10 rounded-full border bg-background\", direction === \"horizontal\" ? \"h-6 w-2\" : \"h-2 w-6\")} /> : null}\n    </div>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "Layouts whose parts the person sizes: a list beside a detail view, an editor beside its preview, a map beside its table. For a panel docked beside the whole page use dock; for two fixed columns use split.",
    "example": "<ResizablePanelGroup defaultSizes={[30, 70]} aria-label=\"Mail\">\n  <ResizablePanel minSize={20} id=\"folders\">Folders</ResizablePanel>\n  <ResizableHandle aria-label=\"Resize the folders\" />\n  <ResizablePanel id=\"messages\">Messages</ResizablePanel>\n</ResizablePanelGroup>",
    "client": true
  }
}
