diff options
author | Alexander Tseung <alextsg@gmail.com> | 2017-10-23 13:40:03 +0800 |
---|---|---|
committer | Alexander Tseung <alextsg@gmail.com> | 2017-10-23 13:40:03 +0800 |
commit | 2c032e0df44a2d589aae62d3fc532df82441580b (patch) | |
tree | 7c6e3f79ac79f8ec99873cf9f51aafa1ec79ad8e /ui/app/components/dropdowns | |
parent | 8f3b762461ada222f82089e686a61183dd167428 (diff) | |
download | tangerine-wallet-browser-2c032e0df44a2d589aae62d3fc532df82441580b.tar tangerine-wallet-browser-2c032e0df44a2d589aae62d3fc532df82441580b.tar.gz tangerine-wallet-browser-2c032e0df44a2d589aae62d3fc532df82441580b.tar.bz2 tangerine-wallet-browser-2c032e0df44a2d589aae62d3fc532df82441580b.tar.lz tangerine-wallet-browser-2c032e0df44a2d589aae62d3fc532df82441580b.tar.xz tangerine-wallet-browser-2c032e0df44a2d589aae62d3fc532df82441580b.tar.zst tangerine-wallet-browser-2c032e0df44a2d589aae62d3fc532df82441580b.zip |
Update settings screen to new UI
Diffstat (limited to 'ui/app/components/dropdowns')
-rw-r--r-- | ui/app/components/dropdowns/simple-dropdown.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/ui/app/components/dropdowns/simple-dropdown.js b/ui/app/components/dropdowns/simple-dropdown.js new file mode 100644 index 000000000..8cea78518 --- /dev/null +++ b/ui/app/components/dropdowns/simple-dropdown.js @@ -0,0 +1,91 @@ +const { Component, PropTypes } = require('react') +const h = require('react-hyperscript') +const classnames = require('classnames') +const R = require('ramda') + +class SimpleDropdown extends Component { + constructor (props) { + super(props) + this.state = { + isOpen: false, + } + } + + getDisplayValue () { + const { selectedOption, options } = this.props + const matchesOption = option => option.value === selectedOption + const matchingOption = R.find(matchesOption)(options) + return matchingOption + ? matchingOption.displayValue || matchingOption.value + : selectedOption + } + + handleClose () { + this.setState({ isOpen: false }) + } + + toggleOpen () { + const { isOpen } = this.state + this.setState({ isOpen: !isOpen }) + } + + renderOptions () { + const { options, onSelect, selectedOption } = this.props + + return h('div', [ + h('div.simple-dropdown__close-area', { + onClick: event => { + event.stopPropagation() + this.handleClose() + }, + }), + h('div.simple-dropdown__options', [ + ...options.map(option => { + return h( + 'div.simple-dropdown__option', + { + className: classnames({ + 'simple-dropdown__option--selected': option.value === selectedOption, + }), + key: option.value, + onClick: () => { + if (option.value !== selectedOption) { + onSelect(option.value) + } + + this.handleClose() + }, + }, + option.displayValue || option.value, + ) + }), + ]), + ]) + } + + render () { + const { placeholder } = this.props + const { isOpen } = this.state + + return h( + 'div.simple-dropdown', + { + onClick: () => this.toggleOpen(), + }, + [ + h('div.simple-dropdown__selected', this.getDisplayValue() || placeholder || 'Select'), + h('i.fa.fa-caret-down.fa-lg.simple-dropdown__caret'), + isOpen && this.renderOptions(), + ] + ) + } +} + +SimpleDropdown.propTypes = { + options: PropTypes.array.isRequired, + placeholder: PropTypes.string, + onSelect: PropTypes.func, + selectedOption: PropTypes.string, +} + +module.exports = SimpleDropdown |