-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathSidePanel.tsx
More file actions
67 lines (57 loc) · 1.8 KB
/
SidePanel.tsx
File metadata and controls
67 lines (57 loc) · 1.8 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
61
62
63
64
65
66
67
import { ComponentType, PropsWithChildren } from 'react';
import styled from 'styled-components';
import { Flex } from '../Flex';
import { Icon } from '../Icon';
import { Text } from '../Text';
export type SidePanelVariant = 'default';
export type SidePanelItem = {
text: string;
icon: ComponentType;
onClick: (event: React.MouseEvent<HTMLElement>) => void;
isActive?: boolean;
}
export type SidePanelProps = PropsWithChildren<{
items: SidePanelItem[],
isExpanded?: boolean;
}>;
const Component = styled(Flex)<any>(({ theme, isExpanded }) => ({
...(theme.SIDE_PANEL.parent || {}),
...(isExpanded && { width: '240px' })
}));
const StyledFlex = styled(Flex)<any>(({ theme, isActive, isExpanded }) => ({
...(theme.SIDE_PANEL.item || {}),
...(isActive && {
background: theme.COLOR.brandLightest,
svg: {
minWidth: '18px',
path: {
fill: theme.COLOR.brandMain
}
}
}),
'.item-text': {
...theme.SIDE_PANEL.item['.item-text'],
...(isActive && { p: { color: theme.COLOR.brandMain } }),
...(isExpanded && { width: 'fit-content' })
}
}));
const Item = ({ item, isExpanded }: {item: SidePanelItem, isExpanded?: boolean }) => {
return (
<StyledFlex isExpanded={isExpanded} onClick={(e: React.MouseEvent<HTMLElement>) => item.onClick(e)} isActive={item.isActive} variant="raw" >
<Icon size="18px" variant="basic" icon={item.icon} />
<div className="item-text" >
<Text as="p" margin='0 0 0 19px' variant="b1m">{item.text}</Text>
</div>
</StyledFlex>
);
}
export function SidePanel(sidePanelProps: SidePanelProps) {
const { items, isExpanded } = sidePanelProps;
return (
<Component isExpanded={isExpanded} dir="column" >
{
items.map(item => <Item isExpanded={isExpanded} item={item} />)
}
</Component>
);
}