@mmb-digital/ds-lilly 0.3.4 → 0.3.8
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/ds-lilly.js
CHANGED
|
@@ -96310,7 +96310,7 @@ var Dropdown_assign = (undefined && undefined.__assign) || function () {
|
|
|
96310
96310
|
|
|
96311
96311
|
var SCROLL_DEVIATION = 16;
|
|
96312
96312
|
var Dropdown = function (_a) {
|
|
96313
|
-
var children = _a.children, closeOnOutsideClick = _a.closeOnOutsideClick, closeOnTriggerHidden = _a.closeOnTriggerHidden, _b = _a.delayHide, delayHide = _b === void 0 ? 200 : _b, delayShow = _a.delayShow, forceVisibility = _a.forceVisibility, _c = _a.hasSameWidthAsTrigger, hasSameWidthAsTrigger = _c === void 0 ? false : _c, interactive = _a.interactive, _d = _a.isOpenByDefault, isOpenByDefault = _d === void 0 ? false : _d, onOutsideClick = _a.onOutsideClick, onScrollToEnd = _a.onScrollToEnd, onVisibleChange = _a.onVisibleChange, _e = _a.placement, placement = _e === void 0 ? 'auto' : _e, testId = _a.testId, theme = _a.theme, _f = _a.trigger, trigger = _f === void 0 ? 'focus' : _f, triggerComponent = _a.triggerComponent;
|
|
96313
|
+
var children = _a.children, closeOnOutsideClick = _a.closeOnOutsideClick, closeOnTriggerHidden = _a.closeOnTriggerHidden, _b = _a.delayHide, delayHide = _b === void 0 ? 200 : _b, delayShow = _a.delayShow, dropdownId = _a.dropdownId, forceVisibility = _a.forceVisibility, _c = _a.hasSameWidthAsTrigger, hasSameWidthAsTrigger = _c === void 0 ? false : _c, interactive = _a.interactive, _d = _a.isOpenByDefault, isOpenByDefault = _d === void 0 ? false : _d, onOutsideClick = _a.onOutsideClick, onScrollToEnd = _a.onScrollToEnd, onVisibleChange = _a.onVisibleChange, _e = _a.placement, placement = _e === void 0 ? 'auto' : _e, testId = _a.testId, theme = _a.theme, _f = _a.trigger, trigger = _f === void 0 ? 'focus' : _f, triggerComponent = _a.triggerComponent;
|
|
96314
96314
|
var tooltipRef = Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useRef"])();
|
|
96315
96315
|
var _g = usePopperTooltip({
|
|
96316
96316
|
closeOnOutsideClick: closeOnOutsideClick,
|
|
@@ -96342,7 +96342,7 @@ var Dropdown = function (_a) {
|
|
|
96342
96342
|
visible && (external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["Fragment"], null,
|
|
96343
96343
|
external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", Dropdown_assign({ ref: setRef, "data-testid": testId }, getTooltipProps({
|
|
96344
96344
|
className: classBinder_cx('c-dropdown', { 'c-dropdown--fullWidth': hasSameWidthAsTrigger }, theme)
|
|
96345
|
-
}), { onScroll: handleScroll }), children),
|
|
96345
|
+
}), { id: dropdownId, onScroll: handleScroll }), children),
|
|
96346
96346
|
onOutsideClick && external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", { className: "c-dropdown__outside", onClick: onOutsideClick })))));
|
|
96347
96347
|
};
|
|
96348
96348
|
|
|
@@ -98331,11 +98331,11 @@ var Autocomplete2 = function (_a) {
|
|
|
98331
98331
|
.map(function (item, index) { return (!item.isDisabled ? { category: -1, item: index } : undefined); })
|
|
98332
98332
|
.filter(Boolean);
|
|
98333
98333
|
}
|
|
98334
|
-
if (emptyValueLabel) {
|
|
98334
|
+
if (emptyValueLabel && map.length > 0 && (fulltextValue === (buttonValue === null || buttonValue === void 0 ? void 0 : buttonValue.label) || !value)) {
|
|
98335
98335
|
return Autocomplete2_spreadArray([{ item: -1, category: -1 }], map);
|
|
98336
98336
|
}
|
|
98337
98337
|
return map;
|
|
98338
|
-
}, [items, isCategorised]);
|
|
98338
|
+
}, [items, isCategorised, fulltextValue, value, buttonValue]);
|
|
98339
98339
|
var showCreatable = !!onCreateNewItem &&
|
|
98340
98340
|
(itemsIndex.length === 0 || canAlwaysCreateNewItem) &&
|
|
98341
98341
|
typingMode &&
|
|
@@ -98424,9 +98424,11 @@ var Autocomplete2 = function (_a) {
|
|
|
98424
98424
|
}
|
|
98425
98425
|
}, [value]);
|
|
98426
98426
|
Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useEffect"])(function () {
|
|
98427
|
-
|
|
98428
|
-
|
|
98429
|
-
|
|
98427
|
+
if (isDropdownVisible) {
|
|
98428
|
+
var itemIndex = getItemIndexByValue(value);
|
|
98429
|
+
var itemIndexPosition = getItemIndexPosition(itemIndex);
|
|
98430
|
+
setCurrentItemPosition(itemIndexPosition);
|
|
98431
|
+
}
|
|
98430
98432
|
}, [isDropdownVisible]);
|
|
98431
98433
|
Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useEffect"])(function () {
|
|
98432
98434
|
if (pagingState.loading) {
|
|
@@ -98434,11 +98436,22 @@ var Autocomplete2 = function (_a) {
|
|
|
98434
98436
|
}
|
|
98435
98437
|
}, [pagingState.loading]);
|
|
98436
98438
|
var scrollToItem = function (item, category, center) {
|
|
98437
|
-
var _a;
|
|
98439
|
+
var _a, _b, _c, _d, _e, _f;
|
|
98438
98440
|
if (category === void 0) { category = -1; }
|
|
98439
98441
|
if (center === void 0) { center = false; }
|
|
98440
98442
|
var itemElementId = isCategorised ? name + "_option-" + category + "-" + item : name + "_option-" + item;
|
|
98441
|
-
|
|
98443
|
+
if (center) {
|
|
98444
|
+
var dropdownHalfHeight = (((_a = document.getElementById('autocomplete_dropdown')) === null || _a === void 0 ? void 0 : _a.clientHeight) || 0) / 2;
|
|
98445
|
+
var itemHalfHeight = (((_b = document.getElementById(itemElementId)) === null || _b === void 0 ? void 0 : _b.clientHeight) || 0) / 2;
|
|
98446
|
+
var itemOffset = ((_c = document.getElementById(itemElementId)) === null || _c === void 0 ? void 0 : _c.offsetTop) || 0;
|
|
98447
|
+
if (itemOffset > dropdownHalfHeight) {
|
|
98448
|
+
(_d = document
|
|
98449
|
+
.getElementById('autocomplete_dropdown')) === null || _d === void 0 ? void 0 : _d.scrollTo(0, (((_e = document.getElementById(itemElementId)) === null || _e === void 0 ? void 0 : _e.offsetTop) || 0) - dropdownHalfHeight + itemHalfHeight);
|
|
98450
|
+
}
|
|
98451
|
+
}
|
|
98452
|
+
else {
|
|
98453
|
+
(_f = document.getElementById(itemElementId)) === null || _f === void 0 ? void 0 : _f.scrollIntoView({ block: 'nearest' });
|
|
98454
|
+
}
|
|
98442
98455
|
};
|
|
98443
98456
|
var focusCreatable = function () {
|
|
98444
98457
|
var _a, _b;
|
|
@@ -98473,7 +98486,7 @@ var Autocomplete2 = function (_a) {
|
|
|
98473
98486
|
}
|
|
98474
98487
|
};
|
|
98475
98488
|
Object(external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_["useEffect"])(function () {
|
|
98476
|
-
if (fulltextValue && !isDropdownVisible) {
|
|
98489
|
+
if (typingMode && fulltextValue && !isDropdownVisible) {
|
|
98477
98490
|
setIsDropdownVisible(true);
|
|
98478
98491
|
}
|
|
98479
98492
|
if (loadItems) {
|
|
@@ -98499,7 +98512,7 @@ var Autocomplete2 = function (_a) {
|
|
|
98499
98512
|
loadAsyncItems();
|
|
98500
98513
|
}
|
|
98501
98514
|
var selectedItem_1 = itemsIndex[currentItemPosition];
|
|
98502
|
-
if (selectedItem_1) {
|
|
98515
|
+
if (selectedItem_1 && selectedItem_1.item !== -1) {
|
|
98503
98516
|
setTimeout(function () { return scrollToItem(selectedItem_1.item, selectedItem_1.category, true); }, 100);
|
|
98504
98517
|
}
|
|
98505
98518
|
}
|
|
@@ -98562,6 +98575,12 @@ var Autocomplete2 = function (_a) {
|
|
|
98562
98575
|
var handleCreateNewOption = function () {
|
|
98563
98576
|
setButtonValue({ label: fulltextValue, value: fulltextValue });
|
|
98564
98577
|
onCreateNewItem && onCreateNewItem(fulltextValue);
|
|
98578
|
+
setTypingMode(false);
|
|
98579
|
+
};
|
|
98580
|
+
var handleBlur = function (item) {
|
|
98581
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
98582
|
+
// @ts-ignore
|
|
98583
|
+
onBlur && onBlur((item === null || item === void 0 ? void 0 : item.value) || undefined);
|
|
98565
98584
|
};
|
|
98566
98585
|
var handleOptionKeyPress = function (event) {
|
|
98567
98586
|
var ctrlKey = event.ctrlKey, key = event.key, metaKey = event.metaKey, target = event.target;
|
|
@@ -98675,18 +98694,30 @@ var Autocomplete2 = function (_a) {
|
|
|
98675
98694
|
}
|
|
98676
98695
|
if (key === KEYS.Enter) {
|
|
98677
98696
|
event.preventDefault();
|
|
98678
|
-
if (isDropdownVisible
|
|
98679
|
-
|
|
98697
|
+
if (isDropdownVisible) {
|
|
98698
|
+
var minItemsToAutoselect = emptyValueLabel && !value ? 2 : 1;
|
|
98699
|
+
if (showCreatable && itemsIndex.length === 0) {
|
|
98700
|
+
handleCreateNewOption();
|
|
98701
|
+
}
|
|
98702
|
+
else if (fulltextValue && fulltextValue !== (buttonValue === null || buttonValue === void 0 ? void 0 : buttonValue.label) && itemsIndex.length >= minItemsToAutoselect) {
|
|
98703
|
+
var _a = itemsIndex[minItemsToAutoselect - 1], category = _a.category, item = _a.item;
|
|
98704
|
+
var selectedItem = isCategorised
|
|
98705
|
+
? items[category].items[item]
|
|
98706
|
+
: items[item];
|
|
98707
|
+
setFulltextValue(selectedItem.label);
|
|
98708
|
+
propagateChange(selectedItem);
|
|
98709
|
+
setTypingMode(false);
|
|
98710
|
+
}
|
|
98711
|
+
else if (fulltextValue !== (buttonValue === null || buttonValue === void 0 ? void 0 : buttonValue.label)) {
|
|
98712
|
+
resetFulltext(false);
|
|
98713
|
+
setCurrentItemPosition(-1);
|
|
98714
|
+
propagateChange();
|
|
98715
|
+
}
|
|
98716
|
+
setIsDropdownVisible(false);
|
|
98680
98717
|
}
|
|
98681
|
-
else
|
|
98682
|
-
|
|
98683
|
-
var selectedItem = isCategorised
|
|
98684
|
-
? items[category].items[item]
|
|
98685
|
-
: items[item];
|
|
98686
|
-
setFulltextValue(selectedItem.label);
|
|
98687
|
-
propagateChange(selectedItem);
|
|
98718
|
+
else {
|
|
98719
|
+
setIsDropdownVisible(function (prev) { return !prev; });
|
|
98688
98720
|
}
|
|
98689
|
-
setIsDropdownVisible(function (prev) { return !prev; });
|
|
98690
98721
|
return;
|
|
98691
98722
|
}
|
|
98692
98723
|
if (key === KEYS.ArrowUp && isDropdownVisible) {
|
|
@@ -98721,30 +98752,36 @@ var Autocomplete2 = function (_a) {
|
|
|
98721
98752
|
return;
|
|
98722
98753
|
}
|
|
98723
98754
|
if (key === KEYS.Tab) {
|
|
98724
|
-
|
|
98725
|
-
|
|
98726
|
-
handleCreateNewOption();
|
|
98727
|
-
}
|
|
98728
|
-
else if (fulltextValue && itemsIndex.length === 1) {
|
|
98729
|
-
var _c = itemsIndex[0], category = _c.category, item = _c.item;
|
|
98730
|
-
var selectedItem = isCategorised
|
|
98731
|
-
? items[category].items[item]
|
|
98732
|
-
: items[item];
|
|
98733
|
-
setButtonValue(selectedItem);
|
|
98734
|
-
}
|
|
98735
|
-
else if (fulltextValue) {
|
|
98736
|
-
resetFulltext();
|
|
98755
|
+
if (!isDropdownVisible) {
|
|
98756
|
+
handleBlur(buttonValue);
|
|
98737
98757
|
}
|
|
98738
98758
|
else {
|
|
98739
|
-
|
|
98759
|
+
if (showCreatable && itemsIndex.length === 0) {
|
|
98760
|
+
handleCreateNewOption();
|
|
98761
|
+
}
|
|
98762
|
+
else if (fulltextValue && fulltextValue !== (buttonValue === null || buttonValue === void 0 ? void 0 : buttonValue.label) && itemsIndex.length > 0) {
|
|
98763
|
+
var _c = itemsIndex[0], category = _c.category, item = _c.item;
|
|
98764
|
+
var selectedItem = isCategorised
|
|
98765
|
+
? items[category].items[item]
|
|
98766
|
+
: items[item];
|
|
98767
|
+
setButtonValue(selectedItem);
|
|
98768
|
+
propagateChange(selectedItem);
|
|
98769
|
+
handleBlur(selectedItem);
|
|
98770
|
+
}
|
|
98771
|
+
else if (fulltextValue) {
|
|
98772
|
+
handleBlur(buttonValue);
|
|
98773
|
+
}
|
|
98774
|
+
else {
|
|
98775
|
+
setCurrentItemPosition(-1);
|
|
98776
|
+
resetFulltext(false);
|
|
98777
|
+
propagateChange();
|
|
98778
|
+
handleBlur();
|
|
98779
|
+
}
|
|
98740
98780
|
}
|
|
98741
98781
|
setTimeout(function () {
|
|
98782
|
+
setIsDropdownVisible(false);
|
|
98742
98783
|
setTypingMode(false);
|
|
98743
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
98744
|
-
// @ts-ignore
|
|
98745
|
-
onBlur && onBlur(buttonValue === null || buttonValue === void 0 ? void 0 : buttonValue.value);
|
|
98746
98784
|
});
|
|
98747
|
-
return;
|
|
98748
98785
|
}
|
|
98749
98786
|
};
|
|
98750
98787
|
var handleFulltextChange = function (_a) {
|
|
@@ -98780,6 +98817,7 @@ var Autocomplete2 = function (_a) {
|
|
|
98780
98817
|
setIsDropdownVisible(isVisible);
|
|
98781
98818
|
setTypingMode(isVisible);
|
|
98782
98819
|
resetFulltext();
|
|
98820
|
+
handleBlur(buttonValue);
|
|
98783
98821
|
}
|
|
98784
98822
|
};
|
|
98785
98823
|
var renderDropdownContent = function () {
|
|
@@ -98807,7 +98845,7 @@ var Autocomplete2 = function (_a) {
|
|
|
98807
98845
|
};
|
|
98808
98846
|
var focusedItem = itemsIndex[currentItemPosition];
|
|
98809
98847
|
var select2context = {
|
|
98810
|
-
emptyValueLabel: emptyValueLabel,
|
|
98848
|
+
emptyValueLabel: itemsIndex.length > 0 && (fulltextValue === (buttonValue === null || buttonValue === void 0 ? void 0 : buttonValue.label) || !value) ? emptyValueLabel : undefined,
|
|
98811
98849
|
focusedCategoryIndex: focusedItem ? focusedItem.category : -1,
|
|
98812
98850
|
focusedItemIndex: focusedItem ? focusedItem.item : -1,
|
|
98813
98851
|
items: items,
|
|
@@ -98830,7 +98868,7 @@ var Autocomplete2 = function (_a) {
|
|
|
98830
98868
|
};
|
|
98831
98869
|
return (external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(FormGroup2, Autocomplete2_assign({ theme: classBinder_cx({ 'f-group2--open': isDropdownVisible }, theme) }, fromGroupProps),
|
|
98832
98870
|
external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(contexts_Select2Context.Provider, { value: select2context },
|
|
98833
|
-
external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Dropdown, { forceVisibility: isDropdownVisible, hasSameWidthAsTrigger: hasFullWidthOptions, placement: "bottom-start", theme: dropdownTheme, trigger: null, triggerComponent: external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", { className: "f-controlWrap", "data-testid": testId, role: "combobox" }, typingMode ? (external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", { className: classBinder_cx('f-control2 f-control2--select', { 'f-control2--large': displayDetails }) },
|
|
98871
|
+
external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Dropdown, { dropdownId: "autocomplete_dropdown", forceVisibility: isDropdownVisible, hasSameWidthAsTrigger: hasFullWidthOptions, placement: "bottom-start", theme: dropdownTheme, trigger: null, triggerComponent: external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", { className: "f-controlWrap", "data-testid": testId, role: "combobox" }, typingMode ? (external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("div", { className: classBinder_cx('f-control2 f-control2--select', { 'f-control2--large': displayDetails }) },
|
|
98834
98872
|
external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("input", { autoComplete: "off", className: classBinder_cx('f-autocomplete__input'), disabled: isDisabled, id: name + "_input", name: name, placeholder: placeholder, type: "text", value: fulltextValue, onChange: handleFulltextChange, onKeyDown: handleFulltextKeyPress }),
|
|
98835
98873
|
external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("button", { "aria-invalid": !!error, className: classBinder_cx('f-autocomplete__button'), disabled: isDisabled, id: name + "_toggle_button", name: name, tabIndex: -1, type: "button", onClick: toggleDropdown },
|
|
98836
98874
|
external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement(Icon, { name: "arrowDown", size: "small", theme: "f-control2__selectIcon" })))) : (external_root_React_commonjs2_react_commonjs_react_amd_react_umd_react_default.a.createElement("button", { "aria-expanded": isDropdownVisible, "aria-haspopup": "listbox", "aria-invalid": !!error, "aria-labelledby": name + "_label " + name, className: classBinder_cx('f-control2 f-control2--select', {
|
|
@@ -13,6 +13,8 @@ export interface DropdownPropsType extends ComponentPropsType {
|
|
|
13
13
|
delayHide?: number;
|
|
14
14
|
/** Delay in showing the tooltip (ms). */
|
|
15
15
|
delayShow?: number;
|
|
16
|
+
/** Dropdown menu element ID */
|
|
17
|
+
dropdownId?: string;
|
|
16
18
|
/** Set to use same width as triggerComponent. */
|
|
17
19
|
hasSameWidthAsTrigger?: boolean;
|
|
18
20
|
/** If true, hovering the tooltip will keep it open. */
|
|
@@ -33,5 +35,5 @@ export interface DropdownPropsType extends ComponentPropsType {
|
|
|
33
35
|
triggerComponent: ReactElement;
|
|
34
36
|
forceVisibility?: boolean;
|
|
35
37
|
}
|
|
36
|
-
export declare const Dropdown: ({ children, closeOnOutsideClick, closeOnTriggerHidden, delayHide, delayShow, forceVisibility, hasSameWidthAsTrigger, interactive, isOpenByDefault, onOutsideClick, onScrollToEnd, onVisibleChange, placement, testId, theme, trigger, triggerComponent }: DropdownPropsType) => JSX.Element;
|
|
38
|
+
export declare const Dropdown: ({ children, closeOnOutsideClick, closeOnTriggerHidden, delayHide, delayShow, dropdownId, forceVisibility, hasSameWidthAsTrigger, interactive, isOpenByDefault, onOutsideClick, onScrollToEnd, onVisibleChange, placement, testId, theme, trigger, triggerComponent }: DropdownPropsType) => JSX.Element;
|
|
37
39
|
//# sourceMappingURL=Dropdown.d.ts.map
|