@dartech/arsenal-ui 1.4.3 → 1.4.5

Sign up to get free protection for your applications and to get access to all the features.
package/index.js CHANGED
@@ -746,13 +746,13 @@ const ControlAutocomplete = _a => {
746
746
  labelKey
747
747
  });
748
748
  const handleChange = (_, value) => {
749
- onChange(useStringValue ? _get(value, valueKey) : value);
749
+ onChange(useStringValue && valueKey ? _get(value, valueKey) : value);
750
750
  setLocalValue(value);
751
751
  };
752
752
  useEffect(() => {
753
753
  if (typeof value === 'string' && valueKey && useStringValue && !localValue && options.length && !!options[0] && typeof options[0] === 'object') {
754
754
  setLocalValue(options.find(el => _get(el, valueKey) === value));
755
- } else setLocalValue(value);
755
+ }
756
756
  }, [localValue, options, useStringValue, value, valueKey]);
757
757
  return jsx(Autocomplete, Object.assign({}, fieldProps, {
758
758
  value: useStringValue ? localValue !== null && localValue !== void 0 ? localValue : null : value,
@@ -2548,33 +2548,23 @@ var img$2 = "data:image/svg+xml,%3csvg width='32' height='24' viewBox='0 0 32 24
2548
2548
 
2549
2549
  const ControlPhoneInput = _a => {
2550
2550
  var {
2551
+ control,
2551
2552
  name,
2552
2553
  label,
2553
2554
  required,
2554
2555
  mask = '+7 (799) 999 99 99'
2555
2556
  } = _a,
2556
- textFieldProps = __rest(_a, ["name", "label", "required", "mask"]);
2557
- const {
2558
- control,
2559
- watch,
2560
- trigger
2561
- } = useFormContext();
2562
- const phoneNumber = watch(name);
2563
- useEffect(() => {
2564
- if (/(\+7\s\(\d{3}\)\s)(\d{3}\s\d{2})(\s\d{2})/.test(phoneNumber)) {
2565
- trigger(name);
2566
- }
2567
- }, [phoneNumber, trigger, name]);
2557
+ textFieldProps = __rest(_a, ["control", "name", "label", "required", "mask"]);
2568
2558
  return jsx(Controller, {
2569
2559
  control: control,
2570
2560
  name: name,
2571
2561
  rules: {
2572
2562
  required: required && 'Please, fill this field',
2573
2563
  validate: val => {
2574
- if (/(\+7\s\(\d{3}\)\s)(\d{3}\s\d{2})(\s\d{2})/.test(val)) {
2575
- return true;
2564
+ if (!/(\+7\s\(\d{3}\)\s)(\d{3}\s\d{2})(\s\d{2})/.test(val)) {
2565
+ return 'Incorrect phone number format';
2576
2566
  }
2577
- return 'Incorrect phone number format';
2567
+ return true;
2578
2568
  }
2579
2569
  },
2580
2570
  render: ({
@@ -2585,7 +2575,7 @@ const ControlPhoneInput = _a => {
2585
2575
  }) => jsx(InputMask, Object.assign({
2586
2576
  mask: mask
2587
2577
  }, field, {
2588
- children: () => jsx(TextField, Object.assign({
2578
+ children: jsx(TextField, Object.assign({
2589
2579
  fullWidth: true,
2590
2580
  size: "small",
2591
2581
  label: required && label ? jsxs(Fragment, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dartech/arsenal-ui",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "author": "DAR",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -29,7 +29,7 @@
29
29
  "@rollup/plugin-node-resolve": "13.3.0",
30
30
  "lodash": "4.17.21",
31
31
  "qs": "6.11.0",
32
- "react-input-mask": "2.0.4"
32
+ "react-input-mask": "3.0.0-alpha.2"
33
33
  },
34
34
  "module": "./index.js",
35
35
  "main": "./index.js",
@@ -1,10 +1,12 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { TextFieldProps } from '@mui/material/TextField';
3
+ import { Control } from 'react-hook-form';
3
4
  type Props = TextFieldProps & {
5
+ control: Control<any>;
4
6
  name: string;
5
7
  required?: boolean;
6
8
  mask?: string;
7
9
  label?: ReactNode;
8
10
  };
9
- export declare const ControlPhoneInput: ({ name, label, required, mask, ...textFieldProps }: Props) => JSX.Element;
11
+ export declare const ControlPhoneInput: ({ control, name, label, required, mask, ...textFieldProps }: Props) => JSX.Element;
10
12
  export default ControlPhoneInput;