@ssplib/react-components 0.0.215 → 0.0.217

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.
@@ -103,7 +103,11 @@ function FetchAutoComplete({ name, url, title, customLoadingText, shouldRefetch
103
103
  setValue(value);
104
104
  context.formSetValue(name, value.id);
105
105
  onChange(value.id);
106
+ return;
106
107
  }
108
+ setValue(null);
109
+ context.formSetValue(name, '');
110
+ onChange(undefined);
107
111
  }
108
112
  if (defaultValue && list.length <= 0 && !dValue)
109
113
  return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
@@ -50,7 +50,11 @@ function FixedAutoComplete({ name, title, required = false, list, defaultValue,
50
50
  setValue(value);
51
51
  context.formSetValue(name, value.id);
52
52
  onChange(value.id);
53
+ return;
53
54
  }
55
+ setValue(null);
56
+ context.formSetValue(name, '');
57
+ onChange(undefined);
54
58
  }
55
59
  return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
56
60
  title && react_1.default.createElement(material_1.InputLabel, { required: required }, title),
@@ -120,22 +120,22 @@ function Input(_a) {
120
120
  case 'number':
121
121
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
122
122
  mask: numberMask,
123
- } }));
123
+ }, watchValue: watchValue }));
124
124
  case 'cep':
125
125
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
126
126
  mask: '00000-000',
127
- } }));
127
+ }, watchValue: watchValue }));
128
128
  case 'phone':
129
129
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
130
130
  mask: '(00) [#]0000-0000',
131
131
  definitions: {
132
132
  '#': /^9$/,
133
133
  },
134
- } }));
134
+ }, watchValue: watchValue }));
135
135
  case 'sei':
136
136
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
137
137
  mask: '00000-00000000/0000-00',
138
- } }));
138
+ }, watchValue: watchValue }));
139
139
  case 'cpf_cnpj':
140
140
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
141
141
  mask: '000.000.000-00[0]',
@@ -144,19 +144,19 @@ function Input(_a) {
144
144
  setMask('00.000.000/0000-00');
145
145
  else
146
146
  setMask('000.000.000-00[0]');
147
- } }));
147
+ }, watchValue: watchValue }));
148
148
  case 'cpf':
149
149
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
150
150
  mask: '000.000.000-00',
151
- } }));
151
+ }, watchValue: watchValue }));
152
152
  case 'cnpj':
153
153
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
154
154
  mask: '00.000.000/0000-00',
155
- } }));
155
+ }, watchValue: watchValue }));
156
156
  case 'rg':
157
157
  return (react_1.default.createElement(MaskInput_1.default, { formConfig: formConfig, defaultValue: defaultValue, maskProps: {
158
158
  mask: '00000[000000]',
159
- } }));
159
+ }, watchValue: watchValue }));
160
160
  }
161
161
  };
162
162
  return (react_1.default.createElement(material_1.Grid, Object.assign({ item: true }, { xs, sm, md }),
@@ -9,5 +9,6 @@ export default function MaskInput(props: {
9
9
  };
10
10
  };
11
11
  disabled?: boolean;
12
+ watchValue?: string;
12
13
  onMask?: (value: string, setMask: React.Dispatch<React.SetStateAction<string>>) => void;
13
14
  }): JSX.Element;
@@ -39,21 +39,21 @@ const react_1 = __importStar(require("react"));
39
39
  const react_imask_1 = require("react-imask");
40
40
  const form_1 = require("../../../context/form");
41
41
  const TextMaskCustom = react_1.default.forwardRef(function TextMaskCustom(props, ref) {
42
- const { onChange, maskProps, onMask, maskValue, setMaskValue } = props, prop = __rest(props, ["onChange", "maskProps", "onMask", "maskValue", "setMaskValue"]);
42
+ const { onChange, maskProps, onMask, maskValue, setMaskValue, watchValue } = props, prop = __rest(props, ["onChange", "maskProps", "onMask", "maskValue", "setMaskValue", "watchValue"]);
43
43
  const [mask, setMask] = (0, react_1.useState)(maskProps.mask);
44
44
  delete prop.value;
45
45
  const myRef = (0, react_1.useRef)(null);
46
46
  const [myValue, setMyValue] = (0, react_1.useState)('');
47
47
  const context = (0, react_1.useContext)(form_1.FormContext);
48
48
  (0, react_1.useEffect)(() => {
49
- const value = context.formGetValues(prop.name);
50
- if (value) {
51
- setMyValue(value);
49
+ if (watchValue) {
50
+ setMyValue(watchValue);
52
51
  }
53
- }, [context.formWatch(prop.name)]);
52
+ }, [watchValue]);
54
53
  (0, react_1.useEffect)(() => {
55
54
  context.formSetValue(prop.name, myRef.current.element.value);
56
55
  }, [myValue]);
56
+ delete prop.watchValue;
57
57
  return (react_1.default.createElement(react_imask_1.IMaskInput, Object.assign({}, prop, maskProps, { mask: mask, value: myValue, ref: myRef, inputRef: ref, onChange: (e) => { }, onAccept: (value, mask) => {
58
58
  setMyValue(value);
59
59
  mask.updateValue();
@@ -72,7 +72,7 @@ function MaskInput(props) {
72
72
  context.formSetValue(name, value);
73
73
  }, InputProps: {
74
74
  inputComponent: TextMaskCustom,
75
- inputProps: { maskProps: props.maskProps, onMask: props.onMask, maskValue, setMaskValue },
75
+ inputProps: { maskProps: props.maskProps, onMask: props.onMask, maskValue, setMaskValue, watchValue: props.watchValue },
76
76
  }, disabled: props.disabled, fullWidth: true }))));
77
77
  }
78
78
  exports.default = MaskInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ssplib/react-components",
3
- "version": "0.0.215",
3
+ "version": "0.0.217",
4
4
  "description": "SSP React Components",
5
5
  "main": "index.js",
6
6
  "author": "Pedro Henrique <sr.hudrick@gmail.com>",