kiban-design-system 1.0.239-alpha.0 → 1.0.240-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2247,11 +2247,44 @@ const useTheme = () => {
2247
2247
  * @param {string} InputTextProps.ariaLabel - Label to use in automatic tests
2248
2248
  * @returns {symbol} - Element Select
2249
2249
  */
2250
- const Select = ({ ariaLabel, items, sections, isMultiple, placeholder, label, selected, onChange, searchPlaceholder, searchLabel, helperText, isHelperMode, isDisabled = false, onSearchChange, search, tooltip, isDanger, isReadOnly = false, id, emptyState, onBlur, isRequired, tooltipLabel, action, }) => {
2250
+ const Select = ({ ariaLabel, items, sections, isMultiple, placeholder, label, selected, onChange, searchPlaceholder, searchLabel, helperText, isHelperMode, isDisabled = false, tooltip, isDanger, isReadOnly = false, id, emptyState, onBlur, isRequired, tooltipLabel, action, showSearch = true, }) => {
2251
2251
  const [isActivePopover, setIsActive] = useState(false);
2252
2252
  const selectActivatorRef = useRef(null);
2253
2253
  const [parentCoord, setParentCoords] = useState();
2254
+ const [search, setSearch] = useState('');
2255
+ const [sectionsFiltered, setSectionsFiltered] = useState(sections);
2256
+ const [itemsFiltered, setItemsFiltered] = useState(items);
2254
2257
  const { theme } = useTheme();
2258
+ const handleOnSearch = (value) => {
2259
+ setSearch(value || '');
2260
+ if (value) {
2261
+ if (sections) {
2262
+ const newSections = [];
2263
+ sections.forEach((section) => {
2264
+ const { items: itemsSection } = section;
2265
+ if (!itemsSection)
2266
+ newSections.push(section);
2267
+ else {
2268
+ const newItems = itemsSection.filter((item) => item.label
2269
+ .toLocaleLowerCase()
2270
+ .includes(search.toLocaleLowerCase()));
2271
+ newSections.push(Object.assign(Object.assign({}, section), { items: newItems }));
2272
+ }
2273
+ });
2274
+ setSectionsFiltered(newSections);
2275
+ }
2276
+ if (items) {
2277
+ const newItems = items.filter((item) => item.label
2278
+ .toLocaleLowerCase()
2279
+ .includes(search.toLocaleLowerCase()));
2280
+ setItemsFiltered(newItems);
2281
+ }
2282
+ }
2283
+ else {
2284
+ setSectionsFiltered(sections);
2285
+ setItemsFiltered(items);
2286
+ }
2287
+ };
2255
2288
  let totalItems = 0;
2256
2289
  if (sections) {
2257
2290
  sections.forEach((section) => {
@@ -2275,6 +2308,12 @@ const Select = ({ ariaLabel, items, sections, isMultiple, placeholder, label, se
2275
2308
  };
2276
2309
  }
2277
2310
  }, [isActivePopover]);
2311
+ useEffect(() => {
2312
+ setSectionsFiltered(sections);
2313
+ }, [sections]);
2314
+ useEffect(() => {
2315
+ setItemsFiltered(items);
2316
+ }, [items]);
2278
2317
  const handleOpenPopover = () => setIsActive(!isActivePopover);
2279
2318
  const removeTag = (event, value) => {
2280
2319
  event.stopPropagation();
@@ -2366,11 +2405,10 @@ const Select = ({ ariaLabel, items, sections, isMultiple, placeholder, label, se
2366
2405
  }, [action]);
2367
2406
  const actionIconProp = action && action.icon ? { icon: action.icon, outlined: true } : undefined;
2368
2407
  const actionMarkup = action ? (jsxs(Fragment, { children: [(items === null || items === void 0 ? void 0 : items.length) ? jsx(Divider, {}, void 0) : null, jsx(AlphaButton, Object.assign({ isLink: true, isTertiary: true, onClick: handleActionClick, icon: actionIconProp, iconPosition: action.iconPosition, theme: (theme === null || theme === void 0 ? void 0 : theme.toLowerCase()) || undefined }, { children: action.content }), void 0)] }, void 0)) : null;
2369
- const showSearch = (totalItems > 10 && !search) || search;
2370
- const searchMarkup = onSearchChange && showSearch ? (jsx("div", Object.assign({ className: 'Select__search' }, { children: jsx(InputText, { placeholder: searchPlaceholder, icon: 'Search', value: search, label: searchLabel, onChange: (value) => onSearchChange && onSearchChange(value) }, void 0) }), void 0)) : null;
2408
+ const searchMarkup = totalItems > 10 && showSearch ? (jsx("div", Object.assign({ className: 'Select__search' }, { children: jsx(InputText, { placeholder: searchPlaceholder, icon: 'Search', value: search, label: searchLabel, onChange: handleOnSearch }, void 0) }), void 0)) : null;
2371
2409
  const renderInput = () => (jsx("div", Object.assign({ id: id }, { children: jsxs(Popover$1, Object.assign({ isActive: isReadOnly ? false : isActivePopover, activator: jsxs("div", Object.assign({ "aria-label": ariaLabel, tabIndex: 0, className: clasessSelect, id: `select-${id}`, onKeyDown: onKeyDown, onClick: handleClickSelect, onBlur: onBlur }, { children: [selected && selected.length > 0 && (jsx("div", Object.assign({ className: 'Select__selected' }, { children: isMultiple
2372
2410
  ? selected === null || selected === void 0 ? void 0 : selected.map((option, index) => (jsx("div", Object.assign({ className: 'Select__tag-container' }, { children: jsx(Tag, Object.assign({ onRemove: (evt) => removeTag(evt, option), isDisabled: isDisabled, isDanger: isDanger }, { children: getLabelOption(option) }), void 0) }), `Select-tag--${index}`)))
2373
- : selected === null || selected === void 0 ? void 0 : selected.map((option, index) => (jsx("span", { children: getLabelOption(option) }, `option-${index}`))) }), void 0)), (!selected || selected.length <= 0) && placeholder && (jsx("div", Object.assign({ className: 'Select__placeholder' }, { children: placeholder }), void 0)), jsx("div", Object.assign({ className: 'Select__icon', onClick: handleOnClickIcon }, { children: jsx(Icon, { name: isActivePopover && !isReadOnly ? 'ChevronUp' : 'ChevronDown' }, void 0) }), void 0)] }), void 0), isFullWidth: true, onClose: () => setIsActive(false) }, { children: [searchMarkup, emptyState && (jsx(Popover$1.Pane, { children: jsx("div", Object.assign({ className: 'emptyState__container' }, { children: emptyState }), void 0) }, void 0)), !emptyState && (jsxs(Popover$1.Pane, { children: [jsx(OptionList, { sections: sections, items: items, isMultiple: isMultiple, onChange: (value) => {
2411
+ : selected === null || selected === void 0 ? void 0 : selected.map((option, index) => (jsx("span", { children: getLabelOption(option) }, `option-${index}`))) }), void 0)), (!selected || selected.length <= 0) && placeholder && (jsx("div", Object.assign({ className: 'Select__placeholder' }, { children: placeholder }), void 0)), jsx("div", Object.assign({ className: 'Select__icon', onClick: handleOnClickIcon }, { children: jsx(Icon, { name: isActivePopover && !isReadOnly ? 'ChevronUp' : 'ChevronDown' }, void 0) }), void 0)] }), void 0), isFullWidth: true, onClose: () => setIsActive(false) }, { children: [searchMarkup, emptyState && (jsx(Popover$1.Pane, { children: jsx("div", Object.assign({ className: 'emptyState__container' }, { children: emptyState }), void 0) }, void 0)), !emptyState && (jsxs(Popover$1.Pane, { children: [jsx(OptionList, { sections: sectionsFiltered, items: itemsFiltered, isMultiple: isMultiple, onChange: (value) => {
2374
2412
  if (!isMultiple) {
2375
2413
  handleOpenPopover();
2376
2414
  }