|
|
@ -1,7 +1,8 @@
|
|
|
|
import React from 'react'
|
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
import enhanceWithClickOutside from 'react-click-outside'
|
|
|
|
import ArrowDown from './svg/arrowdown'
|
|
|
|
import ArrowDown from './svg/arrowdown'
|
|
|
|
|
|
|
|
|
|
|
|
export default class extends React.Component {
|
|
|
|
class Dropdown extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
constructor(props) {
|
|
|
|
super()
|
|
|
|
super()
|
|
|
|
this.state = {
|
|
|
|
this.state = {
|
|
|
@ -20,6 +21,10 @@ export default class extends React.Component {
|
|
|
|
this.setState({ listVisible: !this.state.listVisible })
|
|
|
|
this.setState({ listVisible: !this.state.listVisible })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
handleClickOutside() {
|
|
|
|
|
|
|
|
this.setState({ listVisible: false });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
renderListItems() {
|
|
|
|
renderListItems() {
|
|
|
|
return this.props.list.map((item, i) => (
|
|
|
|
return this.props.list.map((item, i) => (
|
|
|
|
<div className={`dropdown-list-item ${this.state.selected === item ? "selected" : ""}`} key={i} onClick={this.select.bind(null, item)}>
|
|
|
|
<div className={`dropdown-list-item ${this.state.selected === item ? "selected" : ""}`} key={i} onClick={this.select.bind(null, item)}>
|
|
|
@ -51,8 +56,12 @@ export default class extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render() {
|
|
|
|
render() {
|
|
|
|
|
|
|
|
// find longest list value in number of characters
|
|
|
|
|
|
|
|
const MIN_WIDTH = this.props.list.reduce((max, { name }) =>
|
|
|
|
|
|
|
|
(name.length > max ? name.length : max), 0)
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<div className="dropdown-container" onClick={this.toggle}>
|
|
|
|
<div className="dropdown-container" style={{ minWidth: MIN_WIDTH * 14 }} onClick={this.toggle}>
|
|
|
|
<div className={`dropdown-display ${this.state.listVisible ? 'list-visible' : ''}`}>
|
|
|
|
<div className={`dropdown-display ${this.state.listVisible ? 'list-visible' : ''}`}>
|
|
|
|
<span>{ this.state.selected.name }</span>
|
|
|
|
<span>{ this.state.selected.name }</span>
|
|
|
|
<div className="arrow-down"><ArrowDown /></div>
|
|
|
|
<div className="arrow-down"><ArrowDown /></div>
|
|
|
@ -62,7 +71,8 @@ export default class extends React.Component {
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<style jsx>{`
|
|
|
|
<style jsx>{`
|
|
|
|
.arrow-down {
|
|
|
|
.arrow-down {
|
|
|
|
margin-left: 16px;
|
|
|
|
position: absolute;
|
|
|
|
|
|
|
|
right: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
.list-visible > .arrow-down {
|
|
|
|
.list-visible > .arrow-down {
|
|
|
@ -85,7 +95,7 @@ export default class extends React.Component {
|
|
|
|
user-select: none;
|
|
|
|
user-select: none;
|
|
|
|
padding: 8px 16px;
|
|
|
|
padding: 8px 16px;
|
|
|
|
display: flex;
|
|
|
|
display: flex;
|
|
|
|
justify-content: center;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
align-items: center;
|
|
|
|
position: relative;
|
|
|
|
position: relative;
|
|
|
|
z-index: 1;
|
|
|
|
z-index: 1;
|
|
|
@ -105,9 +115,13 @@ export default class extends React.Component {
|
|
|
|
margin-top: -2px;
|
|
|
|
margin-top: -2px;
|
|
|
|
border: 0.5px solid #333;
|
|
|
|
border: 0.5px solid #333;
|
|
|
|
border-radius: 0px 0px 3px 3px;
|
|
|
|
border-radius: 0px 0px 3px 3px;
|
|
|
|
|
|
|
|
max-height: 350px;
|
|
|
|
|
|
|
|
overflow-y: scroll;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`}</style>
|
|
|
|
`}</style>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default enhanceWithClickOutside(Dropdown)
|
|
|
|