| 1 |
import Select from "react-select"; |
| 2 |
import "./editor.scss"; |
| 3 |
|
| 4 |
const MultipleSelect = ({ |
| 5 |
attributes, |
| 6 |
setAttributes, |
| 7 |
attributesKey, |
| 8 |
label, |
| 9 |
items, |
| 10 |
objectData = false, |
| 11 |
value = false, |
| 12 |
onChange = false, |
| 13 |
flex = false, |
| 14 |
reset = false, |
| 15 |
onInputChange = false, |
| 16 |
helpText = "", |
| 17 |
}) => { |
| 18 |
const defaultValues = items?.filter((f) => attributes.includes(f.value)); |
| 19 |
const updateValue = (data) => { |
| 20 |
if (objectData) { |
| 21 |
const updatedValues = data?.map((d) => { |
| 22 |
return { value: d.value, type: d.type }; |
| 23 |
}); |
| 24 |
setAttributes({ [attributesKey]: updatedValues }); |
| 25 |
} else { |
| 26 |
const updatedValues = data?.map((d) => d.value); |
| 27 |
setAttributes({ [attributesKey]: updatedValues }); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
return ( |
| 32 |
<div className={`sp-smart-post-multi-select ${flex ? "d-flex" : ""} sp-smart-post-component-mb`}> |
| 33 |
<p className="sp-smart-post-component-title">{label}</p> |
| 34 |
<Select |
| 35 |
defaultValue={value ? value : defaultValues} |
| 36 |
// value={ value ?? defaultValues } |
| 37 |
isMulti |
| 38 |
options={items} |
| 39 |
isClearable={reset} |
| 40 |
onChange={(data) => (onChange ? onChange(data) : updateValue(data))} |
| 41 |
onInputChange={(e) => (onInputChange ? onInputChange(e) : "")} |
| 42 |
className="sp-smart-post-basic-multi-select" |
| 43 |
/> |
| 44 |
{helpText && <p className="sp-smart-help-text">{helpText}</p>} |
| 45 |
</div> |
| 46 |
); |
| 47 |
}; |
| 48 |
|
| 49 |
export default MultipleSelect; |
| 50 |
|