@xqmsg/ui-core 0.14.0 → 0.14.2

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,8 @@
1
- import React__default, { useMemo, useCallback, useRef, useState, useEffect } from 'react';
1
+ import React__default, { useMemo, useCallback, useRef, useEffect, useState, memo, forwardRef, createElement } from 'react';
2
2
  import { Image, Alert as Alert$1, AlertDescription, Box, Flex, Button as Button$2, Text as Text$2, Icon as Icon$1, Spinner, InputGroup, Checkbox, Input as Input$2, RadioGroup, Radio, useOutsideClick, InputRightElement, Textarea as Textarea$1, Switch as Switch$1, FormLabel as FormLabel$1, FormControl, FormErrorMessage, FormHelperText, SimpleGrid, useMediaQuery, Grid, GridItem, IconButton, Collapse, TableContainer, Table as Table$2, Thead, Tr, Th, Tbody, Td, TableCaption, Tabs as Tabs$1, TabList, Tab, extendTheme, ChakraProvider } from '@chakra-ui/react';
3
3
  import { FormProvider, useWatch, Controller } from 'react-hook-form';
4
- import { CloseIcon as CloseIcon$1, HamburgerIcon } from '@chakra-ui/icons';
4
+ import { truncate } from 'lodash-es';
5
+ import { CloseIcon, HamburgerIcon } from '@chakra-ui/icons';
5
6
  import { HiOutlineRefresh } from 'react-icons/hi';
6
7
  import { createBreakpoints, transparentize, mode, getColor } from '@chakra-ui/theme-tools';
7
8
  import { defineStyle } from '@chakra-ui/system';
@@ -503,7 +504,8 @@ var Dropdown = function Dropdown(_ref) {
503
504
  color: colors.label.secondary.light,
504
505
  fontSize: "13px",
505
506
  fontWeight: "bold",
506
- px: "8px"
507
+ px: "8px",
508
+ bg: "inherit"
507
509
  }, idx > 0 && /*#__PURE__*/React__default.createElement(Box, {
508
510
  my: "3px",
509
511
  borderTop: "2px solid",
@@ -523,14 +525,18 @@ var Dropdown = function Dropdown(_ref) {
523
525
  color: colors.label.primary.dark,
524
526
  bg: colors.fill.action,
525
527
  borderRadius: '4px'
526
- }
528
+ },
529
+ bg: "inherit"
527
530
  }, option.label));
528
531
  });
529
532
  }, [onSelectItem, options]);
530
533
  return /*#__PURE__*/React__default.createElement(Box, {
531
534
  bg: colors.fill.light.quaternary,
532
- backdropFilter: "blur(64px)",
535
+ backdropFilter: "auto",
536
+ backdropBlur: "64px",
533
537
  borderRadius: "4px",
538
+ border: "0.25px solid",
539
+ borderColor: colors.fill.light.tertiary,
534
540
  mt: "3px",
535
541
  maxH: "320px",
536
542
  overflowY: "auto",
@@ -538,11 +544,18 @@ var Dropdown = function Dropdown(_ref) {
538
544
  py: "4px",
539
545
  position: "absolute",
540
546
  width: "100%",
541
- zIndex: "100"
547
+ zIndex: 100
542
548
  }, DropdownContent);
543
549
  };
544
550
 
545
- var _excluded$1 = ["isRequired", "options", "name", "setValue", "handleOnChange", "defaultValue"];
551
+ var useDidMountEffect = function useDidMountEffect(func, deps) {
552
+ var didMount = useRef(false);
553
+ useEffect(function () {
554
+ if (didMount.current) func();else didMount.current = true; // eslint-disable-next-line
555
+ }, deps);
556
+ };
557
+
558
+ var _excluded$1 = ["isRequired", "options", "name", "setValue", "handleOnChange", "value"];
546
559
  /**
547
560
  * A functional React component utilized to render the `StackedSelect` component.
548
561
  */
@@ -555,7 +568,7 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
555
568
  name = _ref2.name,
556
569
  setValue = _ref2.setValue,
557
570
  handleOnChange = _ref2.handleOnChange,
558
- defaultValue = _ref2.defaultValue,
571
+ value = _ref2.value,
559
572
  props = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
560
573
 
561
574
  var dropdownRef = useRef(null);
@@ -565,11 +578,18 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
565
578
  setIsFocussed = _useState[1];
566
579
 
567
580
  var _useState2 = useState((_options$find$label = (_options$find = options.find(function (option) {
568
- return option.value === defaultValue;
581
+ return option.value === value;
569
582
  })) == null ? void 0 : _options$find.label) != null ? _options$find$label : ''),
