/
Panel.tsx
89 lines (74 loc) · 2.15 KB
/
Panel.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
78
79
80
81
82
83
84
85
86
87
88
89
import * as React from 'react';
import { API } from '@storybook/api';
import Channel from '@storybook/channels';
import { styled } from '@storybook/theming';
import { HardCodedValues } from '../interfaces/hard-coded-values.interface';
import { TokenGroup } from '../interfaces/token-group.interface';
import { HardCodedValuesTable } from './HardCodedValuesTable';
import { TokenOverview } from './TokenOverview';
import { ViewSwitch } from './ViewSwitch';
interface Props {
active: boolean;
api: API;
channel: Channel;
hardCodedValues: HardCodedValues[];
keyframes: string;
tokenGroups: TokenGroup[];
}
const Container = styled.div(() => ({
padding: '12px'
}));
const Separator = styled.hr(() => ({
backgroundColor: '#f1f1f1',
border: 'none',
height: '1px',
margin: '12px 0',
width: '100%'
}));
export class DesignTokenPanel extends React.Component<Props, any> {
constructor(props) {
super(props);
this.state = { viewType: 'card' };
}
public render() {
if (!this.props.active) {
return <>Test</>;
}
const tokenGroups = this.props.tokenGroups.sort((a, b) => {
const labelA = a.label.toUpperCase();
const labelB = b.label.toUpperCase();
return labelA < labelB ? -1 : labelA > labelB ? 1 : 0;
});
return (
<>
<style>{this.props.keyframes}</style>
<Container className="design-token-container">
<ViewSwitch
onChange={newViewType =>
this.setState(() => ({
viewType: newViewType
}))
}
value={this.state.viewType}
/>
<Separator />
{tokenGroups
.filter(tokenGroup => tokenGroup.tokens.length > 0)
.map((tokenGroup, index) => (
<TokenOverview
key={index}
tokenGroup={tokenGroup}
viewType={this.state.viewType}
/>
))}
<Separator />
{this.props.hardCodedValues.length && (
<HardCodedValuesTable
hardCodedValues={this.props.hardCodedValues}
/>
)}
</Container>
</>
);
}
}