@jobber/components 4.12.0 → 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.
@@ -11,7 +11,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
11
11
 
12
12
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
13
13
 
14
- var css_248z = ".EQDmgmJchDA- {\n margin: 0;\n}\n\n.DkzfClUGQlc- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-wrap: wrap;\n flex-wrap: wrap;\n padding: calc(16px / 2) 0;\n padding: var(--space-small) 0;\n border-bottom: calc(16px / 16) solid rgb(225, 225, 225);\n border-bottom: var(--border-base) solid var(--color-border);\n}\n\n.DkzfClUGQlc-:first-child {\n padding-top: 0;\n}\n\n.DkzfClUGQlc-:last-child {\n padding-bottom: 0;\n border-bottom: none;\n}\n\n.DkzfClUGQlc- dd {\n min-width: calc(16px * 7.5);\n min-width: calc(var(--base-unit) * 7.5);\n box-sizing: border-box;\n padding-right: calc(16px / 2);\n padding-right: var(--space-small);\n -webkit-margin-start: 0;\n margin-left: 0;\n -ms-flex: 1 1 40%;\n flex: 1 1 40%;\n}\n\n.DkzfClUGQlc- dt {\n -ms-flex: 1 1 60%;\n flex: 1 1 60%;\n}\n";
14
+ var css_248z = ".EQDmgmJchDA- {\n margin: 0;\n}\n\n.DkzfClUGQlc- {\n display: -ms-flexbox;\n display: flex;\n -ms-flex-wrap: wrap;\n flex-wrap: wrap;\n padding: calc(16px / 2) 0;\n padding: var(--space-small) 0;\n border-bottom: calc(16px / 16) solid rgb(225, 225, 225);\n border-bottom: var(--border-base) solid var(--color-border);\n}\n\n.DkzfClUGQlc-:first-child {\n padding-top: 0;\n}\n\n.DkzfClUGQlc-:last-child {\n padding-bottom: 0;\n border-bottom: none;\n}\n\n.DkzfClUGQlc- dd {\n min-width: calc(16px * 7.5);\n min-width: calc(var(--base-unit) * 7.5);\n box-sizing: border-box;\n padding-right: calc(16px / 2);\n padding-right: var(--space-small);\n -webkit-margin-start: 0;\n margin-left: 0;\n -ms-flex: 1 1 60%;\n flex: 1 1 60%;\n}\n\n.DkzfClUGQlc- dt {\n -ms-flex: 1 1 40%;\n flex: 1 1 40%;\n}\n";
15
15
  var styles = {"descriptionList":"EQDmgmJchDA-","termGroup":"DkzfClUGQlc-"};
16
16
  styleInject_es.styleInject(css_248z);
17
17
 
@@ -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
- // Remove space, parenthesis and hyphen
95
- const cleanValue = value.replace(/[- )(]/g, "");
96
- if (cleanValue.length < 10) {
97
- return `${errorSubject} must contain ten or more digits`;
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.12.0",
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": "76676bbc5392f8d5d20fcf8812f1b051f900fb6d"
86
+ "gitHead": "fe570a5bf87a69defb2bb360af5f3442cc10c77c"
87
87
  }