2020-03-27 20:28:36 +01:00
|
|
|
import React from 'react';
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
2023-06-07 15:05:35 +02:00
|
|
|
import Select from '../Select';
|
|
|
|
|
import InputLabelWrapper from '../InputLabelWrapper';
|
2020-03-27 20:28:36 +01:00
|
|
|
|
|
|
|
|
const InputMultiSelect = ({
|
2021-03-01 16:52:54 +01:00
|
|
|
id,
|
2020-03-27 20:28:36 +01:00
|
|
|
label,
|
|
|
|
|
isSortable,
|
|
|
|
|
sortDirection,
|
|
|
|
|
onLabelClick,
|
2024-05-27 20:30:25 +02:00
|
|
|
value = [],
|
|
|
|
|
placeholder = '',
|
|
|
|
|
options = [],
|
2020-03-27 20:28:36 +01:00
|
|
|
onChange,
|
|
|
|
|
}) => {
|
|
|
|
|
return (
|
|
|
|
|
<InputLabelWrapper
|
|
|
|
|
label={label}
|
|
|
|
|
isSortable={isSortable}
|
|
|
|
|
sortDirection={sortDirection}
|
|
|
|
|
onLabelClick={onLabelClick}
|
|
|
|
|
>
|
|
|
|
|
<Select
|
2021-03-01 16:52:54 +01:00
|
|
|
id={id}
|
2020-03-27 20:28:36 +01:00
|
|
|
placeholder={placeholder}
|
|
|
|
|
className="mt-2"
|
|
|
|
|
options={options}
|
|
|
|
|
value={value}
|
|
|
|
|
isMulti={true}
|
|
|
|
|
isClearable={false}
|
|
|
|
|
isSearchable={false}
|
|
|
|
|
closeMenuOnSelect={false}
|
|
|
|
|
hideSelectedOptions={false}
|
2020-05-12 07:04:20 +02:00
|
|
|
onChange={(selectedOptions, action) => {
|
2020-03-27 20:28:36 +01:00
|
|
|
switch (action) {
|
|
|
|
|
case 'select-option':
|
|
|
|
|
case 'remove-value':
|
|
|
|
|
case 'deselect-option':
|
|
|
|
|
case 'clear':
|
2020-05-12 07:04:20 +02:00
|
|
|
onChange(selectedOptions);
|
2020-03-27 20:28:36 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</InputLabelWrapper>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
InputMultiSelect.propTypes = {
|
2021-03-01 16:52:54 +01:00
|
|
|
id: PropTypes.string,
|
2020-03-27 20:28:36 +01:00
|
|
|
label: PropTypes.string.isRequired,
|
|
|
|
|
isSortable: PropTypes.bool.isRequired,
|
2023-09-01 22:19:39 +02:00
|
|
|
sortDirection: PropTypes.oneOf(['ascending', 'descending', 'none']).isRequired,
|
2020-03-27 20:28:36 +01:00
|
|
|
onLabelClick: PropTypes.func.isRequired,
|
2020-04-02 21:32:27 +02:00
|
|
|
onChange: PropTypes.func.isRequired,
|
2020-03-27 20:28:36 +01:00
|
|
|
placeholder: PropTypes.string,
|
2020-05-12 15:43:32 +02:00
|
|
|
/** Array of options to list as options */
|
2020-03-27 20:28:36 +01:00
|
|
|
options: PropTypes.arrayOf(
|
|
|
|
|
PropTypes.shape({
|
|
|
|
|
value: PropTypes.string,
|
|
|
|
|
label: PropTypes.string,
|
|
|
|
|
})
|
|
|
|
|
),
|
2020-05-12 15:43:32 +02:00
|
|
|
/** Array of string values that exist in our list of options */
|
|
|
|
|
value: PropTypes.arrayOf(PropTypes.string),
|
2020-03-27 20:28:36 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default InputMultiSelect;
|