Skip to content

ComponentsIdentity & presence

SourceSource

Role Tag

A compact bordered tag with a coloured dot for displaying a member's role.

A compact bordered tag with a coloured dot for displaying a member’s role. Compose it from the exported registry parts so local content and behaviour stay in the application while the visual contract stays token-driven.

Root class newt-role-tag
import { RoleTag, RoleTagDot } from "@/registry/bases/newt/ui/role-tag"

export default function RoleTagDemo() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <RoleTag>
        <RoleTagDot />
        Role name
      </RoleTag>
      <RoleTag color="#5865f2">
        <RoleTagDot />
        Admin
      </RoleTag>
      <RoleTag color="#23a55a">
        <RoleTagDot />
        Moderator
      </RoleTag>
    </div>
  )
}
<script setup lang="ts">
import { RoleTag, RoleTagDot } from "~~/registry/bases/newt/ui/role-tag"
</script>

<template>
  <div class="flex flex-wrap items-center gap-2">
    <RoleTag>
      <RoleTagDot />
      Role name
    </RoleTag>
    <RoleTag color="#5865f2">
      <RoleTagDot />
      Admin
    </RoleTag>
    <RoleTag color="#23a55a">
      <RoleTagDot />
      Moderator
    </RoleTag>
  </div>
</template>

Installation

npx newtui@latest add role-tagnpx shadcn@latest add @newtui/role-tagnpx shadcn-vue@latest add @newtui/role-tagpnpm dlx newtui@latest add role-tagpnpm dlx shadcn@latest add @newtui/role-tagpnpm dlx shadcn-vue@latest add @newtui/role-tagyarn dlx newtui@latest add role-tagyarn dlx shadcn@latest add @newtui/role-tagyarn dlx shadcn-vue@latest add @newtui/role-tagbunx newtui@latest add role-tagbunx shadcn@latest add @newtui/role-tagbunx shadcn-vue@latest add @newtui/role-tagdeno run -A npm:newtui@latest add role-tagdeno run -A npm:shadcn@latest add @newtui/role-tagdeno run -A npm:shadcn-vue@latest add @newtui/role-tagvlx newtui@latest add role-tagvlx shadcn@latest add @newtui/role-tagvlx shadcn-vue@latest add @newtui/role-tagvp dlx newtui@latest add role-tagvp dlx shadcn@latest add @newtui/role-tagvp dlx shadcn-vue@latest add @newtui/role-tagnubx newtui@latest add role-tagnubx shadcn@latest add @newtui/role-tagnubx shadcn-vue@latest add @newtui/role-tagnlx newtui@latest add role-tagnlx shadcn@latest add @newtui/role-tagnlx shadcn-vue@latest add @newtui/role-tagupx newtui@latest add role-tagupx shadcn@latest add @newtui/role-tagupx shadcn-vue@latest add @newtui/role-tag

The shadcn CLI needs the @newtui registry in your components.json. Set it up.

Copy the source into your project

import * as React from "react"

import { cn } from "@/lib/utils"

export interface RoleTagProps extends React.ComponentProps<"span"> {
  /** Role colour applied to the tag; the dot inherits it via `currentColor`. */
  color?: string
}

const RoleTag = React.forwardRef<HTMLSpanElement, RoleTagProps>(
  ({ className, color, style, ...props }, ref) => (
    <span
      ref={ref}
      className={cn(
        "inline-flex items-center gap-1 rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-elevated px-1.5 py-0.5 text-[11px] font-semibold",
        className
      )}
      style={color ? { color, ...style } : style}
      {...props}
    />
  )
)
RoleTag.displayName = "RoleTag"

const RoleTagDot = React.forwardRef<
  HTMLSpanElement,
  React.ComponentProps<"span">
>(({ className, ...props }, ref) => (
  <span
    ref={ref}
    aria-hidden="true"
    className={cn("h-2 w-2 rounded-full bg-current", className)}
    {...props}
  />
))
RoleTagDot.displayName = "RoleTagDot"

export { RoleTag, RoleTagDot }
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{
  /** Role colour applied to the tag; the dot inherits it via `currentColor`. */
  color?: string
  class?: HTMLAttributes["class"]
}>()
</script>

<template>
  <span
    :class="
      cn(
        'inline-flex items-center gap-1 rounded-[var(--newt-radius-sm)] border border-newt-border bg-newt-bg-elevated px-1.5 py-0.5 text-[11px] font-semibold',
        props.class
      )
    "
    :style="props.color ? { color: props.color } : undefined"
  >
    <slot />
  </span>
