bianic-ui 1.14.0 → 1.15.0-alpha.1

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/cjs/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var React = require('react');
4
+ var reactDom = require('react-dom');
4
5
 
5
6
  function Accordions(_a) {
6
7
  var title = _a.title, content = _a.content;
@@ -487,12 +488,12 @@ var variantUnion$1 = [
487
488
  ];
488
489
  var radiusUnion = ['default', 'full-rounded'];
489
490
  var sizeUnion$5 = ['md', 'lg', 'sm', 'tn'];
490
- function Button(_a) {
491
+ var Button = React.forwardRef(function (_a, ref) {
491
492
  var label = _a.label, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.radius, radius = _d === void 0 ? 'default' : _d, _e = _a.size, size = _e === void 0 ? 'md' : _e, _f = _a.variant, variant = _f === void 0 ? 'default' : _f, _g = _a.iconLeft, iconLeft = _g === void 0 ? null : _g, _h = _a.iconRight, iconRight = _h === void 0 ? null : _h, _j = _a.left, left = _j === void 0 ? null : _j, _k = _a.right, right = _k === void 0 ? null : _k, minWidth = _a.minWidth, props = __rest(_a, ["label", "className", "disabled", "radius", "size", "variant", "iconLeft", "iconRight", "left", "right", "minWidth"]);
492
493
  var validatedVariant = validUnion(variant, variantUnion$1);
493
494
  var validatedSize = validUnion(size, sizeUnion$5);
494
495
  var validatedRadius = validUnion(radius, radiusUnion);
495
- var minWidthRules = minWidthConfig$1[size];
496
+ var minWidthRules = minWidthConfig$1[validatedSize];
496
497
  if (minWidth !== undefined) {
497
498
  minWidthRules = "min-w-[".concat(minWidth, "px]");
498
499
  }
@@ -509,23 +510,23 @@ function Button(_a) {
509
510
  var sizeClass = label || variant === 'form-group'
510
511
  ? " ".concat(minWidthRules, " ").concat(sizingRules)
511
512
  : "".concat(iconOnlySizeConfig$1[validatedSize], " ").concat(variant.includes('link') ? '' : "".concat(sidePaddingConfig[validatedSize]));
512
- var classString = "\n ".concat(variantConfig$2[validatedVariant], " \n ").concat(sizeClass, " \n ").concat(radiusConfig$1[validatedRadius][validatedSize], " \n ").concat(className, "\n ");
513
- return (React.createElement("button", __assign({ type: "button", className: "bianic-button bianic-fgc-target flex items-center justify-center font-semibold ".concat(classString), disabled: disabled }, props),
513
+ var classString = "\n ".concat(variantConfig$2[validatedVariant], "\n ").concat(sizeClass, "\n ").concat(radiusConfig$1[validatedRadius][validatedSize], "\n ").concat(className, "\n ");
514
+ return (React.createElement("button", __assign({ ref: ref, type: "button", className: "bianic-button bianic-fgc-target flex items-center justify-center font-semibold ".concat(classString), disabled: disabled }, props),
514
515
  childrenElement(iconLeft || left),
515
516
  childrenElement(label),
516
517
  childrenElement(iconRight || right)));
517
- }
518
+ });
518
519
  Button.defaultProps = {
519
- label: null,
520
+ label: undefined,
520
521
  className: '',
521
522
  disabled: false,
522
523
  radius: 'default',
523
524
  size: 'md',
524
525
  variant: 'default',
525
- iconLeft: null,
526
- iconRight: null,
527
- left: null,
528
- right: null,
526
+ iconLeft: undefined,
527
+ iconRight: undefined,
528
+ left: undefined,
529
+ right: undefined,
529
530
  };
530
531
 
531
532
  var AvatarConfig = {
@@ -2240,7 +2241,7 @@ var fontConfig = {
2240
2241
  md: 'text-[14px] font-[350]',
2241
2242
  };
2242
2243
 
2243
- var DropdownContainer = React.forwardRef(function DropdownContainer(propsComp, ref) {
2244
+ var DropdownContNoAnchor = React.forwardRef(function DropdownContNoAnchor(propsComp, ref) {
2244
2245
  var _a = propsComp.isTopFlat, isTopFlat = _a === void 0 ? false : _a, children = propsComp.children, _b = propsComp.open, open = _b === void 0 ? true : _b, _c = propsComp.onClose, onClose = _c === void 0 ? function () { } : _c, _d = propsComp.className, className = _d === void 0 ? '' : _d, _e = propsComp.isWithOverlay, isWithOverlay = _e === void 0 ? true : _e, _f = propsComp.size, size = _f === void 0 ? 'md' : _f, _g = propsComp.onClickItem, onClickItem = _g === void 0 ? function () { } : _g, _h = propsComp.zIndex, zIndex = _h === void 0 ? 100 : _h, restProps = __rest(propsComp, ["isTopFlat", "children", "open", "onClose", "className", "isWithOverlay", "size", "onClickItem", "zIndex"]);
2245
2246
  var radiusClass = "rounded-b-radius-sm ".concat(!isTopFlat && 'rounded-t-radius-sm');
2246
2247
  var sizeClass = containerSizeConfig[size] || containerSizeConfig['md'];
@@ -2265,51 +2266,10 @@ var DropdownContainer = React.forwardRef(function DropdownContainer(propsComp, r
2265
2266
  : child;
2266
2267
  })))));
2267
2268
  });
2268
- DropdownContainer.defaultProps = {
2269
+ DropdownContNoAnchor.defaultProps = {
2269
2270
  isTopFlat: false,
2270
2271
  };
2271
2272
 
2272
- function DropdownItem(_a) {
2273
- var children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.onClickItem, onClickItem = _c === void 0 ? function () { } : _c, _d = _a.onClose, onClose = _d === void 0 ? function () { } : _d, _e = _a.size, size = _e === void 0 ? 'md' : _e, _f = _a.value, value = _f === void 0 ? '' : _f, content = _a.content, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.zIndex, zIndex = _h === void 0 ? 100 : _h, props = __rest(_a, ["children", "className", "onClickItem", "onClose", "size", "value", "content", "disabled", "zIndex"]);
2274
- var _j = React.useState(false), isHovered = _j[0], setIsHovered = _j[1];
2275
- var _k = React.useState(false), isLeft = _k[0], setIsLeft = _k[1];
2276
- var fontClass = fontConfig[size] || fontConfig['md'];
2277
- var itemSizeClass = itemSizeConfig[size] || itemSizeConfig['md'];
2278
- var itemClass = "".concat(itemSizeClass, " ").concat(fontClass, " ").concat(className);
2279
- var chevronSize = size === 'sm' ? 14 : 18;
2280
- var DropdownContRef = React.useRef(null);
2281
- React.useEffect(function () {
2282
- var _a;
2283
- if (DropdownContRef.current) {
2284
- // Adjust dropdown position to prevent overflow on the right.
2285
- var MenuContRect = (_a = DropdownContRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
2286
- var RectRight = MenuContRect === null || MenuContRect === void 0 ? void 0 : MenuContRect.right;
2287
- var innerWindow = window.innerWidth;
2288
- if (RectRight > innerWindow)
2289
- setIsLeft(true);
2290
- else
2291
- setIsLeft(false);
2292
- }
2293
- }, [isHovered]);
2294
- var translateClass = isLeft
2295
- ? 'left-0 -translate-x-full'
2296
- : 'right-0 translate-x-full';
2297
- var currentZIndex = zIndex + 10;
2298
- return (React.createElement("div", { className: "bianic-dropdown-item group/main relative cursor-pointer first:rounded-t-radius-sm first:pt-[5px] last:rounded-b-radius-sm last:pb-[5px]", onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); } },
2299
- React.createElement("button", __assign({ className: "relative flex w-full !min-w-fit items-center justify-start whitespace-nowrap px-[15px] py-[5px] text-left text-bia-black disabled:cursor-not-allowed disabled:text-bia-coolgrey-light-50 hover:[&:not(:disabled)]:bg-bia-blue-pastel ".concat(itemClass), style: {
2300
- zIndex: isHovered ? currentZIndex : currentZIndex + 15,
2301
- }, onClick: function (e) {
2302
- onClickItem(e, value);
2303
- }, onKeyDown: function () { }, disabled: disabled, type: "button" }, props),
2304
- content,
2305
- React.createElement("div", { className: "ml-auto flex items-center" }, children && (React.createElement(TbChevronRight, { className: "ml-[10px] text-bia-coolgrey", size: chevronSize })))),
2306
- children && (React.createElement(DropdownContainer, { className: "absolute top-0 bg-primary-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] group-first/main:top-[6px] ".concat(translateClass), onClose: onClose, open: isHovered, onClickItem: function (e, value) { return onClickItem(e, value); }, size: size, ref: DropdownContRef, zIndex: currentZIndex + 10 }, children))));
2307
- }
2308
- DropdownItem.defaultProps = {
2309
- className: '',
2310
- onClickItem: function () { },
2311
- };
2312
-
2313
2273
  var sizeUnion$2 = ['md', 'sm'];
2314
2274
  function SelectInput(_a) {
2315
2275
  var descText = _a.descText, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.size, size = _c === void 0 ? 'md' : _c, id = _a.id, label = _a.label, _d = _a.options, options = _d === void 0 ? [] : _d, _e = _a.required, required = _e === void 0 ? false : _e, selected = _a.selected, setSelected = _a.setSelected, _f = _a.onClickDropdown, onClickDropdown = _f === void 0 ? function () { } : _f, children = _a.children, _g = _a.dropContProps, _h = _g === void 0 ? {} : _g, _j = _h.className, dropContClassName = _j === void 0 ? '' : _j, restDropContProps = __rest(_h, ["className"]), props = __rest(_a, ["descText", "disabled", "size", "id", "label", "options", "required", "selected", "setSelected", "onClickDropdown", "children", "dropContProps"]);
@@ -2385,7 +2345,7 @@ function SelectInput(_a) {
2385
2345
  setIsOpen(false);
2386
2346
  } }));
2387
2347
  }))),
