{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "accordion",
  "title": "Accordion",
  "description": "An accordion whose panels open on a transition that turns back from where it is, as flat rows or as a card whose open item breaks away. Content that changes size while open moves the rows below with it.",
  "dependencies": [
    "@ui-sdk/react",
    "@ui-sdk/core",
    "class-variance-authority"
  ],
  "registryDependencies": [
    "https://kinoui.com/r/resize.json",
    "https://kinoui.com/r/scroll.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/components/kino/accordion.tsx",
      "content": "'use client'\n\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { collapseClassName, followPanelContent } from '@/registry/lib/resize'\nimport { holdAtEdge, topEdge } from '@/registry/lib/scroll'\nimport {\n  AccordionHeader as AccordionHeaderPrimitive,\n  AccordionItem as AccordionItemPrimitive,\n  AccordionPanel as AccordionPanelPrimitive,\n  Accordion as AccordionPrimitive,\n  AccordionTrigger as AccordionTriggerPrimitive,\n} from '@ui-sdk/react/accordion'\nimport { cva } from 'class-variance-authority'\nimport {\n  type ComponentProps,\n  createContext,\n  createElement,\n  type MouseEvent,\n  type ReactNode,\n  use,\n  useEffect,\n  useRef,\n} from 'react'\n\nimport { cn } from '@/lib/utils'\n\ntype AccordionVariant = 'default' | 'card'\n\n/** Each part reads its accordion's variant here, so one nested in a panel keeps its own. */\nconst AccordionVariantContext = createContext<AccordionVariant>('default')\n\n/** The element each trigger's heading is: a level under the heading the accordion sits under. */\ntype AccordionHeading = 'h2' | 'h3' | 'h4' | 'h5' | 'h6'\n\nconst AccordionHeadingContext = createContext<AccordionHeading>('h3')\n\n/** The room left above a trigger held at the top edge, so its focus ring and its card's border show. */\nconst EDGE_GAP_PX = 8\n\n/**\n * Keeps the trigger that was pressed on screen. With one item open at a time,\n * opening an item closes the one above it, and a tall one takes the pressed\n * trigger up and out of view. The trigger rides up to the top edge and waits\n * there while the page scrolls under it. The edge is lowered by the scroller's\n * `scroll-padding-top` and the trigger's `scroll-margin-top`, for a sticky\n * header.\n */\nfunction keepPressedTriggerInView(event: MouseEvent<HTMLElement>) {\n  const root = event.currentTarget\n  const trigger =\n    event.target instanceof Element\n      ? event.target.closest<HTMLElement>('[data-slot=accordion-trigger]')\n      : null\n  if (!trigger || trigger.closest('[data-slot=accordion]') !== root) return\n  // A trigger already cut by the edge when pressed stays where it is.\n  holdAtEdge(\n    trigger,\n    root,\n    Math.min(trigger.getBoundingClientRect().top, topEdge(trigger, EDGE_GAP_PX)),\n  )\n}\n\nfunction Accordion({\n  className,\n  variant = 'default',\n  heading = 'h3',\n  onClick,\n  ...props\n}: Omit<ComponentProps<typeof AccordionPrimitive>, 'className'> & {\n  className?: string\n  variant?: AccordionVariant\n  /** Each trigger's heading level: one under the heading the accordion sits under. */\n  heading?: AccordionHeading\n}) {\n  return (\n    <AccordionHeadingContext value={heading}>\n      <AccordionVariantContext value={variant}>\n        <AccordionPrimitive\n          data-variant={variant}\n          className={cn('flex w-full min-w-0 flex-col', className)}\n          onClick={(event) => {\n            onClick?.(event)\n            keepPressedTriggerInView(event)\n          }}\n          {...props}\n        />\n      </AccordionVariantContext>\n    </AccordionHeadingContext>\n  )\n}\n\n// A card item says through variables what its card looks like: which corners are round,\n// whether its shadow shows, and whether it shares its top border with the card above.\n// The gap is the height of a spacer before the card, so the items around it move on the\n// same transition as the panel.\nconst accordionItemVariants = cva('min-w-0', {\n  variants: {\n    variant: {\n      default: 'border-b last:border-b-0',\n      card: 'relative flex flex-col [--accordion-card-bottom:0px] [--accordion-card-lift:0] [--accordion-card-overlap:-1px] [--accordion-card-top:0px] before:block before:h-0 before:shrink-0 before:transition-[height] before:duration-(--motion-layout-duration) before:ease-(--motion-layout-easing) first:[--accordion-card-overlap:0px] first:[--accordion-card-top:var(--surface-radius)] last:[--accordion-card-bottom:var(--surface-radius)] has-[+[data-slot=accordion-item][data-open]]:[--accordion-card-bottom:var(--surface-radius)] data-open:z-10 data-open:[--accordion-card-bottom:var(--surface-radius)] data-open:[--accordion-card-lift:1] data-open:[--accordion-card-top:var(--surface-radius)] not-first:data-open:before:h-[calc(var(--accordion-gap,--spacing(2))+1px)] motion-reduce:before:transition-none [[data-slot=accordion-item][data-open]+&]:[--accordion-card-top:var(--surface-radius)] [[data-slot=accordion-item][data-open]+&]:before:h-[calc(var(--accordion-gap,--spacing(2))+1px)]',\n    },\n  },\n  defaultVariants: { variant: 'default' },\n})\n\nfunction AccordionItem({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof AccordionItemPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const variant = use(AccordionVariantContext)\n  return (\n    <AccordionItemPrimitive\n      className={cn(accordionItemVariants({ variant }), className)}\n      {...props}\n    >\n      {variant === 'card' ? (\n        <div\n          data-slot='accordion-card'\n          // The shadow is a layer of its own that fades in, so nothing is painted again while it shows.\n          className='bg-card text-card-foreground relative mt-(--accordion-card-overlap) min-w-0 rounded-t-(--accordion-card-top) rounded-b-(--accordion-card-bottom) border transition-[border-radius] duration-(--motion-layout-duration) ease-(--motion-layout-easing) after:pointer-events-none after:absolute after:inset-0 after:rounded-[inherit] after:opacity-(--accordion-card-lift) after:shadow-md after:transition-opacity after:duration-(--motion-layout-duration) after:ease-(--motion-layout-easing) has-focus-visible:z-10 motion-reduce:transition-none'\n        >\n          {children}\n        </div>\n      ) : (\n        children\n      )}\n    </AccordionItemPrimitive>\n  )\n}\n\nconst accordionTriggerVariants = cva(\n  \"group/accordion-trigger text-foreground focus-visible:ring-ring/50 flex min-w-0 flex-1 items-start gap-3 text-start text-sm font-medium wrap-anywhere transition-[color,background-color,box-shadow] duration-(--motion-press-duration) ease-(--motion-press-fade-easing) focus-visible:ring-3 focus-visible:outline-hidden data-disabled:text-foreground/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&>svg]:mt-0.5\",\n  {\n    variants: {\n      variant: {\n        default: 'rounded-(--control-radius-capped) py-(--row-padding)',\n        // A card's rows are 2px tighter than flat rows, at every density.\n        card: 'not-data-open:not-data-disabled:hover:bg-muted/60 rounded-[inherit] px-(--surface-padding) py-[calc(var(--row-padding)_-_2px)]',\n      },\n    },\n    defaultVariants: { variant: 'default' },\n  },\n)\n\nconst accordionIndicator =\n  'text-muted-foreground group-hover/accordion-trigger:text-foreground group-data-disabled/accordion-trigger:text-foreground/30 ms-auto'\n\n// The indicator turns with the panel, so the two end together.\nconst accordionIndicatorTurn =\n  'origin-center transition-[rotate] duration-(--motion-layout-duration) ease-(--motion-layout-easing) group-data-open/accordion-trigger:rotate-180 motion-reduce:transition-none'\n\nfunction AccordionTrigger({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof AccordionTriggerPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const variant = use(AccordionVariantContext)\n  const heading = use(AccordionHeadingContext)\n  return (\n    <AccordionHeaderPrimitive\n      render={(headerProps) => createElement(heading, headerProps)}\n      className='flex min-w-0 rounded-[inherit]'\n    >\n      <AccordionTriggerPrimitive\n        className={cn(accordionTriggerVariants({ variant }), className)}\n        {...props}\n      >\n        {children}\n        {variant === 'card' ? (\n          // A plus whose upright bar lies down into a minus, both bars turning the same way.\n          <svg\n            data-slot='accordion-indicator'\n            aria-hidden\n            viewBox='0 0 16 16'\n            fill='none'\n            stroke='currentColor'\n            strokeWidth='1.5'\n            strokeLinecap='round'\n            className={cn(\n              accordionIndicator,\n              'transition-[color] duration-(--motion-press-duration) ease-(--motion-press-fade-easing)',\n            )}\n          >\n            <path d='M3.5 8h9' className={accordionIndicatorTurn} />\n            <path d='M3.5 8h9' className={cn(accordionIndicatorTurn, 'rotate-90')} />\n          </svg>\n        ) : (\n          <IconPlaceholder\n            lucide='ChevronDownIcon'\n            tabler='IconChevronDown'\n            hugeicons='ArrowDown01Icon'\n            phosphor='CaretDownIcon'\n            remixicon='RiArrowDownSLine'\n            data-slot='accordion-indicator'\n            aria-hidden\n            className={cn(\n              accordionIndicator,\n              'transition-[color,rotate] duration-(--motion-layout-duration) ease-[var(--motion-layout-fade-easing),var(--motion-layout-easing)] group-data-open/accordion-trigger:rotate-180 motion-reduce:transition-[color] motion-reduce:ease-(--motion-layout-fade-easing)',\n            )}\n          />\n        )}\n      </AccordionTriggerPrimitive>\n    </AccordionHeaderPrimitive>\n  )\n}\n\n// The panel's states reach only its own content, so an accordion nested in it keeps its own.\nconst accordionPanelVariants = cva(\n  cn(collapseClassName, 'text-sm [--collapse-height:var(--accordion-panel-height)]'),\n  {\n    variants: {\n      variant: {\n        // Clipped down the page only, so a focus ring inside keeps its sides.\n        // It keeps a ring's width (3px) above the first row and starts that\n        // much higher, so a focused control there keeps its whole ring and\n        // nothing moves; shut, the 3px and the pull cancel out.\n        default: '-mt-0.75 overflow-y-clip pt-0.75',\n        card: '-mt-0.75 overflow-clip rounded-b-[inherit] pt-0.75',\n      },\n    },\n    defaultVariants: { variant: 'default' },\n  },\n)\n\nconst accordionContentVariants = cva('text-muted-foreground wrap-break-word', {\n  variants: {\n    variant: {\n      default: 'pb-(--row-padding)',\n      card: 'px-(--surface-padding) pb-(--surface-padding)',\n    },\n  },\n  defaultVariants: { variant: 'default' },\n})\n\n/**\n * The content's own box. It mounts with the panel. ui-sdk sizes the panel\n * while it opens and closes, and leaves it at `auto` once open, so content\n * that grows or shrinks after that would jump: this moves the panel to the\n * new height on the same transition.\n */\nfunction AccordionPanelContent(props: ComponentProps<'div'>) {\n  const ref = useRef<HTMLDivElement>(null)\n\n  useEffect(() => {\n    const inner = ref.current\n    const panel = inner?.parentElement\n    if (!inner || !panel) return\n    return followPanelContent(panel, inner, '--accordion-panel-height')\n  }, [])\n\n  return <div ref={ref} data-slot='accordion-panel-content' {...props} />\n}\n\n/**\n * `className` goes on the content's own box, the one with the padding; the\n * other props go to ui-sdk's panel.\n */\nfunction AccordionPanel({\n  className,\n  children,\n  ...props\n}: Omit<ComponentProps<typeof AccordionPanelPrimitive>, 'className' | 'children'> & {\n  className?: string\n  children?: ReactNode\n}) {\n  const variant = use(AccordionVariantContext)\n  return (\n    <AccordionPanelPrimitive className={accordionPanelVariants({ variant })} {...props}>\n      <AccordionPanelContent\n        className={cn(accordionContentVariants({ variant }), className)}\n      >\n        {children}\n      </AccordionPanelContent>\n    </AccordionPanelPrimitive>\n  )\n}\n\nexport { Accordion, AccordionItem, AccordionTrigger, AccordionPanel }\nexport type { AccordionHeading }\n",
      "type": "registry:component",
      "target": "@components/kino/accordion.tsx"
    }
  ],
  "type": "registry:component"
}