fleetcor-lwc 3.0.0 → 3.3.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.
Files changed (73) hide show
  1. package/README.md +146 -4
  2. package/frontend/components/flt/button/button.scss +2 -1
  3. package/frontend/components/flt/inputEmail/__test__/inputEmail.test.js +39 -0
  4. package/frontend/components/flt/inputEmail/inputEmail.js +8 -0
  5. package/frontend/components/flt/inputPhone/__test__/radioItem.test.js +56 -0
  6. package/frontend/components/flt/inputPhone/arrow.svg +3 -0
  7. package/frontend/components/flt/inputPhone/close-button.svg +3 -0
  8. package/frontend/components/flt/inputPhone/flags/AD@2x.png +0 -0
  9. package/frontend/components/flt/inputPhone/flags/AL@2x.png +0 -0
  10. package/frontend/components/flt/inputPhone/flags/AT@2x.png +0 -0
  11. package/frontend/components/flt/inputPhone/flags/BA@2x.png +0 -0
  12. package/frontend/components/flt/inputPhone/flags/BE@2x.png +0 -0
  13. package/frontend/components/flt/inputPhone/flags/BG@2x.png +0 -0
  14. package/frontend/components/flt/inputPhone/flags/BY@2x.png +0 -0
  15. package/frontend/components/flt/inputPhone/flags/CH@2x.png +0 -0
  16. package/frontend/components/flt/inputPhone/flags/CZ@2x.png +0 -0
  17. package/frontend/components/flt/inputPhone/flags/DE@2x.png +0 -0
  18. package/frontend/components/flt/inputPhone/flags/DK@2x.png +0 -0
  19. package/frontend/components/flt/inputPhone/flags/EE@2x.png +0 -0
  20. package/frontend/components/flt/inputPhone/flags/ES@2x.png +0 -0
  21. package/frontend/components/flt/inputPhone/flags/FI@2x.png +0 -0
  22. package/frontend/components/flt/inputPhone/flags/FO@2x.png +0 -0
  23. package/frontend/components/flt/inputPhone/flags/FR@2x.png +0 -0
  24. package/frontend/components/flt/inputPhone/flags/GB@2x.png +0 -0
  25. package/frontend/components/flt/inputPhone/flags/GI@2x.png +0 -0
  26. package/frontend/components/flt/inputPhone/flags/GR@2x.png +0 -0
  27. package/frontend/components/flt/inputPhone/flags/HR@2x.png +0 -0
  28. package/frontend/components/flt/inputPhone/flags/HU@2x.png +0 -0
  29. package/frontend/components/flt/inputPhone/flags/IE@2x.png +0 -0
  30. package/frontend/components/flt/inputPhone/flags/IS@2x.png +0 -0
  31. package/frontend/components/flt/inputPhone/flags/IT@2x.png +0 -0
  32. package/frontend/components/flt/inputPhone/flags/LI@2x.png +0 -0
  33. package/frontend/components/flt/inputPhone/flags/LT@2x.png +0 -0
  34. package/frontend/components/flt/inputPhone/flags/LU@2x.png +0 -0
  35. package/frontend/components/flt/inputPhone/flags/LV@2x.png +0 -0
  36. package/frontend/components/flt/inputPhone/flags/MC@2x.png +0 -0
  37. package/frontend/components/flt/inputPhone/flags/MD@2x.png +0 -0
  38. package/frontend/components/flt/inputPhone/flags/ME@2x.png +0 -0
  39. package/frontend/components/flt/inputPhone/flags/MK@2x.png +0 -0
  40. package/frontend/components/flt/inputPhone/flags/MT@2x.png +0 -0
  41. package/frontend/components/flt/inputPhone/flags/NL@2x.png +0 -0
  42. package/frontend/components/flt/inputPhone/flags/NO@2x.png +0 -0
  43. package/frontend/components/flt/inputPhone/flags/PL@2x.png +0 -0
  44. package/frontend/components/flt/inputPhone/flags/PT@2x.png +0 -0
  45. package/frontend/components/flt/inputPhone/flags/RO@2x.png +0 -0
  46. package/frontend/components/flt/inputPhone/flags/RS@2x.png +0 -0
  47. package/frontend/components/flt/inputPhone/flags/RU@2x.png +0 -0
  48. package/frontend/components/flt/inputPhone/flags/SE@2x.png +0 -0
  49. package/frontend/components/flt/inputPhone/flags/SI@2x.png +0 -0
  50. package/frontend/components/flt/inputPhone/flags/SK@2x.png +0 -0
  51. package/frontend/components/flt/inputPhone/flags/SM@2x.png +0 -0
  52. package/frontend/components/flt/inputPhone/flags/UA@2x.png +0 -0
  53. package/frontend/components/flt/inputPhone/flags/VA@2x.png +0 -0
  54. package/frontend/components/flt/inputPhone/inputPhone.html +109 -0
  55. package/frontend/components/flt/inputPhone/inputPhone.js +252 -0
  56. package/frontend/components/flt/inputPhone/inputPhone.scss +288 -0
  57. package/frontend/components/flt/inputPhone/utils.js +325 -0
  58. package/frontend/components/flt/inputText/__test__/inputText.test.js +211 -0
  59. package/frontend/components/flt/inputText/inputText.html +24 -0
  60. package/frontend/components/flt/inputText/inputText.js +99 -0
  61. package/frontend/components/flt/inputText/inputText.scss +124 -0
  62. package/frontend/components/flt/modal/__test__/modal.test.js +30 -0
  63. package/frontend/components/flt/modal/modal.html +6 -0
  64. package/frontend/components/flt/modal/modal.js +8 -0
  65. package/frontend/components/flt/modal/modal.scss +34 -0
  66. package/frontend/components/flt/progressStep/__test__/progressStep.test.js +17 -1
  67. package/frontend/components/flt/progressStep/progressStep.scss +6 -6
  68. package/frontend/components/flt/tooltip/tooltip.js +4 -4
  69. package/frontend/core/index.js +2 -0
  70. package/frontend/core/interface/InputElement.js +87 -0
  71. package/frontend/core/interface/ModalViewer.js +26 -0
  72. package/frontend/core/interface/UserDataManager.js +11 -1
  73. package/package.json +12 -7
