oneslash-design-system 2.18.0 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/README.md +1 -1
  2. package/dist/DESIGN.md +26 -1
  3. package/dist/cases/app-shell/sidebar.d.ts +1 -0
  4. package/dist/cases/app-shell/sidebar.jsx +124 -0
  5. package/dist/cases/app-shell/top-tabs.d.ts +1 -0
  6. package/dist/cases/app-shell/top-tabs.jsx +106 -0
  7. package/dist/cases/app-shell.md +364 -0
  8. package/dist/cases/artifact-card/card.jsx +32 -6
  9. package/dist/cases/artifact-card.md +55 -7
  10. package/dist/cases/error-page/in-shell.jsx +26 -17
  11. package/dist/cases/error-page.md +42 -21
  12. package/dist/cases/master-detail/list-then-page.d.ts +1 -0
  13. package/dist/cases/master-detail/list-then-page.jsx +65 -0
  14. package/dist/cases/master-detail/split.d.ts +1 -0
  15. package/dist/cases/master-detail/split.jsx +49 -0
  16. package/dist/cases/master-detail.md +213 -0
  17. package/dist/cases/mobile-menu/links.d.ts +1 -0
  18. package/dist/cases/mobile-menu/links.jsx +24 -0
  19. package/dist/cases/mobile-menu/sections.d.ts +1 -0
  20. package/dist/cases/mobile-menu/sections.jsx +61 -0
  21. package/dist/cases/mobile-menu.md +170 -0
  22. package/dist/cases/not-found-page/in-shell.jsx +26 -17
  23. package/dist/cases/not-found-page.md +41 -20
  24. package/dist/cases/on-this-page/aside.d.ts +1 -0
  25. package/dist/cases/on-this-page/aside.jsx +39 -0
  26. package/dist/cases/on-this-page.md +80 -0
  27. package/dist/cases/page-header/actions.d.ts +1 -0
  28. package/dist/cases/page-header/actions.jsx +65 -0
  29. package/dist/cases/page-header/sub-page.d.ts +1 -0
  30. package/dist/cases/page-header/sub-page.jsx +37 -0
  31. package/dist/cases/page-header.md +195 -0
  32. package/dist/cases/phone-navigation.md +32 -0
  33. package/dist/cases/route-loading/region.jsx +27 -18
  34. package/dist/cases/route-loading.md +42 -21
  35. package/dist/cases/side-pane/beside.d.ts +1 -0
  36. package/dist/cases/side-pane/beside.jsx +79 -0
  37. package/dist/cases/side-pane/over.d.ts +1 -0
  38. package/dist/cases/side-pane/over.jsx +58 -0
  39. package/dist/cases/side-pane.md +238 -0
  40. package/dist/cases/sidebar-nav/flat.d.ts +1 -0
  41. package/dist/cases/sidebar-nav/flat.jsx +81 -0
  42. package/dist/cases/sidebar-nav/nested.d.ts +1 -0
  43. package/dist/cases/sidebar-nav/nested.jsx +122 -0
  44. package/dist/cases/sidebar-nav.md +261 -0
  45. package/dist/cases/site-footer/columns.d.ts +1 -0
  46. package/dist/cases/site-footer/columns.jsx +51 -0
  47. package/dist/cases/site-footer/simple.d.ts +1 -0
  48. package/dist/cases/site-footer/simple.jsx +24 -0
  49. package/dist/cases/site-footer.md +133 -0
  50. package/dist/cases/site-header/links.d.ts +1 -0
  51. package/dist/cases/site-header/links.jsx +26 -0
  52. package/dist/cases/site-header/sections.d.ts +1 -0
  53. package/dist/cases/site-header/sections.jsx +64 -0
  54. package/dist/cases/site-header.md +183 -0
  55. package/dist/cases/theme-switcher/menu.d.ts +1 -0
  56. package/dist/cases/theme-switcher/menu.jsx +47 -0
  57. package/dist/cases/theme-switcher/segmented.d.ts +1 -0
  58. package/dist/cases/theme-switcher/segmented.jsx +26 -0
  59. package/dist/cases/theme-switcher.md +149 -0
  60. package/dist/cases.json +666 -19
  61. package/dist/components/appShell.d.ts +44 -0
  62. package/dist/components/appShell.jsx +121 -0
  63. package/dist/components/drawer.d.ts +31 -0
  64. package/dist/components/drawer.jsx +121 -0
  65. package/dist/components/heading.d.ts +3 -1
  66. package/dist/components/heading.jsx +2 -2
  67. package/dist/components/link.d.ts +6 -1
  68. package/dist/components/link.jsx +11 -3
  69. package/dist/components/menuItem.d.ts +7 -1
  70. package/dist/components/menuItem.jsx +4 -3
  71. package/dist/components/modal.jsx +12 -23
  72. package/dist/components/onThisPage.d.ts +29 -0
  73. package/dist/components/onThisPage.jsx +151 -0
  74. package/dist/components/pageShell.d.ts +7 -1
  75. package/dist/components/pageShell.jsx +14 -1
  76. package/dist/components/popover.jsx +4 -0
  77. package/dist/components/settingsSection.d.ts +6 -1
  78. package/dist/components/settingsSection.jsx +10 -3
  79. package/dist/components/sidePane.d.ts +32 -0
  80. package/dist/components/sidePane.jsx +128 -0
  81. package/dist/components/siteFooter.d.ts +24 -0
  82. package/dist/components/siteFooter.jsx +48 -0
  83. package/dist/components/siteHeader.d.ts +55 -0
  84. package/dist/components/siteHeader.jsx +125 -0
  85. package/dist/components/titleBar.d.ts +17 -0
  86. package/dist/components/titleBar.jsx +17 -0
  87. package/dist/index.d.ts +7 -0
  88. package/dist/index.js +7 -0
  89. package/dist/internal/overlayStack.d.ts +24 -0
  90. package/dist/internal/overlayStack.js +71 -0
  91. package/dist/internal/resize.d.ts +9 -0
  92. package/dist/internal/resize.js +31 -0
  93. package/dist/internal/scrollSpy.d.ts +24 -0
  94. package/dist/internal/scrollSpy.js +53 -0
  95. package/dist/internal/siteBrand.d.ts +6 -0
  96. package/dist/internal/siteBrand.jsx +11 -0
  97. package/dist/native-mapping.json +43 -1
  98. package/dist/stories/AppShell.stories.d.ts +15 -0
  99. package/dist/stories/AppShell.stories.jsx +137 -0
  100. package/dist/stories/Cases.generated.stories.d.ts +19 -0
  101. package/dist/stories/Cases.generated.stories.jsx +38 -0
  102. package/dist/stories/Drawer.stories.d.ts +10 -0
  103. package/dist/stories/Drawer.stories.jsx +123 -0
  104. package/dist/stories/Link.stories.d.ts +1 -0
  105. package/dist/stories/Link.stories.jsx +8 -0
  106. package/dist/stories/OnThisPage.stories.d.ts +10 -0
  107. package/dist/stories/OnThisPage.stories.jsx +105 -0
  108. package/dist/stories/SettingsSection.stories.d.ts +1 -0
  109. package/dist/stories/SettingsSection.stories.jsx +27 -0
  110. package/dist/stories/SidePane.stories.d.ts +6 -0
  111. package/dist/stories/SidePane.stories.jsx +37 -0
  112. package/dist/stories/SiteFooter.stories.d.ts +7 -0
  113. package/dist/stories/SiteFooter.stories.jsx +63 -0
  114. package/dist/stories/SiteHeader.stories.d.ts +10 -0
  115. package/dist/stories/SiteHeader.stories.jsx +94 -0
  116. package/dist/stories/TitleBar.stories.d.ts +6 -0
  117. package/dist/stories/TitleBar.stories.jsx +34 -0
  118. package/package.json +1 -1