2388
- children && isOpen && (React.createElement(DropdownContainer, __assign({ open: isOpen, onClose: function () { return setIsOpen(false); }, size: size, isTopFlat: true, ref: dropdownContRef, className: "bianic-livesearch-dropdown absolute z-10 mt-1 w-full overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none ".concat(dropdownPosition, " ").concat(dropContClassName) }, restDropContProps), React.Children.map(children, function (child) {
2348
+ children && isOpen && (React.createElement(DropdownContNoAnchor, __assign({ open: isOpen, onClose: function () { return setIsOpen(false); }, size: size, isTopFlat: true, ref: dropdownContRef, className: "bianic-livesearch-dropdown absolute z-10 mt-1 w-full overflow-hidden rounded-md bg-white shadow-lg ring-1 ring-black ring-opacity-5 focus:outline-none ".concat(dropdownPosition, " ").concat(dropContClassName) }, restDropContProps), React.Children.map(children, function (child) {
2389
2349
  if (React.isValidElement(child)) {
2390
2350
  return React.cloneElement(child, {
2391
2351
  isSelected: selected && selected.id === child.props.value.id,
@@ -2425,16 +2385,140 @@ var sizeConfig$6 = {
2425
2385
  },
2426
2386
  };
2427
2387
 
2388
+ var getDropdownStyle = function (anchorRef, dropdownRef) {
2389
+ if (!anchorRef.current || !dropdownRef.current) {
2390
+ return { minWidth: 'auto' };
2391
+ }
2392
+ var anchorRect = anchorRef.current.getBoundingClientRect();
2393
+ var dropdownHeight = dropdownRef.current.offsetHeight;
2394
+ var spaceToBottom = window.innerHeight - anchorRect.bottom;
2395
+ var spaceToTop = anchorRect.top;
2396
+ var style = {
2397
+ left: "".concat(anchorRect.left + window.scrollX, "px"),
2398
+ minWidth: "".concat(anchorRect.width, "px"),
2399
+ };
2400
+ // If space below is less than dropdown height,
2401
+ // AND space above is more than space below
2402
+ // then flip up
2403
+ if (spaceToBottom < dropdownHeight && spaceToTop > spaceToBottom) {
2404
+ var topPositionForFlip = anchorRect.top + window.scrollY - dropdownHeight;
2405
+ style.top = "".concat(topPositionForFlip, "px");
2406
+ }
2407
+ else {
2408
+ style.top = "".concat(anchorRect.bottom + window.scrollY, "px");
2409
+ }
2410
+ return style;
2411
+ };
2412
+ var DropdownContainer = function (propsComp) {
2413
+ var _a = propsComp.isTopFlat, isTopFlat = _a === void 0 ? false : _a, children = propsComp.children, _b = propsComp.open, open = _b === void 0 ? true : _b, _c = propsComp.onClose, onClose = _c === void 0 ? function () { } : _c, _d = propsComp.className, className = _d === void 0 ? '' : _d, _e = propsComp.isWithOverlay, isWithOverlay = _e === void 0 ? true : _e, _f = propsComp.size, size = _f === void 0 ? 'md' : _f, _g = propsComp.onClickItem, onClickItem = _g === void 0 ? function () { } : _g, _h = propsComp.zIndex, zIndex = _h === void 0 ? 100 : _h, anchorRef = propsComp.anchorRef, restProps = __rest(propsComp, ["isTopFlat", "children", "open", "onClose", "className", "isWithOverlay", "size", "onClickItem", "zIndex", "anchorRef"]);
2414
+ if (!open)
2415
+ return null;
2416
+ var _j = React.useState({ minWidth: 'auto' }), positionStyle = _j[0], setPositionStyle = _j[1];
2417
+ var radiusClass = "rounded-b-radius-sm ".concat(!isTopFlat && 'rounded-t-radius-sm');
2418
+ var sizeClass = containerSizeConfig[size] || containerSizeConfig['md'];
2419
+ var containerClass = "".concat(sizeClass, " ").concat(radiusClass, " ").concat(className);
2420
+ var dropdownRef = React.useRef(null);
2421
+ var handleClickDrpdownItem = function (e, val) {
2422
+ onClickItem(e, val);
2423
+ onClose();
2424
+ };
2425
+ React.useLayoutEffect(function () {
2426
+ if (!(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current))
2427
+ return;
2428
+ var newStyle = getDropdownStyle(anchorRef, dropdownRef);
2429
+ setPositionStyle(newStyle);
2430
+ var handleScrollOrResize = function () {
2431
+ setPositionStyle(getDropdownStyle(anchorRef, dropdownRef));
2432
+ };
2433
+ window.addEventListener('scroll', handleScrollOrResize);
2434
+ window.addEventListener('resize', handleScrollOrResize);
2435
+ return function () {
2436
+ window.removeEventListener('scroll', handleScrollOrResize);
2437
+ window.removeEventListener('resize', handleScrollOrResize);
2438
+ };
2439
+ }, [anchorRef]);
2440
+ return (React.createElement(React.Fragment, null,
2441
+ isWithOverlay && (React.createElement("div", { className: "bianic-dropdown-overlay fixed left-0 top-0 h-screen w-screen", style: { zIndex: zIndex }, onClick: function () { return onClose(); } })),
2442
+ reactDom.createPortal(React.createElement("div", __assign({ ref: dropdownRef, className: "absolute max-w-fit bianic-dropdown-container bg-bia-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] ".concat(containerClass), style: __assign({ zIndex: zIndex + 10 }, positionStyle) }, restProps), React.Children.map(children, function (child) {
2443
+ return React.isValidElement(child)
2444
+ ? // Kirimkan handleItemClick sebagai props onClick ke setiap DropdownItem
2445
+ React.cloneElement(child, {
2446
+ onClose: function () { return onClose(); },
2447
+ size: size,
2448
+ onClickItem: function (e, val) { return handleClickDrpdownItem(e, val); },
2449
+ zIndex: zIndex + 10,
2450
+ })
2451
+ : child;
2452
+ })), document.body)));
2453
+ };
2454
+ DropdownContainer.defaultProps = {
2455
+ isTopFlat: false,
2456
+ };
2457
+
2458
+ function DropdownItem(_a) {
2459
+ var children = _a.children, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.onClickItem, onClickItem = _c === void 0 ? function () { } : _c, _d = _a.onClose, onClose = _d === void 0 ? function () { } : _d, _e = _a.size, size = _e === void 0 ? 'md' : _e, _f = _a.value, value = _f === void 0 ? '' : _f, content = _a.content, _g = _a.disabled, disabled = _g === void 0 ? false : _g, _h = _a.zIndex, zIndex = _h === void 0 ? 100 : _h, props = __rest(_a, ["children", "className", "onClickItem", "onClose", "size", "value", "content", "disabled", "zIndex"]);
2460
+ var _j = React.useState(false), isHovered = _j[0], setIsHovered = _j[1];
2461
+ var _k = React.useState(false), isLeft = _k[0], setIsLeft = _k[1];
2462
+ var fontClass = fontConfig[size] || fontConfig['md'];
2463
+ var itemSizeClass = itemSizeConfig[size] || itemSizeConfig['md'];
2464
+ var itemClass = "".concat(itemSizeClass, " ").concat(fontClass, " ").concat(className);
2465
+ var chevronSize = size === 'sm' ? 14 : 18;
2466
+ var DropdownContRef = React.useRef(null);
2467
+ React.useEffect(function () {
2468
+ var _a;
2469
+ if (DropdownContRef.current) {
2470
+ // Adjust dropdown position to prevent overflow on the right.
2471
+ var MenuContRect = (_a = DropdownContRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
2472
+ var RectRight = MenuContRect === null || MenuContRect === void 0 ? void 0 : MenuContRect.right;
2473
+ var innerWindow = window.innerWidth;
2474
+ if (RectRight > innerWindow)
2475
+ setIsLeft(true);
2476
+ else
2477
+ setIsLeft(false);
2478
+ }
2479
+ }, [isHovered]);
2480
+ var translateClass = isLeft
2481
+ ? 'left-0 -translate-x-full'
2482
+ : 'right-0 translate-x-full';
2483
+ var currentZIndex = zIndex + 10;
2484
+ return (React.createElement("div", { className: "bianic-dropdown-item group/main relative cursor-pointer first:rounded-t-radius-sm first:pt-[5px] last:rounded-b-radius-sm last:pb-[5px]", onMouseEnter: function () { return setIsHovered(true); }, onMouseLeave: function () { return setIsHovered(false); } },
2485
+ React.createElement("button", __assign({ className: "relative flex w-full !min-w-fit items-center justify-start whitespace-nowrap px-[15px] py-[5px] text-left text-bia-black disabled:cursor-not-allowed disabled:text-bia-coolgrey-light-50 hover:[&:not(:disabled)]:bg-bia-blue-pastel ".concat(itemClass), style: {
2486
+ zIndex: isHovered ? currentZIndex : currentZIndex + 15,
2487
+ }, onClick: function (e) {
2488
+ onClickItem(e, value);
2489
+ }, onKeyDown: function () { }, disabled: disabled, type: "button" }, props),
2490
+ content,
2491
+ React.createElement("div", { className: "ml-auto flex items-center" }, children && (React.createElement(TbChevronRight, { className: "ml-[10px] text-bia-coolgrey", size: chevronSize })))),
2492
+ children && (React.createElement(DropdownContNoAnchor, { className: "absolute top-0 bg-primary-white shadow-[0px_3px_20px_0px_rgba(0,0,0,0.20)] group-first/main:top-[6px] ".concat(translateClass), onClose: onClose, open: isHovered, onClickItem: function (e, value) { return onClickItem(e, value); }, size: size, ref: DropdownContRef, zIndex: currentZIndex + 10 }, children))));
2493
+ }
2494
+ DropdownItem.defaultProps = {
2495
+ className: '',
2496
+ onClickItem: function () { },
2497
+ };
2498
+
2499
+ var matchSearchTerm = function (content, term, variant) {
2500
+ var lowerContent = content.toLowerCase();
2501
+ var lowerTerm = term.toLowerCase();
2502
+ switch (variant) {
2503
+ case 'startsWith':
2504
+ return lowerContent.startsWith(lowerTerm);
2505
+ case 'endsWith':
2506
+ return lowerContent.endsWith(lowerTerm);
2507
+ case 'include':
2508
+ return lowerContent.includes(lowerTerm);
2509
+ default:
2510
+ return lowerContent.includes(lowerTerm);
2511
+ }
2512
+ };
2428
2513
  function LiveSearch(_a) {
2429
- var descText = _a.descText, _b = _a.disabled, disabled = _b === void 0 ? false : _b, id = _a.id, _c = _a.size, size = _c === void 0 ? 'md' : _c, label = _a.label, placeholder = _a.placeholder, _d = _a.required, required = _d === void 0 ? false : _d, options = _a.options, setValue = _a.setValue, value = _a.value, _e = _a.readOnly, readOnly = _e === void 0 ? false : _e, _f = _a.onChangeText, onChangeText = _f === void 0 ? function () { } : _f, _g = _a.onClickDropdown, onClickDropdown = _g === void 0 ? function () { } : _g, _h = _a.autoComplete, autoComplete = _h === void 0 ? 'off' : _h, _j = _a.children, children = _j === void 0 ? undefined : _j, _k = _a.dropContProps, dropContProps = _k === void 0 ? { className: undefined } : _k;
2430
- var _l = React.useState(false), isOpen = _l[0], setIsOpen = _l[1];
2431
- var _m = React.useState(value.label || ''), searchTerm = _m[0], setSearchTerm = _m[1];
2432
- var _o = sizeConfig$6[size], iconClass = _o.iconClass, iconSize = _o.iconSize, inputClass = _o.inputClass;
2514
+ var descText = _a.descText, _b = _a.disabled, disabled = _b === void 0 ? false : _b, id = _a.id, _c = _a.size, size = _c === void 0 ? 'md' : _c, label = _a.label, placeholder = _a.placeholder, _d = _a.required, required = _d === void 0 ? false : _d, options = _a.options, setValue = _a.setValue, value = _a.value, _e = _a.readOnly, readOnly = _e === void 0 ? false : _e, _f = _a.onChangeText, onChangeText = _f === void 0 ? function () { } : _f, _g = _a.onClickDropdown, onClickDropdown = _g === void 0 ? function () { } : _g, _h = _a.autoComplete, autoComplete = _h === void 0 ? 'off' : _h, _j = _a.children, children = _j === void 0 ? undefined : _j, _k = _a.dropContProps, dropContProps = _k === void 0 ? { className: undefined } : _k, _l = _a.searchVariant, searchVariant = _l === void 0 ? 'include' : _l;
2515
+ var _m = React.useState(false), isOpen = _m[0], setIsOpen = _m[1];
2516
+ var _o = React.useState(value.label || ''), searchTerm = _o[0], setSearchTerm = _o[1];
2517
+ var _p = sizeConfig$6[size], iconClass = _p.iconClass, iconSize = _p.iconSize, inputClass = _p.inputClass;
2433
2518
  var dropContClassName = dropContProps.className, restDropContProps = __rest(dropContProps, ["className"]);
2434
2519
  var isValueExist = value && value.label !== undefined && value.label !== '';
2435
2520
  var inputRef = React.useRef(null);
2436
2521
  var dropdownContRef = React.useRef(null);
2437
- var _p = React.useState(false), isDropUp = _p[0], setIsDropUp = _p[1];
2438
2522
  var handleOutsideClick = function (e) {
2439
2523
  if (inputRef.current && !inputRef.current.contains(e.target)) {
2440
2524
  setIsOpen(false);
@@ -2454,22 +2538,6 @@ function LiveSearch(_a) {
2454
2538
  setSearchTerm(value.label || '');
2455
2539
  }
2456
2540
  }, [value.label, searchTerm]);
2457
- React.useEffect(function () {
2458
- var _a, _b;
2459
- if (inputRef.current) {
2460
- // Adjust dropdown position to prevent show up out of screen
2461
- var windowHeight = window.innerHeight;
2462
- var inputRect = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
2463
- var inputBottom = inputRect === null || inputRect === void 0 ? void 0 : inputRect.bottom;
2464
- var diff = windowHeight - inputBottom;
2465
- var dropdownRect = (_b = dropdownContRef.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
2466
- var dropdownHeight = (dropdownRect === null || dropdownRect === void 0 ? void 0 : dropdownRect.height) || 0;
2467
- if (dropdownHeight >= diff)
2468
- setIsDropUp(true);
2469
- else
2470
- setIsDropUp(false);
2471
- }
2472
- }, [isOpen]);
2473
2541
  var filteredOptions = options === null || options === void 0 ? void 0 : options.filter(function (item) {
2474
2542
  return item.label.toLowerCase().includes(value.label.toLowerCase());
2475
2543
  });
@@ -2487,36 +2555,38 @@ function LiveSearch(_a) {
2487
2555
  var processDropdownChildren = function (nodes, currentSearchTerm, includeAllIfNoSearch) {
2488
2556
  return React.Children.map(nodes, function (child) {
2489
2557
  if (!React.isValidElement(child) || child.type !== DropdownItem) {
2490
- return child; // Render non-DropdownItem or other elements as is
2558
+ return child;
2491
2559
  }
2492
- var itemProps = child.props; // Cast to any to access props
2560
+ var itemProps = child.props;
2561
+ // Assume content is a string for filtering; otherwise, filtering won't work well
2562
+ var itemContent = typeof itemProps.content === 'string' ? itemProps.content : '';
2493
2563
  var itemValue = itemProps.value;
2494
2564
  var isDisabled = itemProps.disabled;
2495
- // Filter based on searchTerm only if searchTerm is present
2496
- if (currentSearchTerm &&
2497
- !itemValue.toLowerCase().includes(currentSearchTerm.toLowerCase())) {
2498
- return null; // Do not render if it doesn't match
2565
+ // 2. Filtering Logic (Uses Global Search Variant)
2566
+ if (!includeAllIfNoSearch) {
2567
+ // Use the matchSearchTerm utility with the selected searchVariant
2568
+ if (currentSearchTerm && !matchSearchTerm(itemValue, currentSearchTerm, searchVariant)) {
2569
+ return null; // Item does not match the search criteria
2570
+ }
2499
2571
  }
2500
- // If includeAllIfNoSearch is true (when searchTerm is empty), do not filter.
2501
- // If includeAllIfNoSearch is false (when searchTerm is present), filtering has been done above.
2502
- // Clone its children recursively if any
2572
+ // 3. Process Nested Children (Recursion)
2503
2573
  var clonedChildren = itemProps.children
2504
- ? processDropdownChildren(itemProps.children, currentSearchTerm)
2574
+ ? processDropdownChildren(itemProps.children, currentSearchTerm, includeAllIfNoSearch)
2505
2575
  : null;
2506
- // Clone the DropdownItem to inject the onClick prop
2576
+ // 4. Clone and Inject Click Handler
2507
2577
  return React.cloneElement(child, {
2508
2578
  onClick: function (e) {
2509
2579
  if (!isDisabled) {
2510
2580
  handleDropdownItemClick({
2511
- id: itemValue,
2512
- label: itemValue,
2581
+ id: itemValue !== undefined ? itemValue : itemContent,
2582
+ label: itemValue !== undefined ? itemValue : itemContent
2513
2583
  });
2514
2584
  }
2515
- if (dropContProps === null || dropContProps === void 0 ? void 0 : dropContProps.onClickItem) {
2516
- dropContProps.onClickItem(e, itemValue);
2585
+ if (itemProps.onClick) {
2586
+ itemProps.onClick(e);
2517
2587
  }
2518
2588
  },
2519
- children: clonedChildren, // Ensure processed children are also cloned
2589
+ children: clonedChildren
2520
2590
  });
2521
2591
  });
2522
2592
  };
@@ -2525,21 +2595,20 @@ function LiveSearch(_a) {
2525
2595
  var hasFilteredResults = false;
2526
2596
  if (searchTerm) {
2527
2597
  // If there's a searchTerm, filter children
2528
- renderedChildren = processDropdownChildren(children, searchTerm);
2598
+ renderedChildren = processDropdownChildren(children, searchTerm, false);
2529
2599
  hasFilteredResults =
2530
2600
  React.Children.toArray(renderedChildren).filter(Boolean).length > 0;
2531
2601
  }
2532
2602
  else {
2533
2603
  // If searchTerm is empty, display all children without filtering (but with onClick injected)
2534
- renderedChildren = processDropdownChildren(children, '');
2604
+ renderedChildren = processDropdownChildren(children, '', true);
2535
2605
  hasFilteredResults =
2536
2606
  React.Children.toArray(renderedChildren).filter(Boolean).length > 0; // Should always be true if there are initial children
2537
2607
  }
2538
- var dropdownPosition = isDropUp ? 'bottom-full' : 'top-full';
2539
- return (React.createElement("div", { className: "bianic-livesearch field-group group/form flex w-full flex-col gap-y-2 ", ref: inputRef },
2608
+ return (React.createElement("div", { className: "bianic-livesearch field-group group/form flex w-full flex-col gap-y-2 " },
2540
2609
  label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
2541
2610
  React.createElement("div", { className: "group relative w-full" },
2542
- React.createElement("input", { className: "bianic-livesearch-input field peer w-full rounded border border-bia-grey-dark-10 bg-primary-white read-only:pointer-events-none read-only:border-bia-grey-disabled focus-visible:outline-none enabled:hover:rounded-b-none enabled:hover:border-b-bia-blue enabled:focus:rounded-b-none enabled:focus:border-b-bia-blue disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-10 disabled:text-bia-coolgrey ".concat(inputClass), onClick: function () { return setIsOpen(!isOpen); }, value: searchTerm, required: required, disabled: disabled, id: id, placeholder: placeholder, onChange: function (e) {
2611
+ React.createElement("input", { className: "bianic-livesearch-input field peer w-full rounded border border-bia-grey-dark-10 bg-primary-white read-only:pointer-events-none read-only:border-bia-grey-disabled focus-visible:outline-none enabled:hover:rounded-b-none enabled:hover:border-b-bia-blue enabled:focus:rounded-b-none enabled:focus:border-b-bia-blue disabled:border-bia-grey-dark-10 disabled:bg-bia-grey-light-10 disabled:text-bia-coolgrey ".concat(inputClass), onClick: function () { return setIsOpen(!isOpen); }, value: searchTerm, required: required, disabled: disabled, id: id, placeholder: placeholder, ref: inputRef, onChange: function (e) {
2543
2612
  onChangeText(e);
2544
2613
  setValue({ id: null, label: e.target.value });
2545
2614
  handleInputChange(e);
@@ -2558,10 +2627,10 @@ function LiveSearch(_a) {
2558
2627
  setIsOpen(false);
2559
2628
  } }));
2560
2629
  }))),
2561
- children && isOpen && (React.createElement(DropdownContainer, __assign({ open: isOpen, onClose: function () { return setIsOpen(false); }, size: size, isTopFlat: true, zIndex: 10, className: "bianic-livesearch-dropdown absolute w-full overflow-hidden bg-white shadow-lg ".concat(dropdownPosition, " ").concat(dropContClassName), ref: dropdownContRef }, restDropContProps), hasFilteredResults
2630
+ children && React.createElement(DropdownContainer, __assign({ open: isOpen, onClose: function () { return setIsOpen(false); }, size: size, isTopFlat: true, zIndex: 10, className: "bianic-livesearch-dropdown absolute w-full overflow-hidden bg-white shadow-lg ".concat(dropContClassName), ref: dropdownContRef, anchorRef: inputRef }, restDropContProps), hasFilteredResults
2562
2631
  ? renderedChildren
2563
2632
  : // If no results and searchTerm is present
2564
- searchTerm.length > 0 && (React.createElement(DropdownItem, { content: React.createElement("div", { className: "px-4 py-2 text-gray-500" }, "Tidak ada hasil ditemukan.") }))))),
2633
+ searchTerm.length > 0 && (React.createElement(DropdownItem, { content: React.createElement("div", { className: "px-4 py-2 text-gray-500" }, "Tidak ada hasil ditemukan.") })))),
2565
2634
  descText && (React.createElement("span", { className: "desc text-xs text-primary-cool" }, descText))));
2566
2635
  }
2567
2636
  LiveSearch.defaultProps = {