Skip to content

Customisation

Customise from broad to narrow: redefine tokens, generate a brand theme, restrict the picker, scope a subtree, or override an individual component. Each step is more local than the last.

The override ladder

  1. Tokens via CSS — set --md-sys-* tokens on :root for the page and its overlays, on :root, [data-theme] for every theme (subtrees a ThemeScope re-themes too), or on [data-theme="ocean"] for one (see Overriding tokens).
  2. Component tokens — set M3's --md-comp-* variables to restyle every instance of a component, globally or within a scope.
  3. Brand theme — generate one with createTheme() or the CLI.
  4. Restrict the picker — <ThemeProvider themes={['baseline', 'ocean', 'acme']}>.
  5. Scope a subtree — <ThemeScope theme="forest" mode="dark">.
  6. Component level — className / classNames={{ root, label, icon }}, or extend the exported variant definitions.

Steps 1 and 3–5 are covered in the Theming guide. This page covers component tokens (step 2) and the component level (step 6).

Component tokens

Components with tokens read M3's component tokens as CSS variables, named after M3's own md.comp.* tokens with the dots as dashes: md.comp.filled-card.container.color is --md-comp-filled-card-container-color. Each is unset until you set it, and falls back to the system token the component uses by default. A component's API tab lists its tokens, their defaults and what they paint (Card's Tokens).

tokens.css
/* Every filled card, in every theme. Declared on :root and [data-theme],
   a role value resolves again in each theme, mode, contrast and ThemeScope. */
:root,
[data-theme] {
  --md-comp-filled-card-container-color: var(--md-sys-color-secondary-container);
}

