@xqmsg/ui-core 0.15.4 → 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.
@@ -1,7 +1,7 @@
1
1
  import React__default, { useMemo, useCallback, useRef, useEffect, useState, memo, forwardRef, createElement } from 'react';
2
- import { Button as Button$2, Image, Alert as Alert$1, AlertDescription, Box, Flex, 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';
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';
@@ -50,7 +50,9 @@ var Banner = function Banner(_ref) {
50
50
  var variant = _ref.variant,
51
51
  message = _ref.message,
52
52
  buttonText = _ref.buttonText,
53
- onClick = _ref.onClick;
53
+ onClick = _ref.onClick,
54
+ _ref$type = _ref.type,
55
+ type = _ref$type === void 0 ? 'expanded' : _ref$type;
54
56
  var Icon = useMemo(function () {
55
57
  switch (variant) {
56
58
  case 'error':
@@ -87,18 +89,24 @@ var Banner = function Banner(_ref) {
87
89
  }, [variant]);
88
90
  return /*#__PURE__*/React__default.createElement(Alert$1, {
89
91
  variant: variant
90
- }, /*#__PURE__*/React__default.createElement(AlertDescription, null, /*#__PURE__*/React__default.createElement(Box, {
91
- pb: "8px"
92
- }, Icon), message, onClick && buttonText && /*#__PURE__*/React__default.createElement(Flex, {
93
- pt: "8px",
94
- justifyContent: "flex-end"
92
+ }, /*#__PURE__*/React__default.createElement(AlertDescription, null, /*#__PURE__*/React__default.createElement(Flex, {
93
+ flexDirection: type === 'condensed' ? 'row' : 'column',
94
+ alignItems: type === 'condensed' ? 'center' : ''
95
+ }, /*#__PURE__*/React__default.createElement(Box, {
96
+ pr: "8px"
97
+ }, Icon), /*#__PURE__*/React__default.createElement(Box, {
98
+ pt: type === 'condensed' ? 0 : '8px'
99
+ }, " ", message), onClick && buttonText && /*#__PURE__*/React__default.createElement(Flex, {
100
+ ml: type === 'condensed' ? 'auto' : '',
101
+ pt: type === 'condensed' ? 0 : '8px',
102
+ justifyContent: type === 'condensed' ? 'flex-end' : 'flex-end'
95
103
  }, /*#__PURE__*/React__default.createElement(Button, {
96
104
  variant: "secondary",
97
105
  onClick: onClick,
98
106
  text: buttonText,
99
107
  width: "variable",
100
108
  ariaLabel: "banner button"
101
- }))));
109
+ })))));
102
110
  };
103
111
 
