bianic-ui 1.14.0 → 1.15.0-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/cjs/index.js +128 -78
- package/dist/cjs/lib.css +1 -1
- package/dist/cjs/types/components/Button/Button.d.ts +1 -15
- package/dist/cjs/types/components/Button/PropInterfaceButton.d.ts +2 -2
- package/dist/cjs/types/components/Forms/Dropdown/DropdownContNoAnchor.d.ts +14 -0
- package/dist/cjs/types/components/Forms/Dropdown/DropdownContainer.d.ts +7 -1
- package/dist/cjs/types/components/Forms/LiveSearch/PropsInterface.d.ts +1 -0
- package/dist/cjs/types/components/Forms/LiveSearch/index.d.ts +1 -1
- package/dist/cjs/types/stories/Button/Button.stories.d.ts +2 -2
- package/dist/cjs/types/stories/Form/Dropdown/DropdownContainer.stories.d.ts +6 -1
- package/dist/esm/index.js +129 -79
- package/dist/esm/lib.css +1 -1
- package/dist/esm/types/components/Button/Button.d.ts +1 -15
- package/dist/esm/types/components/Button/PropInterfaceButton.d.ts +2 -2
- package/dist/esm/types/components/Forms/Dropdown/DropdownContNoAnchor.d.ts +14 -0
- package/dist/esm/types/components/Forms/Dropdown/DropdownContainer.d.ts +7 -1
- package/dist/esm/types/components/Forms/LiveSearch/PropsInterface.d.ts +1 -0
- package/dist/esm/types/components/Forms/LiveSearch/index.d.ts +1 -1
- package/dist/esm/types/stories/Button/Button.stories.d.ts +2 -2
- package/dist/esm/types/stories/Form/Dropdown/DropdownContainer.stories.d.ts +6 -1
- package/dist/index.d.ts +11 -18
- package/package.json +2 -1
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
|
-
|
|
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[
|
|
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], "
|
|
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:
|
|
520
|
+
label: undefined,
|
|
520
521
|
className: '',
|
|
521
522
|
disabled: false,
|
|
522
523
|
radius: 'default',
|
|
523
524
|
size: 'md',
|
|
524
525
|
variant: 'default',
|
|
525
|
-
iconLeft:
|
|
526
|
-
iconRight:
|
|
527
|
-
left:
|
|
528
|
-
right:
|
|
526
|
+
iconLeft: undefined,
|
|
527
|
+
iconRight: undefined,
|
|
528
|
+
left: undefined,
|
|
529
|
+
right: undefined,
|
|
529
530
|
};
|
|
530
531
|
|
|
531
532
|
var AvatarConfig = {
|
|
@@ -2240,7 +2241,77 @@ var fontConfig = {
|
|
|
2240
2241
|
md: 'text-[14px] font-[350]',
|
|
2241
2242
|
};
|
|
2242
2243
|
|
|
2243
|
-
var
|
|
2244
|
+
var getDropdownStyle = function (anchorRef, dropdownRef) {
|
|
2245
|
+
if (!anchorRef.current || !dropdownRef.current) {
|
|
2246
|
+
return { minWidth: 'auto' };
|
|
2247
|
+
}
|
|
2248
|
+
var anchorRect = anchorRef.current.getBoundingClientRect();
|
|
2249
|
+
var dropdownHeight = dropdownRef.current.offsetHeight;
|
|
2250
|
+
var spaceToBottom = window.innerHeight - anchorRect.bottom;
|
|
2251
|
+
var spaceToTop = anchorRect.top;
|
|
2252
|
+
var style = {
|
|
2253
|
+
left: "".concat(anchorRect.left + window.scrollX, "px"),
|
|
2254
|
+
minWidth: "".concat(anchorRect.width, "px"),
|
|
2255
|
+
};
|
|
2256
|
+
// If space below is less than dropdown height,
|
|
2257
|
+
// AND space above is more than space below
|
|
2258
|
+
// then flip up
|
|
2259
|
+
if (spaceToBottom < dropdownHeight && spaceToTop > spaceToBottom) {
|
|
2260
|
+
var topPositionForFlip = anchorRect.top + window.scrollY - dropdownHeight;
|
|
2261
|
+
style.top = "".concat(topPositionForFlip, "px");
|
|
2262
|
+
}
|
|
2263
|
+
else {
|
|
2264
|
+
style.top = "".concat(anchorRect.bottom + window.scrollY, "px");
|
|
2265
|
+
}
|
|
2266
|
+
return style;
|
|
2267
|
+
};
|
|
2268
|
+
var DropdownContainer = function (propsComp) {
|
|
2269
|
+
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"]);
|
|
2270
|
+
if (!open)
|
|
2271
|
+
return null;
|
|
2272
|
+
var _j = React.useState({ minWidth: 'auto' }), positionStyle = _j[0], setPositionStyle = _j[1];
|
|
2273
|
+
var radiusClass = "rounded-b-radius-sm ".concat(!isTopFlat && 'rounded-t-radius-sm');
|
|
2274
|
+
var sizeClass = containerSizeConfig[size] || containerSizeConfig['md'];
|
|
2275
|
+
var containerClass = "".concat(sizeClass, " ").concat(radiusClass, " ").concat(className);
|
|
2276
|
+
var dropdownRef = React.useRef(null);
|
|
2277
|
+
var handleClickDrpdownItem = function (e, val) {
|
|
2278
|
+
onClickItem(e, val);
|
|
2279
|
+
onClose();
|
|
2280
|
+
};
|
|
2281
|
+
React.useLayoutEffect(function () {
|
|
2282
|
+
if (!(anchorRef === null || anchorRef === void 0 ? void 0 : anchorRef.current))
|
|
2283
|
+
return;
|
|
2284
|
+
var newStyle = getDropdownStyle(anchorRef, dropdownRef);
|
|
2285
|
+
setPositionStyle(newStyle);
|
|
2286
|
+
var handleScrollOrResize = function () {
|
|
2287
|
+
setPositionStyle(getDropdownStyle(anchorRef, dropdownRef));
|
|
2288
|
+
};
|
|
2289
|
+
window.addEventListener('scroll', handleScrollOrResize);
|
|
2290
|
+
window.addEventListener('resize', handleScrollOrResize);
|
|
2291
|
+
return function () {
|
|
2292
|
+
window.removeEventListener('scroll', handleScrollOrResize);
|
|
2293
|
+
window.removeEventListener('resize', handleScrollOrResize);
|
|
2294
|
+
};
|
|
2295
|
+
}, [anchorRef]);
|
|
2296
|
+
return (React.createElement(React.Fragment, null,
|
|
2297
|
+
isWithOverlay && (React.createElement("div", { className: "bianic-dropdown-overlay fixed left-0 top-0 h-screen w-screen", style: { zIndex: zIndex }, onClick: function () { return onClose(); } })),
|
|
2298
|
+
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) {
|
|
2299
|
+
return React.isValidElement(child)
|
|
2300
|
+
? // Kirimkan handleItemClick sebagai props onClick ke setiap DropdownItem
|
|
2301
|
+
React.cloneElement(child, {
|
|
2302
|
+
onClose: function () { return onClose(); },
|
|
2303
|
+
size: size,
|
|
2304
|
+
onClickItem: function (e, val) { return handleClickDrpdownItem(e, val); },
|
|
2305
|
+
zIndex: zIndex + 10,
|
|
2306
|
+
})
|
|
2307
|
+
: child;
|
|
2308
|
+
})), document.body)));
|
|
2309
|
+
};
|
|
2310
|
+
DropdownContainer.defaultProps = {
|
|
2311
|
+
isTopFlat: false,
|
|
2312
|
+
};
|
|
2313
|
+
|
|
2314
|
+
var DropdownContNoAnchor = React.forwardRef(function DropdownContNoAnchor(propsComp, ref) {
|
|
2244
2315
|
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
2316
|
var radiusClass = "rounded-b-radius-sm ".concat(!isTopFlat && 'rounded-t-radius-sm');
|
|
2246
2317
|
var sizeClass = containerSizeConfig[size] || containerSizeConfig['md'];
|
|
@@ -2265,7 +2336,7 @@ var DropdownContainer = React.forwardRef(function DropdownContainer(propsComp, r
|
|
|
2265
2336
|
: child;
|
|
2266
2337
|
})))));
|
|
2267
2338
|
});
|
|
2268
|
-
|
|
2339
|
+
DropdownContNoAnchor.defaultProps = {
|
|
2269
2340
|
isTopFlat: false,
|
|
2270
2341
|
};
|
|
2271
2342
|
|
|
@@ -2303,7 +2374,7 @@ function DropdownItem(_a) {
|
|
|
2303
2374
|
}, onKeyDown: function () { }, disabled: disabled, type: "button" }, props),
|
|
2304
2375
|
content,
|
|
2305
2376
|
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(
|
|
2377
|
+
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))));
|
|
2307
2378
|
}
|
|
2308
2379
|
DropdownItem.defaultProps = {
|
|
2309
2380
|
className: '',
|
|
@@ -2314,11 +2385,9 @@ var sizeUnion$2 = ['md', 'sm'];
|
|
|
2314
2385
|
function SelectInput(_a) {
|
|
2315
2386
|
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"]);
|
|
2316
2387
|
var _k = React.useState(false), isOpen = _k[0], setIsOpen = _k[1];
|
|
2317
|
-
var _l = React.useState(false), isDropUp = _l[0], setIsDropUp = _l[1];
|
|
2318
2388
|
var validatedSize = validUnion(size, sizeUnion$2);
|
|
2319
|
-
var
|
|
2389
|
+
var _l = sizeConfig$8[validatedSize], searchSize = _l.searchSize, iconSize = _l.iconSize;
|
|
2320
2390
|
var inputRef = React.useRef(null);
|
|
2321
|
-
var dropdownContRef = React.useRef(null);
|
|
2322
2391
|
var handleOutsideClick = function (e) {
|
|
2323
2392
|
if (inputRef.current && !inputRef.current.contains(e.target)) {
|
|
2324
2393
|
setIsOpen(false);
|
|
@@ -2330,22 +2399,6 @@ function SelectInput(_a) {
|
|
|
2330
2399
|
document.removeEventListener('mousedown', handleOutsideClick);
|
|
2331
2400
|
};
|
|
2332
2401
|
});
|
|
2333
|
-
React.useEffect(function () {
|
|
2334
|
-
var _a, _b;
|
|
2335
|
-
if (inputRef.current) {
|
|
2336
|
-
// Adjust dropdown position to prevent show up out of screen
|
|
2337
|
-
var windowHeight = window.innerHeight;
|
|
2338
|
-
var inputRect = (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
2339
|
-
var inputBottom = inputRect === null || inputRect === void 0 ? void 0 : inputRect.bottom;
|
|
2340
|
-
var diff = windowHeight - inputBottom;
|
|
2341
|
-
var dropdownRect = (_b = dropdownContRef.current) === null || _b === void 0 ? void 0 : _b.getBoundingClientRect();
|
|
2342
|
-
var dropdownHeight = (dropdownRect === null || dropdownRect === void 0 ? void 0 : dropdownRect.height) || 0;
|
|
2343
|
-
if (dropdownHeight >= diff)
|
|
2344
|
-
setIsDropUp(true);
|
|
2345
|
-
else
|
|
2346
|
-
setIsDropUp(false);
|
|
2347
|
-
}
|
|
2348
|
-
}, [isOpen]);
|
|
2349
2402
|
var isObjectOptionItem = false;
|
|
2350
2403
|
if (options.every(function (item) { return typeof item === 'object' && item !== null; }))
|
|
2351
2404
|
isObjectOptionItem = true;
|
|
@@ -2365,7 +2418,6 @@ function SelectInput(_a) {
|
|
|
2365
2418
|
optionsElement.style.maxHeight = "".concat(Math.max(0, maxHeight), "px");
|
|
2366
2419
|
}
|
|
2367
2420
|
}, [isOpen]);
|
|
2368
|
-
var dropdownPosition = isDropUp ? 'bottom-full' : 'top-full';
|
|
2369
2421
|
return (React.createElement("div", { className: "field-group flex w-full flex-col", ref: inputRef },
|
|
2370
2422
|
React.createElement("label", { htmlFor: id, className: "label pb-2 text-xs font-semibold" },
|
|
2371
2423
|
childrenElement(label),
|
|
@@ -2385,7 +2437,7 @@ function SelectInput(_a) {
|
|
|
2385
2437
|
setIsOpen(false);
|
|
2386
2438
|
} }));
|
|
2387
2439
|
}))),
|
|
2388
|
-
children && isOpen && (React.createElement(DropdownContainer, __assign({ open: isOpen, onClose: function () { return setIsOpen(false); }, size: size, isTopFlat: true,
|
|
2440
|
+
children && isOpen && (React.createElement(DropdownContainer, __assign({ open: isOpen, onClose: function () { return setIsOpen(false); }, size: size, isTopFlat: true, anchorRef: inputRef, 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(dropContClassName) }, restDropContProps), React.Children.map(children, function (child) {
|
|
2389
2441
|
if (React.isValidElement(child)) {
|
|
2390
2442
|
return React.cloneElement(child, {
|
|
2391
2443
|
isSelected: selected && selected.id === child.props.value.id,
|
|
@@ -2425,16 +2477,29 @@ var sizeConfig$6 = {
|
|
|
2425
2477
|
},
|
|
2426
2478
|
};
|
|
2427
2479
|
|
|
2480
|
+
var matchSearchTerm = function (content, term, variant) {
|
|
2481
|
+
var lowerContent = content.toLowerCase();
|
|
2482
|
+
var lowerTerm = term.toLowerCase();
|
|
2483
|
+
switch (variant) {
|
|
2484
|
+
case 'startsWith':
|
|
2485
|
+
return lowerContent.startsWith(lowerTerm);
|
|
2486
|
+
case 'endsWith':
|
|
2487
|
+
return lowerContent.endsWith(lowerTerm);
|
|
2488
|
+
case 'include':
|
|
2489
|
+
return lowerContent.includes(lowerTerm);
|
|
2490
|
+
default:
|
|
2491
|
+
return lowerContent.includes(lowerTerm);
|
|
2492
|
+
}
|
|
2493
|
+
};
|
|
2428
2494
|
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
|
|
2431
|
-
var
|
|
2432
|
-
var
|
|
2495
|
+
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;
|
|
2496
|
+
var _m = React.useState(false), isOpen = _m[0], setIsOpen = _m[1];
|
|
2497
|
+
var _o = React.useState(value.label || ''), searchTerm = _o[0], setSearchTerm = _o[1];
|
|
2498
|
+
var _p = sizeConfig$6[size], iconClass = _p.iconClass, iconSize = _p.iconSize, inputClass = _p.inputClass;
|
|
2433
2499
|
var dropContClassName = dropContProps.className, restDropContProps = __rest(dropContProps, ["className"]);
|
|
2434
2500
|
var isValueExist = value && value.label !== undefined && value.label !== '';
|
|
2435
2501
|
var inputRef = React.useRef(null);
|
|
2436
2502
|
var dropdownContRef = React.useRef(null);
|
|
2437
|
-
var _p = React.useState(false), isDropUp = _p[0], setIsDropUp = _p[1];
|
|
2438
2503
|
var handleOutsideClick = function (e) {
|
|
2439
2504
|
if (inputRef.current && !inputRef.current.contains(e.target)) {
|
|
2440
2505
|
setIsOpen(false);
|
|
@@ -2454,22 +2519,6 @@ function LiveSearch(_a) {
|
|
|
2454
2519
|
setSearchTerm(value.label || '');
|
|
2455
2520
|
}
|
|
2456
2521
|
}, [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
2522
|
var filteredOptions = options === null || options === void 0 ? void 0 : options.filter(function (item) {
|
|
2474
2523
|
return item.label.toLowerCase().includes(value.label.toLowerCase());
|
|
2475
2524
|
});
|
|
@@ -2487,36 +2536,38 @@ function LiveSearch(_a) {
|
|
|
2487
2536
|
var processDropdownChildren = function (nodes, currentSearchTerm, includeAllIfNoSearch) {
|
|
2488
2537
|
return React.Children.map(nodes, function (child) {
|
|
2489
2538
|
if (!React.isValidElement(child) || child.type !== DropdownItem) {
|
|
2490
|
-
return child;
|
|
2539
|
+
return child;
|
|
2491
2540
|
}
|
|
2492
|
-
var itemProps = child.props;
|
|
2541
|
+
var itemProps = child.props;
|
|
2542
|
+
// Assume content is a string for filtering; otherwise, filtering won't work well
|
|
2543
|
+
var itemContent = typeof itemProps.content === 'string' ? itemProps.content : '';
|
|
2493
2544
|
var itemValue = itemProps.value;
|
|
2494
2545
|
var isDisabled = itemProps.disabled;
|
|
2495
|
-
//
|
|
2496
|
-
if (
|
|
2497
|
-
|
|
2498
|
-
|
|
2546
|
+
// 2. Filtering Logic (Uses Global Search Variant)
|
|
2547
|
+
if (!includeAllIfNoSearch) {
|
|
2548
|
+
// Use the matchSearchTerm utility with the selected searchVariant
|
|
2549
|
+
if (currentSearchTerm && !matchSearchTerm(itemValue, currentSearchTerm, searchVariant)) {
|
|
2550
|
+
return null; // Item does not match the search criteria
|
|
2551
|
+
}
|
|
2499
2552
|
}
|
|
2500
|
-
//
|
|
2501
|
-
// If includeAllIfNoSearch is false (when searchTerm is present), filtering has been done above.
|
|
2502
|
-
// Clone its children recursively if any
|
|
2553
|
+
// 3. Process Nested Children (Recursion)
|
|
2503
2554
|
var clonedChildren = itemProps.children
|
|
2504
|
-
? processDropdownChildren(itemProps.children, currentSearchTerm)
|
|
2555
|
+
? processDropdownChildren(itemProps.children, currentSearchTerm, includeAllIfNoSearch)
|
|
2505
2556
|
: null;
|
|
2506
|
-
// Clone
|
|
2557
|
+
// 4. Clone and Inject Click Handler
|
|
2507
2558
|
return React.cloneElement(child, {
|
|
2508
2559
|
onClick: function (e) {
|
|
2509
2560
|
if (!isDisabled) {
|
|
2510
2561
|
handleDropdownItemClick({
|
|
2511
|
-
id: itemValue,
|
|
2512
|
-
label: itemValue
|
|
2562
|
+
id: itemValue !== undefined ? itemValue : itemContent,
|
|
2563
|
+
label: itemValue !== undefined ? itemValue : itemContent
|
|
2513
2564
|
});
|
|
2514
2565
|
}
|
|
2515
|
-
if (
|
|
2516
|
-
|
|
2566
|
+
if (itemProps.onClick) {
|
|
2567
|
+
itemProps.onClick(e);
|
|
2517
2568
|
}
|
|
2518
2569
|
},
|
|
2519
|
-
children: clonedChildren
|
|
2570
|
+
children: clonedChildren
|
|
2520
2571
|
});
|
|
2521
2572
|
});
|
|
2522
2573
|
};
|
|
@@ -2525,21 +2576,20 @@ function LiveSearch(_a) {
|
|
|
2525
2576
|
var hasFilteredResults = false;
|
|
2526
2577
|
if (searchTerm) {
|
|
2527
2578
|
// If there's a searchTerm, filter children
|
|
2528
|
-
renderedChildren = processDropdownChildren(children, searchTerm);
|
|
2579
|
+
renderedChildren = processDropdownChildren(children, searchTerm, false);
|
|
2529
2580
|
hasFilteredResults =
|
|
2530
2581
|
React.Children.toArray(renderedChildren).filter(Boolean).length > 0;
|
|
2531
2582
|
}
|
|
2532
2583
|
else {
|
|
2533
2584
|
// If searchTerm is empty, display all children without filtering (but with onClick injected)
|
|
2534
|
-
renderedChildren = processDropdownChildren(children, '');
|
|
2585
|
+
renderedChildren = processDropdownChildren(children, '', true);
|
|
2535
2586
|
hasFilteredResults =
|
|
2536
2587
|
React.Children.toArray(renderedChildren).filter(Boolean).length > 0; // Should always be true if there are initial children
|
|
2537
2588
|
}
|
|
2538
|
-
|
|
2539
|
-
return (React.createElement("div", { className: "bianic-livesearch field-group group/form flex w-full flex-col gap-y-2 ", ref: inputRef },
|
|
2589
|
+
return (React.createElement("div", { className: "bianic-livesearch field-group group/form flex w-full flex-col gap-y-2 " },
|
|
2540
2590
|
label && (React.createElement(FormLabel, { htmlFor: id, required: required, readOnly: readOnly }, label)),
|
|
2541
2591
|
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) {
|
|
2592
|
+
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
2593
|
onChangeText(e);
|
|
2544
2594
|
setValue({ id: null, label: e.target.value });
|
|
2545
2595
|
handleInputChange(e);
|
|
@@ -2558,10 +2608,10 @@ function LiveSearch(_a) {
|
|
|
2558
2608
|
setIsOpen(false);
|
|
2559
2609
|
} }));
|
|
2560
2610
|
}))),
|
|
2561
|
-
children &&
|
|
2611
|
+
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
2612
|
? renderedChildren
|
|
2563
2613
|
: // 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.") }))))
|
|
2614
|
+
searchTerm.length > 0 && (React.createElement(DropdownItem, { content: React.createElement("div", { className: "px-4 py-2 text-gray-500" }, "Tidak ada hasil ditemukan.") })))),
|
|
2565
2615
|
descText && (React.createElement("span", { className: "desc text-xs text-primary-cool" }, descText))));
|
|
2566
2616
|
}
|
|
2567
2617
|
LiveSearch.defaultProps = {
|