570
583
  selectedOption = _useState2[0],
571
584
  setSelectedOption = _useState2[1];
572
585
 
586
+ useDidMountEffect(function () {
587
+ var _options$find$label2, _options$find2;
588
+
589
+ setSelectedOption((_options$find$label2 = (_options$find2 = options.find(function (option) {
590
+ return option.value === value;
591
+ })) == null ? void 0 : _options$find2.label) != null ? _options$find$label2 : '');
592
+ }, [value]);
573
593
  useOutsideClick({
574
594
  ref: dropdownRef,
575
595
  handler: function handler() {
@@ -631,7 +651,24 @@ var StackedTextarea = /*#__PURE__*/React__default.forwardRef(function (_ref2, _r
631
651
  }, props));
632
652
  });
633
653
 
634
- var CloseIcon = "data:image/svg+xml,%3Csvg%20width%3D%2256%22%20height%3D%2256%22%20viewBox%3D%220%200%2056%2056%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Cpath%20fill-rule%3D%22evenodd%22%20clip-rule%3D%22evenodd%22%20d%3D%22M27.9995%2056C43.4635%2056%2055.9995%2043.464%2055.9995%2028C55.9995%2012.536%2043.4635%200%2027.9995%200C12.5355%200%20-0.000488281%2012.536%20-0.000488281%2028C-0.000488281%2043.464%2012.5355%2056%2027.9995%2056ZM21.9807%2018.2688C20.9555%2017.2437%2019.2935%2017.2437%2018.2684%2018.2688C17.2432%2019.294%2017.2432%2020.956%2018.2684%2021.9812L24.2872%2028L18.2684%2034.0188C17.2432%2035.044%2017.2432%2036.706%2018.2684%2037.7312C19.2935%2038.7563%2020.9555%2038.7563%2021.9807%2037.7312L27.9995%2031.7123L34.0184%2037.7312C35.0435%2038.7563%2036.7055%2038.7563%2037.7307%2037.7312C38.7558%2036.706%2038.7558%2035.044%2037.7307%2034.0188L31.7118%2028L37.7307%2021.9812C38.7558%2020.956%2038.7558%2019.294%2037.7307%2018.2688C36.7055%2017.2437%2035.0435%2017.2437%2034.0184%2018.2688L27.9995%2024.2877L21.9807%2018.2688Z%22%20fill%3D%22%233C3C43%22%20fill-opacity%3D%220.6%22%2F%3E%3C%2Fsvg%3E";
654
+ var _path;
655
+ function _extends$1() { _extends$1 = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends$1.apply(this, arguments); }
656
+ var SvgClose = function SvgClose(props, ref) {
657
+ return /*#__PURE__*/createElement("svg", _extends$1({
658
+ viewBox: "0 0 56 56",
659
+ fill: "none",
660
+ xmlns: "http://www.w3.org/2000/svg",
661
+ ref: ref
662
+ }, props), _path || (_path = /*#__PURE__*/createElement("path", {
663
+ fillRule: "evenodd",
664
+ clipRule: "evenodd",
665
+ d: "M28 56c15.464 0 28-12.536 28-28S43.463 0 28 0 0 12.536 0 28s12.536 28 28 28Zm-6.02-37.731a2.625 2.625 0 0 0-3.712 3.712L24.288 28l-6.02 6.019a2.625 2.625 0 1 0 3.713 3.712l6.018-6.019 6.02 6.02a2.625 2.625 0 0 0 3.712-3.713L31.71 28l6.02-6.019a2.625 2.625 0 0 0-3.713-3.712L28 24.288l-6.02-6.02Z",
666
+ fill: "#3C3C43",
667
+ fillOpacity: 0.6
668
+ })));
669
+ };
670
+ var ForwardRef = /*#__PURE__*/forwardRef(SvgClose);
671
+ var Memo = /*#__PURE__*/memo(ForwardRef);
635
672
 
