Skip to content

Commit 577e5ee

Browse files
authored
docs(theme): update "Custom theme" example (#2260)
Closes #1525
1 parent 1ccf455 commit 577e5ee

File tree

2 files changed

+73
-6
lines changed

2 files changed

+73
-6
lines changed

docs/src/pages/components/Theme.svx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ Set `persist` to `true` to save the theme preference in [localStorage](https://d
3333

3434
## Custom theme
3535

36-
Override default Carbon theme tokens by providing custom key-value pairs in the `tokens` prop. Refer to the [Carbon website](https://carbondesignsystem.com/guidelines/themes/overview#customizing-a-theme) for guidance on customizing themes.
36+
Override default Carbon theme tokens using the `tokens` prop.
37+
38+
**Understanding token usage:** The Theme component sets CSS custom properties via `--cds-{token}`. However, not all token names directly map to component styles. Components often use **semantic tokens** (like `interactive-01`) rather than component-specific tokens (like `button-primary`).
39+
40+
For example, primary buttons use `interactive-01` for background color, `hover-primary` for hover state, and `active-primary` for active state. Both token types exist in the system but serve different purposes. Refer to the component CSS or Carbon Design System documentation to understand which tokens affect specific components.
3741

3842
<FileSource src="/framed/Theme/ThemeTokens" />
3943

Lines changed: 68 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,77 @@
11
<script>
2-
import { Theme, Button } from "carbon-components-svelte";
2+
import {
3+
Theme,
4+
Button,
5+
Link,
6+
Tag,
7+
TextInput,
8+
Checkbox,
9+
Toggle,
10+
Tile,
11+
InlineNotification,
12+
} from "carbon-components-svelte";
313
</script>
414

515
<Theme
616
theme="g90"
717
tokens={{
8-
"interactive-01": "#d02670",
9-
"hover-primary": "#ee5396",
10-
"active-primary": "#9f1853",
18+
// Interactive elements
19+
"interactive-01": "#d02670", // Primary button background
20+
"hover-primary": "#ee5396", // Primary button hover
21+
"active-primary": "#9f1853", // Primary button active
22+
"interactive-02": "#6f6f6f", // Secondary button background
23+
"hover-secondary": "#5e5e5e", // Secondary button hover
24+
25+
// Links
26+
"link-01": "#ff6eb3", // Link text color
27+
28+
// Tags
29+
"tag-background-blue": "#4a1942", // Tag background
30+
"tag-color-blue": "#ffb3d9", // Tag text color
31+
32+
// Form elements
33+
"field-01": "#2d2d2d", // Input field background
34+
"ui-01": "#2d2d2d", // Tile background
35+
focus: "#ff6eb3", // Focus indicator color
36+
37+
// Text colors
38+
"text-01": "#ffffff", // Primary text
39+
"text-02": "#c6c6c6", // Secondary text
40+
41+
// Notification colors
42+
"support-04": "#a855f7", // Info notification color
1143
}}
1244
/>
1345

14-
<Button>Primary button</Button>
46+
<div style="display: flex; flex-direction: column; gap: 1rem;">
47+
<div>
48+
<Button>Primary button</Button>
49+
<Button kind="secondary">Secondary button</Button>
50+
</div>
51+
52+
<div>
53+
<Link href="#example">Themed link</Link>
54+
</div>
55+
56+
<div>
57+
<Tag type="blue">Themed tag</Tag>
58+
</div>
59+
60+
<TextInput labelText="Text input" placeholder="Enter text..." />
61+
62+
<Checkbox labelText="Checkbox with themed focus" />
63+
64+
<Toggle labelText="Toggle with themed colors" />
65+
66+
<Tile>
67+
<p>Tile with themed background</p>
68+
</Tile>
69+
70+
<InlineNotification
71+
kind="info"
72+
title="Info notification"
73+
subtitle="With themed colors"
74+
hideCloseButton
75+
lowContrast
76+
/>
77+
</div>

0 commit comments

Comments
 (0)