@@ -0,0 +1,252 @@
1
+ import InputText from 'flt/inputText'
2
+ import { api } from 'lwc'
3
+ import { COUNTRIES } from './utils'
4
+ import LIB_PHONE_NUMBER from 'google-libphonenumber'
5
+ import IMask from 'imask'
6
+ import closeButton from './close-button.svg'
7
+
8
+ import './inputPhone.scss'
9
+
10
+ export default class InputPhone extends InputText {
11
+ flagActive
12
+ mask
13
+ input
14
+ closeButton = closeButton
15
+
16
+ required = true
17
+ @api selectedCode
18
+ @api picklistInsideModalView
19
+
20
+ @api isValid() {
21
+ let result = true
22
+
23
+ if (!this.val) {
24
+ result = false
25
+ }
26
+
27
+ try {
28
+ let phoneNumberUtil = new LIB_PHONE_NUMBER.PhoneNumberUtil()
29
+ let number = phoneNumberUtil.parseAndKeepRawInput(this.formattedNumber)
30
+ let regionCode = phoneNumberUtil.getRegionCodeForNumber(number)
31
+ result = phoneNumberUtil.isValidNumberForRegion(number, regionCode)
32
+ } catch (error) {
33
+ result = false
34
+ }
35
+
36
+ return result
37
+ }
38
+
39
+ get valid(){
40
+ let result = true
41
+
42
+ if (!this.val) {
43
+ result = false
44
+ }
45
+
46
+ try {
47
+ let phoneNumberUtil = new LIB_PHONE_NUMBER.PhoneNumberUtil()
48
+ let number = phoneNumberUtil.parseAndKeepRawInput(this.formattedNumber)
49
+ let regionCode = phoneNumberUtil.getRegionCodeForNumber(number)
50
+ result = phoneNumberUtil.isValidNumberForRegion(number, regionCode)
51
+ } catch (error) {
52
+ result = false
53
+ }
54
+
55
+ return result
56
+ }
57
+
58
+ @api getData(silent) {
59
+ return {
60
+ ...super.getData(silent),
61
+ value: `${this.selectedCode} ${this.val}`,
62
+ separateValue: {
63
+ code: this.selectedCode,
64
+ phone: this.val
65
+ }
66
+ }
67
+ }
68
+
69
+ @api
70
+ get value() {
71
+ let result = this.formattedNumber
72
+ if (result) {
73
+ try {
74
+ let phoneNumberUtil = new LIB_PHONE_NUMBER.PhoneNumberUtil()
75
+ let number = phoneNumberUtil.parseAndKeepRawInput(result)
76
+ result = `+${number.getCountryCode()} ${number.getNationalNumber()}`
77
+ } catch (error) {}
78
+ }
79
+ return result
80
+ }
81
+
82
+ set value(value) {
83
+ this.val = value || ''
84
+
85
+ if (this.val) {
86
+ this.touched = true
87
+ try {
88
+ let phoneNumberUtil = new LIB_PHONE_NUMBER.PhoneNumberUtil()
89
+ let number = phoneNumberUtil.parseAndKeepRawInput(this.val)
90
+ this.selectedCode = `+${number.getCountryCode()}`
91
+ this.val = number.getNationalNumber()
92
+ } catch (error) {
93
+ this.val = this.val.replace(`${this.selectedCode} `, '')
94
+ }
95
+ }
96
+ }
97
+
98
+ get formattedNumber() {
99
+ if (this.selectedCode && this.val) {
100
+ return `${this.selectedCode} ${this.val}`
101
+ }
102
+ }
103
+
104
+ get flagOptions() {
105
+ return COUNTRIES.map((item) => {
106
+ return {
107
+ icon: item.flag,
108
+ key: item.code,
109
+ value: item.dialCode,
110
+ label: item.dialCode,
111
+ selected: this.selectedCode == item.dialCode
112
+ }
113
+ })
114
+ }
115
+
116
+ get selectedFlagOption() {
117
+ return this.flagOptions.find((item) => item.value == this.selectedCode)
118
+ }
119
+
120
+ get selectedFlag() {
121
+ if (this.selectedFlagOption) {
122
+ return this.selectedFlagOption.icon
123
+ }
124
+ }
125
+
126
+ get selectedDialCode() {
127
+ if (this.selectedFlagOption) {
128
+ return this.selectedFlagOption.value
129
+ }
130
+ }
131
+
132
+ get dialCodes() {
133
+ return this.flagOptions.map((n) => n.value)
134
+ }
135
+
136
+ get inputStyle() {
137
+ return this.generateClassNameList({
138
+ 'flt-input-phone': true,
139
+ 'flt-input-phone_active': this.val || this.focused,
140
+ 'flt-input-phone_error': this.touched && !this.valid,
141
+ 'flt-input-phone_success': this.val && this.valid,
142
+ 'flt-input-phone_flag_active': this.flagActive,
143
+ 'flt-input-phone_flag_selected': this.selectedCode,
144
+ 'flt-input-phone_picklist-inside-modal-view': this.picklistInsideModalView
145
+ })
146
+ }
147
+
148
+ get computedModalClass() {
149
+ return this.generateClassNameList({
150
+ 'flt-input-phone__modal': true,
151
+ 'flt-input-phone__modal-active': this.flagActive
152
+ })
153
+ }
154
+
155
+ renderedCallback() {
156
+ if (!this.connected) {
157
+ this.input = this.querySelector('input')
158
+ this.mask = IMask(this.input, {
159
+ mask: Number,
160
+ overwrite: true,
161
+ lazy: false
162
+ })
163
+ this.mask.unmaskedValue = this.val + ''
164
+ this.mask.on('accept', this.handleChange.bind(this))
165
+ this.connected = true
166
+ }
167
+ }
168
+
169
+ handleFocused(event) {
170
+ super.handleFocused(event)
171
+ if (!this.mask.unmaskedValue) {
172
+ this.input.setSelectionRange(
173
+ this.mask.unmaskedValue.length,
174
+ this.mask.unmaskedValue.length
175
+ )
176
+ setTimeout(() => {
177
+ this.input.setSelectionRange(
178
+ this.mask.unmaskedValue.length,
179
+ this.mask.unmaskedValue.length
180
+ )
181
+ }, 60)
182
+ }
183
+ }
184
+
185
+ disconnectedCallback() {
186
+ this.connected = false
187
+ }
188
+
189
+ handleFlagActivate() {
190
+ this.flagActive = !this.flagActive
191
+ }
192
+
193
+ handleLabelClick() {
194
+ this.flagActive = false
195
+ }
196
+
197
+ handleSelectFlag(event) {
198
+ this.flagActive = false
199
+ this.selectedCode = event.currentTarget.dataset.value
200
+ this.mask?.updateOptions({
201
+ mask: Number,
202
+ overwrite: 'shift',
203
+ lazy: false
204
+ })
205
+ }
206
+
207
+ handleChange() {
208
+ this.val = this.mask?.unmaskedValue
209
+
210
+ if (this.val && this.val.trimStart().startsWith('+')) {
211
+ if (this.val.includes(this.selectedDialCode)) {
212
+ this.val = this.val.replace(this.selectedDialCode, '').trim()
213
+ } else if (this.val.trimStart().includes(' ')) {
214
+ let code = this.val.trimStart().split(' ')[0]
215
+ if (this.dialCodes.includes(code)) {
216
+ this.val = this.val.replace(code, '').trim()
217
+ this.selectedCode = code
218
+ }
219
+ }
220
+ }
221
+
222
+ this.dispatchEvent(
223
+ new CustomEvent('change', {
224
+ detail: {
225
+ ...this.getData()
226
+ }
227
+ })
228
+ )
229
+ }
230
+
231
+ handleInput(event) {
232
+ event.stopPropagation()
233
+ this.handleChange({
234
+ data: event?.target?.value
235
+ })
236
+ }
237
+
238
+ handleBlur(event) {
239
+ if (this.disabled) return
240
+ this.focused = false
241
+ this.touched = true
242
+ this.val = (event.target.value || '').trimEnd()
243
+ event.target.value = this.val
244
+ this.dispatchEvent(
245
+ new CustomEvent('blur_happend', {
246
+ detail: null,
247
+ cancelable: true,
248
+ bubbles: true
249
+ })
250
+ )
251
+ }
252
+ }
@@ -0,0 +1,288 @@
1
+ .flt-input-phone {
2
+ color: #111827;
3
+ position: relative;
4
+ font-weight: 400;
5
+
6
+ &_active {
7
+ .flt-input-phone__number {
8
+ height: 20px;
9
+ opacity: 1;
10
+ }
11
+
12
+ .flt-input-phone__input,
13
+ .flt-input-phone__code {
14
+ line-height: 20px;
15
+ font-size: 16px;
16
+ }
17
+
18
+ .flt-input-phone__placeholder {
19
+ font-size: 12px;
20
+ line-height: 16px;
21
+ }
22
+
23
+ .flt-input-phone__block {
24
+ border-color: var(--input-border-color-active, #6b7280);
25
+ }
26
+ }
27
+
28
+ &_error {
29
+ .flt-input-phone__block {
30
+ border-color: #ef4444;
31
+ }
32
+
33
+ .flt-input-phone__error {
34
+ height: 16px;
35
+ opacity: 1;
36
+ }
37
+ }
38
+
39
+ &_success {
40
+ .flt-input-phone__block {
41
+ border-color: #59eb9c;
42
+ }
43
+ }
44
+
45
+ &_flag {
46
+ &_active {
47
+ .flt-input-phone__flag-block {
48
+ &:after {
49
+ content: '';
50
+ transform: scale(-1);
51
+ }
52
+ }
53
+
54
+ .flt-input-phone__flag-list {
55
+ height: initial;
56
+ opacity: 1;
57
+ }
58
+ }
59
+ }
60
+
61
+ &__wrapp {
62
+ background-color: #fff;
63
+ height: 100%;
64
+ max-width: 75%;
65
+ flex-grow: 1;
66
+ display: flex;
67
+ flex-direction: column;
68
+ justify-content: center;
69
+ transition: all 0.3s;
70
+ }
71
+
72
+ &__number {
73
+ height: 0;
74
+ opacity: 0;
75
+ line-height: 20px;
76
+ font-size: 16px;
77
+ transition: all 0.3s;
78
+ }
79
+
80
+ &__placeholder {
81
+ font-size: 16px;
82
+ line-height: 20px;
83
+ }
84
+
85
+ &__error {
86
+ height: 0;
87
+ opacity: 0;
88
+ font-size: 12px;
89
+ line-height: 16px;
90
+ color: #ef4444;
91
+ transition: all 0.3s;
92
+ margin-top: 4px;
93
+ }
94
+
95
+ &__block {
96
+ padding-left: 16px;
97
+ padding-right: 16px;
98
+ border: 1px solid #6b7280;
99
+ border-radius: var(--input-border-radius, 12px);
100
+ background-color: #fff;
101
+ display: flex;
102
+ align-items: center;
103
+ height: 44px;
104
+ position: relative;
105
+ z-index: 101;
106
+ }
107
+
108
+ &__flag-block {
109
+ margin-right: 8px;
110
+ display: flex;
111
+ align-items: center;
112
+ justify-content: space-between;
113
+ font-size: 16px;
114
+ width: 56px;
115
+ line-height: 20px;
116
+
117
+ &:after {
118
+ content: '';
119
+ display: inline-block;
120
+ transition: all 0.3s;
121
+ width: 24px;
122
+ height: 24px;
123
+ background: url('./arrow.svg') no-repeat;
124
+ background-size: contain;
125
+ }
126
+ }
127
+
128
+ &__flag-wrapper {
129
+ position: relative;
130
+ flex-shrink: 0;
131
+ }
132
+
133
+ &__flag-list {
134
+ height: 0;
135
+ opacity: 0;
136
+ padding: 0;
137
+ margin: 0;
138
+ list-style-type: none;
139
+ position: absolute;
140
+ z-index: 100;
141
+ background-color: #fff;
142
+ border-bottom-right-radius: 12px;
143
+ border-bottom-left-radius: 12px;
144
+ box-shadow: 0px 10px 15px -3px rgba(16, 24, 40, 0.1);
145
+ left: 0;
146
+ top: 22px;
147
+ width: 100%;
148
+ overflow: hidden;
149
+ transition: all 0.3s;
150
+ max-height: 212px;
151
+ overflow-y: scroll;
152
+ }
153
+
154
+ &__flag-list-item {
155
+ padding: 12px 17px;
156
+ display: flex;
157
+ align-items: center;
158
+ border-bottom: 1px solid #eeeeee;
159
+ background-color: #fff;
160
+
161
+ &:first-child {
162
+ padding-top: 30px;
163
+ }
164
+
165
+ &:last-child {
166
+ border-bottom: none;
167
+ border-bottom-right-radius: 12px;
168
+ border-bottom-left-radius: 12px;
169
+ }
170
+
171
+ &_selected {
172
+ background-color: var(--flag-list-item-selected-bg-color, #f2d400);
173
+ }
174
+ }
175
+
176
+ &__flag-icon-label {
177
+ margin-left: 1rem;
178
+ }
179
+
180
+ &__flag-icon,
181
+ &__flag-selected-icon {
182
+ width: 24px;
183
+ height: 24px;
184
+ border-radius: 100%;
185
+ object-fit: cover;
186
+ }
187
+
188
+ &__flag-selected-value {
189
+ display: flex;
190
+ }
191
+
192
+ &__number {
193
+ display: flex;
194
+ }
195
+
196
+ &__input {
197
+ width: 100%;
198
+ line-height: 0;
199
+ font-size: 0;
200
+ transition: all 0.3s;
201
+ outline: none;
202
+ border: none;
203
+ padding: 0;
204
+ letter-spacing: 1px;
205
+ }
206
+
207
+ &__code {
208
+ line-height: 0;
209
+ font-size: 0;
210
+ transition: all 0.3s;
211
+ margin-right: 8px;
212
+ }
213
+
214
+ &_picklist-inside-modal-view {
215
+ .flt-input-phone__modal-active {
216
+ position: initial;
217
+ display: initial;
218
+ }
219
+
220
+ .flt-input-phone__modal-glass,
221
+ .flt-input-phone__modal-header {
222
+ display: none;
223
+ }
224
+
225
+ @media (max-width: 1279px) {
226
+ .flt-input-phone__modal {
227
+ display: none;
228
+ }
229
+
230
+ .flt-input-phone__modal-active {
231
+ position: fixed;
232
+ display: flex;
233
+ align-items: center;
234
+ justify-content: center;
235
+ top: 0;
236
+ left: 0;
237
+ width: 100%;
238
+ height: 100%;
239
+ z-index: 200000;
240
+ }
241
+
242
+ .flt-input-phone__modal-glass {
243
+ display: block;
244
+ position: absolute;
245
+ width: 100%;
246
+ height: 100%;
247
+ left: 0;
248
+ top: 0;
249
+ background: rgba(0, 0, 0, 0.4);
250
+ }
251
+
252
+ .flt-input-phone__modal-container {
253
+ position: relative;
254
+ background-color: #ffffff;
255
+ border-radius: var(--input-border-radius, 12px);
256
+ overflow: hidden;
257
+
258
+ .flt-input-phone__flag-list {
259
+ position: initial;
260
+ max-width: 300px;
261
+ width: 300px;
262
+ top: initial;
263
+ left: initial;
264
+ }
265
+ }
266
+
267
+ .flt-input-phone__modal-header {
268
+ display: flex;
269
+ align-items: center;
270
+ justify-content: space-between;
271
+ font-weight: 600;
272
+ padding: 12px;
273
+ background-color: var(--gray-5, #f8f8f8);
274
+ }
275
+
276
+ .flt-input-phone__flag-list {
277
+ max-height: 80vh !important;
278
+ overflow: auto !important;
279
+ }
280
+
281
+ .flt-input-phone__flag-list-item {
282
+ &:first-child {
283
+ padding-top: 12px;
284
+ }
285
+ }
286
+ }
287
+ }
288
+ }