@xqmsg/ui-core 0.14.1 → 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, useEffect, useState } 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,7 +544,7 @@ 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
 
@@ -645,7 +651,24 @@ var StackedTextarea = /*#__PURE__*/React__default.forwardRef(function (_ref2, _r
645
651
  }, props));
646
652
  });
647
653
 
648
- 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);
649
672
 
650
673
  var Token = function Token(_ref) {
651
674
  var label = _ref.label,
@@ -655,17 +678,23 @@ var Token = function Token(_ref) {
655
678
  borderRadius: "full",
656
679
  backgroundColor: "#7676801F",
657
680
  alignItems: "center",
658
- // width="100%"
681
+ width: "fit-content",
682
+ w: "auto",
683
+ h: "auto",
659
684
  pl: "8px",
660
685
  pr: "4px",
661
- py: "2px"
686
+ py: "2px",
687
+ position: "relative"
662
688
  }, /*#__PURE__*/React__default.createElement(Text$2, {
663
689
  color: colors.label.primary.light,
664
- fontSize: "13px"
665
- }, label), /*#__PURE__*/React__default.createElement(Image, {
666
- pl: "4px",
667
- boxSize: "16px",
668
- 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",
669
698
  onClick: onDelete,
670
699
  cursor: "pointer"
671
700
  }));
@@ -681,7 +710,9 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
681
710
  control = _ref2.control,
682
711
  name = _ref2.name,
683
712
  placeholder = _ref2.placeholder,
684
- disabled = _ref2.disabled;
713
+ disabled = _ref2.disabled,
714
+ maxLength = _ref2.maxLength,
715
+ setError = _ref2.setError;
685
716
  var watchedValue = useWatch({
686
717
  control: control,
687
718
  name: name
@@ -703,6 +734,12 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
703
734
  useOutsideClick({
704
735
  ref: dropdownRef,
705
736
  handler: function handler() {
737
+ if (maxLength && localValues.length > maxLength) {
738
+ setError(name, {
739
+ message: "Exceeded maximum of " + maxLength + " options"
740
+ });
741
+ }
742
+
706
743
  return setIsFocussed(false);
707
744
  }
708
745
  }); // gets latest watched form value (common delimited) from RHF state and creates a list
@@ -712,16 +749,24 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
712
749
  setLocalValues([]);
713
750
  }
714
751
 
715
- if (watchedValue !== undefined && watchedValue != null && watchedValue.length) {
752
+ if (maxLength && watchedValue !== undefined && watchedValue.length <= maxLength && watchedValue != null && watchedValue.length) {
716
753
  setLocalValues(watchedValue.split(',').filter(Boolean).map(function (value) {
717
754
  return options.find(function (option) {
718
755
  return option.value === value;
719
756
  });
720
757
  }));
721
758
  }
722
- }, [options, watchedValue]);
759
+ }, [maxLength, options, watchedValue]);
723
760
 
