@jobber/components 4.12.1 → 4.13.0
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,8 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import { InputMaskProps } from "./InputMask";
|
|
2
3
|
import { CommonFormFieldProps, FormFieldProps } from "../FormField";
|
|
3
4
|
interface InputPhoneNumberProps extends Omit<CommonFormFieldProps, "align">, Pick<FormFieldProps, "autocomplete" | "onEnter" | "onFocus" | "onBlur" | "validations" | "readonly" | "prefix" | "suffix"> {
|
|
4
5
|
readonly value: string;
|
|
5
6
|
readonly onChange: (value: string) => void;
|
|
7
|
+
/**
|
|
8
|
+
* A pattern to specify the format to display the phone number in.
|
|
9
|
+
* For example if you want to display the format for [Denmark](https://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers#Denmark)
|
|
10
|
+
* you could set it to `** ** ** **`
|
|
11
|
+
* @default "(***) ***-****"
|
|
12
|
+
*/
|
|
13
|
+
readonly pattern?: InputMaskProps["pattern"];
|
|
6
14
|
/**
|
|
7
15
|
* Shows a "required" validation message when the component is left empty.
|
|
8
16
|
*/
|
|
@@ -82,8 +82,7 @@ function getMaskedValue(cleanVal, specialChars) {
|
|
|
82
82
|
|
|
83
83
|
function InputPhoneNumber(_a) {
|
|
84
84
|
var { required } = _a, props = tslib_es6.__rest(_a, ["required"]);
|
|
85
|
-
const { placeholder, validations } = props;
|
|
86
|
-
const pattern = "(***) ***-****";
|
|
85
|
+
const { placeholder, validations, pattern = "(***) ***-****" } = props;
|
|
87
86
|
const errorSubject = placeholder || "Phone number";
|
|
88
87
|
return (React__default["default"].createElement(InputMask, { pattern: pattern, strict: false },
|
|
89
88
|
React__default["default"].createElement(FormField.FormField, Object.assign({}, props, { type: "tel", validations: Object.assign(Object.assign({ required: {
|
|
@@ -91,10 +90,17 @@ function InputPhoneNumber(_a) {
|
|
|
91
90
|
message: `${errorSubject} is required`,
|
|
92
91
|
} }, validations), { validate: getPhoneNumberValidation }) }))));
|
|
93
92
|
function getPhoneNumberValidation(value) {
|
|
94
|
-
//
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
93
|
+
// Get unique characters that aren't * in the pattern
|
|
94
|
+
const patternNonDelimterCharacters = pattern
|
|
95
|
+
.split("")
|
|
96
|
+
.filter(char => char !== "*")
|
|
97
|
+
.filter((char, index, arr) => arr.indexOf(char) === index);
|
|
98
|
+
const specialCharacters = patternNonDelimterCharacters.join(" ");
|
|
99
|
+
// Remove special characters from pattern
|
|
100
|
+
const cleanValue = value.replace(new RegExp(`[${specialCharacters}]`, "g"), "");
|
|
101
|
+
const cleanValueRequiredLength = (pattern.match(/\*/g) || []).length;
|
|
102
|
+
if (cleanValue.length < cleanValueRequiredLength) {
|
|
103
|
+
return `${errorSubject} must contain ${cleanValueRequiredLength} or more digits`;
|
|
98
104
|
}
|
|
99
105
|
if (typeof (validations === null || validations === void 0 ? void 0 : validations.validate) === "function") {
|
|
100
106
|
return validations.validate(value);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.13.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"> 1%",
|
|
84
84
|
"IE 10"
|
|
85
85
|
],
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "fe570a5bf87a69defb2bb360af5f3442cc10c77c"
|
|
87
87
|
}
|