@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,10 +1,13 @@
1
1
  import React from 'react';
2
2
  import { FieldOptions, ReactSelectFieldProps } from '../InputTypes';
3
- import { Control, FieldValues, UseFormSetValue } from 'react-hook-form';
3
+ import { Control, FieldValues, UseFormClearErrors, UseFormSetError, UseFormSetValue } from 'react-hook-form';
4
4
  export interface StackedMultiSelectProps extends ReactSelectFieldProps {
5
5
  options: FieldOptions;
6
6
  setValue: UseFormSetValue<FieldValues>;
7
+ setError: UseFormSetError<FieldValues>;
8
+ clearErrors: UseFormClearErrors<FieldValues>;
7
9
  control: Control<FieldValues, any>;
10
+ maxLength?: number;
8
11
  }
9
12
  /**
10
13
  * A functional React component utilized to render the `StackedMultiSelect` component.
@@ -1,9 +1,12 @@
1
1
  import React from 'react';
2
2
  import { InputFieldProps } from '../InputTypes';
3
- import { Control, FieldValues, UseFormSetValue } from 'react-hook-form';
3
+ import { Control, FieldValues, UseFormClearErrors, UseFormSetError, UseFormSetValue } from 'react-hook-form';
4
4
  export interface StackedPilledInputProps extends InputFieldProps {
5
5
  setValue: UseFormSetValue<FieldValues>;
6
+ setError: UseFormSetError<FieldValues>;
7
+ clearErrors: UseFormClearErrors<FieldValues>;
6
8
  control: Control<FieldValues, any>;
9
+ maxLength?: number;
7
10
  }
8
11
  /**
9
12
  * A functional React component utilized to render the `StackedPilledInput` component.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import { FieldOptions, ValidationProps, InputType } from './InputTypes';
3
- import { Control, FieldValues, UseFormSetValue } from 'react-hook-form';
3
+ import { Control, FieldValues, UseFormClearErrors, UseFormSetError, UseFormSetValue } from 'react-hook-form';
4
4
  export interface InputProps<T extends FieldValues> extends ValidationProps {
5
5
  inputType: InputType;
6
6
  name: string;
@@ -16,9 +16,11 @@ export interface InputProps<T extends FieldValues> extends ValidationProps {
16
16
  onChange?: (value?: string) => void;
17
17
  disabled?: boolean;
18
18
  setValue: UseFormSetValue<T>;
19
+ setError: UseFormSetError<T>;
20
+ clearErrors: UseFormClearErrors<T>;
19
21
  }
20
22
  /**
21
23
  * A functional React component utilized to render the `Input` component. Utilizes a switch statement
22
24
  * to render the correct input based on the `inputType`.
23
25
  */
24
- export declare function Input<T extends FieldValues>({ inputType, label, ariaLabel, className, placeholder, name, helperText, options, isInvalid, errorText, isRequired, maxLength, defaultValue, control, disabled, onChange, setValue, }: InputProps<T>): JSX.Element;
26
+ export declare function Input<T extends FieldValues>({ inputType, label, ariaLabel, className, placeholder, name, helperText, options, isInvalid, errorText, isRequired, maxLength, defaultValue, control, disabled, onChange, setValue, setError, clearErrors, }: InputProps<T>): JSX.Element;
@@ -8,6 +8,7 @@ var React = require('react');
8
8
  var React__default = _interopDefault(React);
9
9
  var react = require('@chakra-ui/react');
10
10
  var reactHookForm = require('react-hook-form');
11
+ var lodash = require('lodash');
11
12
  var icons = require('@chakra-ui/icons');
12
13
  var hi = require('react-icons/hi');
13
14
  var themeTools = require('@chakra-ui/theme-tools');
@@ -510,7 +511,8 @@ var Dropdown = function Dropdown(_ref) {
510
511
  color: colors.label.secondary.light,
511
512
  fontSize: "13px",
512
513
  fontWeight: "bold",
513
- px: "8px"
514
+ px: "8px",
515
+ bg: "inherit"
514
516
  }, idx > 0 && /*#__PURE__*/React__default.createElement(react.Box, {
515
517
  my: "3px",
516
518
  borderTop: "2px solid",
@@ -530,14 +532,18 @@ var Dropdown = function Dropdown(_ref) {
530
532
  color: colors.label.primary.dark,
531
533
  bg: colors.fill.action,
532
534
  borderRadius: '4px'
533
- }
535
+ },
536
+ bg: "inherit"
534
537
  }, option.label));
535
538
  });
536
539
  }, [onSelectItem, options]);
537
540
  return /*#__PURE__*/React__default.createElement(react.Box, {
538
541
  bg: colors.fill.light.quaternary,
539
- backdropFilter: "blur(64px)",
542
+ backdropFilter: "auto",
543
+ backdropBlur: "64px",
540
544
  borderRadius: "4px",
545
+ border: "0.25px solid",
546
+ borderColor: colors.fill.light.tertiary,
541
547
  mt: "3px",
542
548
  maxH: "320px",
543
549
  overflowY: "auto",
@@ -545,7 +551,7 @@ var Dropdown = function Dropdown(_ref) {
545
551
  py: "4px",
546
552
  position: "absolute",
547
553
  width: "100%",
548
- zIndex: "100"
554
+ zIndex: 100
549
555
  }, DropdownContent);
550
556
  };