724
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
+
725
770
  var newValue = [].concat(localValues, [option]).map(function (_ref3) {
726
771
  var value = _ref3.value;
727
772
  return value;
@@ -782,7 +827,14 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
782
827
  cursor: disabled ? 'not-allowed' : 'pointer'
783
828
  }, /*#__PURE__*/React__default.createElement(Flex, {
784
829
  height: "28px",
785
- alignItems: "center"
830
+ alignItems: "center",
831
+ overflowX: "auto",
832
+ maxWidth: "90%",
833
+ style: {
834
+ scrollbarWidth: 'none'
835
+ /* Firefox */
836
+
837
+ }
786
838
  }, localValues.length ? localValues.map(function (option) {
787
839
  return /*#__PURE__*/React__default.createElement(Box, {
788
840
  mr: "4px"
@@ -820,7 +872,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
820
872
  setValue = _ref2.setValue,
821
873
  control = _ref2.control,
822
874
  placeholder = _ref2.placeholder,
823
- disabled = _ref2.disabled;
875
+ disabled = _ref2.disabled,
876
+ maxLength = _ref2.maxLength,
877
+ setError = _ref2.setError,
878
+ clearErrors = _ref2.clearErrors;
824
879
  var watchedValue = useWatch({
825
880
  control: control,
826
881
  name: name
@@ -858,6 +913,13 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
858
913
 
859
914
  var onHandleKeyDown = function onHandleKeyDown(e) {
860
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
+
861
923
  if (e.key === 'Enter' && !localValue.trim().length && tokenIndex !== null) {
862
924
  setLocalValue(lastestFormValueToArray[tokenIndex]);
863
925
 
@@ -933,7 +995,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
933
995
  };
934
996
 
935
997
  var onBlur = function onBlur() {
998
+ clearErrors(name);
999
+
936
1000
  if (localValue.trim()) {
1001
+ if (maxLength && watchedValue.length + localValue.trim().length > maxLength) return setLocalValue('');
937
1002
  var filteredUniqueValues = Array.from(new Set([].concat(lastestFormValueToArray, localValue.trim().split(','))));
938
1003
  setValue(name, filteredUniqueValues.toString().replace(/\s/g, ''), {
939
1004
  shouldValidate: true,
@@ -973,8 +1038,8 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
973
1038
  }, /*#__PURE__*/React__default.createElement(Flex, {
974
1039
  height: "28px",
975
1040
  alignItems: "center",
976
- // width="fit-content"
977
- // maxW="70%"
1041
+ width: "fit-content",
1042
+ maxW: "80%",
978
1043
  overflowX: "auto",
979
1044
  style: {
980
1045
  scrollbarWidth: 'none'
@@ -989,7 +1054,6 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
989
1054
  onClick: function onClick() {
990
1055
  return setTokenIndex(index);
991
1056
  },
992
- // width="fit-content"
993
1057
  width: "100%"
994
1058
  }, /*#__PURE__*/React__default.createElement(Token, {
995
1059
  label: label,
@@ -1081,7 +1145,9 @@ function Input(_ref) {
1081
1145
  control = _ref.control,
1082
1146
  disabled = _ref.disabled,
1083
1147
  onChange = _ref.onChange,
1084
- setValue = _ref.setValue;
1148
+ setValue = _ref.setValue,
1149
+ setError = _ref.setError,
1150
+ clearErrors = _ref.clearErrors;
1085
1151
 
1086
1152
  var selectedInputField = function selectedInputField(onChange, onBlur, ref, value) {
1087
1153
  switch (inputType) {
@@ -1177,7 +1243,10 @@ function Input(_ref) {
1177
1243
  value: value,
1178
1244
  setValue: setValue,
1179
1245
  control: control,
1180
- placeholder: placeholder
1246
+ setError: setError,
1247
+ clearErrors: clearErrors,
1248
+ placeholder: placeholder,
1249
+ maxLength: maxLength
1181
1250
  });
1182
1251
 
1183
1252
  case 'pilled-text':
@@ -1193,7 +1262,10 @@ function Input(_ref) {
1193
1262
  disabled: disabled,
1194
1263
  value: value,
1195
1264
  setValue: setValue,
1196
- control: control
1265
+ setError: setError,
1266
+ clearErrors: clearErrors,
1267
+ control: control,
1268
+ maxLength: maxLength
1197
1269
  });
1198
1270
 
1199
1271
  case 'switch':
@@ -1285,7 +1357,9 @@ function FormSection(_ref) {
1285
1357
  maxLength: maxLength,
1286
1358
  isInvalid: !!form.formState.errors[name],
1287
1359
  defaultValue: defaultValue,
1288
- setValue: form.setValue
1360
+ setValue: form.setValue,
1361
+ setError: form.setError,
1362
+ clearErrors: form.clearErrors
1289
1363
  });
1290
1364
  }));
1291
1365
  }
@@ -1361,7 +1435,7 @@ var Layout = function Layout(_ref) {
1361
1435
  onClick: function onClick() {
1362
1436
  return setShow(!show);
1363
1437
  },
1364
- 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),
1365
1439
  _focus: {
1366
1440
  boxShadow: 'none'
1367
1441
  }