{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "panel",
  "title": "Panel",
  "description": "What Dialog, Alert dialog and Drawer share: the dim behind them, a box that follows its content’s height with the footer on its edge, the close button, and the header, title, description, body and footer; and the sheet look a Popover takes on a phone. Card takes its title and description.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/grip.json",
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/scroll.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/panel.tsx",
      "content": "'use client'\n\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { gripClassName } from '@/registry/lib/grip'\nimport { followHeight } from '@/registry/lib/resize'\nimport {\n  edgeFadeClassName,\n  followEdges,\n  scrollRegionRingClassName,\n  useScrollRegion as useSharedScrollRegion,\n} from '@/registry/lib/scroll'\nimport { type ReactNode, type RefObject, useEffect, useRef } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * What Dialog, Alert dialog, Drawer and a Popover shown as a sheet\n * share: the dim, a box that follows its content's height, the close\n * button, the handle, and the header, title, description, body and footer. Each component names its own parts with\n * `data-slot`; the parts the panel itself looks for carry `data-panel`\n * (`body`, `footer`, `handle`), so the same selectors work in all four. A\n * component that brings its own footer into a panel, as a command menu in a\n * dialog does, marks the element around it `data-panel=parts`.\n */\n\n/**\n * The dim behind a panel. It blurs what is behind it where the browser can.\n * iOS: an absolute backdrop as tall as the screen covers the whole visible\n * viewport, a fixed one doesn't.\n */\nexport const panelDimClassName =\n  'fixed inset-0 isolate z-50 bg-black/15 supports-backdrop-filter:backdrop-blur-xs supports-[-webkit-touch-callout:none]:absolute supports-[-webkit-touch-callout:none]:min-h-dvh dark:bg-black/45'\n\n/** The dim behind a dialog, which fades in and out with it. A drawer's follows the drawer instead. */\nexport const panelOverlayClassName = cn(\n  panelDimClassName,\n  'transition-opacity duration-(--motion-enter-duration) ease-(--motion-enter-easing) data-ending-style:opacity-0 data-ending-style:duration-(--motion-exit-duration) data-ending-style:ease-(--motion-exit-easing) data-starting-style:opacity-0',\n)\n\n/**\n * The same dim and blur behind a popup ui-sdk shows as a sheet, such as a\n * Popover on a phone: ui-sdk paints the `::backdrop` of the sheet's host, its\n * parent, with `--sheet-backdrop`, and fades it in and out.\n */\nexport const panelSheetBackdropClassName =\n  '[--sheet-backdrop:--alpha(var(--color-black)/15%)] dark:[--sheet-backdrop:--alpha(var(--color-black)/45%)] supports-backdrop-filter:[*:has(>&[data-presentation=sheet])::backdrop]:backdrop-blur-xs'\n\n/**\n * The dim over a dialog's surface while another dialog opens on top of it\n * (ui-sdk marks the content around the surface `data-nested-open`). Only the\n * content's own surface dims: the dialog on top sits inside it. A drawer's\n * dim follows the drawer on top instead (`drawer.tsx`).\n */\nexport const panelStackDimClassName =\n  'before:pointer-events-none before:absolute before:inset-0 before:z-20 before:rounded-[inherit] before:bg-black/0 before:transition-colors before:duration-(--motion-enter-duration) before:ease-(--motion-enter-fade-easing) [[data-nested-open]>&]:before:bg-black/10 dark:[[data-nested-open]>&]:before:bg-black/40'\n\n/**\n * A dialog's box on the screen's top layer: it rises `--dialog-rise` into\n * the centre, and steps back while another dialog is open on top of it. On a\n * screen under `sm` it is a sheet that slides up from the bottom edge. A\n * strip under it, in the colour the sheet ends in, covers the gap, the ring\n * and the shadow when a spring overshoots. Laid out `inline`, it sits above\n * its own dim, which ui-sdk then renders after it: one step over the dim's\n * `z-50`. Holds a `PanelSurface`.\n */\nexport const panelDialogClassName =\n  'group/panel fixed inset-0 z-51 m-auto flex h-fit w-[calc(100%-(--spacing(8)))] max-w-md min-w-0 flex-col transition-[translate,scale,opacity] duration-(--motion-enter-duration) ease-(--motion-enter-easing) focus-visible:outline-hidden data-ending-style:translate-y-[calc(var(--dialog-rise,1rem)/2)] data-ending-style:scale-98 data-ending-style:opacity-0 data-ending-style:duration-(--motion-exit-duration) data-ending-style:ease-(--motion-exit-easing) data-nested-open:scale-(--dialog-recede-scale,0.95) data-starting-style:translate-y-[var(--dialog-rise,1rem)] data-starting-style:scale-97 data-starting-style:opacity-0 motion-reduce:transition-[opacity] motion-reduce:data-ending-style:translate-y-0! motion-reduce:data-ending-style:scale-100! motion-reduce:data-ending-style:opacity-0! motion-reduce:data-starting-style:translate-y-0! motion-reduce:data-starting-style:scale-100! motion-reduce:data-starting-style:opacity-0! max-sm:mb-0 max-sm:w-full max-sm:max-w-none max-sm:origin-bottom max-sm:after:absolute max-sm:after:inset-x-0 max-sm:after:top-full max-sm:after:h-24 max-sm:after:bg-background max-sm:has-data-[panel=footer]:after:bg-(--panel-footer) max-sm:data-ending-style:translate-y-full max-sm:data-ending-style:scale-100 max-sm:data-ending-style:opacity-100 max-sm:data-starting-style:translate-y-full max-sm:data-starting-style:scale-100 max-sm:data-starting-style:opacity-100'\n\n/**\n * A panel's box on the bottom edge, as wide as the screen up to 40rem, its\n * top corners rounded. A strip under it, in its colour, covers the gap when\n * a spring overshoots. Starts with a `PanelHandle`.\n */\nexport const panelSheetClassName =\n  'bg-background text-foreground relative flex w-full flex-col rounded-t-(--surface-radius-lg) border-t text-sm shadow-xl after:absolute after:inset-x-0 after:top-full after:h-12 after:bg-inherit forced-colors:outline'\n\n/**\n * A popup of ui-sdk's shown as a sheet, such as a Popover's or a Select's on\n * a phone: on its content, as wide as the screen up to 40rem and clear of the\n * screen's top. Beside `panelSheetBackdropClassName`.\n */\nexport const popupSheetClassName =\n  'data-[presentation=sheet]:max-h-[calc(100dvh-(--spacing(12)))] data-[presentation=sheet]:w-full data-[presentation=sheet]:max-w-160 data-[presentation=sheet]:self-center'\n\n/** The panel of such a sheet, clear of the safe area at its foot. Starts with a `PanelHandle`. */\nexport const popupSheetPanelClassName = cn(\n  panelSheetClassName,\n  'pb-[env(safe-area-inset-bottom)]',\n)\n\n/** The bar at the top of a sheet that says it can be dragged. */\nexport function PanelHandle({ className }: { className?: string }) {\n  return (\n    <div\n      data-panel='handle'\n      aria-hidden\n      className={cn('flex h-5 shrink-0 items-end justify-center', className)}\n    >\n      <span className={cn(gripClassName, 'h-1 w-10')} />\n    </div>\n  )\n}\n\n/** The close button's place: 10px nearer the corner than the content, lower under a drawer's handle. */\nexport const panelCloseClassName =\n  'text-muted-foreground absolute end-[calc(var(--surface-padding-lg)_-_10px)] top-[calc(var(--surface-padding-lg)_-_10px)] group-has-data-[panel=handle]/panel-surface:top-[calc(var(--surface-padding-lg)_-_10px_+_--spacing(3))]'\n\nexport function PanelCloseIcon() {\n  return (\n    <IconPlaceholder\n      lucide='XIcon'\n      tabler='IconX'\n      hugeicons='Cancel01Icon'\n      phosphor='XIcon'\n      remixicon='RiCloseLine'\n      aria-hidden\n    />\n  )\n}\n\n/**\n * A dialog's surface. When its content changes height while it is open, the\n * box resizes and the footer stays on its bottom edge. `closeButton` goes\n * inside what scrolls, so it leaves with the header when the whole dialog\n * scrolls.\n */\nexport function PanelSurface({\n  closeButton,\n  children,\n}: {\n  closeButton?: ReactNode\n  children: ReactNode\n}) {\n  const surfaceRef = useRef<HTMLDivElement>(null)\n  const innerRef = useRef<HTMLDivElement>(null)\n  const scrollRegion = useScrollRegion(innerRef)\n  useFollowHeight(surfaceRef, innerRef)\n\n  return (\n    <div\n      ref={surfaceRef}\n      data-slot='panel-surface'\n      data-close-button={closeButton ? '' : undefined}\n      className={cn(\n        'group/panel-surface bg-background text-foreground ring-foreground/10 @container relative overflow-clip rounded-(--surface-radius) text-sm shadow-xl ring-1 transition-[height] duration-(--motion-layout-duration) ease-(--motion-layout-easing) motion-reduce:transition-none forced-colors:outline max-sm:rounded-b-none',\n        panelStackDimClassName,\n        panelCloseRoomClassName,\n      )}\n    >\n      {/*\n       * As tall as the screen less a margin: past that, the body scrolls\n       * between the header and the footer. On a screen under 28rem tall that\n       * would leave the body a slit, so the whole dialog scrolls instead, as\n       * it does when there is no body. The screen is the window, or for a\n       * dialog laid out `inline`, the size container it sits in, such as a\n       * preview's frame. A form around the parts takes no box, so they still\n       * lay out here.\n       */}\n      <div\n        ref={innerRef}\n        {...scrollRegion}\n        className='focus-visible:ring-ring/50 relative flex max-h-[calc(100cqh-(--spacing(8)))] scrollbar-thin flex-col overscroll-contain rounded-[inherit] focus-visible:ring-3 focus-visible:outline-hidden focus-visible:-outline-offset-2 focus-visible:ring-inset max-sm:max-h-[calc(100cqh-(--spacing(12)))] max-sm:pb-[env(safe-area-inset-bottom)] not-has-data-[panel=body]:overflow-y-auto *:[form]:contents [@media(height<28rem)]:overflow-y-auto [@container_(height<28rem)]:overflow-y-auto'\n      >\n        {children}\n        {closeButton}\n      </div>\n    </div>\n  )\n}\n\n/**\n * The header ends 6px short of the close button, by the room its surface\n * keeps for one (`panelCloseRoomClassName`), and sits closer under a\n * drawer's handle. Above a body it gives back the ring's room the body keeps.\n */\n/**\n * The room a surface's header leaves for its close button. Every surface sets\n * it, so a dialog opened inside another takes its own, never its parent's.\n */\nexport const panelCloseRoomClassName =\n  '[--panel-close-room:0px] data-close-button:[--panel-close-room:calc(var(--control-height-sm)-4px)]'\n\nexport const panelHeaderClassName =\n  'flex shrink-0 flex-col gap-1.5 p-(--surface-padding-lg) pe-[calc(var(--surface-padding-lg)+var(--panel-close-room,0px))] [[data-panel=handle]+&]:pt-2 [&:has(+[data-panel=body])]:pb-[calc(var(--surface-padding-lg)_-_--spacing(0.75))]'\n\n/** A long unbroken word breaks rather than run out of the panel. */\nexport const panelTitleClassName =\n  'text-base leading-snug font-medium text-balance wrap-anywhere'\n\nexport const panelDescriptionClassName =\n  'text-muted-foreground *:[a]:hover:text-foreground text-sm text-pretty *:[a]:underline *:[a]:underline-offset-3'\n\n/**\n * The box around what scrolls between the header and the footer. It draws\n * the scroller's ring, inside, while the scroller takes focus, because the\n * scroller's fading edges would fade a ring of its own.\n */\nexport const panelBodyFrameClassName = cn(\n  'flex min-h-0 flex-1 flex-col',\n  scrollRegionRingClassName,\n)\n\n/**\n * What scrolls between the header and the footer, its edges fading while\n * there is more past them (`useScrollRegion`).\n * A scroller clips what pokes past its edge, so it keeps a ring's width (3px)\n * above its content, and the header above it gives that much back: a focused\n * control on the first row keeps its whole ring, and nothing moves.\n */\nexport const panelBodyClassName = cn(\n  'scrollbar-thin pt-0.75 min-h-0 flex-1 overflow-y-auto overscroll-contain focus-visible:outline-hidden',\n  edgeFadeClassName,\n)\n\nexport const panelBodyContentClassName =\n  'flex flex-col gap-(--surface-gap) px-(--surface-padding-lg) pb-(--surface-padding-lg)'\n\n/**\n * A solid tint, `--panel-footer`: while the box resizes, the footer passes\n * over the content. On the bottom edge it runs on under the home indicator.\n */\nexport const panelFooterClassName =\n  'relative flex shrink-0 flex-col-reverse gap-2 border-t bg-(--panel-footer) px-(--surface-padding-lg) py-(--surface-padding) transition-[translate] duration-(--motion-layout-duration) ease-(--motion-layout-easing) after:absolute after:inset-x-0 after:top-full after:h-[env(safe-area-inset-bottom)] after:bg-inherit motion-reduce:transition-none @xs:flex-row @xs:flex-wrap-reverse @xs:justify-end'\n\n/** The footer's tint, set on the panel. */\nexport const panelFooterTint =\n  '[--panel-footer:color-mix(in_oklab,var(--muted)_50%,var(--background))]'\n\nconst panelOf = (scroller: HTMLElement) =>\n  scroller.closest<HTMLElement>('[role=dialog], [role=alertdialog]')\n\nconst panelTitleOf = (scroller: HTMLElement) =>\n  panelOf(scroller)?.getAttribute('aria-labelledby')\n\n/**\n * The props of a panel's body while its content is taller than it: it takes\n * focus as a region named by the panel's title, and hands focus to the panel\n * when it stops scrolling. Its edges fade while there is more past them.\n */\nexport function useScrollRegion(\n  scrollerRef: RefObject<HTMLElement | null>,\n  contentRef?: RefObject<HTMLElement | null>,\n) {\n  useEffect(() => {\n    const scroller = scrollerRef.current\n    if (!scroller) return\n    return followEdges(scroller, '--scroll-fade', contentRef?.current ?? undefined)\n  }, [scrollerRef, contentRef])\n  return useSharedScrollRegion(scrollerRef, {\n    contentRef,\n    labelledBy: panelTitleOf,\n    refocus: panelOf,\n  })\n}\n\n/** While `follows`, the surface moves to the inner box's height whenever that changes. */\nexport function useFollowHeight(\n  surfaceRef: RefObject<HTMLElement | null>,\n  innerRef: RefObject<HTMLElement | null>,\n  follows = true,\n) {\n  useEffect(() => {\n    const surface = surfaceRef.current\n    const inner = innerRef.current\n    if (!follows || !surface || !inner) return\n    // The footer is already laid out at the new bottom edge, so it starts at\n    // the old one and moves with the edge; where the whole panel scrolls, the\n    // footer is inside what scrolls and stays.\n    return followHeight(surface, inner, {\n      moving: (from, to) => {\n        inner.style.overflow = ''\n        const footer =\n          inner.scrollHeight > inner.clientHeight\n            ? null\n            : inner.querySelector<HTMLElement>(\n                ':scope > [data-panel=footer], :scope > :is(form, [data-panel=parts]) > [data-panel=footer]',\n              )\n        if (!footer) return undefined\n        return (start) => {\n          // The old bottom edge can be outside what scrolls on a short screen.\n          if (start) inner.style.overflow = 'visible'\n          footer.style.transition = start ? 'none' : ''\n          footer.style.translate = start ? `0 ${from - to}px` : ''\n        }\n      },\n      settled: () => {\n        inner.style.overflow = ''\n      },\n    })\n  }, [surfaceRef, innerRef, follows])\n}\n",
      "type": "registry:lib",
      "target": "@lib/panel.tsx"
    }
  ],
  "type": "registry:lib"
}