{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "aside-07",
  "title": "Keyboard shortcuts",
  "description": "Shortcuts grouped by area, filtered as you type with the match highlighted and rows that fold away",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://ui.ndekocode.dev/r/button.json",
    "https://ui.ndekocode.dev/r/icons.json",
    "https://ui.ndekocode.dev/r/input.json",
    "https://ui.ndekocode.dev/r/kbd.json",
    "https://ui.ndekocode.dev/r/sheet.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": "registry/ndeko/components/aside/aside-07.tsx",
      "content": "'use client';\n\nimport { AnimatePresence, motion } from 'motion/react';\nimport { useId, useState } from 'react';\n\nimport { usePrefersReducedMotion } from '@/registry/ndeko/hooks/use-prefers-reduced-motion';\nimport { SearchIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport { Input } from '@/registry/ndeko/ui/input';\nimport { Kbd, KbdGroup } from '@/registry/ndeko/ui/kbd';\n\nimport {\n  AsideCloseButton,\n  AsideDescription,\n  AsidePreview,\n  AsideTitle,\n} from './_parts/aside-frame';\nimport { rowVariantsOf } from './_parts/motion';\n\n/** Each stroke is a set of keys pressed together; several strokes are pressed one after the other. */\ntype Shortcut = { id: string; label: string; strokes: string[][] };\n\ntype ShortcutGroup = { id: string; title: string; shortcuts: Shortcut[] };\n\nconst GROUPS: ShortcutGroup[] = [\n  {\n    id: 'general',\n    title: 'General',\n    shortcuts: [\n      { id: 'command', label: 'Open the command menu', strokes: [['⌘', 'K']] },\n      { id: 'search', label: 'Search tasks', strokes: [['/']] },\n      { id: 'shortcuts', label: 'Show keyboard shortcuts', strokes: [['?']] },\n    ],\n  },\n  {\n    id: 'navigation',\n    title: 'Navigation',\n    shortcuts: [\n      { id: 'go-inbox', label: 'Go to the inbox', strokes: [['G'], ['I']] },\n      { id: 'go-tasks', label: 'Go to my tasks', strokes: [['G'], ['T']] },\n      {\n        id: 'go-timesheets',\n        label: 'Go to timesheets',\n        strokes: [['G'], ['S']],\n      },\n      { id: 'next', label: 'Next task', strokes: [['J']] },\n      { id: 'previous', label: 'Previous task', strokes: [['K']] },\n    ],\n  },\n  {\n    id: 'tasks',\n    title: 'Tasks',\n    shortcuts: [\n      { id: 'create', label: 'Create a task', strokes: [['C']] },\n      { id: 'assign', label: 'Assign to me', strokes: [['I']] },\n      { id: 'status', label: 'Change the status', strokes: [['S']] },\n      { id: 'priority', label: 'Set the priority', strokes: [['P']] },\n      { id: 'timer', label: 'Start or stop the timer', strokes: [['T']] },\n      { id: 'copy', label: 'Copy the task link', strokes: [['⌘', '⇧', 'C']] },\n    ],\n  },\n];\n\nfunction normalized(text: string) {\n  const trimmed = text.trim();\n  return trimmed.toLowerCase();\n}\n\nfunction matchesQuery(shortcut: Shortcut, query: string) {\n  if (query.length === 0) {\n    return true;\n  }\n  const label = shortcut.label.toLowerCase();\n  return label.includes(query);\n}\n\nfunction matchCountLabel(count: number) {\n  if (count === 1) {\n    return '1 shortcut';\n  }\n  return `${count} shortcuts`;\n}\n\nfunction HighlightedLabel({ label, query }: { label: string; query: string }) {\n  const lowerLabel = label.toLowerCase();\n  const start = lowerLabel.indexOf(query);\n  const hasMatch = query.length > 0 && start >= 0;\n  if (!hasMatch) {\n    return <span>{label}</span>;\n  }\n  const end = start + query.length;\n  const before = label.slice(0, start);\n  const match = label.slice(start, end);\n  const after = label.slice(end);\n\n  return (\n    <span>\n      {before}\n      <mark className='bg-primary/15 text-foreground rounded-[3px]'>\n        {match}\n      </mark>\n      {after}\n    </span>\n  );\n}\n\nfunction Strokes({ strokes }: { strokes: string[][] }) {\n  return (\n    <span className='flex shrink-0 items-center gap-1.5'>\n      {strokes.map((keys, index) => {\n        const isFollowUp = index > 0;\n\n        return (\n          <span key={keys.join('+')} className='flex items-center gap-1.5'>\n            {isFollowUp && (\n              <span className='text-muted-foreground text-[11px]'>then</span>\n            )}\n            <KbdGroup>\n              {keys.map((key) => (\n                <Kbd key={key}>{key}</Kbd>\n              ))}\n            </KbdGroup>\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nfunction KeyboardShortcuts() {\n  const [query, setQuery] = useState('');\n  const searchId = useId();\n  const shouldReduceMotion = usePrefersReducedMotion();\n  const rowVariants = rowVariantsOf(shouldReduceMotion);\n  const normalizedQuery = normalized(query);\n  const visibleGroups = GROUPS.map((group) => ({\n    ...group,\n    shortcuts: group.shortcuts.filter((shortcut) =>\n      matchesQuery(shortcut, normalizedQuery)\n    ),\n  }));\n  let matchCount = 0;\n  for (const group of visibleGroups) {\n    matchCount += group.shortcuts.length;\n  }\n  const hasMatches = matchCount > 0;\n\n  function changeQuery(event: React.ChangeEvent<HTMLInputElement>) {\n    setQuery(event.target.value);\n  }\n\n  function clearQuery() {\n    setQuery('');\n  }\n\n  return (\n    <div className='flex flex-col gap-5 p-5'>\n      <div className='flex items-start gap-3'>\n        <div className='flex min-w-0 flex-1 flex-col gap-1'>\n          <AsideTitle>Keyboard shortcuts</AsideTitle>\n          <AsideDescription>{matchCountLabel(matchCount)}</AsideDescription>\n        </div>\n        <AsideCloseButton label='Close shortcuts' className='-mt-1 -mr-2' />\n      </div>\n      <div className='relative'>\n        <label htmlFor={searchId} className='sr-only'>\n          Filter shortcuts\n        </label>\n        <SearchIcon className='text-muted-foreground pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2' />\n        <Input\n          id={searchId}\n          type='search'\n          value={query}\n          placeholder='Filter by action'\n          onChange={changeQuery}\n          className='pl-8'\n        />\n      </div>\n      <div className='-mt-3 flex flex-col'>\n        <AnimatePresence initial={false}>\n          {!hasMatches && (\n            <motion.div\n              key='empty'\n              variants={rowVariants}\n              initial='hidden'\n              animate='shown'\n              exit='hidden'\n            >\n              <div className='flex flex-col items-start gap-2 pt-3'>\n                <p className='text-[13px]'>\n                  {`No shortcut matches “${query.trim()}”`}\n                </p>\n                <Button variant='outline' size='sm' onClick={clearQuery}>\n                  <XIcon />\n                  Clear filter\n                </Button>\n              </div>\n            </motion.div>\n          )}\n        </AnimatePresence>\n        <AnimatePresence initial={false}>\n          {visibleGroups.map((group) => {\n            const hasShortcuts = group.shortcuts.length > 0;\n            if (!hasShortcuts) {\n              return null;\n            }\n\n            return (\n              <motion.section\n                key={group.id}\n                aria-label={group.title}\n                variants={rowVariants}\n                initial='hidden'\n                animate='shown'\n                exit='hidden'\n              >\n                <h3 className='text-muted-foreground pt-3 pb-1 text-xs font-medium'>\n                  {group.title}\n                </h3>\n                <ul className='flex flex-col'>\n                  <AnimatePresence initial={false}>\n                    {group.shortcuts.map((shortcut) => (\n                      <motion.li\n                        key={shortcut.id}\n                        variants={rowVariants}\n                        initial='hidden'\n                        animate='shown'\n                        exit='hidden'\n                      >\n                        <div className='flex min-h-9 items-center gap-3 text-[13px]'>\n                          <span className='min-w-0 flex-1'>\n                            <HighlightedLabel\n                              label={shortcut.label}\n                              query={normalizedQuery}\n                            />\n                          </span>\n                          <Strokes strokes={shortcut.strokes} />\n                        </div>\n                      </motion.li>\n                    ))}\n                  </AnimatePresence>\n                </ul>\n              </motion.section>\n            );\n          })}\n        </AnimatePresence>\n      </div>\n    </div>\n  );\n}\n\nexport default function Aside07() {\n  return (\n    <AsidePreview triggerLabel='Open keyboard shortcuts'>\n      <KeyboardShortcuts />\n    </AsidePreview>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/aside/aside-07.tsx"
    },
    {
      "path": "registry/ndeko/components/aside/_parts/aside-frame.tsx",
      "content": "'use client';\n\nimport { createContext, useContext } from 'react';\n\nimport { PanelsTopLeftIcon, XIcon } from '@/registry/ndeko/lib/icons';\nimport { cn } from '@/registry/ndeko/lib/utils';\nimport { Button } from '@/registry/ndeko/ui/button';\nimport {\n  Sheet,\n  SheetClose,\n  SheetContent,\n  SheetDescription,\n  SheetTitle,\n  SheetTrigger,\n} from '@/registry/ndeko/ui/sheet';\n\n/** Where an aside's content is drawn: open in the page as a preview, or inside the real sheet. */\nexport type AsideHost = 'preview' | 'sheet';\n\nconst AsideHostContext = createContext<AsideHost>('preview');\n\nexport function useAsideHost() {\n  return useContext(AsideHostContext);\n}\n\nexport type AsideSide = 'left' | 'right';\n\nconst TITLE = 'text-lg leading-tight font-semibold';\n\nconst DESCRIPTION = 'text-muted-foreground text-[13px]';\n\n/** The background of the surface the aside sits on, for parts that must cover what scrolls under them. */\nexport const ASIDE_SURFACE = 'bg-[var(--aside-surface)]';\n\ntype AsideTextProps = { className?: string; children: React.ReactNode };\n\nexport function AsideTitle({ className, children }: AsideTextProps) {\n  const host = useAsideHost();\n  if (host === 'sheet') {\n    return <SheetTitle className={className}>{children}</SheetTitle>;\n  }\n  return <h2 className={cn(TITLE, className)}>{children}</h2>;\n}\n\nexport function AsideDescription({ className, children }: AsideTextProps) {\n  const host = useAsideHost();\n  if (host === 'sheet') {\n    return (\n      <SheetDescription className={className}>{children}</SheetDescription>\n    );\n  }\n  return <p className={cn(DESCRIPTION, className)}>{children}</p>;\n}\n\n/** The close button of the sheet's header. The preview has nothing to close, so it draws nothing. */\nexport function AsideCloseButton({\n  label = 'Close panel',\n  className,\n}: {\n  label?: string;\n  className?: string;\n}) {\n  const host = useAsideHost();\n  if (host === 'preview') {\n    return null;\n  }\n  return (\n    <SheetClose\n      render={\n        <Button\n          variant='ghost'\n          size='icon-sm'\n          aria-label={label}\n          className={cn('text-muted-foreground', className)}\n        />\n      }\n    >\n      <XIcon />\n    </SheetClose>\n  );\n}\n\ntype AsidePreviewProps = {\n  /** The content, drawn twice: open in the page, and inside the sheet the trigger opens. */\n  children: React.ReactNode;\n  triggerLabel: string;\n  side?: AsideSide;\n  className?: string;\n};\n\n/** Shows an aside open and whole on the page, with a small trigger that slides the same content in as a real sheet. */\nexport function AsidePreview({\n  children,\n  triggerLabel,\n  side = 'right',\n  className,\n}: AsidePreviewProps) {\n  return (\n    <div className='flex w-full flex-col items-center gap-4'>\n      <AsideHostContext.Provider value='preview'>\n        <div\n          className={cn(\n            'surface-raised flex w-full max-w-sm flex-col overflow-hidden rounded-2xl text-left [--aside-surface:var(--popover)]',\n            className\n          )}\n        >\n          {children}\n        </div>\n      </AsideHostContext.Provider>\n      <Sheet>\n        <SheetTrigger render={<Button variant='outline' size='sm' />}>\n          <PanelsTopLeftIcon />\n          {triggerLabel}\n        </SheetTrigger>\n        <SheetContent\n          side={side}\n          showCloseButton={false}\n          className={cn('gap-0 p-0 [--aside-surface:var(--card)]', className)}\n        >\n          <AsideHostContext.Provider value='sheet'>\n            {children}\n          </AsideHostContext.Provider>\n        </SheetContent>\n      </Sheet>\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/aside/_parts/aside-frame.tsx"
    },
    {
      "path": "registry/ndeko/components/aside/_parts/motion.ts",
      "content": "import type { Transition, Variants } from 'motion/react';\n\nexport const SWAP_TRANSITION: Transition = {\n  duration: 0.15,\n  ease: [0.2, 0, 0, 1],\n};\n\nconst TRAVEL_SPRING: Transition = { type: 'spring', bounce: 0, duration: 0.3 };\n\nconst INSTANT: Transition = { duration: 0 };\n\nconst ENTER: Transition = { duration: 0.2, ease: [0.23, 1, 0.32, 1] };\n\nconst LEAVE: Transition = { duration: 0.14, ease: [0.23, 1, 0.32, 1] };\n\nconst ICON_SWAP: Variants = {\n  enter: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n  visible: { opacity: 1, scale: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, scale: 0.6, filter: 'blur(2px)' },\n};\n\nconst LABEL_SWAP: Variants = {\n  enter: { opacity: 0, filter: 'blur(2px)' },\n  visible: { opacity: 1, filter: 'blur(0px)' },\n  exit: { opacity: 0, filter: 'blur(2px)' },\n};\n\nconst FADE: Variants = {\n  enter: { opacity: 0 },\n  visible: { opacity: 1 },\n  exit: { opacity: 0 },\n};\n\nconst HEIGHT_PRESENCE: Variants = {\n  hidden: { height: 0, opacity: 0, overflow: 'hidden', transition: LEAVE },\n  shown: {\n    height: 'auto',\n    opacity: 1,\n    transition: ENTER,\n    transitionEnd: { overflow: 'visible' },\n  },\n};\n\nconst FADE_PRESENCE: Variants = {\n  hidden: { opacity: 0, transition: LEAVE },\n  shown: { opacity: 1, transition: ENTER },\n};\n\nconst CHIP_PRESENCE: Variants = {\n  hidden: { opacity: 0, scale: 0.9, transition: LEAVE },\n  shown: { opacity: 1, scale: 1, transition: ENTER },\n};\n\nexport type SwapKind = 'icon' | 'label';\n\nexport function swapVariantsOf(\n  shouldReduceMotion: boolean | null,\n  kind: SwapKind = 'icon'\n) {\n  if (shouldReduceMotion) {\n    return FADE;\n  }\n  if (kind === 'label') {\n    return LABEL_SWAP;\n  }\n  return ICON_SWAP;\n}\n\n/** A row that joins or leaves a list: its height opens or collapses, so what follows slides instead of jumping. */\nexport function rowVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_PRESENCE;\n  }\n  return HEIGHT_PRESENCE;\n}\n\nexport function chipVariantsOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return FADE_PRESENCE;\n  }\n  return CHIP_PRESENCE;\n}\n\nexport function travelOf(shouldReduceMotion: boolean | null) {\n  if (shouldReduceMotion) {\n    return INSTANT;\n  }\n  return TRAVEL_SPRING;\n}\n",
      "type": "registry:component",
      "target": "components/aside/_parts/motion.ts"
    }
  ],
  "categories": [
    "components",
    "aside"
  ],
  "type": "registry:component"
}