{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-10",
  "title": "Paper stack",
  "description": "A file card whose sheets of paper and two profile cards rise and fan out behind it on hover or focus, and stay out on a click.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/avatar.json",
    "https://ui.ndekocode.dev/r/chat-motion.json",
    "https://ui.ndekocode.dev/r/demonstration.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/live-region.json",
    "https://ui.ndekocode.dev/r/theme.json",
    "https://ui.ndekocode.dev/r/use-autoplay.json",
    "https://ui.ndekocode.dev/r/use-kept-height.json",
    "https://ui.ndekocode.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/ndeko/components/card/card-10.tsx",
      "content": "'use client';\n\nimport { useState } from 'react';\n\nimport type { AutoplayStep } from '@/registry/ndeko/hooks/use-autoplay';\nimport { PRESS_LEAD_MS, usePress } from '@/registry/ndeko/lib/demonstration';\nimport { FileTextIcon, PinIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Avatar } from '@/registry/ndeko/ui/avatar';\nimport { Swap } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { PEOPLE } from './_parts/people';\nimport { pressedShapeOf } from './_parts/pressed-shape';\nimport { useCardDemo } from './_parts/use-card-demo';\nimport { useHover, usePeek } from './_parts/use-peek';\n\nexport type PaperFile = {\n  name: string;\n  /** The kind and the size as they read: \"PDF\", \"2.4 MB\". */\n  kind: string;\n  size: string;\n  /** When it last changed, as the card shows it: \"Edited 2h ago\". */\n  edited: string;\n};\n\nexport type PaperPerson = {\n  id: string;\n  name: string;\n  role: string;\n};\n\ntype GemStyle = React.CSSProperties & { '--gem': string };\n\nconst FILE_GEM: GemStyle = { '--gem': 'var(--primary)' };\n\nconst STACK = [\n  'group/stack @container relative block h-60 w-full cursor-pointer rounded-xl text-start outline-none',\n  'transition-[scale] duration-150 ease-(--ease-out-strong) active:scale-[0.98]',\n  'focus-visible:ring-ring focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-4',\n].join(' ');\n\n/** A piece rises first and turns a moment later: the second delay is the one of its rotation. */\nconst MOVING = [\n  'origin-bottom transition-[translate,rotate] duration-300 ease-(--ease-out-strong)',\n  '[transition-delay:0ms,70ms]',\n].join(' ');\n\nconst SHEET = cn(\n  'bg-card hairline-ring ring-border absolute inset-x-14 bottom-4 flex h-32 flex-col gap-2 rounded-lg p-3 shadow-[0_1px_2px_rgb(0_0_0/0.04)]',\n  MOVING\n);\n\n/** Two profile cards fan out side by side, so they narrow under 20rem to keep the names in the clear. */\nconst PROFILE = cn(\n  'bg-card hairline-ring ring-border absolute bottom-24 flex h-14 w-36 items-center gap-2 rounded-lg p-2 shadow-[0_1px_2px_rgb(0_0_0/0.04)] @max-xs:w-32',\n  MOVING\n);\n\n/** Each sheet rests behind the card with its top showing, and has its own place in the fan. */\nconst SHEETS = [\n  {\n    id: 'left',\n    pose: '-translate-y-3 -rotate-2 group-data-[fanned=true]/stack:-translate-x-6 group-data-[fanned=true]/stack:-translate-y-16 group-data-[fanned=true]/stack:rotate-[-8deg]',\n  },\n  {\n    id: 'right',\n    pose: '-translate-y-3 rotate-2 group-data-[fanned=true]/stack:translate-x-6 group-data-[fanned=true]/stack:-translate-y-16 group-data-[fanned=true]/stack:rotate-[8deg]',\n  },\n  {\n    id: 'middle',\n    pose: '-translate-y-5 group-data-[fanned=true]/stack:-translate-y-20',\n  },\n];\n\nconst PROFILE_POSES = [\n  'start-7 -rotate-6 group-data-[fanned=true]/stack:-translate-x-5 group-data-[fanned=true]/stack:-translate-y-12 group-data-[fanned=true]/stack:rotate-[-10deg] @max-3xs:start-5',\n  'end-7 rotate-6 group-data-[fanned=true]/stack:translate-x-5 group-data-[fanned=true]/stack:-translate-y-12 group-data-[fanned=true]/stack:rotate-[10deg] @max-3xs:end-5',\n];\n\nfunction Sheet({ pose }: { pose: string }) {\n  return (\n    <span aria-hidden='true' className={cn(SHEET, pose)}>\n      <span className='bg-foreground/10 h-1 w-2/3 rounded-full' />\n      <span className='bg-foreground/10 h-1 rounded-full' />\n      <span className='bg-foreground/10 h-1 w-5/6 rounded-full' />\n    </span>\n  );\n}\n\nfunction ProfileCard({ person, pose }: { person: PaperPerson; pose: string }) {\n  return (\n    <span aria-hidden='true' className={cn(PROFILE, pose)}>\n      <Avatar seed={person.name} className='size-7 @max-xs:size-6' />\n      <span className='min-w-0'>\n        <span className='block truncate text-xs font-medium'>\n          {person.name}\n        </span>\n        <span className='text-muted-foreground block truncate text-xs'>\n          {person.role}\n        </span>\n      </span>\n    </span>\n  );\n}\n\nfunction sharedWithOf(people: PaperPerson[]) {\n  if (people.length === 0) {\n    return 'not shared yet';\n  }\n  const names = people.map((person) => person.name);\n  const list = names.join(' and ');\n  return `shared with ${list}`;\n}\n\nexport type PaperStackProps = {\n  file: PaperFile;\n  /** The people the file is shared with. The first two have their card behind it. */\n  people: PaperPerson[];\n  /** Whether the stack stays fanned out once the pointer has left. */\n  isPinned: boolean;\n  onPinnedChange: (isPinned: boolean) => void;\n  /** Fans the stack out with no pointer on it, for a demonstration. */\n  isFanned?: boolean;\n  /** Shows the stack held down, for a demonstration that presses it. */\n  isPressed?: boolean;\n  className?: string;\n};\n\nexport function PaperStack({\n  file,\n  people,\n  isPinned,\n  onPinnedChange,\n  isFanned = false,\n  isPressed = false,\n  className,\n}: PaperStackProps) {\n  const { isPeeking, peekHandlers } = usePeek();\n  const isHeldOpen = isFanned || isPinned;\n  const showsFan = isPeeking || isHeldOpen;\n  const shownPeople = people.slice(0, PROFILE_POSES.length);\n  const sharedWith = sharedWithOf(people);\n  const label = `${file.name}, ${sharedWith}. Keep the papers fanned out`;\n\n  function togglePinned() {\n    onPinnedChange(!isPinned);\n  }\n\n  return (\n    <button\n      type='button'\n      aria-pressed={isPinned}\n      aria-label={label}\n      data-fanned={showsFan}\n      onClick={togglePinned}\n      className={cn(STACK, pressedShapeOf(isPressed), className)}\n      {...peekHandlers}\n    >\n      {SHEETS.map((sheet) => (\n        <Sheet key={sheet.id} pose={sheet.pose} />\n      ))}\n      {shownPeople.map((person, index) => (\n        <ProfileCard\n          key={person.id}\n          person={person}\n          pose={PROFILE_POSES[index]}\n        />\n      ))}\n      <span className='bg-card hairline-ring ring-border absolute inset-x-10 bottom-0 flex h-36 flex-col justify-between rounded-xl p-4 shadow-[0_1px_2px_rgb(0_0_0/0.04)] @max-xs:inset-x-4'>\n        <span className='flex items-start gap-3'>\n          <span\n            style={FILE_GEM}\n            className='gem-plate flex size-9 shrink-0 items-center justify-center rounded-lg'\n          >\n            <FileTextIcon className='size-4' />\n          </span>\n          <span className='min-w-0 flex-1'>\n            <span className='line-clamp-2 text-[13px] font-medium'>\n              {file.name}\n            </span>\n            <span className='text-muted-foreground block truncate text-xs tabular-nums'>\n              {file.kind} · {file.size}\n            </span>\n          </span>\n          <Swap swapKey={String(isPinned)} className='mt-0.5'>\n            {isPinned && (\n              <PinIcon\n                fill='currentColor'\n                className='text-primary-ink size-4'\n              />\n            )}\n            {!isPinned && <PinIcon className='text-muted-foreground size-4' />}\n          </Swap>\n        </span>\n        <span className='flex items-center justify-between gap-2'>\n          <span className='flex items-center'>\n            {people.map((person) => (\n              <Avatar\n                key={person.id}\n                seed={person.name}\n                className='ring-card -ms-1.5 size-5 ring-2 first:ms-0'\n              />\n            ))}\n          </span>\n          <span className='text-muted-foreground truncate text-xs'>\n            {file.edited}\n          </span>\n        </span>\n      </span>\n    </button>\n  );\n}\n\nconst FILE: PaperFile = {\n  name: 'Board report, third quarter.pdf',\n  kind: 'PDF',\n  size: '2.4 MB',\n  edited: 'Edited 2h ago',\n};\n\nconst SHARED_WITH: PaperPerson[] = [PEOPLE.amara, PEOPLE.jonas];\n\nfunction announcementOf(isPinned: boolean) {\n  if (isPinned) {\n    return 'The papers stay fanned out';\n  }\n  return 'The papers are back behind the card';\n}\n\nexport default function Card10() {\n  const [isPinned, setIsPinned] = useState(false);\n  const [isFanned, setIsFanned] = useState(false);\n  const [announcement, setAnnouncement] = useState('');\n  const { pressed, press } = usePress<'stack'>();\n  const { isHovered, hoverHandlers } = useHover();\n\n  function startOver() {\n    setIsPinned(false);\n    setIsFanned(false);\n  }\n\n  /** Only a person's press is said: a pointer resting on the stack pauses the demonstration, and that pause must stay silent. */\n  function pinFromStack(nextIsPinned: boolean) {\n    setIsPinned(nextIsPinned);\n    setAnnouncement(announcementOf(nextIsPinned));\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 1500, run: () => setIsFanned(true) },\n    { after: 1700, run: () => press('stack') },\n    { after: PRESS_LEAD_MS, run: () => setIsPinned(true) },\n    { after: 500, run: () => setIsFanned(false) },\n    { after: 1900, run: () => press('stack') },\n    { after: PRESS_LEAD_MS, run: () => setIsPinned(false) },\n  ];\n  const { ref, isAutoplaying } = useCardDemo(steps, {\n    loopAfter: 1400,\n    onReset: startOver,\n    isEnabled: !isHovered,\n  });\n  /** A pointer on the piece only pauses the demonstration: its fan holds then, and lets go once a person took over. */\n  const holdsDemoPose = isAutoplaying || isHovered;\n  const isDemoFanned = isFanned && holdsDemoPose;\n\n  return (\n    <div ref={ref} className='min-h-60 w-full max-w-[20rem]' {...hoverHandlers}>\n      <PaperStack\n        file={FILE}\n        people={SHARED_WITH}\n        isPinned={isPinned}\n        onPinnedChange={pinFromStack}\n        isFanned={isDemoFanned}\n        isPressed={pressed === 'stack'}\n      />\n      <LiveRegion message={announcement} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/card/card-10.tsx"
    },
    {
      "path": "registry/ndeko/components/card/_parts/people.ts",
      "content": "export type Person = {\n  id: string;\n  name: string;\n  role: string;\n  company: string;\n};\n\n/** The invented people of the card demos. The same person keeps the same picture on every card. */\nexport const PEOPLE = {\n  amara: {\n    id: 'amara',\n    name: 'Amara Diallo',\n    role: 'Product lead',\n    company: 'Halden Works',\n  },\n  jonas: {\n    id: 'jonas',\n    name: 'Jonas Weber',\n    role: 'Staff engineer',\n    company: 'Brightwater',\n  },\n  mei: {\n    id: 'mei',\n    name: 'Mei Tanaka',\n    role: 'Design director',\n    company: 'Kiln Studio',\n  },\n  rafael: {\n    id: 'rafael',\n    name: 'Rafael Ortega',\n    role: 'Head of support',\n    company: 'Tallyard',\n  },\n  ingrid: {\n    id: 'ingrid',\n    name: 'Ingrid Solheim',\n    role: 'Finance manager',\n    company: 'Quillhouse',\n  },\n} satisfies Record<string, Person>;\n",
      "type": "registry:component",
      "target": "components/card/_parts/people.ts"
    },
    {
      "path": "registry/ndeko/components/card/_parts/pressed-shape.ts",
      "content": "/**\n * A drawn object a demonstration presses, a folder or a pass, has no fill to darken: the press\n * shows as scale alone, and deeper than under a finger, so it reads from across the page.\n */\nconst PRESSED_SHAPE = 'scale-[0.95]';\n\nexport function pressedShapeOf(isPressed: boolean) {\n  if (isPressed) {\n    return PRESSED_SHAPE;\n  }\n  return undefined;\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/pressed-shape.ts"
    },
    {
      "path": "registry/ndeko/components/card/_parts/use-card-demo.ts",
      "content": "'use client';\n\nimport {\n  useAutoplay,\n  type AutoplayOptions,\n  type AutoplayStep,\n} from '@/registry/ndeko/hooks/use-autoplay';\nimport { useKeptHeight } from '@/registry/ndeko/hooks/use-kept-height';\n\n/**\n * What every card demo shares: the demonstration, and the box that keeps its tallest height so a\n * round never moves the page.\n */\nexport function useCardDemo(\n  steps: readonly AutoplayStep[],\n  options?: AutoplayOptions\n) {\n  const demo = useAutoplay(steps, options);\n  const { ref } = demo;\n\n  useKeptHeight(ref);\n\n  return demo;\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/use-card-demo.ts"
    },
    {
      "path": "registry/ndeko/components/card/_parts/use-peek.ts",
      "content": "'use client';\n\nimport { useState } from 'react';\n\n/** Whether a pointer rests on an element. A finger does not hover, so touch is left to the press of the piece. */\nexport function useHover() {\n  const [isHovered, setIsHovered] = useState(false);\n\n  function hoverStarts(event: React.PointerEvent<HTMLElement>) {\n    if (event.pointerType !== 'touch') {\n      setIsHovered(true);\n    }\n  }\n\n  function hoverEnds() {\n    setIsHovered(false);\n  }\n\n  const hoverHandlers = {\n    onPointerEnter: hoverStarts,\n    onPointerLeave: hoverEnds,\n  };\n\n  return { isHovered, hoverHandlers };\n}\n\n/**\n * Whether a person looks closer at an element: the pointer rests on it, or the keyboard brought\n * focus to it. A press with a mouse also focuses a button, and that is not a closer look.\n */\nexport function usePeek() {\n  const { isHovered, hoverHandlers } = useHover();\n  const [isFocused, setIsFocused] = useState(false);\n\n  function focusEnters(event: React.FocusEvent<HTMLElement>) {\n    const isKeyboardFocus = event.target.matches(':focus-visible');\n    setIsFocused(isKeyboardFocus);\n  }\n\n  function focusLeaves() {\n    setIsFocused(false);\n  }\n\n  const isPeeking = isHovered || isFocused;\n  const peekHandlers = {\n    ...hoverHandlers,\n    onFocus: focusEnters,\n    onBlur: focusLeaves,\n  };\n\n  return { isPeeking, peekHandlers };\n}\n",
      "type": "registry:component",
      "target": "components/card/_parts/use-peek.ts"
    }
  ],
  "categories": [
    "components",
    "card"
  ],
  "type": "registry:component"
}