104
112
  var blue = {
@@ -366,12 +374,12 @@ var SpinnerButton = function SpinnerButton(_ref) {
366
374
  type = _ref.type,
367
375
  ariaLabel = _ref.ariaLabel,
368
376
  _ref$variant = _ref.variant,
369
- variant = _ref$variant === void 0 ? 'solid' : _ref$variant,
377
+ variant = _ref$variant === void 0 ? 'primary' : _ref$variant,
370
378
  disabled = _ref.disabled,
371
379
  className = _ref.className;
372
380
  return /*#__PURE__*/React__default.createElement(Button$2, {
373
381
  spinner: /*#__PURE__*/React__default.createElement(Spinner, {
374
- size: 'md'
382
+ size: 'sm'
375
383
  }),
376
384
  isLoading: isLoading,
377
385
  onClick: onClick,
@@ -498,7 +506,8 @@ var Dropdown = function Dropdown(_ref) {
498
506
  var onSelectItem = _ref.onSelectItem,
499
507
  options = _ref.options,
500
508
  dropdownRef = _ref.dropdownRef,
501
- position = _ref.position;
509
+ position = _ref.position,
510
+ optionIndex = _ref.optionIndex;
502
511
  var DropdownContent = useMemo(function () {
503
512
  return options.map(function (option, idx) {
504
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, {
@@ -525,18 +534,19 @@ var Dropdown = function Dropdown(_ref) {
525
534
  px: "8px",
526
535
  py: "4px",
527
536
  width: "100%",
528
- color: colors.label.primary.light,
537
+ color: optionIndex === idx ? colors.label.primary.dark : colors.label.primary.light,
529
538
  _hover: {
530
539
  color: colors.label.primary.dark,
531
540
  bg: colors.fill.action,
532
541
  borderRadius: '4px',
533
542
  width: '100%'
534
543
  },
535
- bg: "inherit",
536
- whiteSpace: "nowrap"
544
+ bg: optionIndex === idx ? colors.fill.action : 'inherit',
545
+ whiteSpace: "nowrap",
546
+ id: option.value
537
547
  }, option.label));
538
548
  });
539
- }, [onSelectItem, options]);
549
+ }, [onSelectItem, optionIndex, options]);
540
550
  return /*#__PURE__*/React__default.createElement(Flex, {
541
551
  flexDirection: "column",
542
552
  ref: dropdownRef,
@@ -595,7 +605,7 @@ function useOnClickOutside(ref, handler) {
595
605
  [ref, handler]);
596
606
  }
597
607
 
598
- var _excluded$1 = ["isRequired", "options", "name", "setValue", "handleOnChange", "value"];
608
+ var _excluded$1 = ["isRequired", "options", "name", "setValue", "handleOnChange", "disabled", "value"];
599
609
  /**
600
610
  * A functional React component utilized to render the `StackedSelect` component.
601
611
  */
@@ -608,6 +618,7 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
608
618
  name = _ref2.name,
609
619
  setValue = _ref2.setValue,
610
620
  handleOnChange = _ref2.handleOnChange,
621
+ disabled = _ref2.disabled,
611
622
  value = _ref2.value,
612
623
  props = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
613
624
 
@@ -624,9 +635,21 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
624
635
  selectedOption = _useState2[0],
625
636
  setSelectedOption = _useState2[1];
626
637
 
627
- var _useState3 = useState('top'),
628
- position = _useState3[0],
629
- setPosition = _useState3[1];
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];
630
653
 
631
654
  var boundingClientRect = (_dropdownRef$current = dropdownRef.current) == null ? void 0 : _dropdownRef$current.getBoundingClientRect();
632
655
  useEffect(function () {
@@ -661,6 +684,92 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
661
684
  setIsFocussed(false);
662
685
  };
663
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
+
664
773
  return /*#__PURE__*/React__default.createElement(Box, {
665
774
  ref: dropdownRef,
666
775
  position: "relative"
@@ -676,29 +785,16 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
676
785
  fontSize: "13px",
677
786
  textShadow: "0 0 0 " + colors.label.primary.light,
678
787
  value: selectedOption,
788
+ disabled: disabled,
679
789
  autoComplete: "off",
680
- onKeyDown: function onKeyDown(e) {
681
- if (isFocussed) {
682
- var _dropdownMenuRef$curr;
683
-
684
- if (e.key === 'Tab') {
685
- return setIsFocussed(false);
686
- }
687
-
688
- var idx = options.findIndex(function (option) {
689
- return option.label[0].toLocaleLowerCase() === e.key;
690
- });
691
- console.log(idx);
692
- (_dropdownMenuRef$curr = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr.scrollTo({
693
- top: idx * 27,
694
- behavior: 'smooth'
695
- });
696
- }
697
- }
790
+ onChange: function onChange(e) {
791
+ return update(debouncedSearchValue.concat(e.target.value));
792
+ },
793
+ onKeyDown: handleOnKeyDown
698
794
  })), /*#__PURE__*/React__default.createElement(InputRightElement, {
699
- cursor: "pointer",
795
+ cursor: disabled ? 'not-allowed' : 'pointer',
700
796
  onClick: function onClick() {
701
- return setIsFocussed(!isFocussed);
797
+ return !disabled && setIsFocussed(!isFocussed);
702
798
  }
703
799
  }, /*#__PURE__*/React__default.createElement(Image, {
704
800
  src: SubtractIcon,
@@ -710,7 +806,8 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
710
806
  onSelectItem: function onSelectItem(option) {
711
807
  return handleOnSelectItem(option);
712
808
  },
713
- options: options
809
+ options: options,
810
+ optionIndex: optionIndex
714
811
  }));
715
812
  });
716
813
 
@@ -816,10 +913,26 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
816
913
  shouldSideScroll = _useState4[0],
817
914
  setShouldSideScroll = _useState4[1];
818
915
 
819
- var _useState5 = useState('top'),
820
- position = _useState5[0],
821
- setPosition = _useState5[1];
916
+ var _useState5 = useState(null),
917
+ optionIndex = _useState5[0],
918
+ setOptionIndex = _useState5[1];
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];
822
931
 
932
+ console.log({
933
+ searchValue: searchValue,
934
+ debouncedSearchValue: debouncedSearchValue
935
+ });
823
936
  var boundingClientRect = (_dropdownRef$current = dropdownRef.current) == null ? void 0 : _dropdownRef$current.getBoundingClientRect();
824
937
  useEffect(function () {
825
938
  if (window.innerHeight - ((boundingClientRect == null ? void 0 : boundingClientRect.y) + 240) >= 0) {
@@ -899,26 +1012,89 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
899
1012
  });
900
1013
  };
