fleetcor-lwc 3.8.4 → 3.8.5
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.
- package/README.md +4 -0
- package/frontend/components/flt/inputPhone/__test__/inputPhone.test.js +5 -9
- package/frontend/components/flt/inputPhone/inputPhone.html +0 -3
- package/frontend/components/flt/inputPhone/inputPhone.js +67 -13
- package/frontend/components/flt/inputPhone/inputPhone.scss +1 -1
- package/package.json +5 -2
package/README.md
CHANGED
|
@@ -50,16 +50,12 @@ describe('flt-input-phone', () => {
|
|
|
50
50
|
return Promise.resolve().then(async () => {
|
|
51
51
|
const data = picklistEl.getData()
|
|
52
52
|
await expect(data.value).toBe('+44')
|
|
53
|
-
const inputEl = inputPhoneEl.querySelector('
|
|
54
|
-
inputEl.
|
|
55
|
-
inputEl.value = '
|
|
56
|
-
inputEl.dispatchEvent(new CustomEvent('
|
|
53
|
+
const inputEl = inputPhoneEl.querySelector('input')
|
|
54
|
+
inputEl.focus()
|
|
55
|
+
inputEl.value = '3435234523'
|
|
56
|
+
inputEl.dispatchEvent(new CustomEvent('input'))
|
|
57
57
|
return Promise.resolve().then(async () => {
|
|
58
|
-
|
|
59
|
-
inputEl.dispatchEvent(new CustomEvent('change', { detail: inputEl.getData() }))
|
|
60
|
-
return Promise.resolve().then(async () => {
|
|
61
|
-
await expect(inputPhoneEl.getData().isValid).toBeTruthy()
|
|
62
|
-
})
|
|
58
|
+
await expect(inputPhoneEl.getData().isValid).toBeTruthy()
|
|
63
59
|
})
|
|
64
60
|
})
|
|
65
61
|
})
|
|
@@ -17,12 +17,9 @@
|
|
|
17
17
|
class="flt-input-phone__number"
|
|
18
18
|
prefix={prefix}
|
|
19
19
|
disabled={disabled}
|
|
20
|
-
type="number"
|
|
21
20
|
onfocus={handleFocus}
|
|
22
21
|
onblur={handleBlur}
|
|
23
22
|
placeholder={placeholder}
|
|
24
|
-
value={phoneNumber}
|
|
25
|
-
onchange={handlePhoneNumberChanged}
|
|
26
23
|
name="phoneNumber"></flt-input-text>
|
|
27
24
|
</div>
|
|
28
25
|
<div class="flt-input-phone__error">{errorMessage}</div>
|
|
@@ -2,6 +2,7 @@ import { api } from 'lwc'
|
|
|
2
2
|
import { COUNTRIES } from './utils'
|
|
3
3
|
import LIB_PHONE_NUMBER from 'google-libphonenumber'
|
|
4
4
|
import { UserDataValidator } from 'fleetcor-lwc'
|
|
5
|
+
import IMask from 'imask'
|
|
5
6
|
import './inputPhone.scss'
|
|
6
7
|
|
|
7
8
|
const CODE_BY_DEFAULT = 'GB'
|
|
@@ -34,7 +35,7 @@ export default class InputPhone extends UserDataValidator {
|
|
|
34
35
|
let phoneNumberUtil = new LIB_PHONE_NUMBER.PhoneNumberUtil()
|
|
35
36
|
let number = phoneNumberUtil.parseAndKeepRawInput(value)
|
|
36
37
|
this.codeValue = `+${number.getCountryCode()}`
|
|
37
|
-
this.phoneNumber = number.getNationalNumber()
|
|
38
|
+
this.phoneNumber = number.getNationalNumber() + ''
|
|
38
39
|
} catch (error) {
|
|
39
40
|
this.phoneNumber = ''
|
|
40
41
|
}
|
|
@@ -81,6 +82,7 @@ export default class InputPhone extends UserDataValidator {
|
|
|
81
82
|
codeValue = ''
|
|
82
83
|
touched
|
|
83
84
|
focused
|
|
85
|
+
mask
|
|
84
86
|
|
|
85
87
|
get prefix() {
|
|
86
88
|
return this.codeValue === CODE_VALUE_SB ? CODE_VALUE_SB + '(0)' : this.codeValue
|
|
@@ -129,24 +131,76 @@ export default class InputPhone extends UserDataValidator {
|
|
|
129
131
|
this.codeValue = this.codeValue || this.codePrefixByCountryCode
|
|
130
132
|
}
|
|
131
133
|
|
|
132
|
-
|
|
133
|
-
this.
|
|
134
|
-
this.
|
|
134
|
+
reInitIMask() {
|
|
135
|
+
this.mask?.destroy()
|
|
136
|
+
this.mask = null
|
|
137
|
+
let settings = {
|
|
138
|
+
mask: Number,
|
|
139
|
+
overwrite: false,
|
|
140
|
+
lazy: false
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (this.codeValue == CODE_VALUE_SB) {
|
|
144
|
+
settings = {
|
|
145
|
+
mask: '#000000000',
|
|
146
|
+
definitions: {
|
|
147
|
+
'#': /[1-9]/
|
|
148
|
+
},
|
|
149
|
+
overwrite: false,
|
|
150
|
+
lazy: false
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const inputEl = this.querySelector('input')
|
|
155
|
+
this.mask = IMask(inputEl, settings)
|
|
156
|
+
const inputElement = this.querySelector('flt-input-text')
|
|
157
|
+
this.mask.unmaskedValue = this.phoneNumber
|
|
158
|
+
inputElement.value = this.mask.value
|
|
159
|
+
this.mask.on('accept', () => {
|
|
160
|
+
if (this.pastePhoneNumber) {
|
|
161
|
+
inputElement.value = this.pastePhoneNumber
|
|
162
|
+
this.mask.value = this.pastePhoneNumber
|
|
163
|
+
this.pastePhoneNumber = null
|
|
164
|
+
}
|
|
165
|
+
this.phoneNumber = this.mask.unmaskedValue
|
|
166
|
+
this.handleChange()
|
|
167
|
+
})
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
renderedCallback() {
|
|
171
|
+
super.renderedCallback()
|
|
172
|
+
if (!this.mask) {
|
|
173
|
+
this.reInitIMask()
|
|
174
|
+
this.querySelector('input').onpaste = (event) => {
|
|
175
|
+
const value =
|
|
176
|
+
'+' + event.clipboardData.getData('text/plain').replace(/[^\w\\s]/gi, '')
|
|
177
|
+
try {
|
|
178
|
+
let phoneNumberUtil = new LIB_PHONE_NUMBER.PhoneNumberUtil()
|
|
179
|
+
let number = phoneNumberUtil.parseAndKeepRawInput(value)
|
|
180
|
+
let regionCode = phoneNumberUtil.getRegionCodeForNumber(number)
|
|
181
|
+
let result = phoneNumberUtil.isValidNumberForRegion(number, regionCode)
|
|
182
|
+
if (result) {
|
|
183
|
+
const newCodeValue = `+${number.getCountryCode()}`
|
|
184
|
+
this.pastePhoneNumber = number.getNationalNumber() + ''
|
|
185
|
+
if (newCodeValue != this.codeValue) {
|
|
186
|
+
this.codeValue = newCodeValue
|
|
187
|
+
this.reInitIMask()
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
} catch (error) {
|
|
191
|
+
console.log('error', error)
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
135
195
|
}
|
|
136
196
|
|
|
137
|
-
|
|
138
|
-
this.
|
|
197
|
+
handleFlagChanged(event) {
|
|
198
|
+
this.codeValue = event.detail.value
|
|
199
|
+
this.reInitIMask()
|
|
139
200
|
this.handleChange()
|
|
140
201
|
}
|
|
141
202
|
|
|
142
203
|
handleChange(event) {
|
|
143
|
-
if (
|
|
144
|
-
this.codeValue === CODE_VALUE_SB &&
|
|
145
|
-
this.phoneNumber[0] === '0' &&
|
|
146
|
-
this.phoneNumber.length > 1
|
|
147
|
-
) {
|
|
148
|
-
this.phoneNumber = this.phoneNumber.slice(1)
|
|
149
|
-
}
|
|
150
204
|
this.dispatchEvent(
|
|
151
205
|
new CustomEvent('change', {
|
|
152
206
|
detail: this.getData()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fleetcor-lwc",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.5",
|
|
4
4
|
"description": "LWC framework by Fleetcor",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -79,5 +79,8 @@
|
|
|
79
79
|
"webpack": "^5.105.2",
|
|
80
80
|
"webpack-cli": "^6.0.1",
|
|
81
81
|
"webpack-dev-server": "^5.2.3"
|
|
82
|
+
},
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"imask": "^7.6.1"
|
|
82
85
|
}
|
|
83
|
-
}
|
|
86
|
+
}
|