{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "domain-switch-command-demo",
  "type": "registry:block",
  "title": "Domain Switch: Command Palette",
  "description": "Dark Mode Toggle example, Command Palette: Press ⌘K (or the search icon) and a domain opens from the icon in which the page becomes a command palette. Run a command or press Esc and it collapses back into the icon. A take on the toggle (switch). Fits navbar and app UI sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "navbar",
    "app-ui",
    "toggle",
    "theme",
    "transition",
    "canvas"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/domain-switch#domain-switch-command-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/domain-switch.json"
  ],
  "files": [
    {
      "path": "components/domain-switch-command-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { cn } from \"@/lib/utils\";\nimport { DomainSwitch, DomainSwitchScope, DomainSwitchToggle } from \"@/components/ui/domain-switch\";\n\ntype Command = { label: string; group: string; hint?: string };\n\nconst commands: Command[] = [\n  { label: \"Redeploy production\", group: \"Actions\", hint: \"⇧R\" },\n  { label: \"Roll back to previous build\", group: \"Actions\" },\n  { label: \"Invite a teammate\", group: \"Actions\", hint: \"I\" },\n  { label: \"Open build logs\", group: \"Go to\", hint: \"G L\" },\n  { label: \"Environment variables\", group: \"Go to\", hint: \"G E\" },\n  { label: \"Domains\", group: \"Go to\", hint: \"G D\" },\n  { label: \"Usage and billing\", group: \"Go to\" },\n];\n\nconst deployments = [\n  { branch: \"main\", message: \"Cache edge responses\", age: \"4m\", state: \"Ready\" },\n  { branch: \"feat/search\", message: \"Fuzzy match on titles\", age: \"38m\", state: \"Building\" },\n  { branch: \"main\", message: \"Bump runtime to 22\", age: \"2h\", state: \"Ready\" },\n  { branch: \"fix/og\", message: \"Fallback social card\", age: \"5h\", state: \"Ready\" },\n  { branch: \"main\", message: \"Drop legacy routes\", age: \"1d\", state: \"Ready\" },\n];\n\nexport function DomainSwitchCommandDemo() {\n  const [open, setOpen] = React.useState(false);\n  const [query, setQuery] = React.useState(\"\");\n  const [active, setActive] = React.useState(0);\n  const [ran, setRan] = React.useState<string | null>(null);\n  const inputRef = React.useRef<HTMLInputElement>(null);\n\n  const results = commands.filter((command) => command.label.toLowerCase().includes(query.trim().toLowerCase()));\n\n  const change = (next: boolean) => {\n    setOpen(next);\n    if (next) {\n      setQuery(\"\");\n      setActive(0);\n    }\n  };\n\n  const run = (command: Command) => {\n    setRan(command.label);\n    change(false);\n  };\n\n  // ⌘K / Ctrl+K opens it from anywhere, Esc puts it away.\n  React.useEffect(() => {\n    const onKeyDown = (event: KeyboardEvent) => {\n      if (event.key.toLowerCase() === \"k\" && (event.metaKey || event.ctrlKey)) {\n        event.preventDefault();\n        setOpen((was) => {\n          if (!was) {\n            setQuery(\"\");\n            setActive(0);\n          }\n          return !was;\n        });\n      } else if (event.key === \"Escape\") {\n        setOpen(false);\n      }\n    };\n    window.addEventListener(\"keydown\", onKeyDown);\n    return () => window.removeEventListener(\"keydown\", onKeyDown);\n  }, []);\n\n  React.useEffect(() => {\n    if (open) inputRef.current?.focus({ preventScroll: true });\n  }, [open]);\n\n  return (\n    <div className=\"w-full overflow-hidden rounded-xl border border-zinc-200 dark:border-zinc-800\">\n      <DomainSwitch checked={open} onCheckedChange={change} duration={0.95}>\n        <DomainSwitchScope\n          className=\"h-[var(--demo-height,520px)]\"\n          seamClassName=\"text-[#05060d]\"\n          outside={\n            <div className=\"flex h-full flex-col bg-white text-zinc-900 dark:bg-zinc-950 dark:text-zinc-100\">\n              <TopBar>\n                <DomainSwitchToggle\n                  aria-label=\"Command palette\"\n                  className=\"size-8 rounded-lg text-zinc-500 hover:bg-zinc-100 hover:text-zinc-900 dark:text-zinc-400 dark:hover:bg-zinc-900 dark:hover:text-zinc-100\"\n                >\n                  <SearchIcon />\n                </DomainSwitchToggle>\n                <kbd className=\"hidden rounded-md border border-zinc-200 px-1.5 py-0.5 font-sans text-[11px] text-zinc-500 sm:block dark:border-zinc-800\">\n                  ⌘K\n                </kbd>\n                <span className=\"ml-auto size-7 rounded-full bg-gradient-to-br from-amber-200 to-rose-300\" />\n              </TopBar>\n              <div className=\"min-h-0 flex-1 overflow-hidden px-4 py-5 sm:px-6\">\n                <div className=\"flex items-baseline justify-between\">\n                  <h2 className=\"text-lg font-semibold tracking-tight\">Deployments</h2>\n                  <p className=\"truncate pl-4 text-xs text-zinc-500\" aria-live=\"polite\">\n                    {ran ? `Ran “${ran}”` : \"Press ⌘K for commands\"}\n                  </p>\n                </div>\n                <ul className=\"mt-4 divide-y divide-zinc-100 rounded-xl border border-zinc-200 dark:divide-zinc-900 dark:border-zinc-800\">\n                  {deployments.map((d) => (\n                    <li key={d.message} className=\"flex items-center gap-3 px-4 py-3 text-sm\">\n                      <span\n                        className={cn(\n                          \"size-2 shrink-0 rounded-full\",\n                          d.state === \"Ready\" ? \"bg-emerald-500\" : \"animate-pulse bg-amber-500\",\n                        )}\n                      />\n                      <span className=\"min-w-0 flex-1 truncate\">{d.message}</span>\n                      <span className=\"hidden font-mono text-xs text-zinc-500 sm:block\">{d.branch}</span>\n                      <span className=\"w-8 text-right text-xs text-zinc-500\">{d.age}</span>\n                    </li>\n                  ))}\n                </ul>\n              </div>\n            </div>\n          }\n          inside={\n            <div className=\"flex h-full flex-col bg-[#0b0c16] text-zinc-200\">\n              <TopBar className=\"border-white/[0.06]\">\n                <DomainSwitchToggle\n                  aria-label=\"Command palette\"\n                  className=\"size-8 rounded-lg bg-indigo-400/15 text-indigo-200 hover:bg-indigo-400/25\"\n                >\n                  <SearchIcon />\n                </DomainSwitchToggle>\n                <input\n                  ref={inputRef}\n                  value={query}\n                  onChange={(event) => {\n                    setQuery(event.target.value);\n                    setActive(0);\n                  }}\n                  onKeyDown={(event) => {\n                    if (event.key === \"ArrowDown\" || event.key === \"ArrowUp\") {\n                      event.preventDefault();\n                      const step = event.key === \"ArrowDown\" ? 1 : -1;\n                      setActive((i) => (results.length ? (i + step + results.length) % results.length : 0));\n                    } else if (event.key === \"Enter\" && results[active]) {\n                      event.preventDefault();\n                      run(results[active]);\n                    }\n                  }}\n                  placeholder=\"Type a command or search\"\n                  aria-label=\"Command\"\n                  className=\"min-w-0 flex-1 bg-transparent text-[16px] text-zinc-100 outline-none placeholder:text-zinc-500 sm:text-sm\"\n                />\n                <kbd className=\"rounded-md border border-white/10 px-1.5 py-0.5 font-sans text-[11px] text-zinc-400\">\n                  Esc\n                </kbd>\n              </TopBar>\n              <div className=\"min-h-0 flex-1 overflow-y-auto px-2 py-3 sm:px-4\">\n                {results.length === 0 && <p className=\"px-3 py-6 text-sm text-zinc-500\">No commands match.</p>}\n                {[\"Actions\", \"Go to\"].map((group) => {\n                  const items = results.filter((command) => command.group === group);\n                  if (!items.length) return null;\n                  return (\n                    <div key={group} className=\"mb-3\">\n                      <p className=\"px-3 pb-1 text-[11px] font-medium tracking-wide text-zinc-500 uppercase\">{group}</p>\n                      {items.map((command) => {\n                        const index = results.indexOf(command);\n                        return (\n                          <button\n                            key={command.label}\n                            type=\"button\"\n                            onPointerMove={() => setActive(index)}\n                            onClick={() => run(command)}\n                            className={cn(\n                              \"flex w-full items-center rounded-lg px-3 py-2.5 text-left text-sm\",\n                              index === active ? \"bg-indigo-400/[0.12] text-white\" : \"text-zinc-300\",\n                            )}\n                          >\n                            {command.label}\n                            {command.hint && (\n                              <span className=\"ml-auto font-mono text-[11px] text-zinc-500\">{command.hint}</span>\n                            )}\n                          </button>\n                        );\n                      })}\n                    </div>\n                  );\n                })}\n              </div>\n            </div>\n          }\n        />\n      </DomainSwitch>\n    </div>\n  );\n}\n\nfunction TopBar({ className, children }: { className?: string; children: React.ReactNode }) {\n  return (\n    <div\n      className={cn(\n        \"flex h-14 shrink-0 items-center gap-2 border-b border-zinc-200 px-3 sm:px-4 dark:border-zinc-800\",\n        className,\n      )}\n    >\n      <span className=\"mr-2 flex items-center gap-2 text-sm font-semibold tracking-tight\">\n        <span className=\"size-4 rotate-45 rounded-[3px] bg-current\" />\n        <span className=\"hidden sm:inline\">Relay</span>\n      </span>\n      {children}\n    </div>\n  );\n}\n\nfunction SearchIcon() {\n  return (\n    <svg viewBox=\"0 0 16 16\" className=\"size-4\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden>\n      <circle cx=\"7\" cy=\"7\" r=\"4.5\" />\n      <path d=\"m10.5 10.5 3 3\" />\n    </svg>\n  );\n}\n"
    }
  ]
}