{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-08",
  "title": "Folder",
  "description": "A folder drawn in CSS whose files fan out on hover or focus, and whose list of files opens under it on Enter or a click.",
  "dependencies": [],
  "registryDependencies": [
    "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-08.tsx",
      "content": "'use client';\n\nimport { useId, useState } from 'react';\n\nimport type { AutoplayStep } from '@/registry/ndeko/hooks/use-autoplay';\nimport { PRESS_LEAD_MS, usePress } from '@/registry/ndeko/lib/demonstration';\nimport {\n  FileArchiveIcon,\n  FileSpreadsheetIcon,\n  FileTextIcon,\n  ImageIcon,\n} from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Fold } from '@/registry/ndeko/ui/chat-motion';\nimport { LiveRegion } from '@/registry/ndeko/ui/live-region';\n\nimport { pressedShapeOf } from './_parts/pressed-shape';\nimport { useCardDemo } from './_parts/use-card-demo';\nimport { useHover, usePeek } from './_parts/use-peek';\n\nexport type FolderFileKind = 'document' | 'image' | 'sheet' | 'archive';\n\nexport type FolderFile = {\n  id: string;\n  name: string;\n  kind: FolderFileKind;\n  /** The size as it reads: \"48 KB\". */\n  size: string;\n};\n\nconst KIND_ICONS: Record<FolderFileKind, React.ReactNode> = {\n  document: <FileTextIcon />,\n  image: <ImageIcon />,\n  sheet: <FileSpreadsheetIcon />,\n  archive: <FileArchiveIcon />,\n};\n\nconst FOLDER = [\n  'group/folder relative mt-10 block h-28 w-40 shrink-0 cursor-pointer rounded-lg outline-none',\n  'transition-[scale] duration-150 ease-(--ease-out-strong) active:scale-[0.97]',\n  'focus-visible:ring-ring focus-visible:ring-offset-background focus-visible:ring-2 focus-visible:ring-offset-4',\n].join(' ');\n\nconst BACK_FILL = 'bg-[color-mix(in_oklab,var(--primary)_32%,var(--card))]';\n\nconst TAB = cn('absolute start-0 top-0 h-5 w-16 rounded-t-md', BACK_FILL);\n\nconst BACK = cn(\n  'absolute inset-x-0 top-3 bottom-0 rounded-lg rounded-ss-none',\n  BACK_FILL\n);\n\nconst SHEET = [\n  'bg-card hairline-ring ring-border absolute inset-x-6 bottom-3 flex h-[4.5rem] origin-bottom flex-col gap-1.5 rounded-md p-2.5',\n  'shadow-[0_1px_2px_rgb(0_0_0/0.04)] transition-transform duration-300 ease-(--ease-out-strong)',\n].join(' ');\n\n/** Each sheet rests tucked in the folder and has its own place in the fan. The middle one is drawn last, on top. */\nconst SHEETS = [\n  {\n    id: 'left',\n    pose: '-translate-x-1.5 -translate-y-2 -rotate-3 group-data-[fanned=true]/folder:-translate-x-10 group-data-[fanned=true]/folder:-translate-y-9 group-data-[fanned=true]/folder:-rotate-12',\n  },\n  {\n    id: 'right',\n    pose: 'translate-x-1.5 -translate-y-2 rotate-3 delay-[80ms] group-data-[fanned=true]/folder:translate-x-10 group-data-[fanned=true]/folder:-translate-y-9 group-data-[fanned=true]/folder:rotate-12',\n  },\n  {\n    id: 'middle',\n    pose: '-translate-y-3 delay-[40ms] group-data-[fanned=true]/folder:-translate-y-12',\n  },\n];\n\nconst FLAP = [\n  'hairline-ring ring-primary/30 absolute inset-x-0 bottom-0 flex h-[4.75rem] origin-bottom flex-col items-start justify-end rounded-lg p-3 text-start',\n  'bg-[color-mix(in_oklab,var(--primary)_14%,var(--card))] transition-transform duration-300 ease-(--ease-out-strong)',\n  '[transform:perspective(500px)_rotateX(0deg)] group-data-[fanned=true]/folder:[transform:perspective(500px)_rotateX(-24deg)]',\n].join(' ');\n\nfunction fileCountOf(count: number) {\n  if (count === 0) {\n    return 'No files';\n  }\n  if (count === 1) {\n    return '1 file';\n  }\n  return `${count} files`;\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-3/4 rounded-full' />\n      <span className='bg-foreground/10 h-1 rounded-full' />\n      <span className='bg-foreground/10 h-1 w-1/2 rounded-full' />\n    </span>\n  );\n}\n\nfunction FileList({ files }: { files: FolderFile[] }) {\n  if (files.length === 0) {\n    return (\n      <p className='text-muted-foreground py-3 text-center text-[13px]'>\n        This folder is empty\n      </p>\n    );\n  }\n\n  return (\n    <ul className='bg-foreground/[0.03] flex flex-col rounded-lg p-1'>\n      {files.map((file) => (\n        <li\n          key={file.id}\n          className='flex h-9 items-center gap-2.5 px-2 text-[13px]'\n        >\n          <span className='keycap-3d text-muted-foreground flex size-6 shrink-0 items-center justify-center rounded-md [&_svg]:size-3.5'>\n            {KIND_ICONS[file.kind]}\n          </span>\n          <span className='min-w-0 flex-1 truncate'>{file.name}</span>\n          <span className='text-muted-foreground text-xs tabular-nums'>\n            {file.size}\n          </span>\n        </li>\n      ))}\n    </ul>\n  );\n}\n\nexport type FolderCardProps = {\n  name: string;\n  files: FolderFile[];\n  /** Whether the list of files shows under the folder. */\n  isOpen: boolean;\n  onOpenChange: (isOpen: boolean) => void;\n  /** Fans the files out with no pointer on the folder, for a demonstration. */\n  isFanned?: boolean;\n  /** Shows the folder held down, for a demonstration that presses it. */\n  isPressed?: boolean;\n  className?: string;\n};\n\nexport function FolderCard({\n  name,\n  files,\n  isOpen,\n  onOpenChange,\n  isFanned = false,\n  isPressed = false,\n  className,\n}: FolderCardProps) {\n  const listId = useId();\n  const { isPeeking, peekHandlers } = usePeek();\n  const isHeldOpen = isFanned || isOpen;\n  const showsFan = isPeeking || isHeldOpen;\n\n  function toggle() {\n    onOpenChange(!isOpen);\n  }\n\n  return (\n    <div className={cn('flex w-full flex-col items-center gap-4', className)}>\n      <button\n        type='button'\n        aria-expanded={isOpen}\n        aria-controls={listId}\n        data-fanned={showsFan}\n        onClick={toggle}\n        className={cn(FOLDER, pressedShapeOf(isPressed))}\n        {...peekHandlers}\n      >\n        <span aria-hidden='true' className={TAB} />\n        <span aria-hidden='true' className={BACK} />\n        {SHEETS.map((sheet) => (\n          <Sheet key={sheet.id} pose={sheet.pose} />\n        ))}\n        <span className={FLAP}>\n          <span className='max-w-full truncate text-[13px] font-medium'>\n            {name}\n          </span>\n          <span className='text-foreground/70 text-xs tabular-nums'>\n            {fileCountOf(files.length)}\n          </span>\n        </span>\n      </button>\n      <Fold open={isOpen} id={listId} className='self-stretch'>\n        <FileList files={files} />\n      </Fold>\n    </div>\n  );\n}\n\nconst FILES: FolderFile[] = [\n  { id: 'logo', name: 'Logo, primary.svg', kind: 'image', size: '48 KB' },\n  { id: 'type', name: 'Type scale.pdf', kind: 'document', size: '1.2 MB' },\n  { id: 'press', name: 'Press sheet.xlsx', kind: 'sheet', size: '310 KB' },\n  { id: 'photos', name: 'Launch photos.zip', kind: 'archive', size: '86 MB' },\n  { id: 'voice', name: 'Voice and tone.pdf', kind: 'document', size: '640 KB' },\n];\n\nconst FOLDER_NAME = 'Brand kit';\n\nfunction announcementOf(isOpen: boolean) {\n  if (isOpen) {\n    const fileCount = fileCountOf(FILES.length);\n    return `${FOLDER_NAME} open, ${fileCount}`;\n  }\n  return `${FOLDER_NAME} closed`;\n}\n\nexport default function Card08() {\n  const [isOpen, setIsOpen] = useState(true);\n  const [isFanned, setIsFanned] = useState(false);\n  const [announcement, setAnnouncement] = useState('');\n  const { pressed, press } = usePress<'folder'>();\n  const { isHovered, hoverHandlers } = useHover();\n\n  function startOver() {\n    setIsOpen(true);\n    setIsFanned(false);\n  }\n\n  /** Only a person's press is said: a pointer resting on the folder pauses the demonstration, and that pause must stay silent. */\n  function openFromFolder(nextIsOpen: boolean) {\n    setIsOpen(nextIsOpen);\n    setAnnouncement(announcementOf(nextIsOpen));\n  }\n\n  const steps: AutoplayStep[] = [\n    { after: 2400, run: () => press('folder') },\n    { after: PRESS_LEAD_MS, run: () => setIsOpen(false) },\n    { after: 1500, run: () => setIsFanned(true) },\n    { after: 1400, run: () => press('folder') },\n    { after: PRESS_LEAD_MS, run: () => setIsOpen(true) },\n    { after: 400, run: () => setIsFanned(false) },\n  ];\n  const { ref, isAutoplaying } = useCardDemo(steps, {\n    loopAfter: 2000,\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\n      ref={ref}\n      className='min-h-[22.25rem] w-full max-w-[20rem]'\n      {...hoverHandlers}\n    >\n      <FolderCard\n        name={FOLDER_NAME}\n        files={FILES}\n        isOpen={isOpen}\n        onOpenChange={openFromFolder}\n        isFanned={isDemoFanned}\n        isPressed={pressed === 'folder'}\n      />\n      <LiveRegion message={announcement} />\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/card/card-08.tsx"
    },
    {
      "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"
}