-
Notifications
You must be signed in to change notification settings - Fork 256
/
DropdownButton.tsx
73 lines (62 loc) · 1.58 KB
/
DropdownButton.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
// Libraries
import React, {Component} from 'react'
import classnames from 'classnames'
// Types
import {
ComponentStatus,
ComponentColor,
ComponentSize,
IconFont,
DropdownChild,
} from 'src/reusable_ui/types'
import {ErrorHandling} from 'src/shared/decorators/errors'
interface Props {
children: DropdownChild
onClick: () => void
status?: ComponentStatus
active?: boolean
color?: ComponentColor
size?: ComponentSize
icon?: IconFont
}
@ErrorHandling
class DropdownButton extends Component<Props> {
public static defaultProps: Partial<Props> = {
color: ComponentColor.Default,
size: ComponentSize.Small,
status: ComponentStatus.Default,
active: false,
}
public render() {
const {onClick, status, children} = this.props
return (
<button
className={this.classname}
onClick={onClick}
disabled={status === ComponentStatus.Disabled}
>
{this.icon}
<span className="dropdown--selected">{children}</span>
<span className="dropdown--caret icon caret-down" />
</button>
)
}
private get classname(): string {
const {status, active, color, size} = this.props
return classnames('dropdown--button button', {
'button-stretch': true,
[`button-${color}`]: color,
[`button-${size}`]: size,
disabled: status === ComponentStatus.Disabled,
active,
})
}
private get icon(): JSX.Element {
const {icon} = this.props
if (icon) {
return <span className={`dropdown--icon icon ${icon}`} />
}
return null
}
}
export default DropdownButton