fleetcor-lwc 3.8.4 → 3.8.6

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 CHANGED
@@ -501,11 +501,12 @@ This component fully extends from `Input Text`
501
501
 
502
502
  #### Input Phone methods
503
503
 
504
- | @api | params | return type | description |
505
- | -------- | ----------- | ----------- | ----------------------------------------------------------------------------------------------------------------------- |
506
- | validate | | void | Check component validation and show error message to user |
507
- | isValid | | bool | Return `true` or `false` |
508
- | getData | silent:bool | object | Return full data of component's state. If `silent` true - return value will be without any errors displaying for client |
504
+ | @api | params | return type | description |
505
+ | -------- | ------------------ | ----------- | ----------------------------------------------------------------------------------------------------------------------- |
506
+ | validate | | void | Check component validation and show error message to user |
507
+ | isValid | | bool | Return `true` or `false` |
508
+ | getData | silent:bool | object | Return full data of component's state. If `silent` true - return value will be without any errors displaying for client |
509
+ | setCode | countryCode:string | void | Change country code |
509
510
 
510
511
  #### Input Phone events
511
512
 
@@ -665,6 +666,14 @@ You can override them as you wish by global css variables as priority.
665
666
 
666
667
  ## Release Notes:
667
668
 
669
+ - v.3.8.6
670
+
671
+ - Bug fix visiability of `flt-input-phone`
672
+
673
+ - v.3.8.5
674
+
675
+ - Bug fix visiability of `flt-input-phone`
676
+
668
677
  - v.3.8.4
669
678
 
670
679
  - Bug fix visiability of `flt-input-text`
@@ -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('flt-input-text')
54
- inputEl.firstChild.focus()
55
- inputEl.value = '3456'
56
- inputEl.dispatchEvent(new CustomEvent('change', { detail: inputEl.getData() }))
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
- inputEl.value = '03435234523'
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
  }
@@ -78,9 +79,29 @@ export default class InputPhone extends UserDataValidator {
78
79
  }
79
80
 
80
81
  phoneNumber = ''
82
+
83
+ @api setCode(countryCode) {
84
+ const restore = !this.touched
85
+ this.codeValue = COUNTRIES.find((c) => c.code === countryCode)?.dialCode || this.codeValue
86
+ if (countryCode == CODE_BY_DEFAULT) {
87
+ this.mask.updateOptions({
88
+ mask: '#000000000',
89
+ definitions: {
90
+ '#': /[1-9]/
91
+ },
92
+ overwrite: false,
93
+ lazy: false
94
+ })
95
+ }
96
+ if (restore) {
97
+ this.touched = false
98
+ }
99
+ }
100
+
81
101
  codeValue = ''
82
102
  touched
83
103
  focused
104
+ mask
84
105
 
85
106
  get prefix() {
86
107
  return this.codeValue === CODE_VALUE_SB ? CODE_VALUE_SB + '(0)' : this.codeValue
@@ -129,24 +150,76 @@ export default class InputPhone extends UserDataValidator {
129
150
  this.codeValue = this.codeValue || this.codePrefixByCountryCode
130
151
  }
131
152
 
132
- handleFlagChanged(event) {
133
- this.codeValue = event.detail.value
134
- this.handleChange()
153
+ reInitIMask() {
154
+ this.mask?.destroy()
155
+ this.mask = null
156
+ let settings = {
157
+ mask: Number,
158
+ overwrite: false,
159
+ lazy: false
160
+ }
161
+
162
+ if (this.codeValue == CODE_VALUE_SB) {
163
+ settings = {
164
+ mask: '#000000000',
165
+ definitions: {
166
+ '#': /[1-9]/
167
+ },
168
+ overwrite: false,
169
+ lazy: false
170
+ }
171
+ }
172
+
173
+ const inputEl = this.querySelector('input')
174
+ this.mask = IMask(inputEl, settings)
175
+ const inputElement = this.querySelector('flt-input-text')
176
+ this.mask.unmaskedValue = this.phoneNumber
177
+ inputElement.value = this.mask.value
178
+ this.mask.on('accept', () => {
179
+ if (this.pastePhoneNumber) {
180
+ inputElement.value = this.pastePhoneNumber
181
+ this.mask.value = this.pastePhoneNumber
182
+ this.pastePhoneNumber = null
183
+ }
184
+ this.phoneNumber = this.mask.unmaskedValue
185
+ this.handleChange()
186
+ })
135
187
  }
136
188
 
137
- handlePhoneNumberChanged(event) {
138
- this.phoneNumber = event.detail.value
189
+ renderedCallback() {
190
+ super.renderedCallback()
191
+ if (!this.mask) {
192
+ this.reInitIMask()
193
+ this.querySelector('input').onpaste = (event) => {
194
+ const value =
195
+ '+' + event.clipboardData.getData('text/plain').replace(/[^\w\\s]/gi, '')
196
+ try {
197
+ let phoneNumberUtil = new LIB_PHONE_NUMBER.PhoneNumberUtil()
198
+ let number = phoneNumberUtil.parseAndKeepRawInput(value)
199
+ let regionCode = phoneNumberUtil.getRegionCodeForNumber(number)
200
+ let result = phoneNumberUtil.isValidNumberForRegion(number, regionCode)
201
+ if (result) {
202
+ const newCodeValue = `+${number.getCountryCode()}`
203
+ this.pastePhoneNumber = number.getNationalNumber() + ''
204
+ if (newCodeValue != this.codeValue) {
205
+ this.codeValue = newCodeValue
206
+ this.reInitIMask()
207
+ }
208
+ }
209
+ } catch (error) {
210
+ console.log('error', error)
211
+ }
212
+ }
213
+ }
214
+ }
215
+
216
+ handleFlagChanged(event) {
217
+ this.codeValue = event.detail.value
218
+ this.reInitIMask()
139
219
  this.handleChange()
140
220
  }
141
221
 
142
222
  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
223
  this.dispatchEvent(
151
224
  new CustomEvent('change', {
152
225
  detail: this.getData()
@@ -37,7 +37,7 @@
37
37
  flex-shrink: 0;
38
38
  position: relative;
39
39
  z-index: 1;
40
- width: 72px;
40
+ width: 76px;
41
41
  }
42
42
 
43
43
  &__error {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fleetcor-lwc",
3
- "version": "3.8.4",
3
+ "version": "3.8.6",
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
  }