@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
32 lines • 1.4 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { PillSelectorControlled } from './pillSelectorControlled';
const PillSelectorUnControlledComponent = ({ defaultSelected = [], multiSelect = false, ...props }, ref) => {
const [pillSelected, setPillSelected] = React.useState(defaultSelected);
const onClickPill = (_checked, value) => {
if (value === undefined) {
return;
}
if (multiSelect) {
// if already in the array, delete the item from the array
if (pillSelected.some(item => item === value.toString())) {
setPillSelected(pillSelected.filter(pill => pill !== value.toString()));
}
else {
// add the item in te array
pillSelected && setPillSelected([...pillSelected, value]);
}
}
else {
setPillSelected([value.toString()]);
}
};
return (_jsx(PillSelectorControlled, { ...props, ref: ref, multiSelect: multiSelect, pillSelected: pillSelected, onPillChange: onClickPill }));
};
const PillSelectorUnControlled = React.forwardRef(PillSelectorUnControlledComponent);
/**
* @deprecated Try the new PillSelectorV2 component
*/
export { PillSelectorUnControlled };
export { PillSelectorUnControlled as PillSelector };
//# sourceMappingURL=pillSelectorUnControlled.js.map