636
673
  var Token = function Token(_ref) {
637
674
  var label = _ref.label,
@@ -641,17 +678,23 @@ var Token = function Token(_ref) {
641
678
  borderRadius: "full",
642
679
  backgroundColor: "#7676801F",
643
680
  alignItems: "center",
644
- // width="100%"
681
+ width: "fit-content",
682
+ w: "auto",
683
+ h: "auto",
645
684
  pl: "8px",
646
685
  pr: "4px",
647
- py: "2px"
686
+ py: "2px",
687
+ position: "relative"
648
688
  }, /*#__PURE__*/React__default.createElement(Text$2, {
649
689
  color: colors.label.primary.light,
650
- fontSize: "13px"
651
- }, label), /*#__PURE__*/React__default.createElement(Image, {
652
- pl: "4px",
653
- boxSize: "16px",
654
- src: CloseIcon,
690
+ fontSize: "13px",
691
+ pr: "4px"
692
+ }, truncate(label.trim(), {
693
+ length: 15,
694
+ omission: '...'
695
+ })), /*#__PURE__*/React__default.createElement(Memo, {
696
+ width: "13px",
697
+ height: "13px",
655
698
  onClick: onDelete,
656
699
  cursor: "pointer"
657
700
  }));
@@ -667,7 +710,9 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
667
710
  control = _ref2.control,
668
711
  name = _ref2.name,
669
712
  placeholder = _ref2.placeholder,
670
- disabled = _ref2.disabled;
713
+ disabled = _ref2.disabled,
714
+ maxLength = _ref2.maxLength,
715
+ setError = _ref2.setError;
671
716
  var watchedValue = useWatch({
672
717
  control: control,
673
718
  name: name
@@ -689,6 +734,12 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
689
734
  useOutsideClick({
690
735
  ref: dropdownRef,
691
736
  handler: function handler() {
737
+ if (maxLength && localValues.length > maxLength) {
738
+ setError(name, {
739
+ message: "Exceeded maximum of " + maxLength + " options"
740
+ });
741
+ }
742
+
692
743
  return setIsFocussed(false);
693
744
  }
694
745
  }); // gets latest watched form value (common delimited) from RHF state and creates a list
@@ -698,16 +749,24 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
698
749
  setLocalValues([]);
699
750
  }
700
751
 
701
- if (watchedValue !== undefined && watchedValue != null && watchedValue.length) {
752
+ if (maxLength && watchedValue !== undefined && watchedValue.length <= maxLength && watchedValue != null && watchedValue.length) {
702
753
  setLocalValues(watchedValue.split(',').filter(Boolean).map(function (value) {
703
754
  return options.find(function (option) {
704
755
  return option.value === value;
705
756
  });
706
757
  }));
707
758
  }
708
- }, [options, watchedValue]);
759
+ }, [maxLength, options, watchedValue]);
709
760
 
