-
-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathThemeList.tsx
77 lines (68 loc) · 1.49 KB
/
ThemeList.tsx
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { useAddonState } from '@storybook/api';
import React, { useCallback } from 'react';
import styled from 'styled-components';
import themes from '../../src/common/themes';
import { Theme } from '../../src/types';
import { THEMES_ID } from './constants';
import { ThemeButton } from './ThemeButton';
const {
original,
rainyDay,
vaporTeal,
theSixtiesUSA,
olive,
tokyoDark,
rose,
plum,
matrix,
travel,
...otherThemes
} = themes;
const themeList = [
original,
rainyDay,
vaporTeal,
theSixtiesUSA,
olive,
tokyoDark,
rose,
plum,
matrix,
travel,
...Object.values(otherThemes)
];
type ThemesProps = {
active?: boolean;
};
const Wrapper = styled.div<{ theme: Theme }>`
display: grid;
padding: 1em;
gap: 1em;
grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
grid-template-rows: repeat(auto-fill, 40px);
background-color: ${({ theme }) => theme.material};
`;
export function ThemeList({ active }: ThemesProps) {
const [themeName, setThemeName] = useAddonState(THEMES_ID, 'original');
const handleChoose = useCallback(
(newThemeName: string) => {
setThemeName(newThemeName);
},
[setThemeName]
);
if (!active) {
return <></>;
}
return (
<Wrapper key={THEMES_ID} theme={themes.original}>
{themeList.map(theme => (
<ThemeButton
active={themeName === theme.name}
key={theme.name}
onChoose={handleChoose}
theme={theme}
/>
))}
</Wrapper>
);
}