From 1cac6f27687cbc452b3483287cf556f9dfd0db25 Mon Sep 17 00:00:00 2001 From: Whymarrh Whitby Date: Sun, 24 Nov 2019 17:48:58 -0330 Subject: [PATCH] Convert SimpleDropdown component to use JSX (#7540) --- .../app/dropdowns/simple-dropdown.js | 98 +++++++++---------- 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/ui/app/components/app/dropdowns/simple-dropdown.js b/ui/app/components/app/dropdowns/simple-dropdown.js index bba088ed1..081674397 100644 --- a/ui/app/components/app/dropdowns/simple-dropdown.js +++ b/ui/app/components/app/dropdowns/simple-dropdown.js @@ -1,15 +1,18 @@ -const { Component } = require('react') -const PropTypes = require('prop-types') -const h = require('react-hyperscript') -const classnames = require('classnames') -const R = require('ramda') +import classnames from 'classnames' +import PropTypes from 'prop-types' +import React, { Component } from 'react' +import R from 'ramda' class SimpleDropdown extends Component { - constructor (props) { - super(props) - this.state = { - isOpen: false, - } + static propTypes = { + options: PropTypes.array.isRequired, + placeholder: PropTypes.string, + onSelect: PropTypes.func, + selectedOption: PropTypes.string, + } + + state = { + isOpen: false, } getDisplayValue () { @@ -26,67 +29,58 @@ class SimpleDropdown extends Component { } toggleOpen () { - const { isOpen } = this.state - this.setState({ isOpen: !isOpen }) + this.setState((prevState) => ({ + isOpen: !prevState.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({ + return ( +
+
{ + event.stopPropagation() + this.handleClose() + }} + /> +
+ {options.map((option) => ( +
{ + })} + key={option.value} + onClick={() => { if (option.value !== selectedOption) { onSelect(option.value) } this.handleClose() - }, - }, - option.displayValue || option.value, - ) - }), - ]), - ]) + }} + > + {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(), - ] + return ( +
this.toggleOpen()}> +
{this.getDisplayValue() || placeholder || 'Select'}
+ + {isOpen && this.renderOptions()} +
) } } -SimpleDropdown.propTypes = { - options: PropTypes.array.isRequired, - placeholder: PropTypes.string, - onSelect: PropTypes.func, - selectedOption: PropTypes.string, -} - module.exports = SimpleDropdown