@descope/web-components-ui 1.0.174 → 1.0.176
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/index.cjs.js +785 -587
- package/dist/cjs/index.cjs.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +993 -622
- package/dist/index.esm.js.map +1 -1
- package/dist/umd/{descope-phone-field-descope-phone-field-internal-index-js.js → 7262.js} +1 -1
- package/dist/umd/index.js +1 -1
- package/dist/umd/phone-fields-descope-phone-field-descope-phone-field-internal-index-js.js +1 -0
- package/dist/umd/{descope-phone-field-index-js.js → phone-fields-descope-phone-field-index-js.js} +1 -1
- package/dist/umd/phone-fields-descope-phone-input-box-field-descope-phone-input-box-internal-index-js.js +1 -0
- package/dist/umd/phone-fields-descope-phone-input-box-field-index-js.js +1 -0
- package/package.json +1 -1
- package/src/components/{descope-phone-field → phone-fields/descope-phone-field}/PhoneFieldClass.js +8 -7
- package/src/components/{descope-phone-field → phone-fields/descope-phone-field}/descope-phone-field-internal/PhoneFieldInternal.js +36 -19
- package/src/components/{descope-phone-field → phone-fields/descope-phone-field}/descope-phone-field-internal/index.js +2 -2
- package/src/components/{descope-phone-field → phone-fields/descope-phone-field}/index.js +2 -2
- package/src/components/phone-fields/descope-phone-input-box-field/PhoneFieldInputBoxClass.js +174 -0
- package/src/components/phone-fields/descope-phone-input-box-field/descope-phone-input-box-internal/PhoneFieldInternalInputBox.js +158 -0
- package/src/components/phone-fields/descope-phone-input-box-field/descope-phone-input-box-internal/index.js +5 -0
- package/src/components/phone-fields/descope-phone-input-box-field/index.js +9 -0
- package/src/components/phone-fields/helpers.js +5 -0
- package/src/index.cjs.js +2 -1
- package/src/index.d.ts +2 -1
- package/src/index.js +2 -1
- package/src/theme/components/index.js +2 -0
- package/src/theme/components/phoneField.js +1 -1
- package/src/theme/components/phoneInputBoxField.js +30 -0
- /package/src/components/{descope-phone-field → phone-fields}/CountryCodes.js +0 -0
- /package/src/components/{descope-phone-field → phone-fields/descope-phone-field}/helpers.js +0 -0
@@ -0,0 +1,158 @@
|
|
1
|
+
import { createBaseInputClass } from '../../../../baseClasses/createBaseInputClass';
|
2
|
+
import { getComponentName } from '../../../../helpers/componentHelpers';
|
3
|
+
import { getCountryByCodeId } from '../../helpers';
|
4
|
+
|
5
|
+
export const componentName = getComponentName('phone-field-internal-input-box');
|
6
|
+
|
7
|
+
const observedAttributes = [
|
8
|
+
'disabled',
|
9
|
+
'size',
|
10
|
+
'bordered',
|
11
|
+
'invalid',
|
12
|
+
'readonly',
|
13
|
+
'phone-input-placeholder',
|
14
|
+
];
|
15
|
+
const mapAttrs = {
|
16
|
+
'phone-input-placeholder': 'placeholder',
|
17
|
+
};
|
18
|
+
|
19
|
+
const BaseInputClass = createBaseInputClass({ componentName, baseSelector: 'div' });
|
20
|
+
|
21
|
+
class PhoneFieldInternal extends BaseInputClass {
|
22
|
+
static get observedAttributes() {
|
23
|
+
return [].concat(BaseInputClass.observedAttributes || [], observedAttributes);
|
24
|
+
}
|
25
|
+
|
26
|
+
constructor() {
|
27
|
+
super();
|
28
|
+
|
29
|
+
this.innerHTML = `
|
30
|
+
<div>
|
31
|
+
<descope-text-field tabindex="1"></descope-text-field>
|
32
|
+
</div>
|
33
|
+
`;
|
34
|
+
|
35
|
+
this.phoneNumberInput = this.querySelector('descope-text-field');
|
36
|
+
}
|
37
|
+
|
38
|
+
get defaultCountryCode() {
|
39
|
+
return getCountryByCodeId(this.getAttribute('default-code'));
|
40
|
+
}
|
41
|
+
|
42
|
+
get hasDefaultCode() {
|
43
|
+
return !!this.getAttribute('default-code');
|
44
|
+
}
|
45
|
+
|
46
|
+
get value() {
|
47
|
+
if (!this.phoneNumberValue) {
|
48
|
+
return '';
|
49
|
+
}
|
50
|
+
|
51
|
+
if (this.hasDefaultCode) {
|
52
|
+
// we want to transform phone numbers to a valid {dialCode}-{phoneNumber} format
|
53
|
+
// e.g.:
|
54
|
+
// +972-12345 => +972-12345
|
55
|
+
// 972-12345 => +972-12345
|
56
|
+
// 12345 => +972-12345
|
57
|
+
//
|
58
|
+
// we also want to handle any extra dash if added in the start of the phone number
|
59
|
+
// e.g.:
|
60
|
+
// +972--12345 => +972-12345
|
61
|
+
const pattern = new RegExp(`\\+?${parseInt(this.defaultCountryCode, 10)}--?`);
|
62
|
+
return `${this.defaultCountryCode}-${this.phoneNumberInput.value.replace(pattern, '')}`;
|
63
|
+
}
|
64
|
+
|
65
|
+
return this.phoneNumberInput.value;
|
66
|
+
}
|
67
|
+
|
68
|
+
set value(val) {
|
69
|
+
this.phoneNumberInput.value = val;
|
70
|
+
}
|
71
|
+
|
72
|
+
get phoneNumberValue() {
|
73
|
+
return this.phoneNumberInput.value;
|
74
|
+
}
|
75
|
+
|
76
|
+
get minLength() {
|
77
|
+
return parseInt(this.getAttribute('minlength'), 10) || 0;
|
78
|
+
}
|
79
|
+
|
80
|
+
get maxLength() {
|
81
|
+
return parseInt(this.getAttribute('maxlength'), 10) || 50;
|
82
|
+
}
|
83
|
+
|
84
|
+
getValidity() {
|
85
|
+
const validPhonePattern = /^\+\d{1,4}-(?:\d-?){1,15}$/;
|
86
|
+
const stripValue = this.value.replace(/\D/g, '');
|
87
|
+
|
88
|
+
if (this.isRequired && !this.value) {
|
89
|
+
return { valueMissing: true };
|
90
|
+
}
|
91
|
+
|
92
|
+
if (stripValue.length < this.minLength) {
|
93
|
+
return { tooShort: true };
|
94
|
+
}
|
95
|
+
|
96
|
+
if (stripValue.length > this.maxLength) {
|
97
|
+
return { tooLong: true };
|
98
|
+
}
|
99
|
+
|
100
|
+
if (!validPhonePattern.test(this.value)) {
|
101
|
+
return { patternMismatch: true };
|
102
|
+
}
|
103
|
+
|
104
|
+
return {};
|
105
|
+
}
|
106
|
+
|
107
|
+
init() {
|
108
|
+
this.addEventListener('focus', (e) => {
|
109
|
+
// we want to ignore focus events we are dispatching
|
110
|
+
if (e.isTrusted) this.phoneNumberInput.focus();
|
111
|
+
});
|
112
|
+
|
113
|
+
super.init?.();
|
114
|
+
this.initInputs();
|
115
|
+
}
|
116
|
+
|
117
|
+
getCountryByDialCode(countryDialCode) {
|
118
|
+
return this.countryCodeInput.items?.find(
|
119
|
+
(c) => c.getAttribute('data-dial-code') === countryDialCode
|
120
|
+
);
|
121
|
+
}
|
122
|
+
|
123
|
+
initInputs() {
|
124
|
+
// Sanitize phone input value to filter everything but digits
|
125
|
+
this.phoneNumberInput.addEventListener('input', (e) => {
|
126
|
+
if (e.target.value.length === 1 && e.target.value === '-') {
|
127
|
+
e.target.value = '';
|
128
|
+
}
|
129
|
+
|
130
|
+
e.target.value = e.target.value
|
131
|
+
.replace(/(?!^)\+/g, '')
|
132
|
+
.replace('--', '-')
|
133
|
+
.replace('+-', '+');
|
134
|
+
|
135
|
+
const telDigitsRegExp = /^[+\d-]+$/;
|
136
|
+
const sanitizedInput = e.target.value
|
137
|
+
.split('')
|
138
|
+
.filter((char) => telDigitsRegExp.test(char))
|
139
|
+
.join('');
|
140
|
+
|
141
|
+
e.target.value = sanitizedInput;
|
142
|
+
});
|
143
|
+
|
144
|
+
this.handleFocusEventsDispatching([this.phoneNumberInput]);
|
145
|
+
this.handleInputEventDispatching();
|
146
|
+
}
|
147
|
+
|
148
|
+
attributeChangedCallback(attrName, oldValue, newValue) {
|
149
|
+
super.attributeChangedCallback(attrName, oldValue, newValue);
|
150
|
+
|
151
|
+
if (oldValue !== newValue && observedAttributes.includes(attrName)) {
|
152
|
+
const attr = mapAttrs[attrName] || attrName;
|
153
|
+
this.phoneNumberInput.setAttribute(attr, newValue);
|
154
|
+
}
|
155
|
+
}
|
156
|
+
}
|
157
|
+
|
158
|
+
export default PhoneFieldInternal;
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import './descope-phone-input-box-internal';
|
2
|
+
import '../../descope-combo-box';
|
3
|
+
import '../../descope-text-field';
|
4
|
+
|
5
|
+
import { componentName, PhoneFieldInputBoxClass } from './PhoneFieldInputBoxClass';
|
6
|
+
|
7
|
+
customElements.define(componentName, PhoneFieldInputBoxClass);
|
8
|
+
|
9
|
+
export { PhoneFieldInputBoxClass };
|
package/src/index.cjs.js
CHANGED
@@ -22,6 +22,7 @@ export { TextClass } from './components/descope-text/TextClass';
|
|
22
22
|
export { TextAreaClass } from './components/descope-text-area/TextAreaClass';
|
23
23
|
export { TextFieldClass } from './components/descope-text-field/TextFieldClass';
|
24
24
|
export { ImageClass } from './components/descope-image/ImageClass';
|
25
|
-
export { PhoneFieldClass } from './components/descope-phone-field/PhoneFieldClass';
|
25
|
+
export { PhoneFieldClass } from './components/phone-fields/descope-phone-field/PhoneFieldClass';
|
26
|
+
export { PhoneFieldInputBoxClass } from './components/phone-fields/descope-phone-input-box-field/PhoneFieldInputBoxClass';
|
26
27
|
export { NewPasswordClass } from './components/descope-new-password/NewPasswordClass';
|
27
28
|
export { RecaptchaClass } from './components/descope-recaptcha/RecaptchaClass';
|
package/src/index.d.ts
CHANGED
@@ -27,7 +27,8 @@ export { TextClass } from './components/descope-text';
|
|
27
27
|
export { TextAreaClass } from './components/descope-text-area';
|
28
28
|
export { TextFieldClass } from './components/descope-text-field';
|
29
29
|
export { ImageClass } from './components/descope-image';
|
30
|
-
export { PhoneFieldClass } from './components/descope-phone-field';
|
30
|
+
export { PhoneFieldClass } from './components/phone-fields/descope-phone-field';
|
31
|
+
export { PhoneFieldInputBoxClass } from './components/phone-fields/descope-phone-input-box-field';
|
31
32
|
export { NewPasswordClass } from './components/descope-new-password';
|
32
33
|
export { RecaptchaClass } from './components/descope-recaptcha';
|
33
34
|
export { UploadFileClass } from './components/descope-upload-file';
|
package/src/index.js
CHANGED
@@ -17,7 +17,8 @@ export * from './components/descope-text';
|
|
17
17
|
export * from './components/descope-text-area';
|
18
18
|
export * from './components/descope-text-field';
|
19
19
|
export * from './components/descope-image';
|
20
|
-
export * from './components/descope-phone-field';
|
20
|
+
export * from './components/phone-fields/descope-phone-field';
|
21
|
+
export * from './components/phone-fields/descope-phone-input-box-field';
|
21
22
|
export * from './components/descope-new-password';
|
22
23
|
export * from './components/descope-recaptcha';
|
23
24
|
export * from './components/descope-upload-file';
|
@@ -17,6 +17,7 @@ import { loaderRadial, loaderLinear } from './loader';
|
|
17
17
|
import * as comboBox from './comboBox';
|
18
18
|
import * as image from './image';
|
19
19
|
import * as phoneField from './phoneField';
|
20
|
+
import * as phoneInputBoxField from './phoneInputBoxField';
|
20
21
|
import * as newPassword from './newPassword';
|
21
22
|
import * as inputWrapper from './inputWrapper';
|
22
23
|
import * as uploadFile from './uploadFile';
|
@@ -42,6 +43,7 @@ const components = {
|
|
42
43
|
comboBox,
|
43
44
|
image,
|
44
45
|
phoneField,
|
46
|
+
phoneInputBoxField,
|
45
47
|
newPassword,
|
46
48
|
inputWrapper,
|
47
49
|
uploadFile,
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { PhoneFieldClass } from '../../components/descope-phone-field/PhoneFieldClass';
|
1
|
+
import { PhoneFieldClass } from '../../components/phone-fields/descope-phone-field/PhoneFieldClass';
|
2
2
|
import { refs } from './inputWrapper';
|
3
3
|
|
4
4
|
const vars = PhoneFieldClass.cssVarList;
|
@@ -0,0 +1,30 @@
|
|
1
|
+
import { PhoneFieldInputBoxClass } from '../../components/phone-fields/descope-phone-input-box-field/PhoneFieldInputBoxClass';
|
2
|
+
import { refs } from './inputWrapper';
|
3
|
+
|
4
|
+
const vars = PhoneFieldInputBoxClass.cssVarList;
|
5
|
+
|
6
|
+
const phoneInputBoxField = {
|
7
|
+
[vars.hostWidth]: '16em',
|
8
|
+
[vars.hostMinWidth]: refs.minWidth,
|
9
|
+
[vars.fontSize]: refs.fontSize,
|
10
|
+
[vars.fontFamily]: refs.fontFamily,
|
11
|
+
[vars.labelTextColor]: refs.labelTextColor,
|
12
|
+
[vars.labelRequiredIndicator]: refs.requiredIndicator,
|
13
|
+
[vars.errorMessageTextColor]: refs.errorMessageTextColor,
|
14
|
+
[vars.inputValueTextColor]: refs.valueTextColor,
|
15
|
+
[vars.inputPlaceholderTextColor]: refs.placeholderTextColor,
|
16
|
+
[vars.inputBorderStyle]: refs.borderStyle,
|
17
|
+
[vars.inputBorderWidth]: refs.borderWidth,
|
18
|
+
[vars.inputBorderColor]: refs.borderColor,
|
19
|
+
[vars.inputBorderRadius]: refs.borderRadius,
|
20
|
+
[vars.inputOutlineStyle]: refs.outlineStyle,
|
21
|
+
[vars.inputOutlineWidth]: refs.outlineWidth,
|
22
|
+
[vars.inputOutlineColor]: refs.outlineColor,
|
23
|
+
[vars.inputOutlineOffset]: refs.outlineOffset,
|
24
|
+
_fullWidth: {
|
25
|
+
[vars.hostWidth]: refs.width,
|
26
|
+
},
|
27
|
+
};
|
28
|
+
|
29
|
+
export default phoneInputBoxField;
|
30
|
+
export { vars };
|
File without changes
|
File without changes
|