Skip to content

XDSToken component #81

Closed
Closed

Description

@cixzhang

Spec

A chip/tag component for displaying entities inline. Used standalone for tags/labels and composed by XDSTokenizer for multi-select inputs.

API

type XDSTokenColor =
  | "default"
  | "red" | "orange" | "yellow" | "green" | "teal"
  | "cyan" | "blue" | "purple" | "pink" | "gray";

interface XDSTokenProps {
  /** Text displayed in the token (required) */
  label: string;
  /** Color variant */
  color?: XDSTokenColor; // default: "default"
  /** Icon before the label */
  icon?: ReactNode;
  /** Whether the token is disabled */
  isDisabled?: boolean;
  /** Shows X button. Called when remove is activated. */
  onRemove?: (event: MouseEvent | KeyboardEvent) => void;
  /** Click handler. Makes the token interactive/clickable. */
  onClick?: (event: MouseEvent) => void;
  /** Link href. Makes the token a link. */
  href?: string;
  /** Description text below the label */
  description?: string;
  /** Content after the label, before the remove button (e.g., badge) */
  endContent?: ReactNode;
  /** Hide the label (icon-only token) */
  isLabelHidden?: boolean;
  /** StyleX overrides (margins) */
  xstyle?: StyleXStyles;
  /** Test ID */
  "data-testid"?: string;
}

Usage

// Basic
<XDSToken label="React" />

// With color and remove
<XDSToken label="Bug" color="red" onRemove={() => removeTag("bug")} />

// Clickable
<XDSToken label="Alice" icon={<XDSAvatar ... />} onClick={() => showProfile("alice")} />

// Link
<XDSToken label="Issue #42" href="/issues/42" color="blue" />

// With end content
<XDSToken label="Priority" endContent={<XDSBadge label="3" />} />

Visual design

  • Pill shape (rounded corners)
  • Background uses non-semantic color tokens: --color-{name}-background
  • Text uses --color-{name}-text
  • Border uses --color-{name}-border
  • Default color uses --color-deemphasized background
  • Interactive tokens show hover/press states
  • Disabled: 50% opacity, not-allowed cursor
  • Remove button (X): appears when onRemove is provided

Color tokens used

Color Background Text Border
default --color-deemphasized --color-text-primary none
red --color-red-background --color-red-text --color-red-border
blue --color-blue-background --color-blue-text --color-blue-border
... --color-{name}-background --color-{name}-text --color-{name}-border

Accessibility

  • Interactive tokens (onClick/href): role="button" or <a>, focusable
  • Remove button: aria-label="Remove {label}"
  • Disabled: aria-disabled="true"
  • Non-interactive: no role, just display

Design decisions

Decision Choice Rationale
Non-semantic colors 10 colors from token palette Matches internal pattern, covers tag/category use cases
No highlighted variant Removed Only used for tokenizer focus state, handle internally
onRemove shows X If provided, X button appears always Skip hasRemoveOnHover (17 internal usages vs 6k total)
onClick + href both supported ~700 onClick + ~200 href internally Significant usage of interactive tokens

Depends on

  • Non-semantic color tokens already exist in tokens.stylex.ts

Used by


External comparison

Capability XDSToken Chakra Tag Mantine Badge / Pill MUI Chip Ant Tag
Component model Single <XDSToken> Compound: Tag.Root > Tag.Label, Tag.StartElement, Tag.EndElement, Tag.CloseTrigger Badge (display) + Pill (removable, input-oriented) Single <Chip> Single <Tag>
Label label (required string) Tag.Label child children label children
Color color — 10 named + "default" colorPalette — any palette token color — any theme color; variant — filled / light / outline / gradient color — "default" / "primary" / "secondary" / "error" / "info" / "success" / "warning" color — preset names or hex string
Icon icon (ReactNode, start) Tag.StartElement / Tag.EndElement (composition) leftSection / rightSection icon (start), deleteIcon (end) icon
Remove / close onRemove callback → shows X Tag.CloseTrigger child Pill with withRemoveButton + onRemove onDelete callback → shows delete icon closable boolean + onClose callback
Clickable onClick prop onClick on root Polymorphic component prop onClick + clickable boolean Wrap children in <a>
Link href prop Polymorphic as="a" Polymorphic component="a" component="a" + href Wrap in <a> child
End content endContent (ReactNode) Tag.EndElement (composition) rightSection deleteIcon (limited to icon) Not supported
Disabled isDisabled disabled on root Not built-in disabled Not built-in
Sizes Not in v1 (single size) size (sm/md/lg) size (xs–xl) size (small/medium) Not built-in
Styling escape xstyle (StyleX only) css / Panda classNames / styles (Styles API) sx / className className / style
Hidden label isLabelHidden Not built-in Not built-in Not built-in Not built-in

Key takeaways:

  • Chakra v3 uses compound composition (Tag.Root > Tag.Label); all others use flat prop APIs like XDSToken.
  • Mantine splits the concept: Badge for display, Pill for removable tags inside inputs — XDSToken covers both.
  • MUI Chip requires an explicit clickable boolean; XDSToken infers interactivity from onClick / href.
  • endContent as a generic ReactNode slot is unique to XDSToken — MUI limits the end slot to a delete icon, Ant has no end slot.
  • isLabelHidden (icon-only token) is not offered by any compared library.

Internal usage data

~6,000+ total usages of XDSToken across the internal codebase.

Prop Count % of total Notes
label 3,427 ~57% Required prop — gap from 6k suggests some legacy patterns without explicit label
icon 1,462 ~24% Nearly 1 in 4 tokens has an icon (often avatars for people tokens)
onClick 948 ~16% Interactive / clickable tokens
endContent 623 ~10% Badge counts, status indicators, etc.
onRemove 557 ~9% Removable tokens (most via XDSTokenizer composition)
href 527 ~9% Link tokens — combined with onClick, ~25% of tokens are interactive

Color distribution:

Color Count
blue 22
green 22
red 19
purple 7
yellow 5
  • Total colored tokens: 75 out of 6,000+ (~1.2%). The vast majority use the default color.
  • Blue, green, and red account for 84% of colored usage — confirms these are the most important non-default colors.
  • Low overall color usage validates the decision to keep color optional with a sensible default.

Activity

  1. added this to the Component set 2 milestone on Feb 6, 2026
  2. czarandy commented on Feb 13, 2026

    @czarandy
    Collaborator

    one annoying thing with XDSToken is it has built-in margin which makes it awkward to use outside of XDSTokenizer
    we should make sure to avoid that

  3. added
    enhancement
    on Feb 18, 2026
  4. changed the title [-]Tokens[/-] [+]XDSToken component[/+] on Feb 18, 2026
  5. added 2 commits that reference this issue on Feb 20, 2026
    06ea2a6
    e476f07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions