{
  "name": "message-composer",
  "type": "registry:ui",
  "framework": "react",
  "title": "Message Composer",
  "description": "The channel input bar: attachment control, text field with combobox hooks, and send.",
  "dependencies": [
    "class-variance-authority"
  ],
  "files": [
    {
      "path": "ui/message-composer.tsx",
      "content": "\"use client\"\n\nimport { cva, type VariantProps } from \"class-variance-authority\"\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/** The composer's own names. Pass `labels` to translate them. */\nexport interface MessageComposerLabels {\n  /** Accessible name of the whole bar, built from the channel name. */\n  group: (channelName: string) => string\n  /** Placeholder and name of the field, when `placeholder` is not set. */\n  placeholder: (channelName: string) => string\n  /** Accessible name of the add button. */\n  add: string\n  /** Accessible name of the send button. */\n  send: string\n}\n\n/** The English defaults. */\nexport const defaultMessageComposerLabels: MessageComposerLabels = {\n  group: (channelName) => `Message composer for #${channelName}`,\n  placeholder: (channelName) => `Message #${channelName}`,\n  add: \"Add attachment\",\n  send: \"Send message\",\n}\n\nconst AddIcon = () => (\n  <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"h-5 w-5\">\n    <path\n      fill=\"currentColor\"\n      d=\"M11 5a1 1 0 1 1 2 0v6h6a1 1 0 1 1 0 2h-6v6a1 1 0 1 1-2 0v-6H5a1 1 0 1 1 0-2h6z\"\n    />\n  </svg>\n)\n\nconst SendIcon = () => (\n  <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\" className=\"h-5 w-5\">\n    <path fill=\"currentColor\" d=\"M3 20.5v-6l8-2.5-8-2.5v-6l19 8.5z\" />\n  </svg>\n)\n\nconst messageComposerVariants = cva(\n  \"flex min-w-0 items-center gap-2 text-newt-text-muted\",\n  {\n    variants: {\n      layout: {\n        default:\n          \"min-h-11 rounded-[var(--newt-radius-md)] border border-newt-border bg-newt-bg-input-elevated px-4\",\n        /* A phone: no frame, a pill field, round buttons beside it. */\n        narrow: \"min-h-10\",\n      },\n    },\n    defaultVariants: { layout: \"default\" },\n  }\n)\n\nconst fieldVariants = cva(\"flex min-w-0 flex-1 items-center gap-2\", {\n  variants: {\n    layout: {\n      default: \"\",\n      narrow: \"min-h-10 rounded-full bg-newt-bg-input-elevated pe-1 ps-4\",\n    },\n  },\n  defaultVariants: { layout: \"default\" },\n})\n\n/**\n * The style of the composer's icon buttons. Give it to a button you add, so\n * it matches the built-in ones. In the narrow layout, use `layout: \"narrow\"`\n * for a button beside the field and the default for one inside it.\n */\nconst messageComposerButtonVariants = cva(\n  \"inline-flex shrink-0 cursor-pointer items-center justify-center border-0 p-0 text-inherit hover:bg-newt-bg-hover hover:text-newt-text-primary focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link disabled:cursor-not-allowed disabled:opacity-50\",\n  {\n    variants: {\n      layout: {\n        default: \"h-8 w-8 rounded-[var(--newt-radius-sm)] bg-transparent\",\n        narrow: \"h-10 w-10 rounded-full bg-newt-bg-input-elevated\",\n      },\n    },\n    defaultVariants: { layout: \"default\" },\n  }\n)\n\n/* The send control only lights up once there is something to send. */\nconst sendReady = {\n  default: \"text-newt-brand\",\n  narrow:\n    \"bg-newt-brand text-newt-on-accent hover:bg-newt-brand-hover hover:text-newt-on-accent\",\n}\n\ntype MessageComposerLayout = NonNullable<\n  VariantProps<typeof messageComposerVariants>[\"layout\"]\n>\n\n/** Attributes for the focusable field. Spread them on it. */\nexport interface MessageComposerInputAttributes {\n  placeholder: string\n  \"aria-label\": string\n  role: \"combobox\" | undefined\n  autoComplete: \"off\" | undefined\n  \"aria-controls\": string | undefined\n  \"aria-expanded\": boolean | undefined\n  \"aria-activedescendant\": string | undefined\n  disabled: boolean\n  spellCheck: false\n  /** Enter submits, Escape and the arrow keys reach their callbacks. */\n  onKeyDown: (event: React.KeyboardEvent<HTMLElement>) => void\n}\n\n/** What `renderInput` receives: the state of the built-in input. */\nexport interface MessageComposerInputProps {\n  value: string\n  /** Changes the value, as typing in the built-in input does. */\n  setValue: (value: string) => void\n  /** Sends the value, as Enter does. Does nothing while it is empty. */\n  submit: () => void\n  disabled: boolean\n  inputProps: MessageComposerInputAttributes\n}\n\nexport interface MessageComposerProps extends Omit<\n  React.HTMLAttributes<HTMLDivElement>,\n  \"onSubmit\" | \"onChange\" | \"children\"\n> {\n  /** Channel the message goes to; drives the default placeholder and labels. */\n  channelName: string\n  value?: string\n  defaultValue?: string\n  onValueChange?: (value: string) => void\n  placeholder?: string\n  /** Sent on Enter and on the send control. */\n  onSubmit?: (value: string) => void\n  onEscape?: () => void\n  /** Arrow keys, for driving a suggestion list above the composer. */\n  onNavigate?: (direction: \"up\" | \"down\") => void\n  /** Wire the input up as a combobox for slash-command autocomplete. */\n  autocomplete?: boolean\n  ariaControls?: string\n  ariaExpanded?: boolean\n  ariaActiveDescendant?: string\n  /** Turns off the input, the add button and the send button. */\n  disabled?: boolean\n  /** `\"narrow\"` is the phone layout: a pill field and round buttons. */\n  layout?: MessageComposerLayout\n  /** Shows the add button. */\n  showAdd?: boolean\n  onAdd?: () => void\n  /** Controls after the add button, before the field. */\n  leading?: React.ReactNode\n  /**\n   * Replaces the built-in input with your own field. It receives the value,\n   * a setter, the submit action and the attributes to spread on the field.\n   * The Vue port takes the same content through its `#input` slot.\n   */\n  renderInput?: (props: MessageComposerInputProps) => React.ReactNode\n  /** Extra controls at the end of the field, before the send button. */\n  actions?: React.ReactNode\n  /** Shown in place of the send button while the field is empty. */\n  trailing?: React.ReactNode\n  /** Replaces the English names; omitted keys keep their default. */\n  labels?: Partial<MessageComposerLabels>\n}\n\nconst MessageComposer = React.forwardRef<HTMLDivElement, MessageComposerProps>(\n  (\n    {\n      className,\n      channelName,\n      value,\n      defaultValue = \"\",\n      onValueChange,\n      placeholder,\n      onSubmit,\n      onEscape,\n      onNavigate,\n      autocomplete = false,\n      ariaControls,\n      ariaExpanded,\n      ariaActiveDescendant,\n      disabled = false,\n      layout = \"default\",\n      showAdd = true,\n      onAdd,\n      leading,\n      renderInput,\n      actions,\n      trailing,\n      labels: labelOverrides,\n      ...props\n    },\n    ref\n  ) => {\n    const text = { ...defaultMessageComposerLabels, ...labelOverrides }\n    const [uncontrolled, setUncontrolled] = React.useState(defaultValue)\n    const current = value ?? uncontrolled\n    const hasValue = current.trim().length > 0\n    const label = placeholder ?? text.placeholder(channelName)\n\n    const setValue = (next: string) => {\n      if (value === undefined) setUncontrolled(next)\n      onValueChange?.(next)\n    }\n\n    const submit = () => {\n      if (!hasValue || disabled) return\n      onSubmit?.(current)\n    }\n\n    const onKeyDown = (event: React.KeyboardEvent<HTMLElement>) => {\n      switch (event.key) {\n        case \"Enter\":\n          event.preventDefault()\n          submit()\n          return\n        case \"Escape\":\n          event.preventDefault()\n          onEscape?.()\n          return\n        case \"ArrowUp\":\n        case \"ArrowDown\":\n          if (!onNavigate) return\n          event.preventDefault()\n          onNavigate(event.key === \"ArrowUp\" ? \"up\" : \"down\")\n      }\n    }\n\n    const inputProps: MessageComposerInputAttributes = {\n      placeholder: label,\n      \"aria-label\": label,\n      role: autocomplete ? \"combobox\" : undefined,\n      autoComplete: autocomplete ? \"off\" : undefined,\n      \"aria-controls\": autocomplete ? ariaControls : undefined,\n      \"aria-expanded\": autocomplete ? ariaExpanded : undefined,\n      \"aria-activedescendant\": autocomplete ? ariaActiveDescendant : undefined,\n      disabled,\n      spellCheck: false,\n      onKeyDown,\n    }\n\n    return (\n      <div\n        ref={ref}\n        role=\"group\"\n        aria-label={text.group(channelName)}\n        className={cn(messageComposerVariants({ layout }), className)}\n        {...props}\n      >\n        {showAdd && (\n          <button\n            type=\"button\"\n            aria-label={text.add}\n            disabled={disabled}\n            className={messageComposerButtonVariants({ layout })}\n            onClick={onAdd}\n          >\n            <AddIcon />\n          </button>\n        )}\n        {leading}\n        <div className={fieldVariants({ layout })}>\n          {renderInput ? (\n            renderInput({\n              value: current,\n              setValue,\n              submit,\n              disabled,\n              inputProps,\n            })\n          ) : (\n            <input\n              type=\"text\"\n              value={current}\n              {...inputProps}\n              onChange={(event) => setValue(event.target.value)}\n              className=\"w-full min-w-0 border-0 bg-transparent font-[family-name:var(--newt-font-sans)] text-[15px] text-newt-text-primary outline-none placeholder:text-newt-text-muted disabled:cursor-not-allowed\"\n            />\n          )}\n          {actions}\n        </div>\n        {Boolean(trailing) && !hasValue ? (\n          trailing\n        ) : (\n          <button\n            type=\"button\"\n            aria-label={text.send}\n            disabled={disabled || !hasValue}\n            onClick={submit}\n            className={cn(\n              messageComposerButtonVariants({ layout }),\n              hasValue && !disabled && sendReady[layout]\n            )}\n          >\n            <SendIcon />\n          </button>\n        )}\n      </div>\n    )\n  }\n)\nMessageComposer.displayName = \"MessageComposer\"\n\nexport { MessageComposer, messageComposerButtonVariants }\n",
      "type": "registry:ui"
    }
  ]
}