MCPcopy Create free account
hub / github.com/nodejs/nodejs.org / ThemeToggle

Function ThemeToggle

packages/ui-components/src/Common/ThemeToggle/index.tsx:30–75  ·  view source on GitHub ↗
({
  onChange = () => {},
  currentTheme = 'system',
  ariaLabel,
  themeLabels = { system: 'System', light: 'Light', dark: 'Dark' },
})

Source from the content-addressed store, hash-verified

28const themes: Array<Theme> = ['system', 'light', 'dark'];
29
30const ThemeToggle: FC<ThemeToggleProps> = ({
31 onChange = () => {},
32 currentTheme = 'system',
33 ariaLabel,
34 themeLabels = { system: 'System', light: 'Light', dark: 'Dark' },
35}) => {
36 const TriggerIcon = themeIcons[currentTheme];
37
38 return (
39 <DropdownMenu.Root>
40 <DropdownMenu.Trigger asChild>
41 <button
42 type="button"
43 className={styles.themeToggle}
44 aria-label={ariaLabel}
45 >
46 <TriggerIcon height="20" />
47 </button>
48 </DropdownMenu.Trigger>
49
50 <DropdownMenu.Portal>
51 <DropdownMenu.Content
52 align="end"
53 className={styles.dropDownContent}
54 sideOffset={5}
55 >
56 {themes.map(theme => {
57 const Icon = themeIcons[theme];
58 return (
59 <DropdownMenu.Item
60 key={theme}
61 onClick={() => onChange(theme)}
62 className={classNames(styles.dropDownItem, {
63 [styles.activeItem]: theme === currentTheme,
64 })}
65 >
66 <Icon height="16" />
67 {themeLabels[theme]}
68 </DropdownMenu.Item>
69 );
70 })}
71 </DropdownMenu.Content>
72 </DropdownMenu.Portal>
73 </DropdownMenu.Root>
74 );
75};
76
77export default ThemeToggle;

Callers

nothing calls this directly

Calls 1

onChangeFunction · 0.85

Tested by

no test coverage detected