@weareconceptstudio/form 0.2.0 → 0.2.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.
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import classNames from 'classnames';
|
|
3
|
-
import
|
|
3
|
+
import PhoneInput from 'react-phone-number-input/input';
|
|
4
4
|
import useFormInstance from '../form/hooks/useFormInstance';
|
|
5
|
+
import { Controller } from 'react-hook-form';
|
|
5
6
|
const PhoneNumber = ({ name, className, autoComplete = 'new-password', options = {} }) => {
|
|
6
|
-
const { control } = useFormInstance();
|
|
7
|
+
const { control, setValue, getValues, trigger } = useFormInstance();
|
|
7
8
|
const classString = classNames('phone-number-input', {
|
|
8
9
|
[className]: className,
|
|
9
10
|
});
|
|
10
|
-
return (React.createElement(
|
|
11
|
+
return (React.createElement(Controller, { name: name, control: control, render: ({ field: { onChange, value, onBlur } }) => (React.createElement(PhoneInput, { name: name, country: 'AM', maxLength: 14, international: true, withCountryCallingCode: true, className: classString, autoComplete: autoComplete, value: getValues(name), onChange: (value) => {
|
|
12
|
+
setValue(name, value);
|
|
13
|
+
trigger(name);
|
|
14
|
+
}, onBlur: () => {
|
|
15
|
+
onBlur();
|
|
16
|
+
}, ...options })) }));
|
|
11
17
|
};
|
|
12
18
|
export default PhoneNumber;
|
package/dist/select/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useMemo } from 'react';
|
|
1
|
+
import React, { useState, useMemo, useEffect, useRef } from 'react';
|
|
2
2
|
import ReactSelect, { components } from 'react-select';
|
|
3
3
|
import classNames from 'classnames';
|
|
4
4
|
import { bottom_arrow, empty } from './icons';
|
|
@@ -14,10 +14,18 @@ const Select = (props) => {
|
|
|
14
14
|
let selectProps = {};
|
|
15
15
|
if (formInstance == null) {
|
|
16
16
|
const [val, setVal] = useState(value);
|
|
17
|
+
const isInternalUpdate = useRef(false);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
if (!isInternalUpdate.current) {
|
|
20
|
+
setVal(value);
|
|
21
|
+
}
|
|
22
|
+
isInternalUpdate.current = false;
|
|
23
|
+
}, [value]);
|
|
17
24
|
selectProps = {
|
|
18
25
|
onChange: (e) => {
|
|
19
26
|
onChange?.(e.value);
|
|
20
27
|
setVal(e.value);
|
|
28
|
+
isInternalUpdate.current = true;
|
|
21
29
|
},
|
|
22
30
|
value: val,
|
|
23
31
|
};
|