{
  "name": "mention",
  "type": "registry:ui",
  "framework": "react",
  "title": "Mention Chip",
  "description": "An inline chip for user, channel, role and app mentions, with an optional avatar.",
  "dependencies": [
    "class-variance-authority"
  ],
  "files": [
    {
      "path": "ui/mention.tsx",
      "content": "import { cva, type VariantProps } from \"class-variance-authority\"\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\n/*\n * Every variant only sets two custom properties: the tint the chip renders at\n * rest and the solid colour it fills with on hover. A role mention overrides\n * `--newt-mention-color` inline with the role's own hue, and its hover fill\n * follows automatically.\n */\nconst mentionVariants = cva(\n  \"inline-flex min-h-[22px] items-center gap-0.5 rounded-[var(--newt-radius-sm)] border-0 bg-[color-mix(in_srgb,var(--newt-mention-color)_15%,transparent)] px-1 align-middle font-[family-name:var(--newt-font-sans)] text-[14px] font-medium leading-5 text-[var(--newt-mention-color)] no-underline transition-colors duration-fast ease-newt\",\n  {\n    variants: {\n      variant: {\n        user: \"[--newt-mention-color:var(--newt-mention-text)] [--newt-mention-solid:var(--newt-brand)]\",\n        channel:\n          \"[--newt-mention-color:var(--newt-text-link)] [--newt-mention-solid:var(--newt-brand)]\",\n        role: \"[--newt-mention-color:var(--newt-mention-role)] [--newt-mention-solid:var(--newt-mention-color)]\",\n        app: \"[--newt-mention-color:var(--newt-mention-text)] [--newt-mention-solid:var(--newt-brand)]\",\n      },\n      /*\n       * A mention that opens nothing (`as=\"span\"`) keeps the tint but drops\n       * the pointer, the hover fill and the focus ring: it is text, not a\n       * control, and stays out of the tab order.\n       */\n      interactive: {\n        true: \"cursor-pointer hover:bg-[var(--newt-mention-solid)] hover:text-newt-on-accent focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-newt-text-link\",\n        false: \"\",\n      },\n    },\n    defaultVariants: {\n      variant: \"user\",\n      interactive: true,\n    },\n  }\n)\n\n/** The element a mention renders as. */\nexport type MentionElement = \"button\" | \"a\" | \"span\"\n\nexport interface MentionProps\n  extends\n    Omit<React.HTMLAttributes<HTMLElement>, \"color\">,\n    Omit<VariantProps<typeof mentionVariants>, \"interactive\"> {\n  /**\n   * `button` (the default) for a mention that opens something in place, `a`\n   * for one that navigates (pass `href`), `span` for a read-only mention that\n   * is neither focusable nor clickable.\n   */\n  as?: MentionElement\n  /** Link target, for `as=\"a\"`. Passing it without `as` renders a link. */\n  href?: string\n  /** Avatar URL. Rendered from 48rem up; below that the chip stays text-only. */\n  avatar?: string\n  /** Role colour, for `variant=\"role\"`. Any CSS colour. */\n  color?: string\n}\n\n/* Widens the tag so one ref type serves all three elements it can be. */\nfunction asElementType(element: MentionElement): React.ElementType {\n  return element\n}\n\nconst Mention = React.forwardRef<HTMLElement, MentionProps>(\n  (\n    { as, href, className, variant, avatar, color, children, style, ...props },\n    ref\n  ) => {\n    const element: MentionElement = as ?? (href === undefined ? \"button\" : \"a\")\n    const Tag = asElementType(element)\n    return (\n      <Tag\n        ref={ref}\n        type={element === \"button\" ? \"button\" : undefined}\n        href={element === \"a\" ? href : undefined}\n        data-variant={variant ?? \"user\"}\n        /*\n         * SAFETY: `CSSProperties` has no index signature for custom properties,\n         * but React forwards unknown `--*` keys to the style attribute\n         * verbatim, so the extra key is written out exactly as spelled here.\n         */\n        style={\n          color\n            ? ({\n                ...style,\n                \"--newt-mention-color\": color,\n              } as React.CSSProperties)\n            : style\n        }\n        className={cn(\n          mentionVariants({ variant, interactive: element !== \"span\" }),\n          avatar && \"ps-0.5\",\n          className\n        )}\n        {...props}\n      >\n        {avatar ? (\n          <img\n            src={avatar}\n            alt=\"\"\n            aria-hidden=\"true\"\n            className=\"hidden h-5 w-5 shrink-0 rounded-full object-cover md:block\"\n          />\n        ) : null}\n        {children}\n      </Tag>\n    )\n  }\n)\nMention.displayName = \"Mention\"\n\nexport { Mention, mentionVariants }\n",
      "type": "registry:ui"
    }
  ]
}