@usssa/component-library 1.0.0-alpha.196 → 1.0.0-alpha.198
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 +1 -1
- package/package.json +1 -1
- package/src/components/core/UInputAddressLookup.vue +38 -25
- package/src/utils/data.ts +10 -10
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -13,9 +13,9 @@ const props = defineProps({
|
|
|
13
13
|
type: Boolean,
|
|
14
14
|
default: false,
|
|
15
15
|
},
|
|
16
|
-
dataTestId:{
|
|
16
|
+
dataTestId: {
|
|
17
17
|
type: String,
|
|
18
|
-
default: 'address-lookup'
|
|
18
|
+
default: 'address-lookup',
|
|
19
19
|
},
|
|
20
20
|
disable: {
|
|
21
21
|
type: Boolean,
|
|
@@ -77,12 +77,13 @@ const props = defineProps({
|
|
|
77
77
|
},
|
|
78
78
|
validationRules: {
|
|
79
79
|
type: Array,
|
|
80
|
-
}
|
|
80
|
+
},
|
|
81
81
|
})
|
|
82
82
|
|
|
83
83
|
let sessionToken, autocompleteSuggestion
|
|
84
84
|
|
|
85
85
|
const inputRef = ref(null)
|
|
86
|
+
const menuWidth = ref(0)
|
|
86
87
|
const predictions = ref([])
|
|
87
88
|
const resultItem = ref({})
|
|
88
89
|
const resultsMenuRef = ref(null)
|
|
@@ -99,27 +100,6 @@ const handleClear = () => {
|
|
|
99
100
|
modelValue.value = ''
|
|
100
101
|
}
|
|
101
102
|
|
|
102
|
-
const parseAddressComponents = (addressComponents) => {
|
|
103
|
-
const address = {}
|
|
104
|
-
for (const component of addressComponents) {
|
|
105
|
-
const { types, longText, shortText } = component
|
|
106
|
-
if (types.includes('street_number')) address.street_number = longText
|
|
107
|
-
if (types.includes('route')) address.street = longText
|
|
108
|
-
if (types.includes('locality')) address.city = longText
|
|
109
|
-
if (types.includes('administrative_area_level_1')) address.state = shortText
|
|
110
|
-
if (types.includes('administrative_area_level_2')) address.county = longText
|
|
111
|
-
if (types.includes('country')) address.country = shortText
|
|
112
|
-
if (types.includes('postal_code')) address.postal_code = longText
|
|
113
|
-
if (types.includes('plus_code')) address.plus_code = longText
|
|
114
|
-
}
|
|
115
|
-
if (address.street && address.street_number)
|
|
116
|
-
address.street_address = `${address.street_number} ${address.street}`
|
|
117
|
-
if (address.street && !address.street_number)
|
|
118
|
-
address.street_address = address.street
|
|
119
|
-
|
|
120
|
-
return address
|
|
121
|
-
}
|
|
122
|
-
|
|
123
103
|
const handleUpdate = async (input) => {
|
|
124
104
|
// fetchAutocompleteSuggestions reference
|
|
125
105
|
// https://developers.google.com/maps/documentation/javascript/reference/autocomplete-data#AutocompleteRequest
|
|
@@ -196,6 +176,35 @@ const onClick = (item) => {
|
|
|
196
176
|
emit('onUpdate', item)
|
|
197
177
|
}
|
|
198
178
|
|
|
179
|
+
const onMenuShow = () => {
|
|
180
|
+
const el =
|
|
181
|
+
inputRef.value?.$el.querySelector('.q-field__control') ||
|
|
182
|
+
inputRef.value?.$el
|
|
183
|
+
menuWidth.value = `${el?.offsetWidth || 0}px`
|
|
184
|
+
resultsMenuShowing.value = true
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const parseAddressComponents = (addressComponents) => {
|
|
188
|
+
const address = {}
|
|
189
|
+
for (const component of addressComponents) {
|
|
190
|
+
const { types, longText, shortText } = component
|
|
191
|
+
if (types.includes('street_number')) address.street_number = longText
|
|
192
|
+
if (types.includes('route')) address.street = longText
|
|
193
|
+
if (types.includes('locality')) address.city = longText
|
|
194
|
+
if (types.includes('administrative_area_level_1')) address.state = shortText
|
|
195
|
+
if (types.includes('administrative_area_level_2')) address.county = longText
|
|
196
|
+
if (types.includes('country')) address.country = shortText
|
|
197
|
+
if (types.includes('postal_code')) address.postal_code = longText
|
|
198
|
+
if (types.includes('plus_code')) address.plus_code = longText
|
|
199
|
+
}
|
|
200
|
+
if (address.street && address.street_number)
|
|
201
|
+
address.street_address = `${address.street_number} ${address.street}`
|
|
202
|
+
if (address.street && !address.street_number)
|
|
203
|
+
address.street_address = address.street
|
|
204
|
+
|
|
205
|
+
return address
|
|
206
|
+
}
|
|
207
|
+
|
|
199
208
|
onMounted(async () => {
|
|
200
209
|
const { AutocompleteSessionToken, AutocompleteSuggestion } =
|
|
201
210
|
await google.maps.importLibrary('places')
|
|
@@ -272,12 +281,16 @@ watch(modelValue, async (value) => {
|
|
|
272
281
|
:standout="!outlined"
|
|
273
282
|
type="text"
|
|
274
283
|
>
|
|
284
|
+
<!-- The 'fit' prop is used to ensure the menu matches the anchor's width for correct positioning,
|
|
285
|
+
while the manual width styling enforces a specific width for visual consistency. -->
|
|
275
286
|
<q-menu
|
|
276
287
|
v-model="resultsMenuShowing"
|
|
288
|
+
fit
|
|
277
289
|
no-focus
|
|
278
290
|
ref="resultsMenuRef"
|
|
291
|
+
:style="{ width: menuWidth }"
|
|
279
292
|
@hide="resultsMenuShowing = false"
|
|
280
|
-
@show="
|
|
293
|
+
@show="onMenuShow"
|
|
281
294
|
>
|
|
282
295
|
<q-list bordered>
|
|
283
296
|
<q-item
|
package/src/utils/data.ts
CHANGED
|
@@ -4,23 +4,23 @@
|
|
|
4
4
|
* @returns {string} - Returns Formatted Date
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
export const formatDate = (date: Date | string | number) => {
|
|
9
|
+
const d = new Date(date);
|
|
8
10
|
return (
|
|
9
|
-
String(
|
|
10
|
-
'/' +
|
|
11
|
-
(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
}
|
|
11
|
+
String(d.getDate()).padStart(2, '0') + '/' +
|
|
12
|
+
String(d.getMonth() + 1).padStart(2, '0') + '/' +
|
|
13
|
+
String(d.getFullYear()).slice(-2)
|
|
14
|
+
);
|
|
15
|
+
};
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @description Return String with Fixed Length
|
|
19
19
|
* @param {string} string, length
|
|
20
20
|
* @returns {string} - Returns Return partial String
|
|
21
21
|
*/
|
|
22
|
-
export const fixStringLength = (str, length) => {
|
|
23
|
-
if (str
|
|
22
|
+
export const fixStringLength = (str: string, length: number) => {
|
|
23
|
+
if (str?.length > length) {
|
|
24
24
|
return str.substring(0, length) + '....'
|
|
25
25
|
} else {
|
|
26
26
|
return str.padEnd(length, ' ')
|