/* Squarer elevated cards in one part of the page. */
.compact {
  --md-comp-elevated-card-container-shape: 4px;
}
  • Declare role values on :root, [data-theme]. A value that reads another variable resolves where it's declared: on :root alone, var(--md-sys-color-secondary-container) would keep the root theme's colour inside a dark or differently themed ThemeScope. A ThemeScope or overlay that changes the theme, mode or contrast carries data-theme, so the value resolves again there.
  • A literal value (#0050c8, 4px) is the same in every theme, mode and contrast level. Check a literal colour's contrast yourself.
  • Set them on the component or an ancestor, never on an inner slot: the component resolves its tokens on its root.
  • Icon colour in a container: --md-comp-icon-button-icon-color (M3's baseline name) colours every standard and outlined icon button inside the element that sets it; the per-variant --md-comp-icon-button-standard-icon-color and --md-comp-icon-button-outlined-icon-color come first. App bars, search bars and vibrant toolbars set it to currentColor, so their icons follow their own text colour.
  • Overlays portal to body, so tokens set on an arbitrary ancestor don't reach them. Tokens on :root, on [data-theme], on the overlay's own className, or through the class or the inline style variables of a ThemeScope around it do.
  • Precedence: system token, then component token, then className and classNames, which still win.
  • Styling hooks: a component with tokens marks its root with the props its tokens depend on: data-variant, data-size where it has sizes, and a few others such as the FAB's data-color. They're public, so your own selectors can use them ([data-variant="outlined"]).
scoped-tokens.tsx
import { Card, ThemeScope } from '@windmorph/react';

// A ThemeScope's class and the CSS variables of its style also go on the
// overlays opened inside it (menus, dialogs, tooltips), so tokens set through
// either reach them.
<ThemeScope className="compact">
  <Card variant="elevated">…</Card>
</ThemeScope>;

// One instance: set the variable on the component itself.
<Card className="[--md-comp-filled-card-container-color:var(--md-sys-color-tertiary-container)]">
  …
</Card>;

Coming from Material Web

Material Web names the same tokens without comp-: its --md-outlined-card-outline-color is Windmorph's --md-comp-outlined-card-outline-color, and --md-icon-button-icon-color is --md-comp-icon-button-icon-color. Windmorph follows M3's current token tables, which are newer than Material Web, so:

  • Where M3 Expressive renamed a component's tokens, Windmorph uses the new name. The component's Tokens table is the reference.
  • Expressive sizes have their own shapes, so a single container-shape becomes one per size where M3 has sizes.
  • Expressive-only tokens, such as a toggle button's selected-* and unselected-* colours, have no Material Web equivalent.
  • Typography, state-layer, disabled and spacing tokens aren't exposed. Use --md-sys-typescale-*, className or classNames, and the size prop.

className & classNames

Every component takes className for its outermost element and classNames for its named slots (for example a button’s root, content, label and icon). The consumer’s class always wins.

overrides.tsx
import { Button } from '@windmorph/react';

// A consumer className always wins over the library's conflicting class (via cn()).
<Button variant="filled" className="rounded-corner-full px-8">Rounded</Button>;

// Per-slot overrides with classNames.
<Button classNames={{ root: 'shadow-none', label: 'tracking-wide', icon: 'text-primary' }}>
  Save
</Button>;

Extending variants

Each component exports its variant recipe as a *Styles definition — buttonStyles, iconButtonStyles, cardStyles, chipStyles, textFieldStyles, menuStyles and many more. Compose a new variant on top of one with tv (a pre-configured tailwind-variants re-export) and VariantProps.

brand-button.ts
import { tv, buttonStyles } from '@windmorph/react';
import type { VariantProps } from '@windmorph/react';

// Extend an exported *Styles recipe with a new variant using tv (tailwind-variants,
// pre-configured with the M3 twMergeConfig).
const brandButton = tv({
  extend: buttonStyles,
  variants: {
    color: { brand: 'bg-tertiary text-on-tertiary', muted: 'bg-surface-container' },
  },
  defaultVariants: { color: 'brand' },
});

type BrandButtonProps = VariantProps<typeof brandButton>;

Why the consumer wins: cn()

cn() is tailwind-merge extended with the library’s theme keys — colour roles, type roles, corner-* radii, elevation-* shadows, and m3-* easings and durations. Later classes override earlier conflicting ones, which is why a className you pass always beats the library’s own class for that property.

cn
import { cn } from '@windmorph/react';

// cn is tailwind-merge extended with the M3 theme keys (colour roles, type roles,
// corner-* radii, elevation-* shadows, m3-* easings and durations). Later classes win,
// so a consumer class always overrides a conflicting library class.
cn('bg-primary', 'bg-secondary'); // -> 'bg-secondary'
cn('rounded-corner-small', 'rounded-corner-large'); // -> 'rounded-corner-large'

Layout safety

A component’s internals never depend on the root’s position, overflow, display or transform, so you can put any layout class on any component and it looks and behaves the same.

  • className and style always land on the outermost element; style is merged, never replaced.
  • To animate a button’s size or position, put the transition on a wrapper: while pressed, the button’s own motion replaces the timing of a transition added through className.
  • State layer and ripple are painted as background layers, so they follow border-radius and need neither relative nor overflow-hidden.
  • Motion never animates the root’s transform, and containers never set transform/filter/contain/will-change on their root, so fixed children are never trapped.
  • The focus ring is a CSS outline, so an overflow-hidden on the component itself can’t clip it. An ancestor that clips its overflow still can, so leave room around focusable items.
layout.tsx
import { Button, DockedToolbar } from '@windmorph/react';

// className / style land on the outermost element, so any layout class is safe:
<Button className="fixed bottom-4 right-4">New</Button>;
<DockedToolbar aria-label="Actions" className="fixed inset-x-0 bottom-0 w-full">
  …
</DockedToolbar>;

Three documented exceptions: overlays portal to body on a z-index token scale (--md-sys-z-*, which you can override); scroll-driven app bars and toolbars manage their own expansion (useToolbarScrollExpansion, TopAppBarScrollBehavior); and a FAB or toolbar that you hide (visible={false}) scales or slides with a transform on its root while hidden. That uses the transform property only, so Tailwind's translate-* and scale-* classes still apply.