import { Dropdown } from '@edx/paragon'; import PropTypes from 'prop-types'; import React, { useState } from 'react'; function SelectableDropdown({ options, defaultOption, onChange, label, }) { const [selected, setSelected] = useState(options.find(option => (option.value === defaultOption))); return ( { label || selected.label } { options .map(option => ( { setSelected(option); if (onChange) { onChange(option); } } } > { option.label } )) } ); } SelectableDropdown.propTypes = { options: PropTypes.arrayOf( PropTypes.shape({ value: PropTypes.string, label: PropTypes.string, }), ).isRequired, defaultOption: PropTypes.string.isRequired, onChange: PropTypes.func, label: PropTypes.node, }; SelectableDropdown.defaultProps = { onChange: null, label: null, }; export default SelectableDropdown;