710
761
  var handleChange = function handleChange(option) {
762
+ console.log(localValues.length, maxLength);
763
+
764
+ if (maxLength && localValues.length > maxLength) {
765
+ return setError(name, {
766
+ message: "Exceeded maximum of " + maxLength + " options"
767
+ });
768
+ }
769
+
711
770
  var newValue = [].concat(localValues, [option]).map(function (_ref3) {
712
771
  var value = _ref3.value;
713
772
  return value;
@@ -768,7 +827,14 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
768
827
  cursor: disabled ? 'not-allowed' : 'pointer'
769
828
  }, /*#__PURE__*/React__default.createElement(Flex, {
770
829
  height: "28px",
771
- alignItems: "center"
830
+ alignItems: "center",
831
+ overflowX: "auto",
832
+ maxWidth: "90%",
833
+ style: {
834
+ scrollbarWidth: 'none'
835
+ /* Firefox */
836
+
837
+ }
772
838
  }, localValues.length ? localValues.map(function (option) {
773
839
  return /*#__PURE__*/React__default.createElement(Box, {
774
840
  mr: "4px"
@@ -806,7 +872,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
806
872
  setValue = _ref2.setValue,
807
873
  control = _ref2.control,
808
874
  placeholder = _ref2.placeholder,
809
- disabled = _ref2.disabled;
875
+ disabled = _ref2.disabled,
876
+ maxLength = _ref2.maxLength,
877
+ setError = _ref2.setError,
878
+ clearErrors = _ref2.clearErrors;
810
879
  var watchedValue = useWatch({
811
880
  control: control,
812
881
  name: name
@@ -844,6 +913,13 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
844
913
 
845
914
  var onHandleKeyDown = function onHandleKeyDown(e) {
846
915
  if (e.key === ' ' || e.key === 'Enter' || e.key === ',') {
916
+ if (maxLength && lastestFormValueToArray.length >= maxLength) {
917
+ return setError(name, {
918
+ type: 'maxLength',
919
+ message: "Exceeded maximum of " + maxLength + " options"
920
+ });
921
+ }
922
+
847
923
  if (e.key === 'Enter' && !localValue.trim().length && tokenIndex !== null) {
848
924
  setLocalValue(lastestFormValueToArray[tokenIndex]);
849
925
 
@@ -919,7 +995,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
919
995
  };
920
996
 
921
997
  var onBlur = function onBlur() {
998
+ clearErrors(name);
999
+
922
1000
  if (localValue.trim()) {
1001
+ if (maxLength && watchedValue.length + localValue.trim().length > maxLength) return setLocalValue('');
923
1002
  var filteredUniqueValues = Array.from(new Set([].concat(lastestFormValueToArray, localValue.trim().split(','))));
924
1003
  setValue(name, filteredUniqueValues.toString().replace(/\s/g, ''), {
925
1004
  shouldValidate: true,
@@ -959,8 +1038,8 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
959
1038
  }, /*#__PURE__*/React__default.createElement(Flex, {
960
1039
  height: "28px",
961
1040
  alignItems: "center",
962
- // width="fit-content"
963
- // maxW="70%"
1041
+ width: "fit-content",
1042
+ maxW: "80%",
964
1043
  overflowX: "auto",
965
1044
  style: {
966
1045
  scrollbarWidth: 'none'
@@ -975,7 +1054,6 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
975
1054
  onClick: function onClick() {
976
1055
  return setTokenIndex(index);
977
1056
  },
978
- // width="fit-content"
979
1057
  width: "100%"
980
1058
  }, /*#__PURE__*/React__default.createElement(Token, {
981
1059
  label: label,
@@ -1067,8 +1145,11 @@ function Input(_ref) {
1067
1145
  control = _ref.control,
1068
1146
  disabled = _ref.disabled,
1069
1147
  onChange = _ref.onChange,
1070
- setValue = _ref.setValue;
1071
- var selectedInputField = useCallback(function (onChange, onBlur, ref, value) {
1148
+ setValue = _ref.setValue,
1149
+ setError = _ref.setError,
1150
+ clearErrors = _ref.clearErrors;
1151
+
1152
+ var selectedInputField = function selectedInputField(onChange, onBlur, ref, value) {
1072
1153
  switch (inputType) {
1073
1154
  case 'text':
1074
1155
  return /*#__PURE__*/React__default.createElement(StackedInput, {
@@ -1162,7 +1243,10 @@ function Input(_ref) {
1162
1243
  value: value,
1163
1244
  setValue: setValue,
1164
1245
  control: control,
1165
- placeholder: placeholder
1246
+ setError: setError,
1247
+ clearErrors: clearErrors,
1248
+ placeholder: placeholder,
1249
+ maxLength: maxLength
1166
1250
  });
1167
1251
 
1168
1252
  case 'pilled-text':
@@ -1178,7 +1262,10 @@ function Input(_ref) {
1178
1262
  disabled: disabled,
1179
1263
  value: value,
1180
1264
  setValue: setValue,
1181
- control: control
1265
+ setError: setError,
1266
+ clearErrors: clearErrors,
1267
+ control: control,
1268
+ maxLength: maxLength
1182
1269
  });
1183
1270
 
1184
1271
  case 'switch':
@@ -1196,7 +1283,8 @@ function Input(_ref) {
1196
1283
  default:
1197
1284
  return null;
1198
1285
  }
1199
- }, [ariaLabel, className, control, defaultValue, disabled, inputType, isInvalid, isRequired, maxLength, name, options, placeholder, setValue]);
1286
+ };
1287
+
1200
1288
  return /*#__PURE__*/React__default.createElement(Controller, {
1201
1289
  control: control,
1202
1290
  name: name,
@@ -1269,7 +1357,9 @@ function FormSection(_ref) {
1269
1357
  maxLength: maxLength,
1270
1358
  isInvalid: !!form.formState.errors[name],
1271
1359
  defaultValue: defaultValue,
1272
- setValue: form.setValue
1360
+ setValue: form.setValue,
1361
+ setError: form.setError,
1362
+ clearErrors: form.clearErrors
1273
1363
  });
1274
1364
  }));
1275
1365
  }
@@ -1345,7 +1435,7 @@ var Layout = function Layout(_ref) {
1345
1435
  onClick: function onClick() {
1346
1436
  return setShow(!show);
1347
1437
  },
1348
- icon: show ? /*#__PURE__*/React__default.createElement(CloseIcon$1, null) : /*#__PURE__*/React__default.createElement(HamburgerIcon, null),
1438
+ icon: show ? /*#__PURE__*/React__default.createElement(CloseIcon, null) : /*#__PURE__*/React__default.createElement(HamburgerIcon, null),
1349
1439
  _focus: {
1350
1440
  boxShadow: 'none'
1351
1441
  }