UNPKG

@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

35 lines 1.73 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.PillSelector = exports.PillSelectorUnControlled = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); const pillSelectorControlled_1 = require("./pillSelectorControlled"); const PillSelectorUnControlledComponent = ({ defaultSelected = [], multiSelect = false, ...props }, ref) => { const [pillSelected, setPillSelected] = react_1.default.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 ((0, jsx_runtime_1.jsx)(pillSelectorControlled_1.PillSelectorControlled, { ...props, ref: ref, multiSelect: multiSelect, pillSelected: pillSelected, onPillChange: onClickPill })); }; const PillSelectorUnControlled = react_1.default.forwardRef(PillSelectorUnControlledComponent); exports.PillSelectorUnControlled = PillSelectorUnControlled; exports.PillSelector = PillSelectorUnControlled; //# sourceMappingURL=pillSelectorUnControlled.js.map