@@ -1,73 +1,114 @@
11import React from 'react'
22import PropTypes from 'prop-types';
33
4+import { DropdownItem, DropdownDivider } from '../components/Base'
45
5−const InnerLabelDropdown = props => {
6−
7− const menuVisibility = props.isOpen === true
8− ? 'visible'
9− : 'hidden';
10−
11− const selectedClasses = props.isOpen === true
12− ? 'br-blue'
13− : 'br-gray-50';
14−
15− const fullWidthClass = props.fullWidth ? 'full-width' : ''
16−
17− return (
18− <div className={`rel table ${fullWidthClass}`}>
19− <div
20− className={`fix full o-0 ${menuVisibility}`}
21− onClick={props.handleClose}
22− />
23−
24− <button
25− className={`h-10 mp-0 bg-white outline-blue sans ${props.className} ${fullWidthClass}`}
26− onClick={props.handleToggle}
27− disabled={props.disabled}>
28− <div className={'flex'}>
29− <div className={`ph-4 flex-center-all b-2 br-0 b-solid h-10 ${selectedClasses} ${fullWidthClass}`}>
30− <div className={'text-400 mr-2'}>{props.title}</div>
31− <div className={'text-600'}>{props.currentSelectionTitle}</div>
6+class InnerLabelDropdown extends React.Component {
7+ constructor(props) {
8+ super(props)
9+
10+ this.state = {
11+ isOpen: false
12+ }
13+
14+ this.toggle = this.toggle.bind(this)
15+ this.close = this.close.bind(this)
16+ }
17+
18+ toggle() {
19+ this.setState({
20+ isOpen: !this.state.isOpen
21+ })
22+ }
23+
24+ close() {
25+ this.setState({
26+ isOpen: false
27+ })
28+ }
29+
30+ selectOption(opt) {
31+ this.close()
32+ this.props.handleUpdate(opt)
33+ }
34+
35+ getOptionElems() {
36+ return this.props.options.map(opt => {
37+ if (opt.type === "divider") {
38+ return <DropdownDivider />
39+ } else {
40+ return (
41+ <DropdownItem onClick={() => this.selectOption(opt.value)}>
42+ { opt.title }
43+ </DropdownItem>
44+ )
45+ }
46+ })
47+ }
48+
49+ render() {
50+ const { props, state } = this
51+
52+ const optionElems = this.getOptionElems()
53+
54+ const menuVisibility = state.isOpen === true
55+ ? 'visible'
56+ : 'hidden';
57+
58+ const selectedClasses = state.isOpen === true
59+ ? 'br-blue'
60+ : 'br-gray-50';
61+
62+ const fullWidthClass = props.fullWidth ? 'full-width' : ''
63+
64+ return (
65+ <div className={`rel table ${fullWidthClass}`}>
66+ <div
67+ className={`fix full o-0 ${menuVisibility}`}
68+ onClick={this.close}
69+ />
70+
71+ <button
72+ className={`h-10 mp-0 bg-white outline-blue sans ${props.className} ${fullWidthClass}`}
73+ onClick={this.toggle}
74+ disabled={props.disabled}>
75+ <div className={'flex'}>
76+ <div className={`ph-4 flex align-center b-2 br-0 b-solid h-10 ${selectedClasses} ${fullWidthClass}`}>
77+ <div className={'text-400 mr-2'}>{props.title}</div>
78+ <div className={'text-600'}>{props.currentSelectionTitle}</div>
79+ </div>
80+ <div className={'white bg-blue s-10 flex-center-all text-sm'}>{'▼'}</div>
3281 </div>
33− <div className={'white bg-blue s-10 flex-center-all text-sm'}>{'▼'}</div>
34− </div>
35− </button>
82+ </button>
3683
37− <div className={`abs flex-column bg-white t-12 l-0 w-100 ${menuVisibility}`}>
38− <div className={'pv-1 b-solid b-gray-50 b-2 bb-0'} />
84+ <div className={`abs flex-column bg-white t-12 l-0 w-100 z-1 ${menuVisibility}`}>
85+ <div className={'pv-1 b-solid b-gray-50 b-2 bb-0'} />
3986
40− { props.children }
87+ { optionElems }
4188
42− <div className={'pv-1 b-solid b-gray-50 b-2 bt-0'} />
43− </div>
89+ <div className={'pv-1 b-solid b-gray-50 b-2 bt-0'} />
90+ </div>
4491
45− </div>
46− )
92+ </div>
93+ )
94+ }
4795}
4896
4997InnerLabelDropdown.propTypes = {
5098 disabled: PropTypes.bool,
51− isOpen: PropTypes.bool,
52− handleToggle: PropTypes.func,
53− handleClose: PropTypes.func,
5499 className: PropTypes.string,
55100 title: PropTypes.string,
56− children: PropTypes.node,
57101 style: PropTypes.object,
58102 currentSelectionTitle: PropTypes.string,
103+ children: PropTypes.node,
59104};
60105
61−
62106InnerLabelDropdown.defaultProps = {
63− isOpen: false,
107+ disabled: false,
64108 className: '',
65109 title: '',
66− currentSelectionTitle: '',
67− handleToggle: () => {},
68− handleClose: () => {},
69− disabled: false,
70110 style: {},
111+ currentSelectionTitle: '',
71112};
72113
73114export default InnerLabelDropdown