labsense-ui-kit 1.3.62 → 1.3.64
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/Dropdown/SelectOption.d.ts +1 -0
- package/dist/index.js +279 -50
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +279 -50
- package/dist/index.modern.js.map +1 -1
- package/package.json +1 -1
package/dist/index.modern.js
CHANGED
|
@@ -7858,15 +7858,24 @@ var DatePicker = function DatePicker(_ref22) {
|
|
|
7858
7858
|
|
|
7859
7859
|
var _templateObject$a, _templateObject2$7, _templateObject3$4, _templateObject4$3, _templateObject5$3, _templateObject6$3;
|
|
7860
7860
|
var OptionContainer = styled.div(_templateObject$a || (_templateObject$a = _taggedTemplateLiteralLoose([""])));
|
|
7861
|
-
var OptionItem = styled.div(_templateObject2$7 || (_templateObject2$7 = _taggedTemplateLiteralLoose(["\n border-bottom: ", ";\n"])), function (_ref) {
|
|
7861
|
+
var OptionItem = styled.div(_templateObject2$7 || (_templateObject2$7 = _taggedTemplateLiteralLoose(["\n border-bottom: ", ";\n background-color: ", ";\n border-radius: ", ";\n"])), function (_ref) {
|
|
7862
7862
|
var $optionBorder = _ref.$optionBorder,
|
|
7863
7863
|
$isborder = _ref.$isborder,
|
|
7864
7864
|
theme = _ref.theme;
|
|
7865
7865
|
return $isborder ? $optionBorder || "1px solid " + theme.vms.border.extraLight : '';
|
|
7866
|
-
})
|
|
7867
|
-
var
|
|
7868
|
-
var $optionColor = _ref2.$optionColor,
|
|
7866
|
+
}, function (_ref2) {
|
|
7867
|
+
var $isHighlighted = _ref2.$isHighlighted,
|
|
7869
7868
|
theme = _ref2.theme;
|
|
7869
|
+
return $isHighlighted ? theme.vms.hover.primary : 'transparent';
|
|
7870
|
+
}, function (_ref3) {
|
|
7871
|
+
var $isHighlighted = _ref3.$isHighlighted;
|
|
7872
|
+
return $isHighlighted ? '4px' : '0';
|
|
7873
|
+
});
|
|
7874
|
+
var OptionLabel = styled.label(_templateObject3$4 || (_templateObject3$4 = _taggedTemplateLiteralLoose(["\n cursor: pointer;\n display: flex;\n gap: 8px;\n padding: 8px 12px;\n word-break: break-word;\n box-sizing: border-box;\n display: flex;\n align-items: center;\n font-weight: 500;\n font-size: 14px;\n line-height: 14px;\n color: ", ";\n"])), function (_ref4) {
|
|
7875
|
+
var $optionColor = _ref4.$optionColor,
|
|
7876
|
+
$isHighlighted = _ref4.$isHighlighted,
|
|
7877
|
+
theme = _ref4.theme;
|
|
7878
|
+
if ($isHighlighted) return theme.vms.text.white;
|
|
7870
7879
|
switch ($optionColor) {
|
|
7871
7880
|
case 'dark':
|
|
7872
7881
|
return theme.vms.text.dark;
|
|
@@ -7888,9 +7897,9 @@ var OptionLabel = styled.label(_templateObject3$4 || (_templateObject3$4 = _tagg
|
|
|
7888
7897
|
return $optionColor || theme.vms.text.medium;
|
|
7889
7898
|
}
|
|
7890
7899
|
});
|
|
7891
|
-
var SearchContainer = styled.div(_templateObject4$3 || (_templateObject4$3 = _taggedTemplateLiteralLoose(["\n width: 100%;\n height: auto;\n background: ", ";\n border-bottom: ", ";\n border-radius: ", ";\n padding: 8px 8px;\n display: flex;\n align-items: center;\n gap: 8px;\n"])), function (
|
|
7892
|
-
var $background =
|
|
7893
|
-
theme =
|
|
7900
|
+
var SearchContainer = styled.div(_templateObject4$3 || (_templateObject4$3 = _taggedTemplateLiteralLoose(["\n width: 100%;\n height: auto;\n background: ", ";\n border-bottom: ", ";\n border-radius: ", ";\n padding: 8px 8px;\n display: flex;\n align-items: center;\n gap: 8px;\n"])), function (_ref5) {
|
|
7901
|
+
var $background = _ref5.$background,
|
|
7902
|
+
theme = _ref5.theme;
|
|
7894
7903
|
switch ($background) {
|
|
7895
7904
|
case 'dark':
|
|
7896
7905
|
return theme.vms.text.dark;
|
|
@@ -7911,19 +7920,19 @@ var SearchContainer = styled.div(_templateObject4$3 || (_templateObject4$3 = _ta
|
|
|
7911
7920
|
default:
|
|
7912
7921
|
return $background;
|
|
7913
7922
|
}
|
|
7914
|
-
}, function (
|
|
7915
|
-
var $borderBottom =
|
|
7923
|
+
}, function (_ref6) {
|
|
7924
|
+
var $borderBottom = _ref6.$borderBottom;
|
|
7916
7925
|
return $borderBottom || 'none';
|
|
7917
|
-
}, function (
|
|
7918
|
-
var $borderRadius =
|
|
7926
|
+
}, function (_ref7) {
|
|
7927
|
+
var $borderRadius = _ref7.$borderRadius;
|
|
7919
7928
|
return $borderRadius || '8px';
|
|
7920
7929
|
});
|
|
7921
|
-
var SearchBar = styled.input(_templateObject5$3 || (_templateObject5$3 = _taggedTemplateLiteralLoose(["\n border: none;\n outline: none;\n width: 100%;\n font-weight: 400;\n font-size: 14px;\n line-height: 14px;\n background: ", ";\n color: ", ";\n &::placeholder {\n color: ", ";\n font-style: italic;\n }\n"])), function (
|
|
7922
|
-
var theme =
|
|
7930
|
+
var SearchBar = styled.input(_templateObject5$3 || (_templateObject5$3 = _taggedTemplateLiteralLoose(["\n border: none;\n outline: none;\n width: 100%;\n font-weight: 400;\n font-size: 14px;\n line-height: 14px;\n background: ", ";\n color: ", ";\n &::placeholder {\n color: ", ";\n font-style: italic;\n }\n"])), function (_ref8) {
|
|
7931
|
+
var theme = _ref8.theme;
|
|
7923
7932
|
return theme.vms["default"].tertiary;
|
|
7924
|
-
}, function (
|
|
7925
|
-
var $inputColor =
|
|
7926
|
-
theme =
|
|
7933
|
+
}, function (_ref9) {
|
|
7934
|
+
var $inputColor = _ref9.$inputColor,
|
|
7935
|
+
theme = _ref9.theme;
|
|
7927
7936
|
switch ($inputColor) {
|
|
7928
7937
|
case 'dark':
|
|
7929
7938
|
return theme.vms.text.dark;
|
|
@@ -7944,9 +7953,9 @@ var SearchBar = styled.input(_templateObject5$3 || (_templateObject5$3 = _tagged
|
|
|
7944
7953
|
default:
|
|
7945
7954
|
return $inputColor;
|
|
7946
7955
|
}
|
|
7947
|
-
}, function (
|
|
7948
|
-
var $placeholderColor =
|
|
7949
|
-
theme =
|
|
7956
|
+
}, function (_ref10) {
|
|
7957
|
+
var $placeholderColor = _ref10.$placeholderColor,
|
|
7958
|
+
theme = _ref10.theme;
|
|
7950
7959
|
switch ($placeholderColor) {
|
|
7951
7960
|
case 'dark':
|
|
7952
7961
|
return theme.vms.text.dark;
|
|
@@ -7969,28 +7978,34 @@ var SearchBar = styled.input(_templateObject5$3 || (_templateObject5$3 = _tagged
|
|
|
7969
7978
|
}
|
|
7970
7979
|
});
|
|
7971
7980
|
var Text = styled.span(_templateObject6$3 || (_templateObject6$3 = _taggedTemplateLiteralLoose(["\n word-break: break-word;\n"])));
|
|
7972
|
-
var OptionComponent = function OptionComponent(
|
|
7973
|
-
var options =
|
|
7974
|
-
selectedOptions =
|
|
7975
|
-
onChange =
|
|
7976
|
-
|
|
7977
|
-
placeholder =
|
|
7978
|
-
placeholderColor =
|
|
7979
|
-
optionBorder =
|
|
7980
|
-
optionColor =
|
|
7981
|
-
searchIcon =
|
|
7982
|
-
searchbarTextColor =
|
|
7983
|
-
searchBoxBorder =
|
|
7984
|
-
searchBoxBorderRadius =
|
|
7985
|
-
searchBoxBackground =
|
|
7986
|
-
|
|
7987
|
-
searchBox =
|
|
7988
|
-
NoOptionsText =
|
|
7981
|
+
var OptionComponent = function OptionComponent(_ref11) {
|
|
7982
|
+
var options = _ref11.options,
|
|
7983
|
+
selectedOptions = _ref11.selectedOptions,
|
|
7984
|
+
onChange = _ref11.onChange,
|
|
7985
|
+
_ref11$placeholder = _ref11.placeholder,
|
|
7986
|
+
placeholder = _ref11$placeholder === void 0 ? 'Search...' : _ref11$placeholder,
|
|
7987
|
+
placeholderColor = _ref11.placeholderColor,
|
|
7988
|
+
optionBorder = _ref11.optionBorder,
|
|
7989
|
+
optionColor = _ref11.optionColor,
|
|
7990
|
+
searchIcon = _ref11.searchIcon,
|
|
7991
|
+
searchbarTextColor = _ref11.searchbarTextColor,
|
|
7992
|
+
searchBoxBorder = _ref11.searchBoxBorder,
|
|
7993
|
+
searchBoxBorderRadius = _ref11.searchBoxBorderRadius,
|
|
7994
|
+
searchBoxBackground = _ref11.searchBoxBackground,
|
|
7995
|
+
_ref11$searchBox = _ref11.searchBox,
|
|
7996
|
+
searchBox = _ref11$searchBox === void 0 ? true : _ref11$searchBox,
|
|
7997
|
+
NoOptionsText = _ref11.NoOptionsText;
|
|
7989
7998
|
var _useState = useState(''),
|
|
7990
7999
|
searchQuery = _useState[0],
|
|
7991
8000
|
setSearchQuery = _useState[1];
|
|
8001
|
+
var _useState2 = useState(-1),
|
|
8002
|
+
highlightedIndex = _useState2[0],
|
|
8003
|
+
setHighlightedIndex = _useState2[1];
|
|
8004
|
+
var optionContainerRef = useRef(null);
|
|
8005
|
+
var searchInputRef = useRef(null);
|
|
7992
8006
|
var handleSearchChange = function handleSearchChange(e) {
|
|
7993
8007
|
setSearchQuery(e.target.value.trimStart());
|
|
8008
|
+
setHighlightedIndex(-1);
|
|
7994
8009
|
};
|
|
7995
8010
|
var handleOptionToggle = function handleOptionToggle(currentOption) {
|
|
7996
8011
|
var newOption = selectedOptions.includes(currentOption) ? selectedOptions.filter(function (item) {
|
|
@@ -7998,6 +8013,36 @@ var OptionComponent = function OptionComponent(_ref9) {
|
|
|
7998
8013
|
}) : [].concat(selectedOptions, [currentOption]);
|
|
7999
8014
|
onChange === null || onChange === void 0 ? void 0 : onChange(newOption);
|
|
8000
8015
|
};
|
|
8016
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
8017
|
+
if (finalOptions.length === 0) return;
|
|
8018
|
+
switch (e.key) {
|
|
8019
|
+
case 'ArrowDown':
|
|
8020
|
+
e.preventDefault();
|
|
8021
|
+
setHighlightedIndex(function (prev) {
|
|
8022
|
+
return prev < finalOptions.length - 1 ? prev + 1 : prev;
|
|
8023
|
+
});
|
|
8024
|
+
break;
|
|
8025
|
+
case 'ArrowUp':
|
|
8026
|
+
e.preventDefault();
|
|
8027
|
+
setHighlightedIndex(function (prev) {
|
|
8028
|
+
return prev > 0 ? prev - 1 : -1;
|
|
8029
|
+
});
|
|
8030
|
+
break;
|
|
8031
|
+
case 'Enter':
|
|
8032
|
+
e.preventDefault();
|
|
8033
|
+
if (highlightedIndex >= 0 && highlightedIndex < finalOptions.length) {
|
|
8034
|
+
var selectedOption = finalOptions[highlightedIndex];
|
|
8035
|
+
handleOptionToggle(selectedOption.value);
|
|
8036
|
+
}
|
|
8037
|
+
break;
|
|
8038
|
+
case 'Escape':
|
|
8039
|
+
setHighlightedIndex(-1);
|
|
8040
|
+
if (searchInputRef.current) {
|
|
8041
|
+
searchInputRef.current.blur();
|
|
8042
|
+
}
|
|
8043
|
+
break;
|
|
8044
|
+
}
|
|
8045
|
+
};
|
|
8001
8046
|
var filteredOptions = options.filter(function (option) {
|
|
8002
8047
|
return option.labelText.toLowerCase().includes(searchQuery.toLowerCase());
|
|
8003
8048
|
});
|
|
@@ -8008,6 +8053,17 @@ var OptionComponent = function OptionComponent(_ref9) {
|
|
|
8008
8053
|
})) : filteredOptions.sort(function (a, b) {
|
|
8009
8054
|
return a.labelText.localeCompare(b.labelText);
|
|
8010
8055
|
});
|
|
8056
|
+
useEffect(function () {
|
|
8057
|
+
if (highlightedIndex >= 0 && optionContainerRef.current) {
|
|
8058
|
+
var highlightedElement = optionContainerRef.current.children[highlightedIndex];
|
|
8059
|
+
if (highlightedElement) {
|
|
8060
|
+
highlightedElement.scrollIntoView({
|
|
8061
|
+
block: 'nearest',
|
|
8062
|
+
behavior: 'smooth'
|
|
8063
|
+
});
|
|
8064
|
+
}
|
|
8065
|
+
}
|
|
8066
|
+
}, [highlightedIndex]);
|
|
8011
8067
|
return React.createElement(Container, {
|
|
8012
8068
|
"$flexDirection": 'column',
|
|
8013
8069
|
"$gap": '8px',
|
|
@@ -8022,20 +8078,26 @@ var OptionComponent = function OptionComponent(_ref9) {
|
|
|
8022
8078
|
color: searchIcon === null || searchIcon === void 0 ? void 0 : searchIcon.color,
|
|
8023
8079
|
weight: (searchIcon === null || searchIcon === void 0 ? void 0 : searchIcon.weight) || '0px'
|
|
8024
8080
|
}), React.createElement(SearchBar, {
|
|
8081
|
+
ref: searchInputRef,
|
|
8025
8082
|
type: 'text',
|
|
8026
8083
|
placeholder: placeholder,
|
|
8027
8084
|
value: searchQuery,
|
|
8028
8085
|
onChange: handleSearchChange,
|
|
8086
|
+
onKeyDown: handleKeyDown,
|
|
8029
8087
|
"$inputColor": searchbarTextColor,
|
|
8030
8088
|
"$placeholderColor": placeholderColor
|
|
8031
|
-
})), React.createElement(OptionContainer,
|
|
8089
|
+
})), React.createElement(OptionContainer, {
|
|
8090
|
+
ref: optionContainerRef
|
|
8091
|
+
}, finalOptions.length > 0 ? finalOptions.map(function (option, id) {
|
|
8032
8092
|
return React.createElement(OptionItem, {
|
|
8033
8093
|
key: option.value,
|
|
8034
8094
|
"$optionBorder": optionBorder,
|
|
8035
|
-
"$isborder": id !== finalOptions.length - 1
|
|
8095
|
+
"$isborder": id !== finalOptions.length - 1,
|
|
8096
|
+
"$isHighlighted": id === highlightedIndex
|
|
8036
8097
|
}, React.createElement(OptionLabel, {
|
|
8037
8098
|
htmlFor: option.value,
|
|
8038
|
-
"$optionColor": optionColor
|
|
8099
|
+
"$optionColor": optionColor,
|
|
8100
|
+
"$isHighlighted": id === highlightedIndex
|
|
8039
8101
|
}, React.createElement("input", {
|
|
8040
8102
|
id: option.value,
|
|
8041
8103
|
type: 'checkbox',
|
|
@@ -8330,6 +8392,7 @@ var MultiSelectDropdown = function MultiSelectDropdown(_ref32) {
|
|
|
8330
8392
|
isOpen = _useState2[0],
|
|
8331
8393
|
setIsOpen = _useState2[1];
|
|
8332
8394
|
var dropdownRef = useRef(null);
|
|
8395
|
+
var dropdownButtonRef = useRef(null);
|
|
8333
8396
|
var toggleDropdown = function toggleDropdown() {
|
|
8334
8397
|
if (disabled) return;
|
|
8335
8398
|
var refToUse = dropdownRef.current;
|
|
@@ -8395,6 +8458,34 @@ var MultiSelectDropdown = function MultiSelectDropdown(_ref32) {
|
|
|
8395
8458
|
return v !== SELECT_ALL_VALUE;
|
|
8396
8459
|
}));
|
|
8397
8460
|
};
|
|
8461
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
8462
|
+
if (disabled) return;
|
|
8463
|
+
switch (e.key) {
|
|
8464
|
+
case 'Enter':
|
|
8465
|
+
case ' ':
|
|
8466
|
+
e.preventDefault();
|
|
8467
|
+
toggleDropdown();
|
|
8468
|
+
break;
|
|
8469
|
+
case 'Escape':
|
|
8470
|
+
if (isOpen) {
|
|
8471
|
+
e.preventDefault();
|
|
8472
|
+
setIsOpen(false);
|
|
8473
|
+
}
|
|
8474
|
+
break;
|
|
8475
|
+
case 'ArrowDown':
|
|
8476
|
+
if (!isOpen) {
|
|
8477
|
+
e.preventDefault();
|
|
8478
|
+
toggleDropdown();
|
|
8479
|
+
}
|
|
8480
|
+
break;
|
|
8481
|
+
case 'ArrowUp':
|
|
8482
|
+
if (!isOpen) {
|
|
8483
|
+
e.preventDefault();
|
|
8484
|
+
toggleDropdown();
|
|
8485
|
+
}
|
|
8486
|
+
break;
|
|
8487
|
+
}
|
|
8488
|
+
};
|
|
8398
8489
|
return React.createElement(Container$2, null, title && React.createElement(TitleText, {
|
|
8399
8490
|
"$titleColor": titleColor || themeColors.vms.text.dark,
|
|
8400
8491
|
"$titleSize": titleSize,
|
|
@@ -8406,7 +8497,10 @@ var MultiSelectDropdown = function MultiSelectDropdown(_ref32) {
|
|
|
8406
8497
|
"$height": height,
|
|
8407
8498
|
"$hasTitle": !!title
|
|
8408
8499
|
}, React.createElement(DropdownButton, {
|
|
8500
|
+
ref: dropdownButtonRef,
|
|
8409
8501
|
onClick: toggleDropdown,
|
|
8502
|
+
onKeyDown: handleKeyDown,
|
|
8503
|
+
tabIndex: disabled ? -1 : 0,
|
|
8410
8504
|
"$height": height,
|
|
8411
8505
|
"$width": width,
|
|
8412
8506
|
"$border": border,
|
|
@@ -8577,8 +8671,9 @@ var DropdownButton$1 = styled.div(_templateObject3$6 || (_templateObject3$6 = _t
|
|
|
8577
8671
|
var Options = styled.div(_templateObject4$5 || (_templateObject4$5 = _taggedTemplateLiteralLoose(["\n color: ", ";\n padding: 5px 10px;\n width: 100%;\n font-size: ", ";\n font-weight: ", ";\n background-color: ", ";\n\n \n &:hover {\n background-color: ", ";\n color: ", ";\n cursor: pointer;\n }\n\n"])), function (_ref14) {
|
|
8578
8672
|
var $optionColor = _ref14.$optionColor,
|
|
8579
8673
|
$optionSelected = _ref14.$optionSelected,
|
|
8674
|
+
$isHighlighted = _ref14.$isHighlighted,
|
|
8580
8675
|
theme = _ref14.theme;
|
|
8581
|
-
return $optionSelected ? theme.vms.text.white : $optionColor || theme.vms.text.medium;
|
|
8676
|
+
return $optionSelected || $isHighlighted ? theme.vms.text.white : $optionColor || theme.vms.text.medium;
|
|
8582
8677
|
}, function (_ref15) {
|
|
8583
8678
|
var $optionFontSize = _ref15.$optionFontSize;
|
|
8584
8679
|
return $optionFontSize || '14px';
|
|
@@ -8588,8 +8683,9 @@ var Options = styled.div(_templateObject4$5 || (_templateObject4$5 = _taggedTemp
|
|
|
8588
8683
|
}, function (_ref17) {
|
|
8589
8684
|
var $optionBackgroundColor = _ref17.$optionBackgroundColor,
|
|
8590
8685
|
$optionSelected = _ref17.$optionSelected,
|
|
8686
|
+
$isHighlighted = _ref17.$isHighlighted,
|
|
8591
8687
|
theme = _ref17.theme;
|
|
8592
|
-
return $optionSelected ? theme.vms["default"].primary : $optionBackgroundColor || theme.vms["default"].tertiary;
|
|
8688
|
+
return $optionSelected ? theme.vms["default"].primary : $isHighlighted ? theme.vms.hover.primary : $optionBackgroundColor || theme.vms["default"].tertiary;
|
|
8593
8689
|
}, function (_ref18) {
|
|
8594
8690
|
var theme = _ref18.theme;
|
|
8595
8691
|
return theme.vms.hover.primary;
|
|
@@ -8627,7 +8723,7 @@ var LabelText$1 = styled.div(_templateObject5$5 || (_templateObject5$5 = _tagged
|
|
|
8627
8723
|
return $disabled ? theme.vms.text.medium : $color || theme.vms.text.medium;
|
|
8628
8724
|
});
|
|
8629
8725
|
var NoOptions = styled(Span)(_templateObject6$5 || (_templateObject6$5 = _taggedTemplateLiteralLoose(["\n display: flex;\n align-items: center;\n height: 100%;\n padding: 12px;\n font-size: 14px;\n font-weight: 400;\n"])));
|
|
8630
|
-
var DropdownMenu$1 = styled.div(_templateObject7$3 || (_templateObject7$3 = _taggedTemplateLiteralLoose(["\n height: auto;\n max-height: 170px;\n border: ", ";\n border-radius: ", ";\n min-width: 100%;\n width: ", ";\n background: ", ";\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n overflow: hidden;\n position: absolute;\n z-index: 2;\n ", "\n ", "\n\n ", "\n"])), function (_ref24) {
|
|
8726
|
+
var DropdownMenu$1 = styled.div(_templateObject7$3 || (_templateObject7$3 = _taggedTemplateLiteralLoose(["\n height: auto;\n max-height: 170px;\n border: ", ";\n border-radius: ", ";\n min-width: 100%;\n width: ", ";\n background: ", ";\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);\n overflow: hidden;\n position: absolute;\n z-index: 2;\n outline: none;\n ", "\n ", "\n\n ", "\n"])), function (_ref24) {
|
|
8631
8727
|
var theme = _ref24.theme;
|
|
8632
8728
|
return "1px solid " + theme.vms.border.light;
|
|
8633
8729
|
}, function (_ref25) {
|
|
@@ -8746,13 +8842,28 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8746
8842
|
var _useState3 = useState(''),
|
|
8747
8843
|
searchTerm = _useState3[0],
|
|
8748
8844
|
setSearchTerm = _useState3[1];
|
|
8845
|
+
var _useState4 = useState(-1),
|
|
8846
|
+
highlightedIndex = _useState4[0],
|
|
8847
|
+
setHighlightedIndex = _useState4[1];
|
|
8848
|
+
var optionsWrapperRef = useRef(null);
|
|
8849
|
+
var dropdownMenuRef = useRef(null);
|
|
8850
|
+
var showSearchBox = searchBox && (options.length > 5 || allowCustomValue);
|
|
8749
8851
|
useEffect(function () {
|
|
8750
8852
|
if (loading) {
|
|
8751
8853
|
setIsOpen(false);
|
|
8752
8854
|
setSearchTerm('');
|
|
8855
|
+
setHighlightedIndex(-1);
|
|
8753
8856
|
}
|
|
8754
8857
|
}, [loading]);
|
|
8755
|
-
|
|
8858
|
+
useEffect(function () {
|
|
8859
|
+
if (isOpen) {
|
|
8860
|
+
if (showSearchBox && searchInputRef.current) {
|
|
8861
|
+
searchInputRef.current.focus();
|
|
8862
|
+
} else if (dropdownMenuRef.current) {
|
|
8863
|
+
dropdownMenuRef.current.focus();
|
|
8864
|
+
}
|
|
8865
|
+
}
|
|
8866
|
+
}, [isOpen, showSearchBox]);
|
|
8756
8867
|
var toggleDropdown = function toggleDropdown() {
|
|
8757
8868
|
var refToUse = (positionRef === null || positionRef === void 0 ? void 0 : positionRef.current) || dropdownRef.current;
|
|
8758
8869
|
if (refToUse) {
|
|
@@ -8772,6 +8883,7 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8772
8883
|
});
|
|
8773
8884
|
if (!isOpen) {
|
|
8774
8885
|
setSearchTerm('');
|
|
8886
|
+
setHighlightedIndex(-1);
|
|
8775
8887
|
}
|
|
8776
8888
|
};
|
|
8777
8889
|
var dropdownRef = useRef(null);
|
|
@@ -8796,6 +8908,7 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8796
8908
|
}
|
|
8797
8909
|
setIsOpen(false);
|
|
8798
8910
|
setSearchTerm('');
|
|
8911
|
+
setHighlightedIndex(-1);
|
|
8799
8912
|
};
|
|
8800
8913
|
var filteredOptions = searchTerm ? options.filter(function (option) {
|
|
8801
8914
|
return option.label.toLowerCase().includes(searchTerm.toLowerCase());
|
|
@@ -8820,6 +8933,7 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8820
8933
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
8821
8934
|
setIsOpen(false);
|
|
8822
8935
|
setSearchTerm('');
|
|
8936
|
+
setHighlightedIndex(-1);
|
|
8823
8937
|
}
|
|
8824
8938
|
};
|
|
8825
8939
|
document.addEventListener('mousedown', handleClickOutside);
|
|
@@ -8827,12 +8941,63 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8827
8941
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
8828
8942
|
};
|
|
8829
8943
|
}, []);
|
|
8944
|
+
useEffect(function () {
|
|
8945
|
+
if (highlightedIndex >= 0 && optionsWrapperRef.current) {
|
|
8946
|
+
var children = optionsWrapperRef.current.children;
|
|
8947
|
+
var offset = isCustomValue ? 1 : 0;
|
|
8948
|
+
var highlightedElement = children[highlightedIndex + offset];
|
|
8949
|
+
if (highlightedElement) {
|
|
8950
|
+
highlightedElement.scrollIntoView({
|
|
8951
|
+
block: 'nearest',
|
|
8952
|
+
behavior: 'smooth'
|
|
8953
|
+
});
|
|
8954
|
+
}
|
|
8955
|
+
}
|
|
8956
|
+
}, [highlightedIndex, isCustomValue]);
|
|
8830
8957
|
var selectedOption = options === null || options === void 0 ? void 0 : options.find(function (option) {
|
|
8831
8958
|
return option.value === value;
|
|
8832
8959
|
});
|
|
8833
8960
|
var displayLabel = (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) || (allowCustomValue && value ? value : '');
|
|
8834
8961
|
var handleSearchChange = function handleSearchChange(e) {
|
|
8835
8962
|
setSearchTerm(e.target.value);
|
|
8963
|
+
setHighlightedIndex(-1);
|
|
8964
|
+
};
|
|
8965
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
8966
|
+
var totalOptions = isCustomValue ? filteredOptions.length + 1 : filteredOptions.length;
|
|
8967
|
+
if (totalOptions === 0) return;
|
|
8968
|
+
switch (e.key) {
|
|
8969
|
+
case 'ArrowDown':
|
|
8970
|
+
e.preventDefault();
|
|
8971
|
+
setHighlightedIndex(function (prev) {
|
|
8972
|
+
var newIndex = prev < totalOptions - 1 ? prev + 1 : prev;
|
|
8973
|
+
return prev === -1 ? 0 : newIndex;
|
|
8974
|
+
});
|
|
8975
|
+
break;
|
|
8976
|
+
case 'ArrowUp':
|
|
8977
|
+
e.preventDefault();
|
|
8978
|
+
setHighlightedIndex(function (prev) {
|
|
8979
|
+
return prev > 0 ? prev - 1 : 0;
|
|
8980
|
+
});
|
|
8981
|
+
break;
|
|
8982
|
+
case 'Enter':
|
|
8983
|
+
e.preventDefault();
|
|
8984
|
+
if (highlightedIndex >= 0) {
|
|
8985
|
+
if (isCustomValue && highlightedIndex === 0) {
|
|
8986
|
+
handleCustomValueSelect();
|
|
8987
|
+
} else {
|
|
8988
|
+
var adjustedIndex = isCustomValue ? highlightedIndex - 1 : highlightedIndex;
|
|
8989
|
+
if (adjustedIndex >= 0 && adjustedIndex < filteredOptions.length) {
|
|
8990
|
+
handleOptionClick(filteredOptions[adjustedIndex].value);
|
|
8991
|
+
}
|
|
8992
|
+
}
|
|
8993
|
+
}
|
|
8994
|
+
break;
|
|
8995
|
+
case 'Escape':
|
|
8996
|
+
setIsOpen(false);
|
|
8997
|
+
setSearchTerm('');
|
|
8998
|
+
setHighlightedIndex(-1);
|
|
8999
|
+
break;
|
|
9000
|
+
}
|
|
8836
9001
|
};
|
|
8837
9002
|
return React.createElement(Container, {
|
|
8838
9003
|
"$padding": padding,
|
|
@@ -8885,6 +9050,9 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8885
9050
|
size: 7,
|
|
8886
9051
|
color: color || themeColors.vms.text.medium
|
|
8887
9052
|
})), isOpen && React.createElement(DropdownMenu$1, {
|
|
9053
|
+
ref: dropdownMenuRef,
|
|
9054
|
+
tabIndex: -1,
|
|
9055
|
+
onKeyDown: !showSearchBox ? handleKeyDown : undefined,
|
|
8888
9056
|
"$width": width,
|
|
8889
9057
|
"$menuBackground": menuBackground,
|
|
8890
9058
|
"$optionsBorderRadius": optionsBorderRadius,
|
|
@@ -8906,13 +9074,17 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8906
9074
|
type: 'text',
|
|
8907
9075
|
value: searchTerm,
|
|
8908
9076
|
onChange: handleSearchChange,
|
|
9077
|
+
onKeyDown: handleKeyDown,
|
|
8909
9078
|
placeholder: placeholderText,
|
|
8910
9079
|
"$inputColor": inputColor,
|
|
8911
9080
|
"$placeholderColor": placeholderColor
|
|
8912
|
-
})), React.createElement(OptionsWrapper,
|
|
9081
|
+
})), React.createElement(OptionsWrapper, {
|
|
9082
|
+
ref: optionsWrapperRef
|
|
9083
|
+
}, isCustomValue && React.createElement(Options, {
|
|
8913
9084
|
"$optionSelected": false,
|
|
9085
|
+
"$isHighlighted": highlightedIndex === 0,
|
|
8914
9086
|
onClick: handleCustomValueSelect
|
|
8915
|
-
}, "Add \"", normalizedSearch, "\""), filteredOptions.length ? filteredOptions.map(function (option) {
|
|
9087
|
+
}, "Add \"", normalizedSearch, "\""), filteredOptions.length ? filteredOptions.map(function (option, index) {
|
|
8916
9088
|
return React.createElement(Options, {
|
|
8917
9089
|
key: option.value,
|
|
8918
9090
|
"$optionColor": optionColor,
|
|
@@ -8922,7 +9094,8 @@ var SelectOption = function SelectOption(_ref37) {
|
|
|
8922
9094
|
onClick: function onClick() {
|
|
8923
9095
|
return handleOptionClick(option.value);
|
|
8924
9096
|
},
|
|
8925
|
-
"$optionSelected": option.value === value || allowCustomValue && option.value === displayLabel
|
|
9097
|
+
"$optionSelected": option.value === value || allowCustomValue && option.value === displayLabel,
|
|
9098
|
+
"$isHighlighted": isCustomValue ? index + 1 === highlightedIndex : index === highlightedIndex
|
|
8926
9099
|
}, option.label);
|
|
8927
9100
|
}) : !isCustomValue && React.createElement(NoOptions, null, NoOptionsText)))));
|
|
8928
9101
|
};
|
|
@@ -9716,12 +9889,14 @@ var OptionContainer$1 = styled.div(_templateObject$h || (_templateObject$h = _ta
|
|
|
9716
9889
|
});
|
|
9717
9890
|
var OptionItem$1 = styled.div(_templateObject2$e || (_templateObject2$e = _taggedTemplateLiteralLoose(["\n color: ", ";\n background-color: ", ";\n border-radius: 8px;\n\n &:hover {\n background-color: ", ";\n color: ", ";\n cursor: pointer;\n }\n"])), function (_ref2) {
|
|
9718
9891
|
var $optionSelected = _ref2.$optionSelected,
|
|
9892
|
+
$isHighlighted = _ref2.$isHighlighted,
|
|
9719
9893
|
theme = _ref2.theme;
|
|
9720
|
-
return $optionSelected ? theme.vms.text.white : theme.vms.text.medium;
|
|
9894
|
+
return $optionSelected || $isHighlighted ? theme.vms.text.white : theme.vms.text.medium;
|
|
9721
9895
|
}, function (_ref3) {
|
|
9722
9896
|
var $optionSelected = _ref3.$optionSelected,
|
|
9897
|
+
$isHighlighted = _ref3.$isHighlighted,
|
|
9723
9898
|
theme = _ref3.theme;
|
|
9724
|
-
return $optionSelected ? theme.vms["default"].primary : theme.vms.text.white;
|
|
9899
|
+
return $optionSelected ? theme.vms["default"].primary : $isHighlighted ? theme.vms.hover.primary : theme.vms.text.white;
|
|
9725
9900
|
}, function (_ref4) {
|
|
9726
9901
|
var theme = _ref4.theme;
|
|
9727
9902
|
return theme.vms.hover.primary;
|
|
@@ -9847,19 +10022,57 @@ var TextFieldWithDropdown = function TextFieldWithDropdown(_ref16) {
|
|
|
9847
10022
|
var _useTranslation = useTranslation(),
|
|
9848
10023
|
t = _useTranslation.t;
|
|
9849
10024
|
var searchBoxRef = useRef(null);
|
|
10025
|
+
var optionsWrapperRef = useRef(null);
|
|
9850
10026
|
var _useState = useState(false),
|
|
9851
10027
|
isSearchBarEnabled = _useState[0],
|
|
9852
10028
|
setIsSearchBarEnabled = _useState[1];
|
|
10029
|
+
var _useState2 = useState(-1),
|
|
10030
|
+
highlightedIndex = _useState2[0],
|
|
10031
|
+
setHighlightedIndex = _useState2[1];
|
|
9853
10032
|
var filteredArray = options.filter(function (item) {
|
|
9854
10033
|
return item.labelText.toLowerCase().includes(internalSearchQuery.toLowerCase().trim());
|
|
9855
10034
|
});
|
|
9856
10035
|
var handleSearchChange = function handleSearchChange(e) {
|
|
9857
10036
|
var value = e.target.value.trimStart();
|
|
9858
10037
|
setInternalSearchQuery(value);
|
|
10038
|
+
setHighlightedIndex(-1);
|
|
10039
|
+
};
|
|
10040
|
+
var handleKeyDown = function handleKeyDown(e) {
|
|
10041
|
+
if (!isSearchBarEnabled || filteredArray.length === 0) return;
|
|
10042
|
+
switch (e.key) {
|
|
10043
|
+
case 'ArrowDown':
|
|
10044
|
+
e.preventDefault();
|
|
10045
|
+
setHighlightedIndex(function (prev) {
|
|
10046
|
+
return prev < filteredArray.length - 1 ? prev + 1 : prev;
|
|
10047
|
+
});
|
|
10048
|
+
break;
|
|
10049
|
+
case 'ArrowUp':
|
|
10050
|
+
e.preventDefault();
|
|
10051
|
+
setHighlightedIndex(function (prev) {
|
|
10052
|
+
return prev > 0 ? prev - 1 : -1;
|
|
10053
|
+
});
|
|
10054
|
+
break;
|
|
10055
|
+
case 'Enter':
|
|
10056
|
+
e.preventDefault();
|
|
10057
|
+
if (highlightedIndex >= 0 && highlightedIndex < filteredArray.length) {
|
|
10058
|
+
var _selectedOption = filteredArray[highlightedIndex];
|
|
10059
|
+
setInternalSearchQuery(_selectedOption.labelText);
|
|
10060
|
+
setSearchQuery(_selectedOption.labelText);
|
|
10061
|
+
setIsSearchBarEnabled(false);
|
|
10062
|
+
setHighlightedIndex(-1);
|
|
10063
|
+
if (onSelect) onSelect(_selectedOption);
|
|
10064
|
+
}
|
|
10065
|
+
break;
|
|
10066
|
+
case 'Escape':
|
|
10067
|
+
setIsSearchBarEnabled(false);
|
|
10068
|
+
setHighlightedIndex(-1);
|
|
10069
|
+
break;
|
|
10070
|
+
}
|
|
9859
10071
|
};
|
|
9860
10072
|
var handleClickOutside = function handleClickOutside(event) {
|
|
9861
10073
|
if (searchBoxRef.current && !searchBoxRef.current.contains(event.target)) {
|
|
9862
10074
|
setIsSearchBarEnabled(false);
|
|
10075
|
+
setHighlightedIndex(-1);
|
|
9863
10076
|
}
|
|
9864
10077
|
};
|
|
9865
10078
|
useEffect(function () {
|
|
@@ -9868,6 +10081,17 @@ var TextFieldWithDropdown = function TextFieldWithDropdown(_ref16) {
|
|
|
9868
10081
|
document.removeEventListener('mousedown', handleClickOutside);
|
|
9869
10082
|
};
|
|
9870
10083
|
}, []);
|
|
10084
|
+
useEffect(function () {
|
|
10085
|
+
if (highlightedIndex >= 0 && optionsWrapperRef.current) {
|
|
10086
|
+
var highlightedElement = optionsWrapperRef.current.children[highlightedIndex];
|
|
10087
|
+
if (highlightedElement) {
|
|
10088
|
+
highlightedElement.scrollIntoView({
|
|
10089
|
+
block: 'nearest',
|
|
10090
|
+
behavior: 'smooth'
|
|
10091
|
+
});
|
|
10092
|
+
}
|
|
10093
|
+
}
|
|
10094
|
+
}, [highlightedIndex]);
|
|
9871
10095
|
return React.createElement(Container, {
|
|
9872
10096
|
"$flexDirection": 'column',
|
|
9873
10097
|
"$gap": '8px',
|
|
@@ -9894,6 +10118,7 @@ var TextFieldWithDropdown = function TextFieldWithDropdown(_ref16) {
|
|
|
9894
10118
|
placeholder: placeholder,
|
|
9895
10119
|
value: internalSearchQuery,
|
|
9896
10120
|
onChange: handleSearchChange,
|
|
10121
|
+
onKeyDown: handleKeyDown,
|
|
9897
10122
|
"$inputColor": searchbarTextColor,
|
|
9898
10123
|
"$placeholderColor": isSearchBarEnabled ? themeColors.vms.text.light : themeColors.vms.text.medium,
|
|
9899
10124
|
disabled: !!searchQuery
|
|
@@ -9913,16 +10138,20 @@ var TextFieldWithDropdown = function TextFieldWithDropdown(_ref16) {
|
|
|
9913
10138
|
"$fontSize": '12px',
|
|
9914
10139
|
"$fontWeight": '400',
|
|
9915
10140
|
"$color": themeColors.vms.text.light
|
|
9916
|
-
}, t('Showing_results') + " (" + filteredArray.length + " of " + (options === null || options === void 0 ? void 0 : options.length) + ")")), React.createElement(OptionsWrapper$1,
|
|
10141
|
+
}, t('Showing_results') + " (" + filteredArray.length + " of " + (options === null || options === void 0 ? void 0 : options.length) + ")")), React.createElement(OptionsWrapper$1, {
|
|
10142
|
+
ref: optionsWrapperRef
|
|
10143
|
+
}, filteredArray.length > 0 ? filteredArray.map(function (option, index) {
|
|
9917
10144
|
return React.createElement(OptionItem$1, {
|
|
9918
10145
|
key: option.value,
|
|
9919
|
-
"$optionSelected": option.value === selectedOption
|
|
10146
|
+
"$optionSelected": option.value === selectedOption,
|
|
10147
|
+
"$isHighlighted": index === highlightedIndex
|
|
9920
10148
|
}, React.createElement(OptionLabel$1, {
|
|
9921
10149
|
htmlFor: option.value,
|
|
9922
10150
|
onClick: function onClick() {
|
|
9923
10151
|
setInternalSearchQuery(option.labelText);
|
|
9924
10152
|
setSearchQuery(option.labelText);
|
|
9925
10153
|
setIsSearchBarEnabled(false);
|
|
10154
|
+
setHighlightedIndex(-1);
|
|
9926
10155
|
if (onSelect) onSelect(option);
|
|
9927
10156
|
}
|
|
9928
10157
|
}, option.labelText));
|