import React from 'react'; import PropTypes from 'prop-types'; import {LineInput, Label, Select} from './'; import {get} from 'lodash'; /** * @ngdoc react * @name SelectInput * @description Component to select a list from dropdown with field label */ export const SelectInput: React.StatelessComponent = ({ field, label, value, options, keyField, labelField, onChange, readOnly, clearable, autoFocus, refNode, onFocus, ...props }) => { const key = clearable ? get(value, keyField, '') : get(value, keyField, get(options, `[0].${keyField}`)); const opts = options.map((opt) => ({ key: get(opt, keyField), label: get(opt, labelField), })); const onChangeHandler = (_field, _key) => { const _value = options.find( (option) => get(option, keyField) === _key, ) || null; onChange(_field, _value); }; return (