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 ( ); }) : null } { isMultiSelect ? null : value }
{ hint != null && includeHint ?
{hint}
: null }
); } HintedSelectInputSelectedValue.propTypes = { value: PropTypes.oneOfType([PropTypes.number, 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;