</template>
<script setup lang="ts">
import type { HTMLAttributes } from "vue"

import { cn } from "@/lib/utils"

const props = defineProps<{
  class?: HTMLAttributes["class"]
}>()
</script>

<template>
  <span
    aria-hidden="true"
    :class="cn('h-2 w-2 rounded-full bg-current', props.class)"
  />
</template>
export { default as RoleTag } from "./RoleTag.vue"
export { default as RoleTagDot } from "./RoleTagDot.vue"

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 Role Tag 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 Role Tag 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 { RoleTag } from "@/components/ui/role-tag"

export function Example() {
  return <RoleTag />
}
<script setup lang="ts">
import { RoleTag, RoleTagDot } from "@/components/ui/role-tag"
</script>

<template>
  <RoleTag />
</template>

Examples

Without a dot

Leave RoleTagDot out when the tag works as a plain label. The color prop still tints the text.

Root class newt-role-tag
import { RoleTag } from "@/registry/bases/newt/ui/role-tag"

/* Without `RoleTagDot` the tag is a label; `color` still tints the text. */
export default function RoleTagPlainDemo() {
  return (
    <div className="flex flex-wrap items-center gap-2">
      <RoleTag>Member</RoleTag>
      <RoleTag color="#f0b232">Event host</RoleTag>
      <RoleTag color="#eb459e">Artist</RoleTag>
    </div>
  )
}
<script setup lang="ts">
import { RoleTag } from "~~/registry/bases/newt/ui/role-tag"

/* Without `RoleTagDot` the tag is a label; `color` still tints the text. */
</script>

<template>
  <div class="flex flex-wrap items-center gap-2">
    <RoleTag>Member</RoleTag>
    <RoleTag color="#f0b232">Event host</RoleTag>
    <RoleTag color="#eb459e">Artist</RoleTag>
  </div>
</template>

Role list

Several tags wrap inside a narrow column, such as a member profile. Mark the group up as a list so the number of roles is announced.

Root class newt-role-tag
import { RoleTag, RoleTagDot } from "@/registry/bases/newt/ui/role-tag"

const ROLES = [
  { name: "Admin", color: "#5865f2" },
  { name: "Moderator", color: "#23a55a" },
  { name: "Event host", color: "#f0b232" },
  { name: "Artist", color: "#eb459e" },
  { name: "Early member", color: "#949ba4" },
]

/* A member's roles as a real list, so the count is announced with them. */
export default function RoleTagListDemo() {
  return (
    <div className="flex w-full max-w-[260px] flex-col gap-2 text-start">
      <span
        id="role-tag-list-heading"
        className="text-xs font-bold uppercase text-newt-text-muted"
      >
        Roles
      </span>
      <ul
        aria-labelledby="role-tag-list-heading"
        className="m-0 flex list-none flex-wrap gap-1 p-0"
      >
        {ROLES.map((role) => (
          <li key={role.name} className="flex">
            <RoleTag color={role.color}>
              <RoleTagDot />
              {role.name}
            </RoleTag>
          </li>
        ))}
      </ul>
    </div>
  )
}
<script setup lang="ts">
import { RoleTag, RoleTagDot } from "~~/registry/bases/newt/ui/role-tag"

/* A member's roles as a real list, so the count is announced with them. */
const roles = [
  { name: "Admin", color: "#5865f2" },
  { name: "Moderator", color: "#23a55a" },
  { name: "Event host", color: "#f0b232" },
  { name: "Artist", color: "#eb459e" },
  { name: "Early member", color: "#949ba4" },
]
</script>

<template>
  <div class="flex w-full max-w-[260px] flex-col gap-2 text-start">
    <span
      id="role-tag-list-heading"
      class="text-xs font-bold uppercase text-newt-text-muted"
    >
      Roles
    </span>
    <ul
      aria-labelledby="role-tag-list-heading"
      class="m-0 flex list-none flex-wrap gap-1 p-0"
    >
      <li v-for="role in roles" :key="role.name" class="flex">
        <RoleTag :color="role.color">
          <RoleTagDot />
          {{ role.name }}
        </RoleTag>
      </li>
    </ul>
  </div>
</template>

API reference

RoleTag

PropType
color?string | undefined

Role colour applied to the tag; the dot inherits it via `currentColor`.

Typestring | undefined

The registry exports RoleTag, RoleTagDot. 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

Role Tag 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-role-tag.

  • --newt-radius-sm
  • --newt-bg-elevated
  • --newt-border