-
Notifications
You must be signed in to change notification settings - Fork 295
/
NavDropdown.tsx
71 lines (69 loc) · 1.73 KB
/
NavDropdown.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
// @flow
import React, { Component } from 'react';
import { observer } from 'mobx-react';
import classnames from 'classnames';
import { Dropdown } from 'react-polymorph/lib/components/Dropdown';
import NavButton from './NavButton';
import styles from './NavDropdown.scss';
type Props = {
label: string,
activeItem: string,
icon?: string,
isActive: boolean,
options: Array<{
value: number | string,
label: string,
}>,
onChange: Function,
hasNotification?: boolean,
};
@observer
export default class NavDropdown extends Component<Props> {
render() {
const {
label,
icon,
isActive,
onChange,
options,
activeItem,
hasNotification,
} = this.props;
const componentStyles = classnames([
styles.component,
hasNotification ? styles.hasNotification : null,
]);
const getOptionLabelStyles = (optionHasNotification: boolean) =>
classnames([
styles.optionLabel,
optionHasNotification ? styles.hasNotification : null,
]);
return (
<div className={componentStyles}>
<Dropdown
label={
<NavButton
label={label}
icon={icon}
isActive={isActive}
onClick={() => {}}
hasNotification={hasNotification}
/>
}
onItemSelected={({ value }) => {
onChange(value);
}}
optionRenderer={(o) => (
<div className={getOptionLabelStyles(o.hasNotification)}>
{o.label}
</div>
)}
items={options}
activeItem={options.find((o) => o.value === activeItem)}
noArrow
optionHeight={32}
/>
</div>
);
}
}