Skip to content

Commit 831bc44

Browse files
committed
docs(theme): add "Exported themes constant" example
1 parent 9a2be8e commit 831bc44

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

docs/src/pages/components/Theme.svx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,28 @@ 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. This is useful when building custom theme UIs or dynamically generating theme options.
71+
72+
```js
73+
import { themes } from "carbon-components-svelte";
74+
75+
// themes = {
76+
// white: "White",
77+
// g10: "Gray 10",
78+
// g80: "Gray 80",
79+
// g90: "Gray 90",
80+
// g100: "Gray 100"
81+
// }
82+
83+
// Get all theme keys programmatically
84+
const themeKeys = Object.keys(themes); // ["white", "g10", "g80", "g90", "g100"]
85+
86+
// Build custom theme selectors with correct labels
87+
Object.entries(themes).forEach(([key, label]) => {
88+
console.log(`${key}: ${label}`); // "white: White", etc.
89+
});
90+
```

0 commit comments

Comments
 (0)