@map-colonies/react-components 3.10.2 → 3.10.3

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/CHANGELOG.md CHANGED
@@ -3,6 +3,18 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [3.10.3](https://github.com/MapColonies/shared-components/compare/@map-colonies/react-components@3.10.2...@map-colonies/react-components@3.10.3) (2022-02-22)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * auto complete input bug ([cdb9220](https://github.com/MapColonies/shared-components/commit/cdb9220177e81087b90eacdf05a5f80b04e2ed67))
12
+ * autocomplete prettier ([eff39e8](https://github.com/MapColonies/shared-components/commit/eff39e8e469d6d9ca831be3718204ad58e77d850))
13
+
14
+
15
+
16
+
17
+
6
18
  ## [3.10.2](https://github.com/MapColonies/shared-components/compare/@map-colonies/react-components@3.10.1...@map-colonies/react-components@3.10.2) (2022-02-20)
7
19
 
8
20
 
@@ -3,10 +3,10 @@ import './autocomplete.css';
3
3
  export interface IAutocompleteProps {
4
4
  Component: React.ReactElement;
5
5
  ComponentProps: Record<string, unknown>;
6
- defaultValue: string;
6
+ defaultValue: string | undefined;
7
7
  disabled: boolean;
8
8
  maxOptions: number;
9
- onBlur: () => void;
9
+ onBlur: (evt: any) => void;
10
10
  onChange: (val: string) => void;
11
11
  onKeyDown: (evt: any) => void;
12
12
  onRequestOptions: (val: string) => void;
@@ -59,9 +59,10 @@ var KEY_TAB = 9;
59
59
  var OPTION_LIST_Y_OFFSET = 10;
60
60
  var OPTION_LIST_MIN_WIDTH = 100;
61
61
  var Autocomplete = function (props) {
62
- var _a = react_1.useState(props.defaultValue), recentValue = _a[0], setRecentValue = _a[1];
63
- var _b = react_1.useState(false), enableSpaceRemovers = _b[0], setEnableSpaceRemovers = _b[1];
64
- var _c = react_1.useState({
62
+ var _a;
63
+ var _b = react_1.useState((_a = props.defaultValue) !== null && _a !== void 0 ? _a : ''), recentValue = _b[0], setRecentValue = _b[1];
64
+ var _c = react_1.useState(false), enableSpaceRemovers = _c[0], setEnableSpaceRemovers = _c[1];
65
+ var _d = react_1.useState({
65
66
  helperVisible: false,
66
67
  left: 0,
67
68
  right: 0,
@@ -74,7 +75,7 @@ var Autocomplete = function (props) {
74
75
  value: '',
75
76
  caret: 0,
76
77
  width: 'unset',
77
- }), state = _c[0], setState = _c[1];
78
+ }), state = _d[0], setState = _d[1];
78
79
  var refInput = react_1.useRef(null);
79
80
  react_1.useEffect(function () {
80
81
  window.addEventListener('resize', handleResize);
@@ -87,6 +88,14 @@ var Autocomplete = function (props) {
87
88
  }
88
89
  };
89
90
  }, []);
91
+ react_1.useEffect(function () {
92
+ if (typeof props.value !== 'undefined') {
93
+ setRecentValue(props.value);
94
+ }
95
+ if (typeof props.defaultValue !== 'undefined') {
96
+ setRecentValue(props.defaultValue);
97
+ }
98
+ }, [props.value, props.defaultValue]);
90
99
  react_1.useEffect(function () {
91
100
  var options = props.options;
92
101
  var caret = state.caret;
@@ -421,32 +430,21 @@ var Autocomplete = function (props) {
421
430
  return (react_1.default.createElement("ul", { className: "react-autocomplete-input", style: __assign(__assign({}, horizontalPosition), { top: top + offsetY, width: width }) }, helperOptions));
422
431
  };
423
432
  var Component = props.Component, ComponentProps = props.ComponentProps, defaultValue = props.defaultValue, disabled = props.disabled, onBlur = props.onBlur, value = props.value, rest = __rest(props, ["Component", "ComponentProps", "defaultValue", "disabled", "onBlur", "value"]);
424
- var stateValue = recentValue; //state.value;
425
433
  var propagated = Object.assign({}, rest);
426
434
  Object.keys(props).forEach(function (k) {
427
435
  delete propagated[k];
428
436
  });
429
- var val = '';
430
- if (stateValue) {
431
- val = stateValue;
432
- }
433
- else if (defaultValue) {
434
- val = defaultValue;
435
- }
436
- else if (value !== undefined) {
437
- val = value;
438
- }
439
437
  return (react_1.default.createElement(react_1.default.Fragment, null,
440
- react_1.default.cloneElement(Component, __assign(__assign({ disabled: disabled, onBlur: onBlur, onChange: handleChange, onKeyDown: handleKeyDown, ref: refInput, value: val }, propagated), ComponentProps)),
438
+ react_1.default.cloneElement(Component, __assign(__assign({ disabled: disabled, onBlur: onBlur, onChange: handleChange, onKeyDown: handleKeyDown, ref: refInput, value: recentValue }, propagated), ComponentProps)),
441
439
  renderAutocompleteList()));
442
440
  };
443
441
  var defaultProps = {
444
442
  Component: react_1.default.createElement("textarea", null),
445
443
  ComponentProps: {},
446
- defaultValue: '',
444
+ defaultValue: undefined,
447
445
  disabled: false,
448
446
  maxOptions: 6,
449
- onBlur: function () { },
447
+ onBlur: function (evt) { },
450
448
  onChange: function (val) { },
451
449
  onKeyDown: function (evt) { },
452
450
  onRequestOptions: function (val) { },
@@ -273,4 +273,4 @@ export interface FilePickerProps extends Partial<FileBrowserProps> {
273
273
  readOnlyMode?: boolean;
274
274
  locale?: SupportedLocales;
275
275
  }
276
- export declare const FilePicker: React.FC<FilePickerProps>;
276
+ export declare const FilePicker: React.MemoExoticComponent<React.ForwardRefExoticComponent<FilePickerProps & React.RefAttributes<FileBrowserHandle>>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@map-colonies/react-components",
3
- "version": "3.10.2",
3
+ "version": "3.10.3",
4
4
  "module": "dist/index.js",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -93,7 +93,7 @@
93
93
  "jest-enzyme": "^7.1.2",
94
94
  "react-test-renderer": "^16.13.1"
95
95
  },
96
- "gitHead": "0b46e28cd15388a779c576920493e2f748cdc2ef",
96
+ "gitHead": "adb44b72ca2bf29dfd89a9fbb480df59e00d274f",
97
97
  "jest": {
98
98
  "coverageReporters": [
99
99
  "text",
@@ -24,10 +24,10 @@ const OPTION_LIST_MIN_WIDTH = 100;
24
24
  export interface IAutocompleteProps {
25
25
  Component: React.ReactElement;
26
26
  ComponentProps: Record<string, unknown>;
27
- defaultValue: string;
27
+ defaultValue: string | undefined;
28
28
  disabled: boolean;
29
29
  maxOptions: number;
30
- onBlur: () => void;
30
+ onBlur: (evt: any) => void;
31
31
  onChange: (val: string) => void;
32
32
  onKeyDown: (evt: any) => void;
33
33
  onRequestOptions: (val: string) => void;
@@ -50,7 +50,7 @@ export interface IAutocompleteProps {
50
50
  }
51
51
 
52
52
  const Autocomplete: React.FC<IAutocompleteProps> = (props) => {
53
- const [recentValue, setRecentValue] = useState(props.defaultValue);
53
+ const [recentValue, setRecentValue] = useState(props.defaultValue ?? '');
54
54
  const [enableSpaceRemovers, setEnableSpaceRemovers] = useState(false);
55
55
 
56
56
  const [state, setState] = useState({
@@ -80,6 +80,16 @@ const Autocomplete: React.FC<IAutocompleteProps> = (props) => {
80
80
  };
81
81
  }, []);
82
82
 
83
+ useEffect(() => {
84
+ if (typeof props.value !== 'undefined') {
85
+ setRecentValue(props.value);
86
+ }
87
+
88
+ if (typeof props.defaultValue !== 'undefined') {
89
+ setRecentValue(props.defaultValue);
90
+ }
91
+ }, [props.value, props.defaultValue]);
92
+
83
93
  useEffect(() => {
84
94
  const { options } = props;
85
95
  const { caret } = state;
@@ -599,23 +609,11 @@ const Autocomplete: React.FC<IAutocompleteProps> = (props) => {
599
609
  ...rest
600
610
  } = props;
601
611
 
602
- const stateValue = recentValue; //state.value;
603
-
604
612
  const propagated: any = Object.assign({}, rest);
605
613
  Object.keys(props).forEach((k) => {
606
614
  delete (propagated as Record<string, unknown>)[k];
607
615
  });
608
616
 
609
- let val = '';
610
-
611
- if (stateValue) {
612
- val = stateValue;
613
- } else if (defaultValue) {
614
- val = defaultValue;
615
- } else if (value !== undefined) {
616
- val = value;
617
- }
618
-
619
617
  return (
620
618
  <>
621
619
  {React.cloneElement(Component, {
@@ -624,7 +622,7 @@ const Autocomplete: React.FC<IAutocompleteProps> = (props) => {
624
622
  onChange: handleChange,
625
623
  onKeyDown: handleKeyDown,
626
624
  ref: refInput,
627
- value: val,
625
+ value: recentValue,
628
626
  ...propagated,
629
627
  ...ComponentProps,
630
628
  })}
@@ -636,10 +634,10 @@ const Autocomplete: React.FC<IAutocompleteProps> = (props) => {
636
634
  const defaultProps: IAutocompleteProps = {
637
635
  Component: <textarea />,
638
636
  ComponentProps: {},
639
- defaultValue: '',
637
+ defaultValue: undefined,
640
638
  disabled: false,
641
639
  maxOptions: 6,
642
- onBlur: () => {},
640
+ onBlur: (evt: any) => {},
643
641
  onChange: (val: string) => {},
644
642
  onKeyDown: (evt: any) => {},
645
643
  onRequestOptions: (val: string) => {},
@@ -62,7 +62,7 @@ export interface FilePickerProps extends Partial<FileBrowserProps> {
62
62
  locale?: SupportedLocales;
63
63
  }
64
64
 
65
- export const FilePicker: React.FC<FilePickerProps> = React.memo(
65
+ export const FilePicker = React.memo(
66
66
  React.forwardRef<FileBrowserHandle, FilePickerProps>(
67
67
  (
68
68
  {