551
557
 
@@ -652,7 +658,24 @@ var StackedTextarea = /*#__PURE__*/React__default.forwardRef(function (_ref2, _r
652
658
  }, props));
653
659
  });
654
660
 
655
- 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";
661
+ var _path;
662
+ 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); }
663
+ var SvgClose = function SvgClose(props, ref) {
664
+ return /*#__PURE__*/React.createElement("svg", _extends$1({
665
+ viewBox: "0 0 56 56",
666
+ fill: "none",
667
+ xmlns: "http://www.w3.org/2000/svg",
668
+ ref: ref
669
+ }, props), _path || (_path = /*#__PURE__*/React.createElement("path", {
670
+ fillRule: "evenodd",
671
+ clipRule: "evenodd",
672
+ 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",
673
+ fill: "#3C3C43",
674
+ fillOpacity: 0.6
675
+ })));
676
+ };
677
+ var ForwardRef = /*#__PURE__*/React.forwardRef(SvgClose);
678
+ var Memo = /*#__PURE__*/React.memo(ForwardRef);
656
679
 
657
680
  var Token = function Token(_ref) {
658
681
  var label = _ref.label,
@@ -662,17 +685,23 @@ var Token = function Token(_ref) {
662
685
  borderRadius: "full",
663
686
  backgroundColor: "#7676801F",
664
687
  alignItems: "center",
665
- // width="100%"
688
+ width: "fit-content",
689
+ w: "auto",
690
+ h: "auto",
666
691
  pl: "8px",
667
692
  pr: "4px",
668
- py: "2px"
693
+ py: "2px",
694
+ position: "relative"
669
695
  }, /*#__PURE__*/React__default.createElement(react.Text, {
670
696
  color: colors.label.primary.light,
671
- fontSize: "13px"
672
- }, label), /*#__PURE__*/React__default.createElement(react.Image, {
673
- pl: "4px",
674
- boxSize: "16px",
675
- src: CloseIcon,
697
+ fontSize: "13px",
698
+ pr: "4px"
699
+ }, lodash.truncate(label.trim(), {
700
+ length: 15,
701
+ omission: '...'
702
+ })), /*#__PURE__*/React__default.createElement(Memo, {
703
+ width: "13px",
704
+ height: "13px",
676
705
  onClick: onDelete,
677
706
  cursor: "pointer"
678
707
  }));
@@ -688,7 +717,9 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
688
717
  control = _ref2.control,
689
718
  name = _ref2.name,
690
719
  placeholder = _ref2.placeholder,
691
- disabled = _ref2.disabled;
720
+ disabled = _ref2.disabled,
721
+ maxLength = _ref2.maxLength,
722
+ setError = _ref2.setError;
692
723
  var watchedValue = reactHookForm.useWatch({
693
724
  control: control,
694
725
  name: name
@@ -710,6 +741,12 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
710
741
  react.useOutsideClick({
711
742
  ref: dropdownRef,
712
743
  handler: function handler() {
744
+ if (maxLength && localValues.length > maxLength) {
745
+ setError(name, {
746
+ message: "Exceeded maximum of " + maxLength + " options"
747
+ });
748
+ }
749
+
713
750
  return setIsFocussed(false);
714
751
  }
715
752
  }); // gets latest watched form value (common delimited) from RHF state and creates a list
@@ -719,16 +756,24 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
719
756
  setLocalValues([]);
720
757
  }
721
758
 
722
- if (watchedValue !== undefined && watchedValue != null && watchedValue.length) {
759
+ if (maxLength && watchedValue !== undefined && watchedValue.length <= maxLength && watchedValue != null && watchedValue.length) {
723
760
  setLocalValues(watchedValue.split(',').filter(Boolean).map(function (value) {
724
761
  return options.find(function (option) {
725
762
  return option.value === value;
726
763
  });
727
764
  }));
728
765
  }
729
- }, [options, watchedValue]);
766
+ }, [maxLength, options, watchedValue]);
730
767
 
