-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathSidebarHeading.js
135 lines (123 loc) · 3.04 KB
/
SidebarHeading.js
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React from 'react';
import PropTypes from 'prop-types';
import { withState } from 'recompose';
import { styled, withTheme } from '@storybook/theming';
import { StorybookLogo, WithTooltip, TooltipLinkList, Button, Icons } from '@storybook/components';
const BrandArea = styled.div(({ theme }) => ({
fontSize: theme.typography.size.s2,
fontWeight: theme.typography.weight.bold,
marginRight: theme.layoutMargin,
display: 'flex',
alignItems: 'center',
paddingTop: 3,
paddingBottom: 3,
minHeight: 28,
'& > *': {
maxWidth: '100%',
height: 'auto',
width: 'auto',
display: 'block',
},
}));
const Logo = styled(StorybookLogo)({
width: 'auto',
height: 22,
display: 'block',
});
const Img = styled.img({
width: 'auto',
display: 'block',
maxWidth: '100%',
});
const LogoLink = styled.a({
display: 'block',
color: 'inherit',
textDecoration: 'none',
});
const MenuButton = styled(Button)(props => ({
position: 'relative',
overflow: 'visible',
padding: 7,
...(props.highlighted && {
'&:after': {
content: '""',
position: 'absolute',
top: 0,
right: 0,
width: 8,
height: 8,
borderRadius: 8,
background: `${props.theme.color.positive}`,
},
}),
}));
const Head = styled.div({
display: 'flex',
alignItems: 'flex-start',
justifyContent: 'space-between',
});
const Brand = withTheme(({ theme: { brand: { title = 'Storybook', url = './', image } } }) => {
if (image === undefined && url === null) {
return <Logo alt={title} />;
}
if (image === undefined && url) {
return (
<LogoLink href={url}>
<Logo alt={title} />
</LogoLink>
);
}
if (image === null && url === null) {
return title;
}
if (image === null && url) {
return <LogoLink href={url}>{title}</LogoLink>;
}
if (image && url === null) {
return <Img src={image} alt={title} />;
}
if (image && url) {
return (
<LogoLink href={url}>
<Img src={image} alt={title} />
</LogoLink>
);
}
return null;
});
const SidebarHeading = withState('tooltipShown', 'onVisibilityChange', false)(
({ menuHighlighted, menu, tooltipShown, onVisibilityChange, ...props }) => (
<Head {...props}>
<BrandArea>
<Brand />
</BrandArea>
<WithTooltip
placement="top"
trigger="click"
tooltipShown={tooltipShown}
onVisibilityChange={onVisibilityChange}
tooltip={
<TooltipLinkList
links={menu.map(i => ({
...i,
onClick: (...args) => onVisibilityChange(false) || i.onClick(...args),
}))}
/>
}
closeOnClick
>
<MenuButton outline small containsIcon highlighted={menuHighlighted}>
<Icons icon="ellipsis" />
</MenuButton>
</WithTooltip>
</Head>
)
);
SidebarHeading.propTypes = {
menuHighlighted: PropTypes.bool,
menu: PropTypes.arrayOf(PropTypes.shape({})).isRequired,
};
SidebarHeading.defaultProps = {
menuHighlighted: false,
};
export { SidebarHeading as default };