@jobber/components 4.12.1 → 4.13.1
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.
|
@@ -43,7 +43,7 @@ var IndexChange;
|
|
|
43
43
|
})(IndexChange || (IndexChange = {}));
|
|
44
44
|
function Menu({ visible, options, selectedOption, onOptionSelect, attachTo, }) {
|
|
45
45
|
const [highlightedIndex, setHighlightedIndex] = React.useState(0);
|
|
46
|
-
const { menuRef, setMenuRef, styles: popperStyles, attributes, targetWidth, } = useRepositionMenu(attachTo);
|
|
46
|
+
const { menuRef, setMenuRef, styles: popperStyles, attributes, targetWidth, } = useRepositionMenu(attachTo, visible);
|
|
47
47
|
const detectSeparatorCondition = (option) => option.description || option.details;
|
|
48
48
|
const detectGroups = (option) => option.options;
|
|
49
49
|
const addSeparators = options.some(detectSeparatorCondition);
|
|
@@ -128,7 +128,7 @@ function isGroup(option) {
|
|
|
128
128
|
return true;
|
|
129
129
|
return false;
|
|
130
130
|
}
|
|
131
|
-
function useRepositionMenu(attachTo) {
|
|
131
|
+
function useRepositionMenu(attachTo, visible = false) {
|
|
132
132
|
var _a;
|
|
133
133
|
const [menuRef, setMenuRef] = React.useState();
|
|
134
134
|
const popper = reactPopper.usePopper(attachTo.current, menuRef, {
|
|
@@ -137,6 +137,10 @@ function useRepositionMenu(attachTo) {
|
|
|
137
137
|
{ name: "flip", options: { fallbackPlacements: ["top"] } },
|
|
138
138
|
],
|
|
139
139
|
});
|
|
140
|
+
React.useLayoutEffect(() => {
|
|
141
|
+
var _a;
|
|
142
|
+
(_a = popper === null || popper === void 0 ? void 0 : popper.update) === null || _a === void 0 ? void 0 : _a.call(popper);
|
|
143
|
+
}, [visible]);
|
|
140
144
|
const targetWidth = (_a = attachTo.current) === null || _a === void 0 ? void 0 : _a.clientWidth;
|
|
141
145
|
return Object.assign(Object.assign({}, popper), { menuRef, setMenuRef, targetWidth });
|
|
142
146
|
}
|
|
@@ -163,7 +167,7 @@ function Autocomplete({ initialOptions = [], value, allowFreeForm = true, size =
|
|
|
163
167
|
}, [value]);
|
|
164
168
|
return (React__default["default"].createElement("div", { className: styles.autocomplete, ref: autocompleteRef },
|
|
165
169
|
React__default["default"].createElement(InputText.InputText, { autocomplete: false, size: size, invalid: invalid, value: inputText, onChange: handleInputChange, placeholder: placeholder, onFocus: handleInputFocus, onBlur: handleInputBlur }),
|
|
166
|
-
menuVisible && (React__default["default"].createElement(Menu, { attachTo: autocompleteRef, visible:
|
|
170
|
+
menuVisible && (React__default["default"].createElement(Menu, { attachTo: autocompleteRef, visible: menuVisible && options.length > 0, options: options, selectedOption: value, onOptionSelect: handleMenuChange }))));
|
|
167
171
|
function updateInput(newText) {
|
|
168
172
|
setInputText(newText);
|
|
169
173
|
if (newText === "") {
|
|
@@ -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.1",
|
|
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": "56af06fdafe3039a0dd9412eded62f771a93a0d0"
|
|
87
87
|
}
|