Mention Chip
An inline chip for user, channel, role and app mentions, with an optional avatar.
An inline chip for user, channel, role and app mentions, with an optional avatar. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.
newt-mentionimport { Mention } from "@/registry/bases/newt/ui/mention"
/* Inline so the demo never reaches out to the network for a placeholder. */
const AVATAR =
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='10' fill='%235865f2'/%3E%3C/svg%3E"
export default function MentionDemo() {
return (
<div className="flex flex-wrap items-center gap-2">
<Mention variant="user">@username</Mention>
<Mention variant="channel">#channel</Mention>
<Mention variant="role" color="#f0b232">
@Moderator
</Mention>
<Mention variant="user" avatar={AVATAR}>
@with-avatar
</Mention>
</div>
)
}<script setup lang="ts">
import { Mention } from "~~/registry/bases/newt/ui/mention"
/* Inline so the demo never reaches out to the network for a placeholder. */
const AVATAR =
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='10' cy='10' r='10' fill='%235865f2'/%3E%3C/svg%3E"
</script>
<template>
<div class="flex flex-wrap items-center gap-2">
<Mention variant="user">@username</Mention>
<Mention variant="channel">#channel</Mention>
<Mention variant="role" color="#f0b232">@Moderator</Mention>
<Mention variant="user" :avatar="AVATAR">@with-avatar</Mention>
</div>
</template>Installation
npx newtui@latest add mentionnpx shadcn@latest add @newtui/mentionnpx shadcn-vue@latest add @newtui/mentionpnpm dlx newtui@latest add mentionpnpm dlx shadcn@latest add @newtui/mentionpnpm dlx shadcn-vue@latest add @newtui/mentionyarn dlx newtui@latest add mentionyarn dlx shadcn@latest add @newtui/mentionyarn dlx shadcn-vue@latest add @newtui/mentionbunx newtui@latest add mentionbunx shadcn@latest add @newtui/mentionbunx shadcn-vue@latest add @newtui/mentiondeno run -A npm:newtui@latest add mentiondeno run -A npm:shadcn@latest add @newtui/mentiondeno run -A npm:shadcn-vue@latest add @newtui/mentionvlx newtui@latest add mentionvlx shadcn@latest add @newtui/mentionvlx shadcn-vue@latest add @newtui/mentionvp dlx newtui@latest add mentionvp dlx shadcn@latest add @newtui/mentionvp dlx shadcn-vue@latest add @newtui/mentionnubx newtui@latest add mentionnubx shadcn@latest add @newtui/mentionnubx shadcn-vue@latest add @newtui/mentionnlx newtui@latest add mentionnlx shadcn@latest add @newtui/mentionnlx shadcn-vue@latest add @newtui/mentionupx newtui@latest add mentionupx shadcn@latest add @newtui/mentionupx shadcn-vue@latest add @newtui/mention- newtui
- shadcn
- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
The shadcn CLI needs the @newtui registry in your components.json. Set it up.
Install the dependencies
npm install class-variance-authoritypnpm add class-variance-authorityyarn add class-variance-authoritybun add class-variance-authoritydeno add npm:class-variance-authorityvlt install class-variance-authorityvp add class-variance-authoritynub add class-variance-authorityni class-variance-authorityupm add class-variance-authority- npm
- pnpm
- yarn
- bun
- deno
- vlt
- vp
- nub
- ni
- upm
Copy the source into your project
import { cva, type VariantProps } from "class-variance-authority"
import * as React from "react"
import { cn } from "@/lib/utils"
/*
* Every variant only sets two custom properties: the tint the chip renders at
* rest and the solid colour it fills with on hover. A role mention overrides
* `--newt-mention-color` inline with the role's own hue, and its hover fill
* follows automatically.
*/
const mentionVariants = cva(
"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",
{
variants: {
variant: {
user: "[--newt-mention-color:var(--newt-mention-text)] [--newt-mention-solid:var(--newt-brand)]",
channel:
"[--newt-mention-color:var(--newt-text-link)] [--newt-mention-solid:var(--newt-brand)]",
role: "[--newt-mention-color:var(--newt-mention-role)] [--newt-mention-solid:var(--newt-mention-color)]",
app: "[--newt-mention-color:var(--newt-mention-text)] [--newt-mention-solid:var(--newt-brand)]",
},
/*
* A mention that opens nothing (`as="span"`) keeps the tint but drops
* the pointer, the hover fill and the focus ring: it is text, not a
* control, and stays out of the tab order.
*/
interactive: {
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",
false: "",
},
},
defaultVariants: {
variant: "user",
interactive: true,
},
}
)
/** The element a mention renders as. */
export type MentionElement = "button" | "a" | "span"
export interface MentionProps
extends
Omit<React.HTMLAttributes<HTMLElement>, "color">,
Omit<VariantProps<typeof mentionVariants>, "interactive"> {
/**
* `button` (the default) for a mention that opens something in place, `a`
* for one that navigates (pass `href`), `span` for a read-only mention that
* is neither focusable nor clickable.
*/
as?: MentionElement
/** Link target, for `as="a"`. Passing it without `as` renders a link. */
href?: string
/** Avatar URL. Rendered from 48rem up; below that the chip stays text-only. */
avatar?: string
/** Role colour, for `variant="role"`. Any CSS colour. */
color?: string
}
/* Widens the tag so one ref type serves all three elements it can be. */
function asElementType(element: MentionElement): React.ElementType {
return element
}
const Mention = React.forwardRef<HTMLElement, MentionProps>(
(
{ as, href, className, variant, avatar, color, children, style, ...props },
ref
) => {
const element: MentionElement = as ?? (href === undefined ? "button" : "a")
const Tag = asElementType(element)
return (
<Tag
ref={ref}
type={element === "button" ? "button" : undefined}
href={element === "a" ? href : undefined}
data-variant={variant ?? "user"}
/*
* SAFETY: `CSSProperties` has no index signature for custom properties,
* but React forwards unknown `--*` keys to the style attribute
* verbatim, so the extra key is written out exactly as spelled here.
*/
style={
color
? ({
...style,
"--newt-mention-color": color,
} as React.CSSProperties)
: style
}
className={cn(
mentionVariants({ variant, interactive: element !== "span" }),
avatar && "ps-0.5",
className
)}
{...props}
>
{avatar ? (
<img
src={avatar}
alt=""
aria-hidden="true"
className="hidden h-5 w-5 shrink-0 rounded-full object-cover md:block"
/>
) : null}
{children}
</Tag>
)
}
)
Mention.displayName = "Mention"
export { Mention, mentionVariants }<script setup lang="ts">
import type { CSSProperties, HTMLAttributes } from "vue"
import { computed } from "vue"
import { cn } from "@/lib/utils"
import { mentionVariants, type MentionElement, type MentionVariants } from "."
const props = defineProps<{
class?: HTMLAttributes["class"]
variant?: MentionVariants["variant"]
/**
* `button` (the default) for a mention that opens something in place, `a`
* for one that navigates (pass `href`), `span` for a read-only mention that
* is neither focusable nor clickable.
*/
as?: MentionElement
/** Link target, for `as="a"`. Passing it without `as` renders a link. */
href?: string
/** Avatar URL. Rendered from 48rem up; below that the chip stays text-only. */
avatar?: string
/** Role colour, for `variant="role"`. Any CSS colour. */
color?: string
}>()
const tag = computed<MentionElement>(
() => props.as ?? (props.href === undefined ? "button" : "a")
)
/*
* SAFETY: `CSSProperties` has no index signature for custom properties, but
* Vue writes unknown `--*` keys to the style attribute verbatim, so the extra
* key lands exactly as spelled here.
*/
const style = computed<CSSProperties | undefined>(() =>
props.color
? ({ "--newt-mention-color": props.color } as CSSProperties)
: undefined
)
</script>
<template>
<component
:is="tag"
:type="tag === 'button' ? 'button' : undefined"
:href="tag === 'a' ? props.href : undefined"
:data-variant="props.variant ?? 'user'"
:style="style"
:class="
cn(
mentionVariants({
variant: props.variant,
interactive: tag !== 'span',
}),
props.avatar && 'ps-0.5',
props.class
)
"
>
<img
v-if="props.avatar"
:src="props.avatar"
alt=""
aria-hidden="true"
class="hidden h-5 w-5 shrink-0 rounded-full object-cover md:block"
/>
<slot />
</component>
</template>import { cva, type VariantProps } from "class-variance-authority"
export { default as Mention } from "./Mention.vue"
/*
* Every variant only sets two custom properties: the tint the chip renders at
* rest and the solid colour it fills with on hover. A role mention overrides
* `--newt-mention-color` inline with the role's own hue, and its hover fill
* follows automatically.
*/
export const mentionVariants = cva(
"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",
{
variants: {
variant: {
user: "[--newt-mention-color:var(--newt-mention-text)] [--newt-mention-solid:var(--newt-brand)]",
channel:
"[--newt-mention-color:var(--newt-text-link)] [--newt-mention-solid:var(--newt-brand)]",
role: "[--newt-mention-color:var(--newt-mention-role)] [--newt-mention-solid:var(--newt-mention-color)]",
app: "[--newt-mention-color:var(--newt-mention-text)] [--newt-mention-solid:var(--newt-brand)]",
},
/*
* A mention that opens nothing (`as="span"`) keeps the tint but drops
* the pointer, the hover fill and the focus ring: it is text, not a
* control, and stays out of the tab order.
*/
interactive: {
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",
false: "",
},
},
defaultVariants: {
variant: "user",
interactive: true,
},
}
)
export type MentionVariants = VariantProps<typeof mentionVariants>
/** The element a mention renders as. */
export type MentionElement = "button" | "a" | "span"Update the import paths
The files import @/lib/utils and sibling components through the aliases in your components.json. Point them at wherever those live in your project.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Mention Chip to your React project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
No CLI, no components.json: paste this into Claude, Cursor, Copilot or any coding assistant and it adds Mention Chip to your Vue project by hand. The prompt carries the source of every file the CLI would write — this component's and those of the components it builds on — with the imports already pointed at the default aliases.
Usage
import { Mention } from "@/components/ui/mention"
export function Example() {
return <Mention />
}<script setup lang="ts">
import { Mention } from "@/components/ui/mention"
</script>
<template>
<Mention />
</template>API reference
Mention
as?"button" | "a" | "span"
`button` opens something in place, `a` navigates, `span` is a read-only mention: not focusable, no hover fill.
"button" | "a" | "span""button", or "a" with `href`href?string | undefined
Link target. Passing it without `as` renders a link.
string | undefinedavatar?string | undefined
Avatar URL. Rendered from 48rem up; below that the chip stays text-only.
string | undefinedcolor?string | undefined
Role colour, for `variant="role"`. Any CSS colour.
string | undefinedThe registry exports Mention. Parts without a table accept the native attributes for the element they render; React uses className, while Vue uses class and fallthrough attributes.
Accessibility
Preserve the native semantics of the rendered elements and pass through ARIA attributes when the surrounding context needs a label or description. Any interactive child needs a visible focus indicator, and meaning must not rely on colour alone.
Tokens
Mention Chip reads its colours, radii and motion from the --newt-* tokens installed with the library. Override a token and every component that reads it follows, including this one — see the token layer. In the plain HTML and CSS distribution the same component is newt-mention.
--newt-radius-sm--newt-duration-fast--newt-ease--newt-mention-text--newt-brand--newt-text-link--newt-mention-role--newt-on-accent--newt-radius-full