Skip to main content

theme.css and Theme Tokens

Usage

import '@patab/widget-sdk/theme.css'

The stylesheet defines semantic classes on top of the host-injected --pt-* tokens and includes a global @media (prefers-reduced-motion: reduce) rule for reduced motion. Importing it is optional — you can also reference var(--pt-*) directly in your own CSS.

Semantic Classes

Class namePurpose
.pt-surfaceRegular container background and text color
.pt-surface-strongEmphasized container (a higher-contrast surface)
.pt-textBody text color
.pt-text-strongHeading/emphasis text color
.pt-text-mutedSecondary/de-emphasized text color
.pt-buttonButton (including hover/active states)
.pt-inputInput field
.pt-focus-ringFocus ring
.pt-dangerDanger/destructive action color
note

The above are all the contract classes provided by theme.css. The pt-card, pt-title, and pt-muted class names that appear in the official examples are not part of the SDK contract (they do not exist in theme.css); use contract classes such as .pt-surface or define your own styles if you need card styling.

Component Style Showcase

The showcase below renders every contract class from theme.css and all 20 theme tokens (demo values come from the host fallback theme table, matching the real runtime environment). Hover, active, and focus-ring states are fully interactive:

Semantic classes

Light theme
.pt-surface

Body .pt-text

Muted text .pt-text-muted

.pt-surface-strong

Heading text .pt-text-strong

.pt-text / .pt-text-strong / .pt-text-muted

Heading text .pt-text-strong

Body text .pt-text

Secondary text .pt-text-muted

.pt-button(hover / active / focus-visible).pt-input.pt-focus-ringClick me, or press Tab to see the focus ring.pt-dangerDestructive action text
Dark theme
.pt-surface

Body .pt-text

Muted text .pt-text-muted

.pt-surface-strong

Heading text .pt-text-strong

.pt-text / .pt-text-strong / .pt-text-muted

Heading text .pt-text-strong

Body text .pt-text

Secondary text .pt-text-muted

.pt-button(hover / active / focus-visible).pt-input.pt-focus-ringClick me, or press Tab to see the focus ring.pt-dangerDestructive action text

Theme token values

TokenPurposePreviewLight valueDark value
--pt-surfaceRegular surface background rgb(255 255 255 / 0.45)rgb(255 255 255 / 0.08)
--pt-surface-strongEmphasized surface background rgb(255 255 255 / 0.8)rgb(24 24 27 / 0.88)
--pt-textBody text rgb(64 64 64)rgb(229 229 229)
--pt-text-strongEmphasized text rgb(38 38 38)rgb(245 245 245)
--pt-text-mutedDe-emphasized text rgb(115 115 115)rgb(161 161 170)
--pt-accentTheme accent color rgb(2 132 199)rgb(56 189 248)
--pt-accent-contrastContrasting text on the accent color rgb(255 255 255)rgb(8 47 73)
--pt-accent-hoverAccent color hover state rgb(3 105 161)rgb(125 211 252)
--pt-borderBorder rgb(255 255 255 / 0.45)rgb(255 255 255 / 0.14)
--pt-inputInput control background rgb(255 255 255 / 0.7)rgb(255 255 255 / 0.14)
--pt-dangerDanger color rgb(220 38 38)rgb(252 165 165)
--pt-focus-ringFocus ring rgb(2 132 199)rgb(125 211 252)
--pt-radius-smBorder radius (small)0.75rem0.75rem
--pt-radius-mdBorder radius (medium)1rem1rem
--pt-radius-lgBorder radius (large)1.5rem1.5rem
--pt-shadowShadow0 10px 15px -3px rgb(0 0 0 / 0.1)0 10px 15px -3px rgb(0 0 0 / 0.32)
--pt-font-sansBody font familyFont sample Aa 中文字体Inter, PingFang SC, Microsoft YaHei, system-ui, sans-serifInter, PingFang SC, Microsoft YaHei, system-ui, sans-serif
--pt-motion-durationMotion duration150ms150ms
--pt-motion-easingMotion easingeaseease
--pt-color-schemecolor-scheme valuelightdark
tip

The showcase stays in sync with the SDK source: the semantic class rules mirror packages/widget-sdk/src/theme.css, and the token values mirror the host's createFallbackTokens. Completeness is verified automatically by pnpm --filter docs-site verify:theme-css.

Theme Tokens (20)

Token names are part of the API v1 contract. The host injects them into the sandbox document's :root and updates them in sync when the theme changes:

TokenPurpose
--pt-surfaceRegular surface background
--pt-surface-strongEmphasized surface background
--pt-textBody text
--pt-text-strongEmphasized text
--pt-text-mutedDe-emphasized text
--pt-accentTheme accent color
--pt-accent-contrastContrasting text color on the accent color
--pt-accent-hoverAccent color hover state
--pt-borderBorder
--pt-inputInput control background
--pt-dangerDanger color
--pt-focus-ringFocus ring
--pt-radius-sm / --pt-radius-md / --pt-radius-lgBorder radii
--pt-shadowShadow
--pt-font-sansBody font family
--pt-motion-duration / --pt-motion-easingMotion duration and easing
--pt-color-schemecolor-scheme value (light/dark)

The corresponding TypeScript union type is WidgetThemeTokenName; the themeChanged event may carry a WidgetThemeTokens ({ version: 1; values: Record<WidgetThemeTokenName, string> }) snapshot.

caution

Do not reference the host's internal --theme-* variables or the host UI framework's utility classes — they are not part of the public contract. The host translates internal variables into --pt-* through an explicit mapping table; unmapped internal variables are never exposed to widgets.