901
1014
 
902
- return /*#__PURE__*/React__default.createElement(Box, {
903
- ref: dropdownRef,
904
- position: "relative",
905
- onKeyDown: function onKeyDown(e) {
906
- if (isFocussed) {
907
- var _dropdownMenuRef$curr;
1015
+ var handleOnKeyDown = function handleOnKeyDown(e) {
1016
+ var initialOptionIndex = options[0].value === 'section_header' ? 1 : 0;
908
1017
 
909
- if (e.key === 'Tab') {
910
- return setIsFocussed(false);
911
- }
1018
+ if (!isFocussed && (e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
1019
+ setIsFocussed(true);
1020
+ return setOptionIndex(initialOptionIndex);
1021
+ }
1022
+
1023
+ if (isFocussed) {
1024
+ if (optionIndex === null && (e.key === 'Enter' || e.key === 'ArrowUp' || e.key === 'ArrowDown')) {
1025
+ return setOptionIndex(initialOptionIndex);
1026
+ }
912
1027
 
913
- var idx = options.findIndex(function (option) {
914
- return option.label[0].toLocaleLowerCase() === e.key;
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'
915
1036
  });
916
- (_dropdownMenuRef$curr = dropdownMenuRef.current) == null ? void 0 : _dropdownMenuRef$curr.scrollTo({
917
- top: idx * 27,
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,
918
1047
  behavior: 'smooth'
919
1048
  });
920
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('');
921
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
922
1098
  }, /*#__PURE__*/React__default.createElement(Flex, {
923
1099
  fontSize: "13px",
924
1100
  h: "26px",
@@ -1001,7 +1177,8 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
1001
1177
  return handleChange(option);
1002
1178
  },
1003
1179
  options: localOptions,
1004
- position: position
1180
+ position: position,
1181
+ optionIndex: optionIndex
1005
1182
  }));
1006
1183
  });
1007
1184
 
@@ -1805,7 +1982,7 @@ var EmptyTable = function EmptyTable() {
1805
1982
  return i + 1;
1806
1983
  }).map(function (i) {
1807
1984
  return /*#__PURE__*/React__default.createElement(Tr, null, /*#__PURE__*/React__default.createElement(Td, {
1808
- height: "23px",
1985
+ height: "26px",
1809
1986
  opacity: getOpacity(i)
1810
1987
  }));
1811
1988
  })));
@@ -2067,6 +2244,7 @@ var baseStyle$2 = /*#__PURE__*/defineStyle({
2067
2244
  fontSize: '13px',
2068
2245
  bg: colors.fill.action,
2069
2246
  color: colors.label.primary.dark,
2247
+ h: '26px',
2070
2248
  border: 'none',
2071
2249
  px: '8px',
2072
2250
  py: '4px',
@@ -2710,8 +2888,12 @@ var baseStyle$c = {
2710
2888
  },
2711
2889
  tr: {
2712
2890
  fontSize: '13px',
2891
+ h: '26px',
2892
+ lineHeight: 'normal',
2713
2893
  _odd: {
2714
2894
  td: {
2895
+ h: '26px ',
2896
+ lineHeight: 'normal',
2715
2897
  bg: colors.fill.light.tertiary,
2716
2898
  _first: {
2717
2899
  borderTopLeftRadius: 'md',
@@ -2725,7 +2907,9 @@ var baseStyle$c = {
2725
2907
  }
2726
2908
  },
2727
2909
  td: {
2728
- padding: '5px 8px !important'
2910
+ padding: '5px 8px !important',
2911
+ lineHeight: 'normal',
2912
+ h: '26px'
2729
2913
  }
2730
2914
  };
2731
2915
  var Table$1 = {
@@ -2996,7 +3180,7 @@ var baseStyle$f = {
2996
3180
  fontWeight: typography.fontWeights.normal,
2997
3181
  fontFamily: typography.fonts.base,
2998
3182
  fontSize: typography.fontSizes.sm,
2999
- lineHeight: typography.lineHeights.base,
3183
+ lineHeight: typography.lineHeights.normal,
3000
3184
  letterSpacing: typography.letterSpacings.wide
3001
3185
  };
3002
3186
 
@@ -3044,7 +3228,8 @@ var styles = {
3044
3228
  overflow: {
3045
3229
  base: 'visible',
3046
3230
  lg: 'hidden'
3047
- }
3231
+ },
3232
+ lineHeight: 'normal'
3048
3233
  },
3049
3234
  '*, *::before, *::after': {
3050
3235
  borderColor: 'gray.200'