@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.
- package/dist/components/input/StackedMultiSelect/index.d.ts +4 -1
- package/dist/components/input/StackedPilledInput/index.d.ts +4 -1
- package/dist/components/input/index.d.ts +4 -2
- package/dist/ui-core.cjs.development.js +119 -29
- 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 +122 -32
- package/dist/ui-core.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/form/section/index.tsx +2 -0
- package/src/components/input/Input.stories.tsx +10 -0
- package/src/components/input/StackedMultiSelect/index.tsx +153 -101
- package/src/components/input/StackedPilledInput/index.tsx +231 -191
- package/src/components/input/StackedSelect/StackedSelect.tsx +9 -10
- package/src/components/input/components/dropdown/index.tsx +7 -2
- package/src/components/input/components/token/assets/svg/close.svg +1 -1
- package/src/components/input/components/token/index.tsx +15 -9
- package/src/components/input/index.tsx +155 -160
|
@@ -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: "
|
|
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,11 +551,18 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
545
551
|
py: "4px",
|
|
546
552
|
position: "absolute",
|
|
547
553
|
width: "100%",
|
|
548
|
-
zIndex:
|
|
554
|
+
zIndex: 100
|
|
549
555
|
}, DropdownContent);
|
|
550
556
|
};
|
|
551
557
|
|
|
552
|
-
var
|
|
558
|
+
var useDidMountEffect = function useDidMountEffect(func, deps) {
|
|
559
|
+
var didMount = React.useRef(false);
|
|
560
|
+
React.useEffect(function () {
|
|
561
|
+
if (didMount.current) func();else didMount.current = true; // eslint-disable-next-line
|
|
562
|
+
}, deps);
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
var _excluded$1 = ["isRequired", "options", "name", "setValue", "handleOnChange", "value"];
|
|
553
566
|
/**
|
|
554
567
|
* A functional React component utilized to render the `StackedSelect` component.
|
|
555
568
|
*/
|
|
@@ -562,7 +575,7 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
|
|
|
562
575
|
name = _ref2.name,
|
|
563
576
|
setValue = _ref2.setValue,
|
|
564
577
|
handleOnChange = _ref2.handleOnChange,
|
|
565
|
-
|
|
578
|
+
value = _ref2.value,
|
|
566
579
|
props = _objectWithoutPropertiesLoose(_ref2, _excluded$1);
|
|
567
580
|
|
|
568
581
|
var dropdownRef = React.useRef(null);
|
|
@@ -572,11 +585,18 @@ var StackedSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2, _ref
|
|
|
572
585
|
setIsFocussed = _useState[1];
|
|
573
586
|
|
|
574
587
|
var _useState2 = React.useState((_options$find$label = (_options$find = options.find(function (option) {
|
|
575
|
-
return option.value ===
|
|
588
|
+
return option.value === value;
|
|
576
589
|
})) == null ? void 0 : _options$find.label) != null ? _options$find$label : ''),
|
|
577
590
|
selectedOption = _useState2[0],
|
|
578
591
|
setSelectedOption = _useState2[1];
|
|
579
592
|
|
|
593
|
+
useDidMountEffect(function () {
|
|
594
|
+
var _options$find$label2, _options$find2;
|
|
595
|
+
|
|
596
|
+
setSelectedOption((_options$find$label2 = (_options$find2 = options.find(function (option) {
|
|
597
|
+
return option.value === value;
|
|
598
|
+
})) == null ? void 0 : _options$find2.label) != null ? _options$find$label2 : '');
|
|
599
|
+
}, [value]);
|
|
580
600
|
react.useOutsideClick({
|
|
581
601
|
ref: dropdownRef,
|
|
582
602
|
handler: function handler() {
|
|
@@ -638,7 +658,24 @@ var StackedTextarea = /*#__PURE__*/React__default.forwardRef(function (_ref2, _r
|
|
|
638
658
|
}, props));
|
|
639
659
|
});
|
|
640
660
|
|
|
641
|
-
var
|
|
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);
|
|
642
679
|
|
|
643
680
|
var Token = function Token(_ref) {
|
|
644
681
|
var label = _ref.label,
|
|
@@ -648,17 +685,23 @@ var Token = function Token(_ref) {
|
|
|
648
685
|
borderRadius: "full",
|
|
649
686
|
backgroundColor: "#7676801F",
|
|
650
687
|
alignItems: "center",
|
|
651
|
-
|
|
688
|
+
width: "fit-content",
|
|
689
|
+
w: "auto",
|
|
690
|
+
h: "auto",
|
|
652
691
|
pl: "8px",
|
|
653
692
|
pr: "4px",
|
|
654
|
-
py: "2px"
|
|
693
|
+
py: "2px",
|
|
694
|
+
position: "relative"
|
|
655
695
|
}, /*#__PURE__*/React__default.createElement(react.Text, {
|
|
656
696
|
color: colors.label.primary.light,
|
|
657
|
-
fontSize: "13px"
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
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",
|
|
662
705
|
onClick: onDelete,
|
|
663
706
|
cursor: "pointer"
|
|
664
707
|
}));
|
|
@@ -674,7 +717,9 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
674
717
|
control = _ref2.control,
|
|
675
718
|
name = _ref2.name,
|
|
676
719
|
placeholder = _ref2.placeholder,
|
|
677
|
-
disabled = _ref2.disabled
|
|
720
|
+
disabled = _ref2.disabled,
|
|
721
|
+
maxLength = _ref2.maxLength,
|
|
722
|
+
setError = _ref2.setError;
|
|
678
723
|
var watchedValue = reactHookForm.useWatch({
|
|
679
724
|
control: control,
|
|
680
725
|
name: name
|
|
@@ -696,6 +741,12 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
696
741
|
react.useOutsideClick({
|
|
697
742
|
ref: dropdownRef,
|
|
698
743
|
handler: function handler() {
|
|
744
|
+
if (maxLength && localValues.length > maxLength) {
|
|
745
|
+
setError(name, {
|
|
746
|
+
message: "Exceeded maximum of " + maxLength + " options"
|
|
747
|
+
});
|
|
748
|
+
}
|
|
749
|
+
|
|
699
750
|
return setIsFocussed(false);
|
|
700
751
|
}
|
|
701
752
|
}); // gets latest watched form value (common delimited) from RHF state and creates a list
|
|
@@ -705,16 +756,24 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
705
756
|
setLocalValues([]);
|
|
706
757
|
}
|
|
707
758
|
|
|
708
|
-
if (watchedValue !== undefined && watchedValue != null && watchedValue.length) {
|
|
759
|
+
if (maxLength && watchedValue !== undefined && watchedValue.length <= maxLength && watchedValue != null && watchedValue.length) {
|
|
709
760
|
setLocalValues(watchedValue.split(',').filter(Boolean).map(function (value) {
|
|
710
761
|
return options.find(function (option) {
|
|
711
762
|
return option.value === value;
|
|
712
763
|
});
|
|
713
764
|
}));
|
|
714
765
|
}
|
|
715
|
-
}, [options, watchedValue]);
|
|
766
|
+
}, [maxLength, options, watchedValue]);
|
|
716
767
|
|
|
717
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
|
+
|
|
718
777
|
var newValue = [].concat(localValues, [option]).map(function (_ref3) {
|
|
719
778
|
var value = _ref3.value;
|
|
720
779
|
return value;
|
|
@@ -775,7 +834,14 @@ var StackedMultiSelect = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
775
834
|
cursor: disabled ? 'not-allowed' : 'pointer'
|
|
776
835
|
}, /*#__PURE__*/React__default.createElement(react.Flex, {
|
|
777
836
|
height: "28px",
|
|
778
|
-
alignItems: "center"
|
|
837
|
+
alignItems: "center",
|
|
838
|
+
overflowX: "auto",
|
|
839
|
+
maxWidth: "90%",
|
|
840
|
+
style: {
|
|
841
|
+
scrollbarWidth: 'none'
|
|
842
|
+
/* Firefox */
|
|
843
|
+
|
|
844
|
+
}
|
|
779
845
|
}, localValues.length ? localValues.map(function (option) {
|
|
780
846
|
return /*#__PURE__*/React__default.createElement(react.Box, {
|
|
781
847
|
mr: "4px"
|
|
@@ -813,7 +879,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
813
879
|
setValue = _ref2.setValue,
|
|
814
880
|
control = _ref2.control,
|
|
815
881
|
placeholder = _ref2.placeholder,
|
|
816
|
-
disabled = _ref2.disabled
|
|
882
|
+
disabled = _ref2.disabled,
|
|
883
|
+
maxLength = _ref2.maxLength,
|
|
884
|
+
setError = _ref2.setError,
|
|
885
|
+
clearErrors = _ref2.clearErrors;
|
|
817
886
|
var watchedValue = reactHookForm.useWatch({
|
|
818
887
|
control: control,
|
|
819
888
|
name: name
|
|
@@ -851,6 +920,13 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
851
920
|
|
|
852
921
|
var onHandleKeyDown = function onHandleKeyDown(e) {
|
|
853
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
|
+
|
|
854
930
|
if (e.key === 'Enter' && !localValue.trim().length && tokenIndex !== null) {
|
|
855
931
|
setLocalValue(lastestFormValueToArray[tokenIndex]);
|
|
856
932
|
|
|
@@ -926,7 +1002,10 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
926
1002
|
};
|
|
927
1003
|
|
|
928
1004
|
var onBlur = function onBlur() {
|
|
1005
|
+
clearErrors(name);
|
|
1006
|
+
|
|
929
1007
|
if (localValue.trim()) {
|
|
1008
|
+
if (maxLength && watchedValue.length + localValue.trim().length > maxLength) return setLocalValue('');
|
|
930
1009
|
var filteredUniqueValues = Array.from(new Set([].concat(lastestFormValueToArray, localValue.trim().split(','))));
|
|
931
1010
|
setValue(name, filteredUniqueValues.toString().replace(/\s/g, ''), {
|
|
932
1011
|
shouldValidate: true,
|
|
@@ -966,8 +1045,8 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
966
1045
|
}, /*#__PURE__*/React__default.createElement(react.Flex, {
|
|
967
1046
|
height: "28px",
|
|
968
1047
|
alignItems: "center",
|
|
969
|
-
|
|
970
|
-
|
|
1048
|
+
width: "fit-content",
|
|
1049
|
+
maxW: "80%",
|
|
971
1050
|
overflowX: "auto",
|
|
972
1051
|
style: {
|
|
973
1052
|
scrollbarWidth: 'none'
|
|
@@ -982,7 +1061,6 @@ var StackedPilledInput = /*#__PURE__*/React__default.forwardRef(function (_ref2,
|
|
|
982
1061
|
onClick: function onClick() {
|
|
983
1062
|
return setTokenIndex(index);
|
|
984
1063
|
},
|
|
985
|
-
// width="fit-content"
|
|
986
1064
|
width: "100%"
|
|
987
1065
|
}, /*#__PURE__*/React__default.createElement(Token, {
|
|
988
1066
|
label: label,
|
|
@@ -1074,8 +1152,11 @@ function Input(_ref) {
|
|
|
1074
1152
|
control = _ref.control,
|
|
1075
1153
|
disabled = _ref.disabled,
|
|
1076
1154
|
onChange = _ref.onChange,
|
|
1077
|
-
setValue = _ref.setValue
|
|
1078
|
-
|
|
1155
|
+
setValue = _ref.setValue,
|
|
1156
|
+
setError = _ref.setError,
|
|
1157
|
+
clearErrors = _ref.clearErrors;
|
|
1158
|
+
|
|
1159
|
+
var selectedInputField = function selectedInputField(onChange, onBlur, ref, value) {
|
|
1079
1160
|
switch (inputType) {
|
|
1080
1161
|
case 'text':
|
|
1081
1162
|
return /*#__PURE__*/React__default.createElement(StackedInput, {
|
|
@@ -1169,7 +1250,10 @@ function Input(_ref) {
|
|
|
1169
1250
|
value: value,
|
|
1170
1251
|
setValue: setValue,
|
|
1171
1252
|
control: control,
|
|
1172
|
-
|
|
1253
|
+
setError: setError,
|
|
1254
|
+
clearErrors: clearErrors,
|
|
1255
|
+
placeholder: placeholder,
|
|
1256
|
+
maxLength: maxLength
|
|
1173
1257
|
});
|
|
1174
1258
|
|
|
1175
1259
|
case 'pilled-text':
|
|
@@ -1185,7 +1269,10 @@ function Input(_ref) {
|
|
|
1185
1269
|
disabled: disabled,
|
|
1186
1270
|
value: value,
|
|
1187
1271
|
setValue: setValue,
|
|
1188
|
-
|
|
1272
|
+
setError: setError,
|
|
1273
|
+
clearErrors: clearErrors,
|
|
1274
|
+
control: control,
|
|
1275
|
+
maxLength: maxLength
|
|
1189
1276
|
});
|
|
1190
1277
|
|
|
1191
1278
|
case 'switch':
|
|
@@ -1203,7 +1290,8 @@ function Input(_ref) {
|
|
|
1203
1290
|
default:
|
|
1204
1291
|
return null;
|
|
1205
1292
|
}
|
|
1206
|
-
}
|
|
1293
|
+
};
|
|
1294
|
+
|
|
1207
1295
|
return /*#__PURE__*/React__default.createElement(reactHookForm.Controller, {
|
|
1208
1296
|
control: control,
|
|
1209
1297
|
name: name,
|
|
@@ -1276,7 +1364,9 @@ function FormSection(_ref) {
|
|
|
1276
1364
|
maxLength: maxLength,
|
|
1277
1365
|
isInvalid: !!form.formState.errors[name],
|
|
1278
1366
|
defaultValue: defaultValue,
|
|
1279
|
-
setValue: form.setValue
|
|
1367
|
+
setValue: form.setValue,
|
|
1368
|
+
setError: form.setError,
|
|
1369
|
+
clearErrors: form.clearErrors
|
|
1280
1370
|
});
|
|
1281
1371
|
}));
|
|
1282
1372
|
}
|