@@ -0,0 +1,183 @@
1
+ # Site header
2
+
3
+ A site's pages name the site at the top and show the person where to go and what to do next.
4
+
5
+ ## Do
6
+
7
+ - Follow the rule 'On a phone, a sidebar opens as a drawer and a list opens its detail': below `md` the links go into a menu and one main action stays in the bar.
8
+ - Use `SiteHeader` for a few pages. Pass the brand, at most five `links`, and mark the page the person is on with `current`.
9
+ - Pass what must stay in the bar on a phone as `phoneAction`. On a product site that is the main action, named 'Open App' or 'Sign Up'. It is last at every width. Do not repeat it in `actions`.
10
+ - Pass the secondary Buttons, such as 'Log In', as `actions`. They go into the menu on a phone.
11
+ - Give `PageShell` `id` and `tabIndex={-1}` to match `mainId`, so the 'Skip to content' link moves focus into the page.
12
+ - Give a site with sections one `TabsContainer` of `Tab`s with `href`, four sections or fewer and one short word each. Pass it as `nav` to `SiteHeader` with `links` empty: it is a second row of the bar at every width.
13
+ - Pass search and the theme menu as `phoneAction`, so they stay at the end of the bar on a phone. With no `links` and no `actions` there is no menu.
14
+ - Keep the section tabs in the bar, so no section is hidden. On a phone, put the pages of the open section in a menu, as the case 'Menu on a phone' shows in 'Sections with their pages'.
15
+ - Open the theme menu as the case 'Theme switcher' says, and name the search `IconButton` 'Search'.
16
+
17
+ ## Don't
18
+
19
+ - Do not show more than five links in the bar.
20
+ - Do not show two primary Buttons in the bar.
21
+ - Do not hide a link on a phone without a menu that holds it.
22
+ - Do not put a Button that opens a Modal in `actions`. On a phone the menu closes when it is chosen, so the Modal has no Button to give focus back to. Link to a page instead.
23
+ - Do not turn a product site's few pages into tabs. Use `links`. Tabs are for sections that each hold many pages.
24
+
25
+ ## Option: Links and one main action
26
+
27
+ Use when: A product site has a few pages and one main action, such as 'Sign Up'.
28
+
29
+ Uses: `Button`, `Heading`, `PageShell`, `Paragraph`, `SiteHeader`, `Stack`
30
+
31
+ ```tsx
32
+ 'use client';
33
+ import SiteHeader from 'oneslash-design-system/components/siteHeader';
34
+ import PageShell from 'oneslash-design-system/components/pageShell';
35
+ import Button from 'oneslash-design-system/components/button';
36
+ import Heading from 'oneslash-design-system/components/heading';
37
+ import Paragraph from 'oneslash-design-system/components/paragraph';
38
+ import { Stack } from 'oneslash-design-system/components/layout';
39
+
40
+ const links = [
41
+ { label: 'Features', href: '#features' },
42
+ { label: 'Pricing', href: '#pricing', current: true },
43
+ { label: 'Changelog', href: '#changelog' },
44
+ { label: 'Docs', href: '#docs' },
45
+ ];
46
+
47
+ export default function SiteHeaderLinks() {
48
+ return (
49
+ <>
50
+ {/* From md the links are a row in the bar. Below md they and 'Log In' are in the Menu; Sign Up stays beside it. */}
51
+ <SiteHeader
52
+ brand={{ href: '#top', name: 'Acme' }}
53
+ links={links}
54
+ actions={<Button size="medium" type="tertiary" state="enabled" label="Log In" href="#log-in" />}
55
+ phoneAction={<Button size="medium" type="primary" state="enabled" label="Sign Up" href="#sign-up" />}
56
+ mainId="site-header-main"
57
+ />
58
+ {/* The skip link goes here: the id matches mainId, and tabIndex -1 lets focus move in. */}
59
+ <PageShell id="site-header-main" tabIndex={-1}>
60
+ <Stack gap="large">
61
+ <Heading level={1} size="h5">Pricing</Heading>
62
+ <Paragraph tone="secondary" measure="none">Acme is free for up to three people. Add more people when your team grows.</Paragraph>
63
+ </Stack>
64
+ </PageShell>
65
+ </>
66
+ );
67
+ }
68
+ ```
69
+
70
+ ## Option: Sections with their own tabs
71
+
72
+ Use when: A docs site has sections that each hold many pages.
73
+
74
+ Uses: `Heading`, `IconButton`, `Menu`, `MenuItem`, `PageShell`, `Paragraph`, `Popover`, `SiteHeader`, `Stack`, `Tab`, `TabsContainer`, `Tooltip`
75
+
76
+ ```tsx
77
+ 'use client';
78
+ import { useState } from 'react';
79
+ import SiteHeader from 'oneslash-design-system/components/siteHeader';
80
+ import TabsContainer from 'oneslash-design-system/components/tabsContainer';
81
+ import Tab from 'oneslash-design-system/components/tab';
82
+ import IconButton from 'oneslash-design-system/components/iconButton';
83
+ import Tooltip from 'oneslash-design-system/components/tooltip';
84
+ import Popover from 'oneslash-design-system/components/popover';
85
+ import Menu from 'oneslash-design-system/components/menu';
86
+ import MenuItem from 'oneslash-design-system/components/menuItem';
87
+ import PageShell from 'oneslash-design-system/components/pageShell';
88
+ import Heading from 'oneslash-design-system/components/heading';
89
+ import Paragraph from 'oneslash-design-system/components/paragraph';
90
+ import { Stack } from 'oneslash-design-system/components/layout';
91
+
92
+ type Mode = 'light' | 'dark' | 'system';
93
+
94
+ // Four sections, one short word each. Each holds many pages.
95
+ const sections = [
96
+ { id: 'start', label: 'Start', page: 'Start here' },
97
+ { id: 'guides', label: 'Guides', page: 'Guides' },
98
+ { id: 'reference', label: 'API', page: 'API reference' },
99
+ { id: 'updates', label: 'News', page: 'News' },
100
+ ];
101
+
102
+ const modes: { value: Mode; label: string; icon: 'Sun' | 'Moon' | 'Monitor' }[] = [
103
+ { value: 'light', label: 'Light', icon: 'Sun' },
104
+ { value: 'dark', label: 'Dark', icon: 'Moon' },
105
+ { value: 'system', label: 'System', icon: 'Monitor' },
106
+ ];
107
+
108
+ export default function SiteHeaderSections() {
109
+ const [sectionId, setSectionId] = useState('guides');
110
+ const [mode, setMode] = useState<Mode>('system');
111
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
112
+ const [open, setOpen] = useState(false);
113
+ const section = sections.find((s) => s.id === sectionId) ?? sections[0];
114
+ const current = modes.find((m) => m.value === mode) ?? modes[2];
115
+ // A real app passes the router from its framework, such as Next's useRouter(). Here it sets the open section.
116
+ const router = { push: (url: string) => setSectionId(url.split('/').pop() ?? 'start') };
117
+
118
+ return (
119
+ <>
120
+ {/* The brand, then search and the theme menu as `phoneAction`, so they stay in the bar at every width. The section Tabs are `nav`, a second row of the bar. */}
121
+ <SiteHeader
122
+ brand={{ href: '#top', name: 'Acme Docs' }}
123
+ links={[]}
124
+ phoneAction={
125
+ <>
126
+ <Tooltip title="Search">
127
+ <IconButton color="iconOnly" state="enabled" size="medium" iconName="Search" ariaLabel="Search" />
128
+ </Tooltip>
129
+ <Tooltip title={`Theme: ${current.label}`}>
130
+ <IconButton
131
+ color="iconOnly"
132
+ state={open ? 'selected' : 'enabled'}
133
+ size="medium"
134
+ iconName={current.icon}
135
+ ariaLabel={`Theme: ${current.label}`}
136
+ aria-haspopup="menu"
137
+ aria-expanded={open}
138
+ onClick={(e: { currentTarget: HTMLElement }) => {
139
+ setAnchor(e.currentTarget);
140
+ setOpen((o) => !o);
141
+ }}
142
+ />
143
+ </Tooltip>
144
+ </>
145
+ }
146
+ nav={
147
+ <TabsContainer fill>
148
+ {sections.map((s) => (
149
+ <Tab key={s.id} label={s.label} href={`/${s.id}`} router={router} isSelected={s.id === section.id} onClickTab={() => setSectionId(s.id)} />
150
+ ))}
151
+ </TabsContainer>
152
+ }
153
+ mainId="site-header-sections-main"
154
+ />
155
+ <PageShell id="site-header-sections-main" tabIndex={-1}>
156
+ <Stack gap="large">
157
+ <Heading level={1} size="h5">{section.page}</Heading>
158
+ <Paragraph tone="secondary" measure="none">The pages in {section.label} are listed beside this page on a wide screen, and in the menu on a phone.</Paragraph>
159
+ </Stack>
160
+ </PageShell>
161
+ <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
162
+ <Menu navigable aria-label="Theme" width={180}>
163
+ {modes.map((m) => (
164
+ <MenuItem
165
+ key={m.value}
166
+ size="small"
167
+ iconName={m.icon}
168
+ label={m.label}
169
+ isSelected={m.value === mode}
170
+ role="menuitemradio"
171
+ onClick={() => { setMode(m.value); setOpen(false); }}
172
+ />
173
+ ))}
174
+ </Menu>
175
+ </Popover>
176
+ </>
177
+ );
178
+ }
179
+ ```
180
+
181
+ ## Native
182
+
183
+ On Apple a site header has no counterpart: an app uses a `NavigationStack` with a navigation bar. On Android use a top app bar.
@@ -0,0 +1 @@
1
+ export default function ThemeSwitcherMenu(): import("react").JSX.Element;
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import IconButton from '../../components/iconButton';
4
+ import Tooltip from '../../components/tooltip';
5
+ import Popover from '../../components/popover';
6
+ import Menu from '../../components/menu';
7
+ import MenuItem from '../../components/menuItem';
8
+ import PageShell from '../../components/pageShell';
9
+ import Heading from '../../components/heading';
10
+ import Paragraph from '../../components/paragraph';
11
+ import Link from '../../components/link';
12
+ import { Cluster, Stack } from '../../components/layout';
13
+ var modes = [
14
+ { value: 'light', label: 'Light', icon: 'Sun' },
15
+ { value: 'dark', label: 'Dark', icon: 'Moon' },
16
+ { value: 'system', label: 'System', icon: 'Monitor' },
17
+ ];
18
+ export default function ThemeSwitcherMenu() {
19
+ var _a;
20
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
21
+ var _b = useState('system'), mode = _b[0], setMode = _b[1];
22
+ var _c = useState(null), anchor = _c[0], setAnchor = _c[1];
23
+ var _d = useState(false), open = _d[0], setOpen = _d[1];
24
+ var current = (_a = modes.find(function (m) { return m.value === mode; })) !== null && _a !== void 0 ? _a : modes[2];
25
+ return (<PageShell>
26
+ <Stack gap="large">
27
+ <Cluster justify="between">
28
+ <Link href="#top" size="subtitle1">Acme</Link>
29
+ <Tooltip title={"Theme: ".concat(current.label)}>
30
+ <IconButton color="iconOnly" state={open ? 'selected' : 'enabled'} size="medium" iconName={current.icon} ariaLabel={"Theme: ".concat(current.label)} aria-haspopup="menu" aria-expanded={open} onClick={function (e) {
31
+ setAnchor(e.currentTarget);
32
+ setOpen(function (o) { return !o; });
33
+ }}/>
34
+ </Tooltip>
35
+ </Cluster>
36
+ <Heading level={1} size="h5">Welcome back, Dana</Heading>
37
+ <Paragraph tone="secondary" measure="none">
38
+ {mode === 'system' ? 'Acme follows your device.' : "Acme is set to ".concat(mode, ".")} In a real app the page changes now.
39
+ </Paragraph>
40
+ </Stack>
41
+ <Popover open={open} anchorEl={anchor} onClose={function () { return setOpen(false); }} returnFocus>
42
+ <Menu navigable aria-label="Theme" width={180}>
43
+ {modes.map(function (m) { return (<MenuItem key={m.value} size="small" iconName={m.icon} label={m.label} isSelected={m.value === mode} role="menuitemradio" onClick={function () { setMode(m.value); setOpen(false); }}/>); })}
44
+ </Menu>
45
+ </Popover>
46
+ </PageShell>);
47
+ }
@@ -0,0 +1 @@
1
+ export default function ThemeSwitcherSegmented(): import("react").JSX.Element;
@@ -0,0 +1,26 @@
1
+ 'use client';
2
+ import { useState } from 'react';
3
+ import Heading from '../../components/heading';
4
+ import SettingsSection from '../../components/settingsSection';
5
+ import SegmentedControl from '../../components/segmentedControl';
6
+ import { Center, Cluster, Stack } from '../../components/layout';
7
+ var options = [
8
+ { value: 'light', label: 'Light' },
9
+ { value: 'dark', label: 'Dark' },
10
+ { value: 'system', label: 'System' },
11
+ ];
12
+ export default function ThemeSwitcherSegmented() {
13
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
14
+ var _a = useState('system'), mode = _a[0], setMode = _a[1];
15
+ return (<Center width="page">
16
+ <Stack gap="large">
17
+ <Heading level={1} size="h5">Settings</Heading>
18
+ <SettingsSection title="Appearance" description="System follows your device.">
19
+ {/* Kept on the device, so it saves in place and shows nothing: the page changes at once. */}
20
+ <Cluster>
21
+ <SegmentedControl size="small" width="fit" aria-label="Theme" options={options} value={mode} onChange={setMode}/>
22
+ </Cluster>
23
+ </SettingsSection>
24
+ </Stack>
25
+ </Center>);
26
+ }
@@ -0,0 +1,149 @@
1
+ # Theme switcher
2
+
3
+ A person chooses between a light page, a dark page, or the one their device uses.
4
+
5
+ ## Do
6
+
7
+ - Offer three choices, in this order: 'Light', 'Dark' and 'System'. 'System' follows the device and is the default.
8
+ - Name the menu's `IconButton` for the current choice, in sentence case: 'Theme: Dark'. Show the icon of the current choice: a sun, a moon or a monitor.
9
+ - Open a navigable menu: `<Popover returnFocus>` around `<Menu navigable aria-label="Theme">`. Set `aria-haspopup="menu"` and `aria-expanded` on the button, and `state="selected"` while the menu is open.
10
+ - Give each item `role="menuitemradio"` and `isSelected` on the current one, and close the menu on a choice.
11
+ - Use a `SegmentedControl` named 'Theme' with `width="fit"` in a `SettingsSection` on a settings page. It saves in place and shows nothing, as the rule 'A setting saves in place, or with one Save Button' says.
12
+ - Change the page as soon as a choice is made. A choice kept on the device cannot fail, so show no message and no toast.
13
+ - Keep the choice on the device, such as in a cookie or local storage, and read it before the page paints, so the page never flashes the wrong theme.
14
+ - For 'System', set no class and follow `prefers-color-scheme`, and change the page when the device changes.
15
+ - Set the choice's class on `<html>`. The example keeps the choice in state, because it must not touch the document.
16
+
17
+ ## Don't
18
+
19
+ - Do not add a brand theme as a fourth choice. A brand theme is another setting.
20
+ - Do not name the button for the action, such as 'Dark mode'. Name it for what is on.
21
+ - Do not use a toggle that only flips between light and dark. It hides System.
22
+ - Do not mark the current choice with color only.
23
+ - Do not show both the menu and the segmented control on the same page.
24
+ - Do not save the theme to the person's account with this case. A save that can fail follows the rule 'A setting saves in place, or with one Save Button'.
25
+
26
+ ## Option: Menu in the header
27
+
28
+ Use when: The site has no settings page, or the person should reach the theme from every page.
29
+
30
+ Uses: `Cluster`, `Heading`, `IconButton`, `Link`, `Menu`, `MenuItem`, `PageShell`, `Paragraph`, `Popover`, `Stack`, `Tooltip`
31
+
32
+ ```tsx
33
+ 'use client';
34
+ import { useState } from 'react';
35
+ import IconButton from 'oneslash-design-system/components/iconButton';
36
+ import Tooltip from 'oneslash-design-system/components/tooltip';
37
+ import Popover from 'oneslash-design-system/components/popover';
38
+ import Menu from 'oneslash-design-system/components/menu';
39
+ import MenuItem from 'oneslash-design-system/components/menuItem';
40
+ import PageShell from 'oneslash-design-system/components/pageShell';
41
+ import Heading from 'oneslash-design-system/components/heading';
42
+ import Paragraph from 'oneslash-design-system/components/paragraph';
43
+ import Link from 'oneslash-design-system/components/link';
44
+ import { Cluster, Stack } from 'oneslash-design-system/components/layout';
45
+
46
+ type Mode = 'light' | 'dark' | 'system';
47
+
48
+ const modes: { value: Mode; label: string; icon: 'Sun' | 'Moon' | 'Monitor' }[] = [
49
+ { value: 'light', label: 'Light', icon: 'Sun' },
50
+ { value: 'dark', label: 'Dark', icon: 'Moon' },
51
+ { value: 'system', label: 'System', icon: 'Monitor' },
52
+ ];
53
+
54
+ export default function ThemeSwitcherMenu() {
55
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
56
+ const [mode, setMode] = useState<Mode>('system');
57
+ const [anchor, setAnchor] = useState<HTMLElement | null>(null);
58
+ const [open, setOpen] = useState(false);
59
+ const current = modes.find((m) => m.value === mode) ?? modes[2];
60
+
61
+ return (
62
+ <PageShell>
63
+ <Stack gap="large">
64
+ <Cluster justify="between">
65
+ <Link href="#top" size="subtitle1">Acme</Link>
66
+ <Tooltip title={`Theme: ${current.label}`}>
67
+ <IconButton
68
+ color="iconOnly"
69
+ state={open ? 'selected' : 'enabled'}
70
+ size="medium"
71
+ iconName={current.icon}
72
+ ariaLabel={`Theme: ${current.label}`}
73
+ aria-haspopup="menu"
74
+ aria-expanded={open}
75
+ onClick={(e: { currentTarget: HTMLElement }) => {
76
+ setAnchor(e.currentTarget);
77
+ setOpen((o) => !o);
78
+ }}
79
+ />
80
+ </Tooltip>
81
+ </Cluster>
82
+ <Heading level={1} size="h5">Welcome back, Dana</Heading>
83
+ <Paragraph tone="secondary" measure="none">
84
+ {mode === 'system' ? 'Acme follows your device.' : `Acme is set to ${mode}.`} In a real app the page changes now.
85
+ </Paragraph>
86
+ </Stack>
87
+ <Popover open={open} anchorEl={anchor} onClose={() => setOpen(false)} returnFocus>
88
+ <Menu navigable aria-label="Theme" width={180}>
89
+ {modes.map((m) => (
90
+ <MenuItem
91
+ key={m.value}
92
+ size="small"
93
+ iconName={m.icon}
94
+ label={m.label}
95
+ isSelected={m.value === mode}
96
+ role="menuitemradio"
97
+ onClick={() => { setMode(m.value); setOpen(false); }}
98
+ />
99
+ ))}
100
+ </Menu>
101
+ </Popover>
102
+ </PageShell>
103
+ );
104
+ }
105
+ ```
106
+
107
+ ## Option: Segmented control on a settings page
108
+
109
+ Use when: The choice is a setting among others, on a settings page.
110
+
111
+ Uses: `Center`, `Cluster`, `Heading`, `SegmentedControl`, `SettingsSection`, `Stack`
112
+
113
+ ```tsx
114
+ 'use client';
115
+ import { useState } from 'react';
116
+ import Heading from 'oneslash-design-system/components/heading';
117
+ import SettingsSection from 'oneslash-design-system/components/settingsSection';
118
+ import SegmentedControl from 'oneslash-design-system/components/segmentedControl';
119
+ import { Center, Cluster, Stack } from 'oneslash-design-system/components/layout';
120
+
121
+ const options = [
122
+ { value: 'light', label: 'Light' },
123
+ { value: 'dark', label: 'Dark' },
124
+ { value: 'system', label: 'System' },
125
+ ];
126
+
127
+ export default function ThemeSwitcherSegmented() {
128
+ // The example keeps the choice in state. A real app keeps it for the person and sets the `dark` class on <html>.
129
+ const [mode, setMode] = useState('system');
130
+
131
+ return (
132
+ <Center width="page">
133
+ <Stack gap="large">
134
+ <Heading level={1} size="h5">Settings</Heading>
135
+ <SettingsSection title="Appearance" description="System follows your device.">
136
+ {/* Kept on the device, so it saves in place and shows nothing: the page changes at once. */}
137
+ <Cluster>
138
+ <SegmentedControl size="small" width="fit" aria-label="Theme" options={options} value={mode} onChange={setMode} />
139
+ </Cluster>
140
+ </SettingsSection>
141
+ </Stack>
142
+ </Center>
143
+ );
144
+ }
145
+ ```
146
+
147
+ ## Native
148
+
149
+ On Apple and Android follow the system appearance and offer no switcher. If the app has one, use a `Picker` of Light, Dark and System in settings.