Themes and design tokens
ConfigProvider configures the design of its subtree. Start with general design tokens and change individual component tokens when it really needs an exception.
General theme
<script lang="ts">
import { Button, ConfigProvider } from '@woodger/antd';
let color = $state('#389e0d');
</script>
<ConfigProvider theme={{ token: { colorPrimary: color, borderRadius: 8 } }}>
<Button type="primary">Сохранить</Button>
</ConfigProvider>
Changing color updates the theme reactively. Don't replace components via the key block just to change the color: this will reset their local state.
Token levels
Seed Token specifies initial decisions such as colorPrimary, fontSize and borderRadius. The algorithm receives the seed and calculates the Map Token: palettes, states and metrics. Alias Token associates calculated values with the purpose of interface elements, such as colorTextSecondary or colorBgContainer.
Start with seed when the change should have a consistent effect on the palette. A dotted alias override does not replace the recalculation of associated states. Do not save a separately calculated palette in application state unless necessary.
For one family, use theme.components. Its record may contain published component tokens and allowed general overrides. Having a name in types is not a substitute for checking whether a particular token is used; Current restrictions are listed on the family page.
Algorithms and nesting
theme accepts defaultAlgorithm, darkAlgorithm and compactAlgorithm from the theme public object. Algorithms can be combined:
<script lang="ts">
import { Button, ConfigProvider, theme } from '@woodger/antd';
</script>
<ConfigProvider theme={{ mode: 'dark', compact: true, algorithm: [theme.darkAlgorithm, theme.compactAlgorithm] }}>
<Button>Тёмная компактная тема</Button>
</ConfigProvider>
Algorithms are applied in order. mode and compact in the example also match the native mode of the area with the selected algorithms. For a light regular theme, use defaultAlgorithm.
A nested provider allows you to configure a separate area. General settings and local exceptions are shown on page ConfigProvider.
Dynamic theme
Example switches color, dark and compact modes without re-creating the Input. The area has its own theme; the current tokens are read by the child ThemeReadout. Both files are shown in the source.
The theme object can be computed reactively from the Svelte state. Don't wrap an area in a key block to change the algorithm. Store selected settings in the application; for the same initial theme with SSR, transfer the mode from the server, as in cookie example.
Theme without state reset
Independent scope, reactive algorithms and child component tokens.
ThemeExample.svelte<script lang="ts"> import { Button, Checkbox, ConfigProvider, Input, theme } from '@woodger/antd'; import ThemeReadout from './ThemeReadout.svelte'; let dark = $state(false); let compact = $state(false); let purple = $state(false); let draft = $state(''); let saved = $state(''); const algorithms = $derived([ dark ? theme.darkAlgorithm : theme.defaultAlgorithm, ...(compact ? [theme.compactAlgorithm] : []) ]); </script> <style> .example, .surface { display: grid; gap: 16px; } .controls { display: flex; flex-wrap: wrap; gap: 12px; } .surface { padding: 16px; border-radius: 12px; background: var(--ant-color-bg-container); } .surface :global(.ant-btn) { justify-self: start; } output { overflow-wrap: anywhere; } </style> <div class="example"> <div class="controls"> <Checkbox bind:checked={dark}>{("Dark theme example")}</Checkbox> <Checkbox bind:checked={compact}>{("Compact example theme")}</Checkbox> <Checkbox bind:checked={purple}>{("Purple main color")}</Checkbox> </div> <ConfigProvider theme={{ inherit: false, mode: dark ? 'dark' : 'light', compact, algorithm: algorithms, token: { colorPrimary: purple ? '#722ed1' : '#389e0d', motion: false }, components: { Button: { borderRadius: 12 } } }}> <div class="surface"> <Input aria-label={("Draft topic")} placeholder={("Enter text")} bind:value={draft} /> <Button type="primary" onclick={() => { saved = draft; }} >{("Save draft")}</Button> <output aria-label={("Case Study Result")}>{(saved || ("Not saved yet"))}</output> <ThemeReadout /> </div> </ConfigProvider> </div>ThemeReadout.svelte<script lang="ts"> import { theme } from '@woodger/antd'; const current = theme.useToken(); </script> <style> output { display: block; font-size: 12px; overflow-wrap: anywhere; } </style> <output aria-label={("Example topic tokens")}> primary: {(current.token.colorPrimary)}; height: {(current.token.controlHeight)}; font: {(current.token.fontSize)}; background: {(current.token.colorBgContainer)} </output>
Inheritance and isolation
theme.token is combined with parent overrides. Records in theme.components are combined by the name of the component and one level of its properties. Algorithm selects the scope algorithm, and inherit:false resets parent tokens/algorithm/components. Call
Inherit:false does not reset the entire ConfigProvider: locale, direction and component config live separately. Hashed/cssVar/zeroRuntime have their own inheritance; if necessary, specify them explicitly. An empty theme.components.Button does not remove previously inherited Button tokens.
Component config, for example ConfigProvider.button, works differently: its own record, including {}, replaces the entire parent one. These are defaults props/styles, not a token map. Full examples are in ConfigProvider.
Reading tokens
For native elements, call theme.useToken when initializing a child component under provider:
<script lang="ts">
import { theme } from '@woodger/antd';
const current = theme.useToken();
</script>
<p style:color={current.token.colorTextSecondary}>Дополнительное пояснение</p>
Object returns reactive getters. Read current.token in markup or $derived; destructuring once saves a snapshot of the value.
Component design
Tokens of a specific family are specified in theme.components. Semantic classNames/styles refer to parts of the component and are described on its page; Not all families have the same slots and render API.
See ConfigProvider component tokens and Button design. size and variant are separate settings and not a replacement for theme tokens.
CSS variables and hash
theme.cssVar accepts a prefix/key object, for example { prefix: 'product', key: 'editor-theme' }. Prefix specifies the names of the CSS variables, key is the theme area class. For several different topics, set different strong keys or leave their generation to the provider. The same key for different values can create a CSS conflict.
This is not a prefixCls component. The selected variable prefix does not rename buttons and popups. For custom CSS, it's convenient to use the token from theme.useToken: this way you don't have to manually guess the variable name.
The generic ConfigProvider.prefixCls changes the connected families classes. When creating the theme's source area, it also sets the fallback namespace CSS variables. The inherited cssVar.prefix takes precedence over the new prefixCls; local cssVar.prefix takes precedence over both. Explicit cssVar.prefix:undefined clears the inherited namespace and returns the current provider's fallback, even if inherit=false.
Without a local theme, the parent theme scope and namespace are preserved. In a tree configured only through mode/primary/compact without source settings, the namespace remains ant. Example of prefixes reads the current references to variables through the child useToken; namespace inheritance is separated from tokens/algorithm/components reset.
Hashed:false returns an empty hashId, but does not replace its CSS isolation or remove all scope classes. The result of useToken.cssVar is a map of converted tokens, not a prefix/key configuration object.
zeroRuntime is not a CSS extraction command. Components continue to use published styles; React CSS-in-JS tooling instructions do not apply to this package.
Static calculation and motion
theme.getDesignToken(config) calculates tokens without context and does not update the page theme. Use it for a separate calculation; For reactive markup inside provider, useToken is suitable.
token.motion:false disables supported component animations. Consider the application's own animations and reduced motion preferences separately. Don't expect that changing the color will automatically correct the contrast of all custom surfaces.
Working settings of tokens are given on the ConfigProvider page; dot design - in styles.