Styling and theming
The styling system gives the Vue component library one visual language for color, type, spacing, borders, elevation, focus, and responsive layout. Design tokens become CSS variables and Tailwind utilities, while the shared color-scheme state selects the light or dark semantic values that components use.
Visual system
The visual system separates reusable design decisions from component behavior. Components express intent with semantic classes such as surface, ink, outline, radius, and elevation utilities instead of owning separate light and dark palettes.
The main design areas are:
| Area | Role |
|---|---|
| Color | Provides primitive ramps and semantic roles for surfaces, text, borders, overlays, and alpha colors. |
| Typography | Provides the Inter variable font plus named size and weight combinations. |
| Shape and elevation | Provides numbered radius tokens and shared shadow levels. |
| Focus | Provides a visible keyboard focus ring that can change with the color scheme. |
| Layout | Provides Tailwind spacing, breakpoints, and library-specific layout utilities. |
The token source and its conversion into Tailwind outputs are described in Tailwind and token pipeline. The public Tailwind setup for consuming applications is also summarized in the repository’s Tailwind setup guide.
Semantic color roles
Semantic colors describe what a color is used for rather than which hue or numeric shade it has. The light and dark token sets map the same roles to different values, so a component can keep the same class while the page changes appearance.
The role groups have these broad meanings:
surfacecolors fill controls, cards, pages, and other regions.inkcolors represent text and foreground content.outlinecolors represent borders, dividers, and rings.surface-alphaandoutline-alphasupport translucent layers.
Primitive ramps remain available for direct hue and shade choices. Components that offer a status or theme axis usually combine a semantic surface, ink, and outline choice. For example, the Badge component keeps its visual variants aligned by pairing those roles for each supported hue (src/…/Badge.vue• L35-79).
References: tailwind/colorPalette.js• L25-74 tailwind/tokens.js• L35-89 src/…/Badge.vue• L35-79
Typography and shape
Typography uses the Inter variable font as the library’s base face. Named text utilities carry the size, line height, letter spacing, and weight together so a named style remains consistent across components. Paragraph variants provide a separate reading rhythm where body copy needs more space.
Radius tokens use a numbered scale. Tailwind utilities such as rounded-4 therefore point to shared values instead of repeating pixel values in component code. Elevation and focus tokens follow the same model: components request a shared level and the theme supplies the value.
References: src/…/inter.css• L6-60 tailwind/…/typography.js• L4-80 tailwind/…/radius.js• L4-17 tailwind/plugin.js• L20-43 tailwind/plugin.js• L227-244
Global styles
Global styles establish the baseline that Tailwind utilities and components build on. The library stylesheet loads the Inter font, enables Tailwind’s base, component, and utility layers, and provides the short transition pause needed during a color-scheme change (src/style.css• L1-16).
The Tailwind theme plugin adds the rest of the shared base. It sets the font family and font rendering, gives plain paragraphs a relaxed line height, and applies a default :focus-visible outline. Form controls receive a common shape, surface, border, and focus treatment through shared component styles rather than separate defaults in each control (tailwind/plugin.js• L152-200).
The library also keeps styles close to specialized surfaces when global rules are not enough. Charts define their own color ramps and plot rules, while rich text styles use the typography layer for editor content. This keeps those surfaces connected to the visual system without forcing their internal layout rules onto all components (src/…/style.css• L1-138, tailwind/plugin.js• L320-681).
References: src/style.css• L1-16 tailwind/plugin.js• L152-200 tailwind/plugin.js• L320-681 src/…/style.css• L1-138
Color schemes
Color schemes control which theme values the document paints. The shared useColorScheme composable exposes light, dark, and system preferences, resolves the system preference when needed, writes the resolved result to <html data-theme>, and stores the selected preference for the next visit (src/…/useColorScheme.ts• L1-23, src/…/useColorScheme.ts• L91-117).
The state is shared across all callers. A theme control and a separate component can therefore read the same preference and update one document attribute. CSS targets [data-theme='dark'], and the generated semantic variables switch at that boundary (src/…/useColorScheme.ts• L25-36, tailwind/colorPalette.js• L78-125).
The system follows this sequence when an application selects a scheme:
sequenceDiagram
participant UI as Theme control
participant Scheme as useColorScheme
participant Root as <html>
participant CSS as Theme CSS
UI->>Scheme: set light, dark, or system
Scheme->>Scheme: resolve system preference
Scheme->>Root: set data-theme
Root->>CSS: select semantic variables
CSS-->>UI: repaint shared surfaces and text
Scheme->>Scheme: persist preference
During the attribute swap, the document receives no-transition for two animation frames. This prevents every surface that has a color transition from cross-fading at once. The transition suppression is part of the library stylesheet, so applications that use the color-scheme composable should also load the library style entry (src/…/useColorScheme.ts• L67-89, src/style.css• L7-16).
References: src/…/useColorScheme.ts• L25-117 src/style.css• L7-16 tailwind/colorPalette.js• L78-125
Scheme controls
Applications normally use useColorScheme directly for a switch, menu, or settings control. The older ThemeSwitcher component remains as a compatibility surface and offers the same three choices, but it is deprecated in favor of the composable (src/…/ThemeSwitcher.vue• L84-95, src/index.ts• L123-137).
The system choice follows the operating system while it remains selected. A direct light or dark choice becomes the saved preference and stops following later operating-system changes.
References: src/…/ThemeSwitcher.vue• L84-95 src/…/ThemeSwitcher.vue• L120-147 src/…/useColorScheme.ts• L101-117 src/index.ts• L123-137
Tailwind integration
Tailwind is the main authoring interface for component styling. The package exports a Tailwind v3 preset that supplies the visual theme, plugins, dark-mode selector, complete integer spacing steps, and safelisted classes needed by generated or computed markup (tailwind/preset.js• L1-36, tailwind/index.js• L1-2).
The preset’s theme and plugins merge into a consuming application. Its content globs do not. Each application must add the exported content list to its own Tailwind configuration so Tailwind sees the library classes and emits the utilities that components use (tailwind/content.js• L1-58). The repository’s existing setup guide explains this boundary in Tailwind setup.
The integration has two paths:
- The token pipeline supplies colors, type, radius, effects, and semantic utility mappings to the theme plugin. The public token entry also exposes framework-neutral values to tools that do not load Tailwind.
- Tailwind scans application and library sources, then emits only the classes found in the configured content set or safelist.
The detailed token transformation and Tailwind plugin stages belong in Tailwind and token pipeline. The high-level relationship is:
flowchart LR
Tokens[Design token sources] --> Generated[Framework-neutral token data]
Generated --> Plugin[Tailwind theme plugin]
Plugin --> Vars[CSS variables and semantic utilities]
Content[Application and library content] --> Scan[Tailwind content scan]
Scan --> CSS[Generated application CSS]
Vars --> CSS
Scheme[Color scheme] --> Vars
References: tailwind/preset.js• L1-36 tailwind/content.js• L20-58 tailwind/tokens.js• L1-33 tailwind/plugin.js• L201-240 tailwind/colorPalette.js• L54-98 docs/…/tailwind.md• L1-62
Extension points
Applications can extend the visual system without replacing its core contracts. They can redefine CSS variables for a local brand or chart palette, add Tailwind utilities, and use the shared semantic classes for components that should follow the active scheme.
Charts expose a global variable-based palette for product-wide chart rebranding and a per-chart palette for local changes. Other specialized surfaces follow the same principle: use the shared tokens for broad changes and local styles for behavior that only belongs to that surface (src/…/style.css• L4-13).
The main boundary to preserve is the semantic role. A replacement should provide the role that a component asks for, not only a new raw hue. That keeps light and dark values, focus states, and related component variants aligned.
References: src/…/style.css• L4-13 tailwind/plugin.js• L226-280 tailwind/colorPalette.js• L79-98
Change checklist
When these files or sections are changed, remember to consider these:
- When token source files change, regenerate the Tailwind token modules and check that semantic light and dark references still resolve to valid primitive or overlay values.
- When adding a class that is built at runtime or assembled from data, add the needed literal classes to the relevant safelist or change the authoring path so Tailwind can scan it.
- When changing the color-scheme attribute or preference names, update CSS selectors, persisted values, and any consuming controls as one contract.
- When adding a supported source surface, update the exported Tailwind content globs so consuming applications compile its classes.
- When changing focus or elevation tokens, check both the CSS variable form and the Tailwind utility form because components can use either interface.
- When adding or renaming public token exports, update tailwind/tokens.d.ts with the generated token module and preserve the additive-only token contract.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A consuming app uses the preset but omits the exported content globs. | Library classes are not emitted, so components lose parts of their layout or visual state. | Spread content from frappe-ui/tailwind into the app’s top-level Tailwind content array. |
| A component builds a Tailwind class only at runtime and does not safelist it. | Tailwind purges the class from the generated CSS. | Use literal class maps or add the exact generated classes to the safelist. |
An app changes data-theme handling without loading the library stylesheet. | The theme can switch, but the transition suppression is missing and the swap can flash. | Load frappe-ui/style.css with the component package. |
| A semantic token points to a missing or stale primitive. | A surface, text color, border, or focus ring can resolve to an invalid value or fall back unexpectedly. | Regenerate the token modules and validate the token references before release. |
A second color-scheme state is created outside useColorScheme. | Controls can disagree about the selected preference even though the document has one theme attribute. | Use the shared composable or update the document through its public setter. |
Key files
| File | Why to read it |
|---|---|
| src/…/useColorScheme.ts | Defines the shared light, dark, and system preference contract and the document-level theme switch. |
| src/style.css | Defines the package stylesheet entry and the transition guard used during theme changes. |
| tailwind/preset.js | Shows the Tailwind preset boundary exposed to consuming applications. |
| tailwind/content.js | Defines the source globs that applications must scan for library classes. |
| tailwind/tokens.js | Provides framework-neutral token values and CSS-variable maps for tools and the Tailwind theme. |
| tailwind/…/colors.js | Provides generated light, dark, overlay, neutral, and semantic color source data. |
| tailwind/…/effects.js | Provides generated elevation and focus source data. |
| tailwind/plugin.js | Connects token data to CSS variables, semantic utilities, typography, radius, elevation, and focus behavior. |
| tailwind/colorPalette.js | Defines primitive palettes, semantic color variables, and Tailwind opacity handling. |
| tailwind/lucideIconsPlugin.js | Defines the shared visual contract for Lucide icon utilities. |
| tailwind/figma-tokens-to-theme.js | Shows the source-to-generated-token stage described in Tailwind and token pipeline. |
| src/…/ThemeSwitcher.vue | Illustrates the compatibility theme control and its link to the shared scheme state. |
| src/…/style.css | Illustrates a specialized visual surface that uses theme-aware CSS variables. |