{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-linear-modal",
  "title": "Linear modal",
  "description": "Feature cards that grow into a modal with their full story and a list of what they do.",
  "dependencies": [
    "@base-ui/react",
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-prefers-reduced-motion.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "components/core/linear-modal.tsx",
      "content": "'use client';\n\nimport { Dialog } from '@base-ui/react/dialog';\nimport { AnimatePresence, motion, type Transition } from 'motion/react';\nimport { useId, useRef, useState } from 'react';\n\nimport { cn } from '@/lib/utils';\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { PlusIcon, XIcon, type Icon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\n\nexport type LinearModalPoint = {\n  title: string;\n  description: string;\n  icon?: Icon;\n};\n\nexport type LinearModalFeature = {\n  id: string;\n  title: string;\n  summary: string;\n  description: string;\n  image: { src: string; alt: string };\n  points?: LinearModalPoint[];\n};\n\ntype LayoutIds = {\n  frame: string;\n  image: string;\n  title: string;\n};\n\ntype Transitions = {\n  open: Transition;\n  close: Transition;\n  content: Transition;\n};\n\nconst MOTION: Transitions = {\n  open: { type: 'spring', bounce: 0, duration: 0.36 },\n  close: { type: 'spring', bounce: 0, duration: 0.28 },\n  content: { duration: 0.2, delay: 0.12, ease: [0.23, 1, 0.32, 1] },\n};\n\nconst STILL: Transitions = {\n  open: { duration: 0 },\n  close: { duration: 0 },\n  content: { duration: 0.15 },\n};\n\nconst BACKDROP_IN: Transition = { duration: 0.2 };\n\nconst BACKDROP_OUT: Transition = { duration: 0.15 };\n\nconst CARD_RADIUS = 14;\n\nconst MODAL_RADIUS = 18;\n\nfunction transitionsOf(prefersReducedMotion: boolean | null) {\n  if (prefersReducedMotion) {\n    return STILL;\n  }\n  return MOTION;\n}\n\nfunction layoutIdsOf(scope: string, feature: LinearModalFeature): LayoutIds {\n  const prefix = `${scope}-${feature.id}`;\n  return {\n    frame: `${prefix}-frame`,\n    image: `${prefix}-image`,\n    title: `${prefix}-title`,\n  };\n}\n\nconst CARD = [\n  'group/card flex w-full cursor-pointer flex-col overflow-hidden bg-card text-left text-card-foreground',\n  'outline-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring',\n].join(' ');\n\n/*\n * Shadows go through `style`, not classes: motion corrects a style shadow while the frame scales\n * between card and dialog, where a class shadow or ring would thicken and thin on every frame.\n */\nconst CARD_SHADOW =\n  '0 1px 2px rgba(0, 0, 0, 0.06), 0 1px 1px rgba(0, 0, 0, 0.03)';\n\nconst MODAL_SHADOW = '0 24px 48px -16px rgba(0, 0, 0, 0.28)';\n\nconst PLUS_TILE = [\n  'keycap-3d grid size-7 shrink-0 place-items-center rounded-full text-muted-foreground',\n  'transition-colors duration-150 group-hover/card:text-foreground',\n].join(' ');\n\ntype FeatureCardProps = {\n  feature: LinearModalFeature;\n  ids: LayoutIds;\n  transition: Transition;\n  onOpen: (feature: LinearModalFeature, trigger: HTMLButtonElement) => void;\n};\n\nfunction FeatureCard({ feature, ids, transition, onOpen }: FeatureCardProps) {\n  function open(event: React.MouseEvent<HTMLButtonElement>) {\n    onOpen(feature, event.currentTarget);\n  }\n\n  return (\n    <motion.button\n      type='button'\n      aria-haspopup='dialog'\n      layoutId={ids.frame}\n      layoutCrossfade={false}\n      transition={transition}\n      onClick={open}\n      className={CARD}\n      style={{ borderRadius: CARD_RADIUS, boxShadow: CARD_SHADOW }}\n    >\n      <motion.img\n        layoutId={ids.image}\n        layoutCrossfade={false}\n        transition={transition}\n        src={feature.image.src}\n        alt={feature.image.alt}\n        className='aspect-video w-full object-cover'\n      />\n      <span className='flex items-end gap-3 p-4'>\n        <span className='flex min-w-0 flex-1 flex-col gap-1'>\n          <motion.span\n            layoutId={ids.title}\n            layoutCrossfade={false}\n            transition={transition}\n            className='text-foreground w-fit text-sm font-medium'\n          >\n            {feature.title}\n          </motion.span>\n          <motion.span\n            layout='position'\n            transition={transition}\n            className='text-muted-foreground text-[13px]'\n          >\n            {feature.summary}\n          </motion.span>\n        </span>\n        <motion.span\n          aria-hidden='true'\n          layout='position'\n          transition={transition}\n          className={PLUS_TILE}\n        >\n          <PlusIcon className='size-3.5' />\n        </motion.span>\n      </span>\n    </motion.button>\n  );\n}\n\nfunction PointRow({ point }: { point: LinearModalPoint }) {\n  const PointIcon = point.icon;\n\n  return (\n    <li className='flex gap-3'>\n      {PointIcon && (\n        <span className='keycap-3d text-muted-foreground grid size-8 shrink-0 place-items-center rounded-lg'>\n          <PointIcon className='size-4' />\n        </span>\n      )}\n      <span className='flex flex-col gap-0.5'>\n        <span className='text-foreground text-[13px] font-medium'>\n          {point.title}\n        </span>\n        <span className='text-muted-foreground text-[13px]'>\n          {point.description}\n        </span>\n      </span>\n    </li>\n  );\n}\n\ntype FeatureModalProps = {\n  feature: LinearModalFeature;\n  ids: LayoutIds;\n  transitions: Transitions;\n  closeLabel: string;\n  finalFocus: React.RefObject<HTMLButtonElement | null>;\n};\n\nconst MODAL = [\n  'relative m-auto flex w-full max-w-xl flex-col overflow-hidden bg-card text-card-foreground outline-none',\n].join(' ');\n\nfunction FeatureModal({\n  feature,\n  ids,\n  transitions,\n  closeLabel,\n  finalFocus,\n}: FeatureModalProps) {\n  const points = feature.points ?? [];\n  const hasPoints = points.length > 0;\n\n  return (\n    <Dialog.Portal keepMounted>\n      <Dialog.Backdrop\n        className='fixed inset-0 z-50 bg-black/40 backdrop-blur-xs'\n        render={\n          <motion.div\n            initial={{ opacity: 0 }}\n            animate={{ opacity: 1, transition: BACKDROP_IN }}\n            exit={{ opacity: 0, transition: BACKDROP_OUT }}\n          />\n        }\n      />\n      <Dialog.Viewport className='fixed inset-0 z-50 flex overflow-y-auto p-4 sm:p-8'>\n        <Dialog.Popup\n          finalFocus={finalFocus}\n          className={MODAL}\n          render={\n            <motion.div\n              layoutId={ids.frame}\n              layoutCrossfade={false}\n              transition={transitions.open}\n              style={{ borderRadius: MODAL_RADIUS, boxShadow: MODAL_SHADOW }}\n            />\n          }\n        >\n          <motion.img\n            layoutId={ids.image}\n            layoutCrossfade={false}\n            transition={transitions.open}\n            src={feature.image.src}\n            alt={feature.image.alt}\n            className='aspect-video w-full object-cover'\n          />\n          <Dialog.Close\n            aria-label={closeLabel}\n            render={\n              <Button\n                variant='outline'\n                size='icon-sm'\n                className='absolute top-3 right-3'\n              />\n            }\n          >\n            <XIcon />\n          </Dialog.Close>\n          <div className='flex flex-col gap-2 p-6'>\n            <Dialog.Title\n              className='text-foreground w-fit text-lg font-semibold text-balance'\n              render={\n                <motion.h2\n                  layoutId={ids.title}\n                  layoutCrossfade={false}\n                  transition={transitions.open}\n                />\n              }\n            >\n              {feature.title}\n            </Dialog.Title>\n            <motion.div\n              layout='position'\n              initial={{ opacity: 0 }}\n              animate={{ opacity: 1, transition: transitions.content }}\n              exit={{ opacity: 0, transition: { duration: 0.08 } }}\n              className='flex flex-col gap-5'\n            >\n              <Dialog.Description className='text-muted-foreground text-[13px] leading-relaxed'>\n                {feature.description}\n              </Dialog.Description>\n              {hasPoints && (\n                <ul className='flex flex-col gap-4'>\n                  {points.map((point) => (\n                    <PointRow key={point.title} point={point} />\n                  ))}\n                </ul>\n              )}\n            </motion.div>\n          </div>\n        </Dialog.Popup>\n      </Dialog.Viewport>\n    </Dialog.Portal>\n  );\n}\n\nexport type LinearModalProps = {\n  features: LinearModalFeature[];\n  className?: string;\n  closeLabel?: string;\n};\n\nexport function LinearModal({\n  features,\n  className,\n  closeLabel = 'Close',\n}: LinearModalProps) {\n  const prefersReducedMotion = usePrefersReducedMotion();\n  const scope = useId();\n  const [active, setActive] = useState<LinearModalFeature | null>(null);\n  const triggerRef = useRef<HTMLButtonElement | null>(null);\n  const transitions = transitionsOf(prefersReducedMotion);\n  const isOpen = active !== null;\n\n  function openFeature(\n    feature: LinearModalFeature,\n    trigger: HTMLButtonElement\n  ) {\n    triggerRef.current = trigger;\n    setActive(feature);\n  }\n\n  function changeOpen(open: boolean) {\n    if (open) {\n      return;\n    }\n    setActive(null);\n  }\n\n  return (\n    <>\n      <div className={cn('grid gap-3 sm:grid-cols-2', className)}>\n        {features.map((feature) => (\n          <FeatureCard\n            key={feature.id}\n            feature={feature}\n            ids={layoutIdsOf(scope, feature)}\n            transition={transitions.close}\n            onOpen={openFeature}\n          />\n        ))}\n      </div>\n      <Dialog.Root open={isOpen} onOpenChange={changeOpen}>\n        <AnimatePresence>\n          {active && (\n            <FeatureModal\n              key={active.id}\n              feature={active}\n              ids={layoutIdsOf(scope, active)}\n              transitions={transitions}\n              closeLabel={closeLabel}\n              finalFocus={triggerRef}\n            />\n          )}\n        </AnimatePresence>\n      </Dialog.Root>\n    </>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/core/linear-modal.tsx"
    }
  ],
  "categories": [
    "motion"
  ],
  "type": "registry:component"
}