{
  "name": "slash-command",
  "type": "registry:ui",
  "framework": "react",
  "title": "Slash Command",
  "description": "An inline /command with its subcommand path and typed options, including the focused one.",
  "files": [
    {
      "path": "ui/slash-command.tsx",
      "content": "import * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface SlashCommandOption {\n  name: string\n  /** The value the user has entered, if any. */\n  value?: string\n  /** Stands in for a missing value, the way the client previews the option. */\n  description?: string\n  /** The option the caret currently sits in. */\n  focused?: boolean\n}\n\nexport interface SlashCommandProps extends React.HTMLAttributes<HTMLSpanElement> {\n  /** Command name rendered after the leading slash. */\n  name: string\n  /** Subcommand segment, e.g. `/ban member`. */\n  subcommand?: string\n  /** Subcommand group segment, e.g. `/settings roles add`. */\n  subcommandGroup?: string\n  options?: readonly SlashCommandOption[]\n  /** Content that follows the command inside the chip, after a space. */\n  children?: React.ReactNode\n  /** Builds the accessible name; `aria-label` still wins when both are set. */\n  formatLabel?: (state: SlashCommandLabelState) => string\n}\n\n/** What the accessible name of a command chip is built from. */\nexport interface SlashCommandLabelState {\n  /** The command path without the slash: `ban member`. */\n  path: string\n  options: readonly SlashCommandOption[]\n}\n\n/** `/name group sub` — the segments a caller can actually reach. */\nfunction commandPath(\n  props: Pick<SlashCommandProps, \"name\" | \"subcommand\" | \"subcommandGroup\">\n) {\n  return [props.name, props.subcommandGroup, props.subcommand]\n    .filter(Boolean)\n    .join(\" \")\n}\n\n/** The English default. Pass `formatLabel` to translate it. */\nexport function defaultSlashCommandLabel({\n  path,\n  options,\n}: SlashCommandLabelState): string {\n  const spoken = options\n    .map(\n      (option) =>\n        `${option.name}: ${option.value ?? option.description ?? option.name}`\n    )\n    .join(\" \")\n  return `Slash command /${path}${spoken ? ` ${spoken}` : \"\"}`\n}\n\n/*\n * The separators are real text: a space between two parts and a colon after\n * an option name, so a copy, a search and a test read\n * `/ban member user:@username`. The chip is inline content, because a flex row\n * drops the space between two items. `word-spacing` draws each space 4px wide\n * (a space is 1ch in a monospace font), and every child resets it, so only the\n * spaces between the parts are narrowed. Each part is its own run of text, so a\n * right-to-left chip orders its parts from the right, as a flex row did.\n */\nconst SlashCommand = React.forwardRef<HTMLSpanElement, SlashCommandProps>(\n  (\n    {\n      className,\n      name,\n      subcommand,\n      subcommandGroup,\n      options = [],\n      children,\n      formatLabel = defaultSlashCommandLabel,\n      ...props\n    },\n    ref\n  ) => {\n    const path = commandPath({ name, subcommand, subcommandGroup })\n    const hasChildren =\n      children !== undefined && children !== null && children !== false\n    return (\n      <span\n        ref={ref}\n        role=\"group\"\n        aria-label={formatLabel({ path, options })}\n        className={cn(\n          \"inline-block rounded-[var(--newt-radius-sm)] bg-[color-mix(in_srgb,var(--newt-brand)_15%,transparent)] py-[2px] ps-[6px] pe-2 font-[family-name:var(--newt-font-mono)] text-[13px] text-newt-mention-text [word-spacing:calc(4px_-_1ch)] [&>*]:[word-spacing:normal] [&>*]:[unicode-bidi:isolate]\",\n          className\n        )}\n        {...props}\n      >\n        {/* No space follows the slash, so the text reads `/ban`. */}\n        <span className=\"me-1 opacity-80\" aria-hidden=\"true\">\n          /\n        </span>\n        <span className=\"font-semibold\">{name}</span>\n        {subcommandGroup ? (\n          <>\n            {\" \"}\n            <span className=\"font-semibold\">{subcommandGroup}</span>\n          </>\n        ) : null}\n        {subcommand ? (\n          <>\n            {\" \"}\n            <span className=\"font-semibold\">{subcommand}</span>\n          </>\n        ) : null}\n        {options.map((option) => (\n          <React.Fragment key={option.name}>\n            {\" \"}\n            <span\n              className={cn(\n                \"inline-block [&>*]:[unicode-bidi:isolate]\",\n                /* The option the caret currently sits in. */\n                option.focused &&\n                  \"rounded-[var(--newt-radius-sm)] bg-[color-mix(in_srgb,var(--newt-brand)_35%,transparent)] px-0.5\"\n              )}\n            >\n              <span className=\"text-newt-text-muted\">{`${option.name}:`}</span>\n              {option.value ? (\n                <span className=\"ms-1 font-medium text-newt-text-primary\">\n                  {option.value}\n                </span>\n              ) : (\n                /* No value yet — the option's description stands in. */\n                <span className=\"ms-1 italic text-newt-text-muted\">\n                  {option.description ?? option.name}\n                </span>\n              )}\n            </span>\n          </React.Fragment>\n        ))}\n        {hasChildren ? (\n          <>\n            {\" \"}\n            <span>{children}</span>\n          </>\n        ) : null}\n      </span>\n    )\n  }\n)\nSlashCommand.displayName = \"SlashCommand\"\n\nexport { SlashCommand }\n",
      "type": "registry:ui"
    }
  ]
}