731
768
  var handleChange = function handleChange(option) {
769
+ console.log(localValues.length, maxLength);
770
+
771
+ if (maxLength && localValues.length > maxLength) {
772
+ return setError(name, {
773
+ message: "Exceeded maximum of " + maxLength + " options"
774
+ });
775
+ }
776
+
732
777
  var newValue = [].concat(localValues, [option]).map(function (_ref3) {
733
778
  var value = _ref3.value;
734
779
  return value;
@@ -789,7 +834,14 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
789
834
  cursor: disabled ? 'not-allowed' : 'pointer'
790
835
  }, /*#__PURE__*/React__default.createElement(react.Flex, {
791
836
  height: "28px",
792
- alignItems: "center"
837
+ alignItems: "center",
838
+ overflowX: "auto",
839
+ maxWidth: "90%",
840
+ style: {
841
+ scrollbarWidth: 'none'
842
+ /* Firefox */
843
+
844
+ }
793
845
  }, localValues.length ? localValues.map(function (option) {
794
846
  return /*#__PURE__*/React__default.createElement(react.Box, {
795
847
  mr: "4px"
@@ -827,7 +879,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
827
879
  setValue = _ref2.setValue,
828
880
  control = _ref2.control,
829
881
  placeholder = _ref2.placeholder,
830
- disabled = _ref2.disabled;
882
+ disabled = _ref2.disabled,
883
+ maxLength = _ref2.maxLength,
884
+ setError = _ref2.setError,
885
+ clearErrors = _ref2.clearErrors;
831
886
  var watchedValue = reactHookForm.useWatch({
832
887
  control: control,
833
888
  name: name
@@ -865,6 +920,13 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
865
920
 
866
921
  var onHandleKeyDown = function onHandleKeyDown(e) {
867
922
  if (e.key === ' ' || e.key === 'Enter' || e.key === ',') {
923
+ if (maxLength && lastestFormValueToArray.length >= maxLength) {
924
+ return setError(name, {
925
+ type: 'maxLength',
926
+ message: "Exceeded maximum of " + maxLength + " options"
927
+ });
928
+ }
929
+
868
930
  if (e.key === 'Enter' && !localValue.trim().length && tokenIndex !== null) {
869
931
  setLocalValue(lastestFormValueToArray[tokenIndex]);
870
932
 
@@ -940,7 +1002,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
940
1002
  };
941
1003
 
942
1004
  var onBlur = function onBlur() {
1005
+ clearErrors(name);
1006
+
943
1007
  if (localValue.trim()) {
1008
+ if (maxLength && watchedValue.length + localValue.trim().length > maxLength) return setLocalValue('');
944
1009
  var filteredUniqueValues = Array.from(new Set([].concat(lastestFormValueToArray, localValue.trim().split(','))));
945
1010
  setValue(name, filteredUniqueValues.toString().replace(/\s/g, ''), {
946
1011
  shouldValidate: true,
@@ -980,8 +1045,8 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
980
1045
  }, /*#__PURE__*/React__default.createElement(react.Flex, {
981
1046
  height: "28px",
982
1047
  alignItems: "center",
983
- // width="fit-content"
984
- // maxW="70%"
1048
+ width: "fit-content",
1049
+ maxW: "80%",
985
1050
  overflowX: "auto",
986
1051
  style: {
987
1052
  scrollbarWidth: 'none'
@@ -996,7 +1061,6 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
996
1061
  onClick: function onClick() {
997
1062
  return setTokenIndex(index);
998
1063
  },
999
- // width="fit-content"
1000
1064
  width: "100%"
1001
1065
  }, /*#__PURE__*/React__default.createElement(Token, {
1002
1066
  label: label,
@@ -1088,7 +1152,9 @@ function Input(_ref) {
1088
1152
  control = _ref.control,
1089
1153
  disabled = _ref.disabled,
1090
1154
  onChange = _ref.onChange,
1091
- setValue = _ref.setValue;
1155
+ setValue = _ref.setValue,
1156
+ setError = _ref.setError,
1157
+ clearErrors = _ref.clearErrors;
1092
1158
 
1093
1159
  var selectedInputField = function selectedInputField(onChange, onBlur, ref, value) {
1094
1160
  switch (inputType) {
@@ -1184,7 +1250,10 @@ function Input(_ref) {
1184
1250
  value: value,
1185
1251
  setValue: setValue,
1186
1252
  control: control,
1187
- placeholder: placeholder
1253
+ setError: setError,
1254
+ clearErrors: clearErrors,
1255
+ placeholder: placeholder,
1256
+ maxLength: maxLength
1188
1257
  });
1189
1258
 
1190
1259
  case 'pilled-text':
@@ -1200,7 +1269,10 @@ function Input(_ref) {
1200
1269
  disabled: disabled,
1201
1270
  value: value,
1202
1271
  setValue: setValue,
1203
- control: control
1272
+ setError: setError,
1273
+ clearErrors: clearErrors,
1274
+ control: control,
1275
+ maxLength: maxLength
1204
1276
  });
1205
1277
 
1206
1278
  case 'switch':
@@ -1292,7 +1364,9 @@ function FormSection(_ref) {
1292
1364
  maxLength: maxLength,
1293
1365
  isInvalid: !!form.formState.errors[name],
1294
1366
  defaultValue: defaultValue,
1295
- setValue: form.setValue
1367
+ setValue: form.setValue,
1368
+ setError: form.setError,
1369
+ clearErrors: form.clearErrors
1296
1370
  });
1297
1371
  }));
1298
1372
  }