Skip to content

XDSBadge: Add non-semantic color variants and darken neutral grey #244

Closed

Description

@rubyycheung

Summary

XDSBadge currently only supports semantic color variants (neutral, info, success, warning, error). We need to add non-semantic color variants to match the internal docs tool reference and darken the grey used for the neutral variant.

Reference: [internal link removed]

What needs to change

1. Add non-semantic color variants

The internal docs tool Badge supports a broader set of color options beyond semantic meaning. We should add variants like:

  • blue
  • purple
  • pink
  • teal
  • cyan
  • orange
  • yellow
  • gray
  • green
  • red

These are useful when badges are used for categorization, tagging, or labeling where the color does not carry semantic meaning (e.g. team labels, category tags, filter chips).

2. Darken the neutral grey

The current neutral variant uses --color-deemphasized which is only ~5% opacity in light mode (#0536590C). It should use --color-gray-background (#0A131733, ~20% opacity) for better visual contrast matching the internal docs tool reference.

Suggested implementation

The token system already has all the non-semantic color sets (--color-{color}-background and --color-{color}-text). The fix maps directly to existing tokens — no new tokens needed.

// In XDSBadge.tsx — add non-semantic variants using existing color tokens

const variants = stylex.create({
  // Semantic variants (existing)
  neutral: {
    backgroundColor: colorVars['--color-gray-background'],  // was --color-deemphasized (too light)
    color: colorVars['--color-text-primary'],
  },
  info: {
    backgroundColor: colorVars['--color-accent'],
    color: colorVars['--color-text-on-media'],
  },
  success: {
    backgroundColor: colorVars['--color-positive'],
    color: colorVars['--color-text-on-media'],
  },
  warning: {
    backgroundColor: colorVars['--color-warning'],
    color: colorVars['--color-text-primary'],
  },
  error: {
    backgroundColor: colorVars['--color-negative'],
    color: colorVars['--color-text-on-media'],
  },

  // Non-semantic color variants (new)
  blue: {
    backgroundColor: colorVars['--color-blue-background'],
    color: colorVars['--color-blue-text'],
  },
  cyan: {
    backgroundColor: colorVars['--color-cyan-background'],
    color: colorVars['--color-cyan-text'],
  },
  gray: {
    backgroundColor: colorVars['--color-gray-background'],
    color: colorVars['--color-gray-text'],
  },
  green: {
    backgroundColor: colorVars['--color-green-background'],
    color: colorVars['--color-green-text'],
  },
  orange: {
    backgroundColor: colorVars['--color-orange-background'],
    color: colorVars['--color-orange-text'],
  },
  pink: {
    backgroundColor: colorVars['--color-pink-background'],
    color: colorVars['--color-pink-text'],
  },
  purple: {
    backgroundColor: colorVars['--color-purple-background'],
    color: colorVars['--color-purple-text'],
  },
  red: {
    backgroundColor: colorVars['--color-red-background'],
    color: colorVars['--color-red-text'],
  },
  teal: {
    backgroundColor: colorVars['--color-teal-background'],
    color: colorVars['--color-teal-text'],
  },
  yellow: {
    backgroundColor: colorVars['--color-yellow-background'],
    color: colorVars['--color-yellow-text'],
  },
});

The type XDSBadgeVariant = keyof typeof variants updates automatically — no manual type changes needed.

Key design notes

  • Non-semantic badges use tinted backgrounds + colored text (subtle style), while semantic badges use solid backgrounds + white text (bold style). This matches the internal docs tool pattern where non-semantic colors are softer.
  • neutral fix: swap --color-deemphasized → --color-gray-background for darker grey.
  • No new tokens required — everything maps to existing --color-{color}-background and --color-{color}-text tokens.

Affected files

  • packages/core/src/Badge/XDSBadge.tsx — add new variant styles (neutral fix + non-semantic colors)
  • packages/core/src/Badge/XDSBadge.test.tsx — tests for new variants
  • apps/storybook/stories/Badge.stories.tsx — add stories for non-semantic variants

Current variants

neutral | info | success | warning | error

Proposed variants

neutral | info | success | warning | error | blue | cyan | gray | green | orange | pink | purple | red | teal | yellow

Activity

  1. rubyycheung commented on Feb 21, 2026

    @rubyycheung
    ContributorAuthor

    @cixzhang Why was the non-semantic colors not added?

  2. cixzhang commented on Feb 22, 2026

    @cixzhang
    Contributor

    Badges were added as part of a test for the PR enrichment flow so likely need refinements.

    You can reference the token now for non semantic colors.

  3. added
    enhancement
    on Feb 25, 2026
  4. added 2 commits that reference this issue on Feb 26, 2026
    1641b5a
    30b636f
  5. added 2 commits that reference this issue on Feb 27, 2026
    852cac9
    9f6364e
  6. added
    component
    on Mar 1, 2026
  7. cixzhang commented on Mar 8, 2026

    @cixzhang
    Contributor

    We need a secondary token for buttons tokens and these default badges

  8. cixzhang commented on Mar 26, 2026

    @cixzhang
    Contributor

    Merged into #719 (Cindy's Components — Badge section). Non-semantic color variants tracked there.

  9. added 4 commits that reference this issue on Apr 4, 2026
    55ffc9b
    f4e86d1
    0cd43df
    1037fd8
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

    componentenhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions