import _ from 'lodash'; import PropTypes from 'prop-types'; import React from 'react'; import Label from 'Components/Label'; import EnhancedSelectInputSelectedValue from './EnhancedSelectInputSelectedValue'; import styles from './HintedSelectInputSelectedValue.css'; function HintedSelectInputSelectedValue(props) { const { value, values, hint, isMultiSelect, includeHint, ...otherProps } = props; const valuesMap = isMultiSelect && _.keyBy(values, 'key'); return (
{ isMultiSelect && value.map((key, index) => { const v = valuesMap[key]; return ( ); }) } { !isMultiSelect && value }
{ hint != null && includeHint &&
{hint}
}
); } HintedSelectInputSelectedValue.propTypes = { value: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.number]))]).isRequired, values: PropTypes.arrayOf(PropTypes.object).isRequired, hint: PropTypes.string, isMultiSelect: PropTypes.bool.isRequired, includeHint: PropTypes.bool.isRequired }; HintedSelectInputSelectedValue.defaultProps = { isMultiSelect: false, includeHint: true }; export default HintedSelectInputSelectedValue;