-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathThemeSelector.tsx
More file actions
60 lines (54 loc) · 1.41 KB
/
ThemeSelector.tsx
File metadata and controls
60 lines (54 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import * as React from "react";
import type { FunctionComponent } from "react";
import { useCallback } from "react";
import { useGlobals } from "storybook/manager-api";
import {
IconButton,
TooltipLinkList,
WithTooltip,
} from "storybook/internal/components";
import { DashboardIcon } from "@storybook/icons";
import { themeNames, VSCodeTheme } from "./theme";
export const ThemeSelector: FunctionComponent = () => {
const [{ vscodeTheme }, updateGlobals] = useGlobals();
const changeTheme = useCallback(
(theme: VSCodeTheme) => {
updateGlobals({
vscodeTheme: theme,
});
},
[updateGlobals],
);
const createLinks = useCallback(
(onHide: () => void) =>
Object.values(VSCodeTheme).map((theme) => ({
id: theme,
onClick() {
changeTheme(theme);
onHide();
},
title: themeNames[theme],
value: theme,
active: vscodeTheme === theme,
})),
[vscodeTheme, changeTheme],
);
return (
<WithTooltip
placement="top"
trigger="click"
closeOnOutsideClick
tooltip={({ onHide }: { onHide: () => void }) => (
<TooltipLinkList links={createLinks(onHide)} />
)}
>
<IconButton
key="theme"
title="Change the theme of the preview"
active={vscodeTheme !== VSCodeTheme.Dark}
>
<DashboardIcon />
</IconButton>
</WithTooltip>
);
};