{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "icon-button",
  "type": "registry:ui",
  "title": "Icon Button",
  "description": "A button with only an icon; the required label is its accessible name and its tooltip, with a 44 px hit area and a toggle state.",
  "dependencies": [],
  "registryDependencies": [
    "https://ui.klarhimmel.com/r/editing.json",
    "https://ui.klarhimmel.com/r/theme.json",
    "https://ui.klarhimmel.com/r/tooltip.json",
    "https://ui.klarhimmel.com/r/utils.json"
  ],
  "files": [
    {
      "path": "src/ui/icon-button.tsx",
      "type": "registry:file",
      "target": "components/klarhimmel/ui/icon-button.tsx",
      "content": "import { forwardRef, useContext, type ButtonHTMLAttributes, type ReactNode } from 'react';\nimport { EditingContext } from '../editing';\nimport { cn } from '../lib/utils';\nimport { Tooltip } from './tooltip';\n\nexport interface IconButtonProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'aria-label'> {\n  /** Required: the accessible name, also shown as the tooltip. */\n  label: string;\n  /** A shortcut shown next to the label in the tooltip. */\n  shortcut?: string;\n  size?: 'sm' | 'md' | 'lg';\n  variant?: 'ghost' | 'soft' | 'secondary' | 'primary';\n  /** A toggle button: sets aria-pressed and the pressed look. */\n  active?: boolean;\n  children: ReactNode;\n  noTooltip?: boolean;\n  tooltipSide?: 'top' | 'right' | 'bottom' | 'left';\n  tooltipDelay?: number;\n}\n\nconst sizes = {\n  sm: 'size-9 after:absolute after:-inset-x-1 after:-inset-y-1 after:content-[\"\"]', // 36 px visual, 44 px hit area\n  md: 'size-11',\n  lg: 'size-12',\n};\nconst variants = {\n  ghost: 'text-kh-ink-2 hover:bg-kh-surface-2 hover:text-kh-ink active:bg-kh-surface-3',\n  soft: 'bg-kh-surface-2 text-kh-ink hover:bg-kh-surface-3',\n  secondary: 'bg-kh-surface text-kh-ink border border-kh-line-strong shadow-kh-1 hover:bg-kh-surface-2 active:bg-kh-surface-3',\n  primary: 'bg-kh-ink text-kh-on-ink hover:bg-[color-mix(in_oklab,var(--kh-ink)_86%,var(--kh-canvas))]',\n};\n\n/** A button with an icon and no visible text. The label is its name and its tooltip, so it can never be unnamed. */\nexport const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton(\n  { label, shortcut, size = 'md', variant = 'ghost', active, className, children, type = 'button', noTooltip, tooltipSide, tooltipDelay, ...rest },\n  ref,\n) {\n  const editing = !!useContext(EditingContext);\n  if (!label.trim() && !editing) return null; // an emptied label: a nameless button is worse than none\n  const btn = (\n    <button\n      ref={ref}\n      type={type}\n      aria-label={label}\n      aria-pressed={active}\n      className={cn(\n        'relative inline-flex shrink-0 select-none items-center justify-center rounded-kh transition-[background-color,color] duration-(--kh-dur)',\n        'focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-(--kh-focus) disabled:pointer-events-none disabled:opacity-50',\n        sizes[size],\n        variants[variant],\n        active && 'bg-kh-surface-3 text-kh-ink',\n        className,\n      )}\n      {...rest}\n    >\n      {children}\n    </button>\n  );\n  return noTooltip ? (\n    btn\n  ) : (\n    <Tooltip content={label} shortcut={shortcut} side={tooltipSide} delay={tooltipDelay}>\n      {btn}\n    </Tooltip>\n  );\n});\n"
    }
  ]
}
