@xqmsg/ui-core 0.16.0 → 0.16.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/components/input/components/dropdown/index.d.ts +1 -0
- package/dist/ui-core.cjs.development.js +211 -44
- package/dist/ui-core.cjs.development.js.map +1 -1
- package/dist/ui-core.cjs.production.min.js +1 -1
- package/dist/ui-core.cjs.production.min.js.map +1 -1
- package/dist/ui-core.esm.js +212 -45
- package/dist/ui-core.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/input/Input.stories.tsx +0 -1
- package/src/components/input/StackedMultiSelect/index.tsx +113 -21
- package/src/components/input/StackedSelect/index.tsx +117 -18
- package/src/components/input/components/dropdown/index.tsx +10 -3
package/dist/ui-core.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React__default, { useMemo, useCallback, useRef, useEffect, useState, memo, forwardRef, createElement } from 'react';
|
|
2
2
|
import { Button as Button$2, Image, Alert as Alert$1, AlertDescription, Flex, Box, Text as Text$2, Icon as Icon$1, Spinner, Checkbox, Input as Input$2, InputGroup, RadioGroup, Radio, InputRightElement, Textarea as Textarea$1, useOutsideClick, Switch as Switch$1, FormLabel as FormLabel$1, FormControl, FormErrorMessage, FormHelperText, SimpleGrid, useMediaQuery, Grid, GridItem, IconButton, Collapse, Table as Table$2, Tbody, Tr, Td, TableContainer, Thead, Th, Tabs as Tabs$1, TabList, Tab, extendTheme } from '@chakra-ui/react';
|
|
3
3
|
import { FormProvider, useWatch, Controller } from 'react-hook-form';
|
|
4
|
-
import { truncate } from 'lodash-es';
|
|
4
|
+
import { debounce, truncate } from 'lodash-es';
|
|
5
5
|
import { CloseIcon, HamburgerIcon } from '@chakra-ui/icons';
|
|
6
6
|
import { HiOutlineRefresh } from 'react-icons/hi';
|
|
7
7
|
import { ChakraProvider } from '@chakra-ui/provider';
|
|
@@ -506,7 +506,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
506
506
|
var onSelectItem = _ref.onSelectItem,
|
|
507
507
|
options = _ref.options,
|
|
508
508
|
dropdownRef = _ref.dropdownRef,
|
|
509
|
-
position = _ref.position
|
|
509
|
+
position = _ref.position,
|
|
510
|
+
optionIndex = _ref.optionIndex;
|
|
510
511
|
var DropdownContent = useMemo(function () {
|
|
511
512
|
return options.map(function (option, idx) {
|
|
512
513
|
return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, option.value === 'section_header' && options[idx + 1] && options[idx + 1].value !== 'section_header' && /*#__PURE__*/React__default.createElement(Box, {
|
|
@@ -533,18 +534,19 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
533
534
|
px: "8px",
|
|
534
535
|
py: "4px",
|
|
535
536
|
width: "100%",
|
|
536
|
-
color: colors.label.primary.light,
|
|
537
|
+
color: optionIndex === idx ? colors.label.primary.dark : colors.label.primary.light,
|
|
537
538
|
_hover: {
|
|
538
539
|
color: colors.label.primary.dark,
|
|
539
540
|
bg: colors.fill.action,
|
|
540
541
|
borderRadius: '4px',
|
|
541
542
|
width: '100%'
|
|
542
543
|
},
|
|
543
|
-
bg:
|
|
544
|
-
whiteSpace: "nowrap"
|
|
544
|
+
bg: optionIndex === idx ? colors.fill.action : 'inherit',
|
|
545
|
+
whiteSpace: "nowrap",
|
|
546
|
+
id: option.value
|
|
545
547
|
}, option.label));
|
|
546
548
|
});
|
|
547
|
-
}, [onSelectItem, options]);
|
|
549
|
+
}, [onSelectItem, optionIndex, options]);
|
|
548
550
|
return /*#__PURE__*/React__default.createElement(Flex, {
|
|
549
551
|
flexDirection: "column",
|
|
550
552
|
ref: dropdownRef,
|
|
@@ -633,9 +635,21 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
|
|
|
633
635
|
selectedOption = _useState2[0],
|
|
634
636
|
setSelectedOption = _useState2[1];
|
|
635
637
|
|
|
636
|
-
var _useState3 = useState(
|
|
637
|
-
|
|
638
|
-
|
|
638
|
+
var _useState3 = useState(null),
|
|
639
|
+
optionIndex = _useState3[0],
|
|
640
|
+
setOptionIndex = _useState3[1];
|
|
641
|
+
|
|
642
|
+
var _useState4 = useState('top'),
|
|
643
|
+
position = _useState4[0],
|
|
644
|
+
setPosition = _useState4[1];
|
|
645
|
+
|
|
646
|
+
var _useState5 = useState(''),
|
|
647
|
+
searchValue = _useState5[0],
|
|
648
|
+
setSearchValue = _useState5[1];
|
|
649
|
+
|
|
650
|
+
var _useState6 = useState(''),
|
|
651
|
+
debouncedSearchValue = _useState6[0],
|
|
652
|
+
setDebouncedSearchValue = _useState6[1];
|
|
639
653
|
|
|
640
654
|
var boundingClientRect = (_dropdownRef$current = dropdownRef.current) == null ? void 0 : _dropdownRef$current.getBoundingClientRect();
|
|
641
655
|
useEffect(function () {
|
|
@@ -670,6 +684,92 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
|
|
|
670
684
|
setIsFocussed(false);
|
|
671
685
|
};
|
|
672
686
|
|
|
687
|
+
var handleOnKeyDown = function handleOnKeyDown(e) {
|
|
688
|
+
var initialOptionIndex = options[0].value === 'section_header' ? 1 : 0;
|
|
689
|
+
|
|
690
|
+
if (!isFocussed && (e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
|
|
691
|
+
setIsFocussed(true);
|
|
692
|
+
return setOptionIndex(initialOptionIndex);
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
if (isFocussed) {
|
|
696
|
+
if (optionIndex === null && (e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
|
|
697
|
+
return setOptionIndex(initialOptionIndex);
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
if (e.key === 'ArrowUp' && optionIndex !== null && optionIndex > 0) {
|
|
701
|
+
var _dropdownMenuRef$curr;
|
|
702
|
+
|
|
703
|
+
var incrementValue = options[optionIndex - 1] && options[optionIndex - 1].value === 'section_header' ? 2 : 1;
|
|
704
|
+
setOptionIndex(optionIndex - incrementValue);
|
|
705
|
+
return (_dropdownMenuRef$curr = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr.scrollTo({
|
|
706
|
+
top: optionIndex * 24,
|
|
707
|
+
behavior: 'smooth'
|
|
708
|
+
});
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if (e.key === 'ArrowDown' && optionIndex !== null && optionIndex < options.length) {
|
|
712
|
+
var _dropdownMenuRef$curr2;
|
|
713
|
+
|
|
714
|
+
var _incrementValue = options[optionIndex + 1] && options[optionIndex + 1].value === 'section_header' ? 2 : 1;
|
|
715
|
+
|
|
716
|
+
setOptionIndex(optionIndex + _incrementValue);
|
|
717
|
+
return (_dropdownMenuRef$curr2 = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr2.scrollTo({
|
|
718
|
+
top: optionIndex * 24,
|
|
719
|
+
behavior: 'smooth'
|
|
720
|
+
});
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
if (e.key === 'Enter' && optionIndex !== null) {
|
|
724
|
+
var option = options.find(function (_, idx) {
|
|
725
|
+
return optionIndex === idx;
|
|
726
|
+
});
|
|
727
|
+
if (!option) return;
|
|
728
|
+
|
|
729
|
+
if (handleOnChange) {
|
|
730
|
+
handleOnChange(option.value);
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
setSelectedOption(option == null ? void 0 : option.label);
|
|
734
|
+
setValue(name, option.value, {
|
|
735
|
+
shouldDirty: true,
|
|
736
|
+
shouldValidate: true
|
|
737
|
+
});
|
|
738
|
+
return setIsFocussed(false);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
if (e.key === 'Tab') {
|
|
742
|
+
return setIsFocussed(false);
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
|
|
747
|
+
useEffect(function () {
|
|
748
|
+
if (searchValue.length) {
|
|
749
|
+
var _dropdownMenuRef$curr3;
|
|
750
|
+
|
|
751
|
+
var idx = options.findIndex(function (option) {
|
|
752
|
+
return option.label.substring(0, searchValue.length).toLowerCase() === searchValue.toLowerCase();
|
|
753
|
+
});
|
|
754
|
+
(_dropdownMenuRef$curr3 = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr3.scrollTo({
|
|
755
|
+
top: idx * 24,
|
|
756
|
+
behavior: 'smooth'
|
|
757
|
+
});
|
|
758
|
+
setSearchValue('');
|
|
759
|
+
setDebouncedSearchValue('');
|
|
760
|
+
}
|
|
761
|
+
}, [options, searchValue]);
|
|
762
|
+
var updateSearchValue = useMemo(function () {
|
|
763
|
+
return debounce(function (val) {
|
|
764
|
+
setSearchValue(val);
|
|
765
|
+
}, 1000);
|
|
766
|
+
}, []);
|
|
767
|
+
|
|
768
|
+
var update = function update(value) {
|
|
769
|
+
updateSearchValue(value);
|
|
770
|
+
setDebouncedSearchValue(value);
|
|
771
|
+
};
|
|
772
|
+
|
|
673
773
|
return /*#__PURE__*/React__default.createElement(Box, {
|
|
674
774
|
ref: dropdownRef,
|
|
675
775
|
position: "relative"
|
|
@@ -687,24 +787,10 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
|
|
|
687
787
|
value: selectedOption,
|
|
688
788
|
disabled: disabled,
|
|
689
789
|
autoComplete: "off",
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
if (e.key === 'Tab') {
|
|
695
|
-
return setIsFocussed(false);
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
var idx = options.findIndex(function (option) {
|
|
699
|
-
return option.label[0].toLocaleLowerCase() === e.key;
|
|
700
|
-
});
|
|
701
|
-
console.log(idx);
|
|
702
|
-
(_dropdownMenuRef$curr = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr.scrollTo({
|
|
703
|
-
top: idx * 27,
|
|
704
|
-
behavior: 'smooth'
|
|
705
|
-
});
|
|
706
|
-
}
|
|
707
|
-
}
|
|
790
|
+
onChange: function onChange(e) {
|
|
791
|
+
return update(debouncedSearchValue.concat(e.target.value));
|
|
792
|
+
},
|
|
793
|
+
onKeyDown: handleOnKeyDown
|
|
708
794
|
})), /*#__PURE__*/React__default.createElement(InputRightElement, {
|
|
709
795
|
cursor: disabled ? 'not-allowed' : 'pointer',
|
|
710
796
|
onClick: function onClick() {
|
|
@@ -720,7 +806,8 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
|
|
|
720
806
|
onSelectItem: function onSelectItem(option) {
|
|
721
807
|
return handleOnSelectItem(option);
|
|
722
808
|
},
|
|
723
|
-
options: options
|
|
809
|
+
options: options,
|
|
810
|
+
optionIndex: optionIndex
|
|
724
811
|
}));
|
|
725
812
|
});
|
|
726
813
|
|
|
@@ -826,10 +913,26 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
826
913
|
shouldSideScroll = _useState4[0],
|
|
827
914
|
setShouldSideScroll = _useState4[1];
|
|
828
915
|
|
|
829
|
-
var _useState5 = useState(
|
|
830
|
-
|
|
831
|
-
|
|
916
|
+
var _useState5 = useState(null),
|
|
917
|
+
optionIndex = _useState5[0],
|
|
918
|
+
setOptionIndex = _useState5[1];
|
|
832
919
|
|
|
920
|
+
var _useState6 = useState('top'),
|
|
921
|
+
position = _useState6[0],
|
|
922
|
+
setPosition = _useState6[1];
|
|
923
|
+
|
|
924
|
+
var _useState7 = useState(''),
|
|
925
|
+
searchValue = _useState7[0],
|
|
926
|
+
setSearchValue = _useState7[1];
|
|
927
|
+
|
|
928
|
+
var _useState8 = useState(''),
|
|
929
|
+
debouncedSearchValue = _useState8[0],
|
|
930
|
+
setDebouncedSearchValue = _useState8[1];
|
|
931
|
+
|
|
932
|
+
console.log({
|
|
933
|
+
searchValue: searchValue,
|
|
934
|
+
debouncedSearchValue: debouncedSearchValue
|
|
935
|
+
});
|
|
833
936
|
var boundingClientRect = (_dropdownRef$current = dropdownRef.current) == null ? void 0 : _dropdownRef$current.getBoundingClientRect();
|
|
834
937
|
useEffect(function () {
|
|
835
938
|
if (window.innerHeight - ((boundingClientRect == null ? void 0 : boundingClientRect.y) + 240) >= 0) {
|
|
@@ -909,26 +1012,89 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
909
1012
|
});
|
|
910
1013
|
};
|
|
911
1014
|
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
position: "relative",
|
|
915
|
-
onKeyDown: function onKeyDown(e) {
|
|
916
|
-
if (isFocussed) {
|
|
917
|
-
var _dropdownMenuRef$curr;
|
|
1015
|
+
var handleOnKeyDown = function handleOnKeyDown(e) {
|
|
1016
|
+
var initialOptionIndex = options[0].value === 'section_header' ? 1 : 0;
|
|
918
1017
|
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
1018
|
+
if (!isFocussed && (e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
|
|
1019
|
+
setIsFocussed(true);
|
|
1020
|
+
return setOptionIndex(initialOptionIndex);
|
|
1021
|
+
}
|
|
922
1022
|
|
|
923
|
-
|
|
924
|
-
|
|
1023
|
+
if (isFocussed) {
|
|
1024
|
+
if (optionIndex === null && (e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
|
|
1025
|
+
return setOptionIndex(initialOptionIndex);
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
if (e.key === 'ArrowUp' && optionIndex !== null && optionIndex > 0) {
|
|
1029
|
+
var _dropdownMenuRef$curr;
|
|
1030
|
+
|
|
1031
|
+
var incrementValue = localOptions[optionIndex - 1] && localOptions[optionIndex - 1].value === 'section_header' ? 2 : 1;
|
|
1032
|
+
setOptionIndex(optionIndex - incrementValue);
|
|
1033
|
+
return (_dropdownMenuRef$curr = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr.scrollTo({
|
|
1034
|
+
top: optionIndex * 24,
|
|
1035
|
+
behavior: 'smooth'
|
|
925
1036
|
});
|
|
926
|
-
|
|
927
|
-
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
if (e.key === 'ArrowDown' && optionIndex !== null && optionIndex < localOptions.length) {
|
|
1040
|
+
var _dropdownMenuRef$curr2;
|
|
1041
|
+
|
|
1042
|
+
var _incrementValue = localOptions[optionIndex + 1] && localOptions[optionIndex + 1].value === 'section_header' ? 2 : 1;
|
|
1043
|
+
|
|
1044
|
+
setOptionIndex(optionIndex + _incrementValue);
|
|
1045
|
+
return (_dropdownMenuRef$curr2 = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr2.scrollTo({
|
|
1046
|
+
top: optionIndex * 24,
|
|
928
1047
|
behavior: 'smooth'
|
|
929
1048
|
});
|
|
930
1049
|
}
|
|
1050
|
+
|
|
1051
|
+
if (e.key === 'Enter' && optionIndex !== null) {
|
|
1052
|
+
var option = localOptions.find(function (_, idx) {
|
|
1053
|
+
return optionIndex === idx;
|
|
1054
|
+
});
|
|
1055
|
+
if (!option) return;
|
|
1056
|
+
handleChange(option);
|
|
1057
|
+
return setIsFocussed(false);
|
|
1058
|
+
}
|
|
1059
|
+
|
|
1060
|
+
if (e.key === 'Tab') {
|
|
1061
|
+
return setIsFocussed(false);
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
return update(debouncedSearchValue.concat(e.key));
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
|
|
1068
|
+
useEffect(function () {
|
|
1069
|
+
if (searchValue.length) {
|
|
1070
|
+
var _dropdownMenuRef$curr3;
|
|
1071
|
+
|
|
1072
|
+
var idx = options.findIndex(function (option) {
|
|
1073
|
+
return option.label.substring(0, searchValue.length).toLowerCase() === searchValue.toLowerCase();
|
|
1074
|
+
});
|
|
1075
|
+
(_dropdownMenuRef$curr3 = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr3.scrollTo({
|
|
1076
|
+
top: idx * 24,
|
|
1077
|
+
behavior: 'smooth'
|
|
1078
|
+
});
|
|
1079
|
+
setSearchValue('');
|
|
1080
|
+
setDebouncedSearchValue('');
|
|
931
1081
|
}
|
|
1082
|
+
}, [options, searchValue]);
|
|
1083
|
+
var updateSearchValue = useMemo(function () {
|
|
1084
|
+
return debounce(function (val) {
|
|
1085
|
+
setSearchValue(val);
|
|
1086
|
+
}, 1000);
|
|
1087
|
+
}, []);
|
|
1088
|
+
|
|
1089
|
+
var update = function update(value) {
|
|
1090
|
+
updateSearchValue(value);
|
|
1091
|
+
setDebouncedSearchValue(value);
|
|
1092
|
+
};
|
|
1093
|
+
|
|
1094
|
+
return /*#__PURE__*/React__default.createElement(Box, {
|
|
1095
|
+
ref: dropdownRef,
|
|
1096
|
+
position: "relative",
|
|
1097
|
+
onKeyDown: handleOnKeyDown
|
|
932
1098
|
}, /*#__PURE__*/React__default.createElement(Flex, {
|
|
933
1099
|
fontSize: "13px",
|
|
934
1100
|
h: "26px",
|
|
@@ -1011,7 +1177,8 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
1011
1177
|
return handleChange(option);
|
|
1012
1178
|
},
|
|
1013
1179
|
options: localOptions,
|
|
1014
|
-
position: position
|
|
1180
|
+
position: position,
|
|
1181
|
+
optionIndex: optionIndex
|
|
1015
1182
|
}));
|
|
1016
1183
|
});
|
|
1017
1184
|
|