@vigdx/ui v2.2.0 on npm (opens in a new tab)

Theming

Every color, radius, shadow and duration of the kit is a CSS custom property declared with @theme default . Override it in your own @theme , on a subtree or on a single instance — components never hardcode a value.

View as Markdown

How tokens work

theme.css declares the tokens inside one @theme default block. Tailwind compiles them to utilities (bg-primary, text-muted-foreground, rounded-button) and to plain CSS custom properties on :root. Because they are defaults, anything you declare in a regular @theme wins regardless of import order.

Semantic names come in families:

  • --color-<name> with -foreground and -hover companions (primary, secondary, info, success, warning, error, accent)
  • Surfaces and text: background, app, subtle, muted, foreground …
  • --radius-<component>, compiled to rounded-<component>
  • --shadow-* for elevation and focus rings, --ease-* and --duration-* for motion

Override globally

Redefine tokens in your stylesheet's @theme block:

styles.css
/* styles.css — after @import '@vigdx/ui/theme.css' */
@theme {
  --color-primary: oklch(0.55 0.2 150);
  --color-primary-hover: oklch(0.5 0.19 150);
  --color-primary-active: oklch(0.45 0.18 150);
  --radius-button: 9999px;
}

Without Tailwind, with the precompiled @vigdx/ui/styles.css, declare the same custom properties in plain CSS. The file keeps its tokens in the vigdx cascade layer, so your declarations outside it win whatever the import order. Unlike an @theme override with Tailwind, a :root override applies in dark mode too (it outranks the kit's .dark palette): re-declare under .dark every token dark mode changes, for a brand color the whole family.

styles.css
/* styles.css — after @import '@vigdx/ui/styles.css' (no Tailwind) */
:root {
  --color-primary: #1f6f4a;
  --color-primary-hover: #185c3d;
  --color-primary-active: #134a31;
  --color-primary-foreground: #ffffff;
  --radius-button: 9999px;
}

/* :root applies in both schemes: re-declare the whole family for dark mode */
.dark {
  --color-primary: #5fc796;
  --color-primary-hover: #84d5ae;
  --color-primary-active: #a9e2c6;
  --color-primary-foreground: #0b0e14;
}

Whichever way you override, keep the contrast contract.

Override a subtree or one instance

Tokens are custom properties, so they cascade. Set them on any element to re-theme what is inside it — try it:

theme default

Badge

Contrast check

Contrast of the token pairs the kit relies on, in the themed preview
PairUsed forRatioMinimumResult
HTML
<!-- Every button inside this section becomes a pill -->
<section style="--radius-button: 9999px">
  <vig-button label="Get started" />
</section>

<!-- One instance -->
<vig-button style="--radius-button: 0" label="Sharp" />
CSS
.marketing-hero {
  --color-primary: var(--color-accent);
  --color-primary-hover: var(--color-accent-hover);
}

WarningOverlays render outside the subtree

Inline components follow subtree overrides. Body-level overlays (menus, dialogs, tooltips) render outside the subtree and inherit from :root.

Customizing: tokens → parts → class

Reach for the three styling layers in this order:

  1. Tokens. Most changes are a custom property: a color, a radius, a duration. They apply everywhere the token is used and survive kit updates.
  2. Parts. Each component marks its meaningful internal elements with a stable data-part attribute and the component's data-scope — trigger, panel, option, close… — and exposes state through data-state and aria-*. Every component page lists its parts under "Styling hooks". Parts are public API: the CI gate records them, so a part is only removed in a major release.
  3. A host class for layout around the component (width, margins, grid placement).
styles.css
/* styles.css — global CSS, outside any @layer (or in a layer after utilities) */
[data-scope='chip'][data-part='close'] {
  color: var(--color-error);
}

/* Overlay panels render outside the host; the scope still matches them */
[data-scope='select'][data-part='panel'] {
  max-height: 20rem;
}

/* State comes from data-state and aria-* */
[data-scope='accordion'][data-part='trigger'][data-state='open'] {
  font-weight: 700;
}
HTML
<!-- The same, as a Tailwind arbitrary variant on the host -->
<vig-chip
  class="[&_[data-scope=chip][data-part=close]]:text-error"
  label="Urgent"
  closable
/>

Select a part by its data-scope and data-part together. A descendant selector such as vig-multi-select [data-part=label] would also hit the parts of kit components nested inside (the chips of a multi-select), and misses overlay panels, which render outside the host.

No !important is needed, as long as the rule is in the right place. The kit's classes are Tailwind utilities, which your build compiles into Tailwind's @layer utilities. A rule wins over them, whatever its specificity, when it is in global CSS outside any cascade layer, or in a layer ordered after utilities. It loses inside @layer components or @layer base, in a stylesheet imported with @import … layer(x) unless that layer comes after utilities, and in a component's own (emulated-encapsulation) styles, which never reach the kit's elements without ::ng-deep. With the precompiled @vigdx/ui/styles.css the kit's utilities are unlayered and scoped to its elements (.p-2:where([data-scope]), specificity 0,1,0): a part selector (0,2,0) beats them anywhere, a rule of equal specificity when loaded after styles.css, and a rule inside any cascade layer never does. Put part overrides in a global stylesheet:

styles.css
/* styles.css — to keep your own rules layered, order an app layer last */
@layer theme, base, components, utilities, app;
@import 'tailwindcss';
@import '@vigdx/ui/theme.css';

@layer app {
  [data-scope='chip'][data-part='close'] {
    color: var(--color-error);
  }
}

Overlays that animate (dialog, drawer, menus, popover, command menu, the tree select, cascade select and color picker panels, the image and galleria viewer) mark the animating element with data-opening while their entrance plays and data-closing while their exit plays, and remove the attribute once the transition settles (two seconds at most). Both are stable hooks, listed with each component's parts: style an entrance or exit with Tailwind's data-opening: and data-closing: variants, and the test harnesses of @vigdx/ui/testing wait on them.

An arbitrary variant such as [&_[data-scope=chip][data-part=close]]:text-error stays inside the utilities layer, but its selector (a class plus two attributes) is more specific than the part's own single-class utilities. For hover and focus styles, which the kit also sets with variants, prefer global CSS. The Storybook story “Core / Styling hooks” checks these cases in a real browser, with zero-specificity :where() rules.

Dark mode

theme.css ships a dark palette under the .dark class: semantic tokens only, with brand and status hues lifted to hold WCAG AA on dark grounds. Put the class on <html> — this site does exactly that from the theme switch in the site navigation.

TypeScript
// Put .dark on <html> so body-level overlays (menus, dialogs) follow too.
document.documentElement.classList.toggle('dark', prefersDark);
CSS
/* Make Tailwind's dark: variant follow the same class */
@custom-variant dark (&:where(.dark, .dark *));

/* Re-theme dark mode: declare your own .dark block after the import */
.dark {
  --color-primary: #7aa2ff;
  --color-background: #0f141c;
}

Contrast contract

The components draw tokens on one another: --color-primary-foreground on --color-primary, a slider fill on a --color-muted track. The defaults and the dark palette meet WCAG AA for every such pair; when you override a token, keeping them there is yours to do. Automated audits miss many of these pairs (text over pseudo-elements and translucent tints, colors that only appear on hover), so check them whenever a token changes. The playground above computes them live for the colors you pick.

  • Text, 4.5:1: every text color on the surface it sits on, including each -foreground on its fill and on the fill's -hover, and the status hues as text on background (messages, field errors).
  • Text on tints, 4.5:1: each hue on its own 10% tint over background (soft badges, hovered text and outlined buttons), and each -hover token on its hue's 15% tint (pressed buttons, whose text takes the -hover token). Composite the tint over background before measuring; a hue that passes on background can fail on its own tint.
  • Non-text, 3:1: control boundaries (--color-border-control) and state indicators: --color-primary on background, muted, subtle and app (checked fills, slider, progress and knob fills on muted tracks, selection marks), and --color-rating on background and muted.
  • Focus rings derive from --color-primary (and --color-error on invalid fields). The offset ring draws a background gap and then primary, so primary needs 3:1 against background and against whatever surrounds the control.
  • Forced colors (Windows High Contrast) replace token colors with system colors and drop box shadows. Every focus ring is paired with an outline and states map to Highlight, GrayText and CanvasText, so no token override can break that mode. Your own CSS around the kit must not convey state with a token color or a shadow alone.
  • Dark mode: check every pair again under .dark. A dark theme on a class of its own, without the kit's .dark, must re-declare the status hues and --color-rating as well: the light ones give status text about 3.1:1 on a near-black surface.

WarningExample: a stock emerald primary

Tailwind's emerald-500 (#10b981) as --color-primary gives white button text 2.54:1 and a slider fill on slate-100 2.32:1, below both minimums. emerald-700 (#047857) holds 5.48:1 and 5.01:1.

Token pairs of the contrast contract
PairMinimumUsed for
--color-foreground on --color-background 4.5:1 Body text
--color-foreground-soft on --color-background 4.5:1 Secondary text
--color-muted-foreground on --color-background 4.5:1 Hints, placeholders, meta text
--color-muted-foreground on --color-subtle 4.5:1 Hints on read-only fields, wells and avatars
--color-link on --color-background 4.5:1 Inline links
--color-primary on --color-background 4.5:1 Text and outlined buttons, soft badges, selected items
--color-primary-foreground on --color-primary 4.5:1 Primary buttons, checked chips
--color-primary-foreground on --color-primary-hover 4.5:1 Hovered primary buttons
--color-primary-foreground on --color-primary-active 4.5:1 Pressed primary buttons
--color-secondary-foreground on --color-secondary 4.5:1 Secondary chips and buttons
--color-secondary-foreground on --color-secondary-hover 4.5:1 Hovered secondary chips and buttons
--color-info-foreground on --color-info 4.5:1 Solid info buttons and badges
--color-info-foreground on --color-info-hover 4.5:1 Hovered info buttons
--color-info on --color-background 4.5:1 Info text: messages
--color-success-foreground on --color-success 4.5:1 Solid success buttons and badges
--color-success-foreground on --color-success-hover 4.5:1 Hovered success buttons
--color-success on --color-background 4.5:1 Success text: messages
--color-warning-foreground on --color-warning 4.5:1 Solid warning buttons and badges
--color-warning-foreground on --color-warning-hover 4.5:1 Hovered warning buttons
--color-warning on --color-background 4.5:1 Warning text: messages
--color-error-foreground on --color-error 4.5:1 Solid error buttons and badges
--color-error-foreground on --color-error-hover 4.5:1 Hovered error buttons
--color-error on --color-background 4.5:1 Error text: messages, field errors, invalid borders
--color-accent-foreground on --color-accent 4.5:1 Solid accent buttons and badges
--color-accent-foreground on --color-accent-hover 4.5:1 Hovered accent buttons
--color-accent on --color-background 4.5:1 Accent text: messages
--color-primary on --color-primary at 10% over --color-background 4.5:1 Primary text on its 10% tint: soft badges and messages, hovered text and outlined buttons, selected toggles
--color-info on --color-info at 10% over --color-background 4.5:1 Info text on its 10% tint: soft badges and messages, hovered text and outlined buttons
--color-success on --color-success at 10% over --color-background 4.5:1 Success text on its 10% tint: soft badges and messages, hovered text and outlined buttons
--color-warning on --color-warning at 10% over --color-background 4.5:1 Warning text on its 10% tint: soft badges and messages, hovered text and outlined buttons
--color-error on --color-error at 10% over --color-background 4.5:1 Error text on its 10% tint: soft badges and messages, hovered text and outlined buttons
--color-accent on --color-accent at 10% over --color-background 4.5:1 Accent text on its 10% tint: soft badges and messages
--color-primary-hover on --color-primary at 15% over --color-background 4.5:1 Pressed primary text and outlined buttons (the text takes the -hover token), hovered selected toggles
--color-info-hover on --color-info at 15% over --color-background 4.5:1 Pressed info text and outlined buttons (the text takes the -hover token)
--color-success-hover on --color-success at 15% over --color-background 4.5:1 Pressed success text and outlined buttons (the text takes the -hover token)
--color-warning-hover on --color-warning at 15% over --color-background 4.5:1 Pressed warning text and outlined buttons (the text takes the -hover token)
--color-error-hover on --color-error at 15% over --color-background 4.5:1 Pressed error text and outlined buttons (the text takes the -hover token)
--color-border-control on --color-background 3:1 Form control boundaries: inputs, triggers, unchecked checkbox and radio, off switch
--color-primary on --color-muted 3:1 Slider range, progress bar, knob and meter fills on muted tracks
--color-primary on --color-subtle 3:1 Selection indicators on subtle rows and hovered items
--color-primary on --color-app 3:1 Focus rings around controls on the app canvas
--color-rating on --color-background 3:1 Filled rating icons
--color-rating on --color-muted 3:1 Filled rating icons on muted surfaces

Color tokens

Swatches are live: they follow the theme switch. The numeric scales (--color-primary-50 … -950, --color-surface-*, --color-viz-1 … -8) are primitives and keep their values in both schemes.

Color tokens
TokenDefaultDarkPurpose
--color-background#ffffffyesComponent surfaces (cards, panels, inputs, overlays)
--color-foreground#151a24yesPrimary text on background
--color-app#f7f8fayesApp canvas behind surfaces
--color-subtle#eff1f5yesLightest neutral fill (hover rows, wells)
--color-muted#e6e9efyesNeutral fill (tracks, skeletons, disabled fields)
--color-foreground-soft#4b5263yesSecondary text
--color-muted-foreground#626a7ayesHints, placeholders, meta text
--color-disabled#9aa2b1yesDisabled text and icons
--color-link#1f49c7yesInline link text
--color-border-subtle#e6e9efyesDividers inside surfaces
--color-border#dce0e8yesDefault surface border
--color-border-strong#c3c9d5yesDecorative and emphasised edges (panels, secondary buttons)
--color-border-control#6b7384yesForm control boundaries: ≥3:1 non-text contrast
--color-primary#2b5ce6yesBrand color: primary buttons, selection, focus rings
--color-secondary#eff1f5yesSecondary (neutral) buttons and chips
--color-info#2b5ce6yesInformational status
--color-success#11754fyesSuccess status
--color-warning#945806yesWarning status
--color-error#be3037yesError status, invalid fields, destructive actions
--color-accent#7c3aedyesViolet for passive indicators (badges and chips only)
--color-backdroprgb(0 0 0 / 0.5)Dialog and drawer backdrop

Radii

Each component has its own radius token, so you can round buttons without rounding cards.

Badge Square badge
Radius tokens
TokenDefaultDarkPurpose
--radius-button0.375remButtons, select and toggle buttons, paginator, stepper
--radius-input0.375remText fields, selects, file drop zone
--radius-popovervar(--radius-input)Popover and date picker panels
--radius-menuvar(--radius-input)Menus and the option panels of select, multi-select and autocomplete
--radius-card0.5remCards
--radius-dialog0.5remDialogs and drawers
--radius-chip0.25remChips
--radius-badgecalc(infinity * 1px)Badges (pill)
--radius-checkbox0.25remCheckboxes
--radius-switchcalc(infinity * 1px)Toggle switch track and thumb
--radius-slidercalc(infinity * 1px)Slider track
--radius-tooltip0.375remTooltips
--radius-message0.375remMessages and toasts
--radius-table0.375remTable frame
--radius-progresscalc(infinity * 1px)Progress bar track
--radius-skeleton0.25remSkeleton blocks
--radius-avatar0.375remSquare avatars
--radius-link0.125remLink focus outline

Focus rings

Focus comes in three shapes: the --shadow-focus halo on bordered text-entry controls and buttons, the offset --shadow-focus-ring on borderless and non-text controls, and the currentColor ring inside tinted surfaces. They derive from --color-primary, --color-error and --color-background, so a rebrand recolors them. Use them in your own controls as focus-visible:shadow-(--shadow-focus-ring).

  • --shadow-focus
  • --shadow-focus-error
  • --shadow-focus-ring
  • --shadow-focus-ring-error
  • --shadow-focus-current
Focus ring tokens
TokenDefaultDarkPurpose
--shadow-focus3px primary haloyesHalo on bordered text-entry controls and buttons
--shadow-focus-error3px error haloyesHalo on invalid text-entry controls
--shadow-focus-ring2px offset + 2px primaryyesOffset ring on borderless and non-text controls
--shadow-focus-ring-error2px offset + 2px erroryesOffset ring on invalid checkboxes, switches and radios
--shadow-focus-current0 0 0 2px currentColorRing inside tinted surfaces (chip remove, message close)

Motion

Durations have no utility namespace: use duration-(--duration-fast). Spinners, progress bars and skeletons fall back to static visuals under prefers-reduced-motion.

Motion tokens
TokenDefaultDarkPurpose
--ease-standardcubic-bezier(0.2, 0, 0, 1)Default curve for state changes
--ease-outcubic-bezier(0.16, 1, 0.3, 1)Entering elements
--ease-incubic-bezier(0.4, 0, 1, 1)Leaving elements
--duration-fast120msTooltips, popovers, switches
--duration-base180msDialogs, accordions, toasts, floating labels
--duration-slow260msDrawers

Global side effects

Importing theme.css redefines some Tailwind defaults app-wide because the components rely on them: --text-base, --text-sm, --text-xs (a denser 14 / 13 / 12px scale), --font-sans, --font-mono, the --shadow-* scale and --ease-in / --ease-out. To keep Tailwind's values, restore them in your @theme; the kit then uses them too.

CSS
@theme {
  --font-sans: ui-sans-serif, system-ui, sans-serif;
  --text-sm: 0.875rem;
  --text-sm--line-height: calc(1.25 / 0.875);
  --text-base: 1rem;
  --text-base--line-height: calc(1.5 / 1);
  /* …and likewise for the other values you rely on */
}

Are you sure?