| 1 |
export default function Select( props ) { |
| 2 |
return ( |
| 3 |
<select multiple={ props.multiple } className={ props.className } value={ props.value } onChange={ props.onChange } ref={ props.elRef } onClick={ () => props.onClick?.() }> |
| 4 |
{ props.options.map( ( option ) => |
| 5 |
option.children |
| 6 |
? <optgroup label={ option.label } key={ option.label }> |
| 7 |
{ option.children.map( ( childOption ) => |
| 8 |
<option key={ childOption.value } value={ childOption.value }> |
| 9 |
{ childOption.label } |
| 10 |
</option>, |
| 11 |
) } |
| 12 |
</optgroup> |
| 13 |
: <option key={ option.value } value={ option.value }> |
| 14 |
{ option.label } |
| 15 |
</option>, |
| 16 |
) } |
| 17 |
</select> |
| 18 |
); |
| 19 |
} |
| 20 |
Select.propTypes = { |
| 21 |
className: PropTypes.string, |
| 22 |
onChange: PropTypes.func, |
| 23 |
options: PropTypes.array, |
| 24 |
elRef: PropTypes.object, |
| 25 |
multiple: PropTypes.bool, |
| 26 |
value: PropTypes.oneOfType( [ PropTypes.array, PropTypes.string ] ), |
| 27 |
onClick: PropTypes.func, |
| 28 |
}; |
| 29 |
Select.defaultProps = { |
| 30 |
className: '', |
| 31 |
options: [], |
| 32 |
}; |
| 33 |
|