Skip to content

Commit 36d71df

Browse files
committed
docs(theme): add "Exported themes constant" example
1 parent 776e471 commit 36d71df

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

docs/src/pages/components/Theme.svx

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,32 @@ Set `render` to `"select"` to display a dropdown menu for selecting from all ava
6363

6464
Customize the select dropdown using the `select` prop. You can specify which themes to include, customize labels, and adjust other select properties.
6565

66-
<FileSource src="/framed/Theme/ThemeSelectCustom" />
66+
<FileSource src="/framed/Theme/ThemeSelectCustom" />
67+
68+
## Exported themes constant
69+
70+
The `themes` constant is exported from the Theme component, providing programmatic access to all available theme keys and their human-readable labels.
71+
72+
`themes` must be imported directly from the Theme component file and used in a `script context="module"` block in Svelte components.
73+
74+
```html
75+
<script context="module">
76+
import { themes } from "carbon-components-svelte/src/Theme/Theme.svelte";
77+
78+
// themes = {
79+
// white: "White",
80+
// g10: "Gray 10",
81+
// g80: "Gray 80",
82+
// g90: "Gray 90",
83+
// g100: "Gray 100"
84+
// }
85+
86+
// Get all theme keys programmatically
87+
const themeKeys = Object.keys(themes); // ["white", "g10", "g80", "g90", "g100"]
88+
89+
// Build custom theme selectors with correct labels
90+
Object.entries(themes).forEach(([key, label]) => {
91+
console.log(`${key}: ${label}`); // "white: White", etc.
92+
});
93+
</script>
94+
```

0 commit comments

Comments
 (0)