sprintify-ui 0.0.164 → 0.0.166
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 +34 -1
- package/dist/sprintify-ui.es.js +16799 -16560
- package/dist/style.css +1 -1
- package/dist/types/src/components/BaseAddressForm.vue.d.ts +45 -0
- package/dist/types/src/components/BaseAutocomplete.vue.d.ts +2 -2
- package/dist/types/src/components/BaseAutocompleteFetch.vue.d.ts +1 -1
- package/dist/types/src/components/BaseCharacterCounter.vue.d.ts +1 -1
- package/dist/types/src/components/BaseFieldI18n.vue.d.ts +1 -1
- package/dist/types/src/components/BaseInput.vue.d.ts +1 -1
- package/dist/types/src/components/BaseInputPercent.vue.d.ts +1 -1
- package/dist/types/src/components/BaseModalCenter.vue.d.ts +1 -1
- package/dist/types/src/components/BaseModalSide.vue.d.ts +1 -1
- package/dist/types/src/components/BaseNumber.vue.d.ts +1 -1
- package/dist/types/src/components/BaseTagAutocomplete.vue.d.ts +2 -2
- package/dist/types/src/components/BaseTagAutocompleteFetch.vue.d.ts +1 -1
- package/dist/types/src/components/BaseTextareaAutoresize.vue.d.ts +1 -1
- package/dist/types/src/components/index.d.ts +2 -1
- package/dist/types/src/index.d.ts +34 -0
- package/dist/types/src/types/Country.d.ts +4 -0
- package/dist/types/src/types/Region.d.ts +5 -0
- package/package.json +2 -1
- package/src/components/BaseAddressForm.stories.js +63 -0
- package/src/components/BaseAddressForm.vue +303 -0
- package/src/components/BaseInput.vue +15 -1
- package/src/components/index.ts +2 -0
- package/src/index.ts +14 -0
- package/src/lang/en.json +7 -0
- package/src/lang/fr.json +7 -0
- package/src/types/Country.ts +4 -0
- package/src/types/Region.ts +5 -0
|
@@ -9,16 +9,21 @@ import { useField } from './composables/field';
|
|
|
9
9
|
declare const messages: {
|
|
10
10
|
en: {
|
|
11
11
|
sui: {
|
|
12
|
+
address: string;
|
|
13
|
+
address_1_placeholder: string;
|
|
14
|
+
address_2_description: string;
|
|
12
15
|
and: string;
|
|
13
16
|
apply_filters: string;
|
|
14
17
|
autocomplete_placeholder: string;
|
|
15
18
|
cancel: string;
|
|
19
|
+
city: string;
|
|
16
20
|
clear: string;
|
|
17
21
|
click_or_select_date: string;
|
|
18
22
|
click_to_copy: string;
|
|
19
23
|
columns: string;
|
|
20
24
|
confirm: string;
|
|
21
25
|
copied: string;
|
|
26
|
+
country: string;
|
|
22
27
|
create_new: string;
|
|
23
28
|
day: string;
|
|
24
29
|
delete_record: string;
|
|
@@ -43,9 +48,11 @@ declare const messages: {
|
|
|
43
48
|
or: string;
|
|
44
49
|
page: string;
|
|
45
50
|
pagination_detail: string;
|
|
51
|
+
postal_code_zip_code: string;
|
|
46
52
|
previous: string;
|
|
47
53
|
previous_month: string;
|
|
48
54
|
read_more: string;
|
|
55
|
+
region: string;
|
|
49
56
|
remove: string;
|
|
50
57
|
remove_file: string;
|
|
51
58
|
remove_file_description: string;
|
|
@@ -77,16 +84,21 @@ declare const messages: {
|
|
|
77
84
|
};
|
|
78
85
|
fr: {
|
|
79
86
|
sui: {
|
|
87
|
+
address: string;
|
|
88
|
+
address_1_placeholder: string;
|
|
89
|
+
address_2_description: string;
|
|
80
90
|
and: string;
|
|
81
91
|
apply_filters: string;
|
|
82
92
|
autocomplete_placeholder: string;
|
|
83
93
|
cancel: string;
|
|
94
|
+
city: string;
|
|
84
95
|
clear: string;
|
|
85
96
|
click_or_select_date: string;
|
|
86
97
|
click_to_copy: string;
|
|
87
98
|
columns: string;
|
|
88
99
|
confirm: string;
|
|
89
100
|
copied: string;
|
|
101
|
+
country: string;
|
|
90
102
|
create_new: string;
|
|
91
103
|
day: string;
|
|
92
104
|
delete_record: string;
|
|
@@ -111,9 +123,11 @@ declare const messages: {
|
|
|
111
123
|
or: string;
|
|
112
124
|
page: string;
|
|
113
125
|
pagination_detail: string;
|
|
126
|
+
postal_code_zip_code: string;
|
|
114
127
|
previous: string;
|
|
115
128
|
previous_month: string;
|
|
116
129
|
read_more: string;
|
|
130
|
+
region: string;
|
|
117
131
|
remove: string;
|
|
118
132
|
remove_file: string;
|
|
119
133
|
remove_file_description: string;
|
|
@@ -146,6 +160,8 @@ declare const messages: {
|
|
|
146
160
|
};
|
|
147
161
|
import './assets/main.css';
|
|
148
162
|
import { Locales } from './types';
|
|
163
|
+
import { Country } from './types/Country';
|
|
164
|
+
import { Region } from './types/Region';
|
|
149
165
|
export interface Options {
|
|
150
166
|
i18n?: I18n<typeof messages, {}, {}, string, true>;
|
|
151
167
|
http?: AxiosInstance;
|
|
@@ -153,21 +169,28 @@ export interface Options {
|
|
|
153
169
|
locales?: Locales;
|
|
154
170
|
formatQueryString?: (params: Record<string, any>) => string;
|
|
155
171
|
parseQueryString?: (params: string) => Record<string, any>;
|
|
172
|
+
countries?: Country[];
|
|
173
|
+
regions?: Region[];
|
|
156
174
|
}
|
|
157
175
|
declare const config: {
|
|
158
176
|
i18n: I18n<{
|
|
159
177
|
en: {
|
|
160
178
|
sui: {
|
|
179
|
+
address: string;
|
|
180
|
+
address_1_placeholder: string;
|
|
181
|
+
address_2_description: string;
|
|
161
182
|
and: string;
|
|
162
183
|
apply_filters: string;
|
|
163
184
|
autocomplete_placeholder: string;
|
|
164
185
|
cancel: string;
|
|
186
|
+
city: string;
|
|
165
187
|
clear: string;
|
|
166
188
|
click_or_select_date: string;
|
|
167
189
|
click_to_copy: string;
|
|
168
190
|
columns: string;
|
|
169
191
|
confirm: string;
|
|
170
192
|
copied: string;
|
|
193
|
+
country: string;
|
|
171
194
|
create_new: string;
|
|
172
195
|
day: string;
|
|
173
196
|
delete_record: string;
|
|
@@ -192,9 +215,11 @@ declare const config: {
|
|
|
192
215
|
or: string;
|
|
193
216
|
page: string;
|
|
194
217
|
pagination_detail: string;
|
|
218
|
+
postal_code_zip_code: string;
|
|
195
219
|
previous: string;
|
|
196
220
|
previous_month: string;
|
|
197
221
|
read_more: string;
|
|
222
|
+
region: string;
|
|
198
223
|
remove: string;
|
|
199
224
|
remove_file: string;
|
|
200
225
|
remove_file_description: string;
|
|
@@ -226,16 +251,21 @@ declare const config: {
|
|
|
226
251
|
};
|
|
227
252
|
fr: {
|
|
228
253
|
sui: {
|
|
254
|
+
address: string;
|
|
255
|
+
address_1_placeholder: string;
|
|
256
|
+
address_2_description: string;
|
|
229
257
|
and: string;
|
|
230
258
|
apply_filters: string;
|
|
231
259
|
autocomplete_placeholder: string;
|
|
232
260
|
cancel: string;
|
|
261
|
+
city: string;
|
|
233
262
|
clear: string;
|
|
234
263
|
click_or_select_date: string;
|
|
235
264
|
click_to_copy: string;
|
|
236
265
|
columns: string;
|
|
237
266
|
confirm: string;
|
|
238
267
|
copied: string;
|
|
268
|
+
country: string;
|
|
239
269
|
create_new: string;
|
|
240
270
|
day: string;
|
|
241
271
|
delete_record: string;
|
|
@@ -260,9 +290,11 @@ declare const config: {
|
|
|
260
290
|
or: string;
|
|
261
291
|
page: string;
|
|
262
292
|
pagination_detail: string;
|
|
293
|
+
postal_code_zip_code: string;
|
|
263
294
|
previous: string;
|
|
264
295
|
previous_month: string;
|
|
265
296
|
read_more: string;
|
|
297
|
+
region: string;
|
|
266
298
|
remove: string;
|
|
267
299
|
remove_file: string;
|
|
268
300
|
remove_file_description: string;
|
|
@@ -298,6 +330,8 @@ declare const config: {
|
|
|
298
330
|
upload_url: string;
|
|
299
331
|
formatQueryString(params: Record<string, any>): string;
|
|
300
332
|
parseQueryString(params: string): Record<string, any>;
|
|
333
|
+
countries: Country[];
|
|
334
|
+
regions: Region[];
|
|
301
335
|
};
|
|
302
336
|
declare function install(app: App, options?: Options): void;
|
|
303
337
|
declare const _default: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprintify-ui",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.166",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"build": "rimraf dist && vue-tsc && vite build",
|
|
6
6
|
"build-fast": "rimraf dist && vite build",
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@tailwindcss/forms": "^0.5.3",
|
|
53
53
|
"@tailwindcss/line-clamp": "^0.4.2",
|
|
54
54
|
"@tailwindcss/typography": "^0.5.8",
|
|
55
|
+
"@types/google.maps": "^3.51.0",
|
|
55
56
|
"@types/humanize-duration": "^3.27.1",
|
|
56
57
|
"@types/luxon": "^3.1.0",
|
|
57
58
|
"@types/object-hash": "^2.2.1",
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import BaseAddressForm from './BaseAddressForm.vue';
|
|
2
|
+
import ShowValue from '../../.storybook/components/ShowValue.vue';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
title: 'Form/BaseAddressForm',
|
|
6
|
+
component: BaseAddressForm,
|
|
7
|
+
argTypes: {},
|
|
8
|
+
args: {
|
|
9
|
+
countries: [
|
|
10
|
+
{ code: 'US', name: 'United States', id: 'us' },
|
|
11
|
+
{ code: 'CA', name: 'Canada', id: 'ca' },
|
|
12
|
+
{ code: 'MX', name: 'Mexico', id: 'mx' },
|
|
13
|
+
],
|
|
14
|
+
regions: [
|
|
15
|
+
{ code: 'AL', name: 'Alabama', id: 'al', country_id: 'us' },
|
|
16
|
+
{ code: 'AK', name: 'Alaska', id: 'ak', country_id: 'us' },
|
|
17
|
+
{ code: 'AZ', name: 'Arizona', id: 'az', country_id: 'us' },
|
|
18
|
+
{ code: 'AB', name: 'Alberta', id: 'ab', country_id: 'ca' },
|
|
19
|
+
{ code: 'BC', name: 'British Columbia', id: 'bc', country_id: 'ca' },
|
|
20
|
+
{ code: 'MB', name: 'Manitoba', id: 'mb', country_id: 'ca' },
|
|
21
|
+
{ code: 'NS', name: 'Nova Scotia', id: 'ns', country_id: 'ca' },
|
|
22
|
+
{ code: 'ON', name: 'Ontario', id: 'on', country_id: 'ca' },
|
|
23
|
+
{ code: 'PE', name: 'Prince Edward Island', id: 'pe', country_id: 'ca' },
|
|
24
|
+
{ code: 'QC', name: 'Quebec', id: 'qc', country_id: 'ca' },
|
|
25
|
+
{ code: 'SK', name: 'Saskatchewan', id: 'sk', country_id: 'ca' },
|
|
26
|
+
{ code: 'NT', name: 'Northwest Territories', id: 'nt', country_id: 'ca' },
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const Template = (args) => ({
|
|
32
|
+
components: { BaseAddressForm, ShowValue },
|
|
33
|
+
setup() {
|
|
34
|
+
const form = ref({});
|
|
35
|
+
return { args, form };
|
|
36
|
+
},
|
|
37
|
+
template: `
|
|
38
|
+
<BaseAddressForm v-model="form.shipping_address" prefix="shipping_address" v-bind="args"></BaseAddressForm>
|
|
39
|
+
<ShowValue :value="form" />
|
|
40
|
+
`,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const Demo = Template.bind({});
|
|
44
|
+
Demo.args = {};
|
|
45
|
+
|
|
46
|
+
const DefaultCountryTemplate = (args) => ({
|
|
47
|
+
components: { BaseAddressForm, ShowValue },
|
|
48
|
+
setup() {
|
|
49
|
+
const form = ref({
|
|
50
|
+
shipping_address: {
|
|
51
|
+
country: 'ca',
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
return { args, form };
|
|
55
|
+
},
|
|
56
|
+
template: `
|
|
57
|
+
<BaseAddressForm v-model="form.shipping_address" prefix="shipping_address" v-bind="args"></BaseAddressForm>
|
|
58
|
+
<ShowValue :value="form" />
|
|
59
|
+
`,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const DefaultCountry = DefaultCountryTemplate.bind({});
|
|
63
|
+
DefaultCountry.args = {};
|
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<BaseField
|
|
3
|
+
:label="$t('sui.address')"
|
|
4
|
+
:name="`${namePrefix}address_1`"
|
|
5
|
+
class="mb-2"
|
|
6
|
+
required
|
|
7
|
+
>
|
|
8
|
+
<BaseInput
|
|
9
|
+
ref="address1Ref"
|
|
10
|
+
:model-value="normalizedModelValue.address_1 ?? ''"
|
|
11
|
+
:placeholder="$t('sui.address_1_placeholder')"
|
|
12
|
+
class="w-full"
|
|
13
|
+
prevent-submit
|
|
14
|
+
:autocomplete="false"
|
|
15
|
+
:required="false"
|
|
16
|
+
@update:model-value="update('address_1', $event)"
|
|
17
|
+
/>
|
|
18
|
+
</BaseField>
|
|
19
|
+
|
|
20
|
+
<BaseField :name="`${namePrefix}address_2`" class="mb-4">
|
|
21
|
+
<BaseInput
|
|
22
|
+
:model-value="normalizedModelValue.address_2 ?? ''"
|
|
23
|
+
:placeholder="$t('sui.address_2_description')"
|
|
24
|
+
class="w-full"
|
|
25
|
+
@update:model-value="update('address_2', $event)"
|
|
26
|
+
/>
|
|
27
|
+
</BaseField>
|
|
28
|
+
|
|
29
|
+
<div class="sm:flex sm:space-x-3">
|
|
30
|
+
<BaseField
|
|
31
|
+
:label="$t('sui.city')"
|
|
32
|
+
required
|
|
33
|
+
:name="`${namePrefix}city`"
|
|
34
|
+
class="mb-4 flex-1"
|
|
35
|
+
>
|
|
36
|
+
<BaseInput
|
|
37
|
+
:model-value="normalizedModelValue.city ?? ''"
|
|
38
|
+
class="w-full"
|
|
39
|
+
@update:model-value="update('city', $event)"
|
|
40
|
+
/>
|
|
41
|
+
</BaseField>
|
|
42
|
+
<BaseField
|
|
43
|
+
:label="$t('sui.postal_code_zip_code')"
|
|
44
|
+
required
|
|
45
|
+
:name="`${namePrefix}postal_code`"
|
|
46
|
+
class="mb-4 flex-1"
|
|
47
|
+
>
|
|
48
|
+
<BaseInput
|
|
49
|
+
:model-value="normalizedModelValue.postal_code ?? ''"
|
|
50
|
+
class="w-full"
|
|
51
|
+
@update:model-value="update('postal_code', $event)"
|
|
52
|
+
/>
|
|
53
|
+
</BaseField>
|
|
54
|
+
</div>
|
|
55
|
+
<div class="sm:flex sm:space-x-3">
|
|
56
|
+
<BaseField
|
|
57
|
+
:label="$t('sui.country')"
|
|
58
|
+
:name="`${namePrefix}country`"
|
|
59
|
+
required
|
|
60
|
+
class="mb-4 flex-1"
|
|
61
|
+
>
|
|
62
|
+
<BaseSelect
|
|
63
|
+
:model-value="normalizedModelValue.country ?? ''"
|
|
64
|
+
class="w-full"
|
|
65
|
+
@update:model-value="update('country', $event)"
|
|
66
|
+
>
|
|
67
|
+
<option
|
|
68
|
+
v-for="country in countries"
|
|
69
|
+
:key="country.id"
|
|
70
|
+
:value="country.id"
|
|
71
|
+
>
|
|
72
|
+
{{ country.name }}
|
|
73
|
+
</option>
|
|
74
|
+
</BaseSelect>
|
|
75
|
+
</BaseField>
|
|
76
|
+
<BaseField
|
|
77
|
+
:label="$t('sui.region')"
|
|
78
|
+
:name="`${namePrefix}country`"
|
|
79
|
+
required
|
|
80
|
+
class="mb-4 flex-1"
|
|
81
|
+
>
|
|
82
|
+
<BaseSelect
|
|
83
|
+
:model-value="normalizedModelValue.region ?? ''"
|
|
84
|
+
:label="$t('sui.region')"
|
|
85
|
+
:name="`${namePrefix}region`"
|
|
86
|
+
class="w-full"
|
|
87
|
+
required
|
|
88
|
+
@update:model-value="update('region', $event)"
|
|
89
|
+
>
|
|
90
|
+
<option v-for="region in regions" :key="region.id" :value="region.id">
|
|
91
|
+
{{ region.name }}
|
|
92
|
+
</option>
|
|
93
|
+
</BaseSelect>
|
|
94
|
+
</BaseField>
|
|
95
|
+
</div>
|
|
96
|
+
</template>
|
|
97
|
+
|
|
98
|
+
<script lang="ts" setup>
|
|
99
|
+
import { ComputedRef } from 'vue';
|
|
100
|
+
import { cloneDeep, isArray } from 'lodash';
|
|
101
|
+
import { Country } from '@/types/Country';
|
|
102
|
+
import { Region } from '@/types/Region';
|
|
103
|
+
import BaseField from './BaseField.vue';
|
|
104
|
+
import BaseInput from './BaseInput.vue';
|
|
105
|
+
import BaseSelect from './BaseSelect.vue';
|
|
106
|
+
import { config } from '..';
|
|
107
|
+
|
|
108
|
+
const props = withDefaults(
|
|
109
|
+
defineProps<{
|
|
110
|
+
modelValue: Record<string, string | number | null | undefined>;
|
|
111
|
+
prefix: string | null;
|
|
112
|
+
countries?: Country[];
|
|
113
|
+
regions?: Region[];
|
|
114
|
+
}>(),
|
|
115
|
+
{
|
|
116
|
+
modelValue() {
|
|
117
|
+
return {};
|
|
118
|
+
},
|
|
119
|
+
prefix: null,
|
|
120
|
+
countries() {
|
|
121
|
+
return [];
|
|
122
|
+
},
|
|
123
|
+
regions() {
|
|
124
|
+
return [];
|
|
125
|
+
},
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const emit = defineEmits(['update:model-value']);
|
|
130
|
+
|
|
131
|
+
const normalizedModelValue = computed(
|
|
132
|
+
(): Record<string, string | number | null | undefined> => {
|
|
133
|
+
const form = cloneDeep(props.modelValue ?? {});
|
|
134
|
+
form.address_1 = form.address_1 ?? '';
|
|
135
|
+
form.address_2 = form.address_2 ?? '';
|
|
136
|
+
form.city = form.city ?? '';
|
|
137
|
+
form.postal_code = form.postal_code ?? '';
|
|
138
|
+
form.country = form.country ?? '';
|
|
139
|
+
form.region = form.region ?? '';
|
|
140
|
+
return form;
|
|
141
|
+
}
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
const countries = computed((): Country[] => {
|
|
145
|
+
if (props.countries && isArray(props.countries) && props.countries.length) {
|
|
146
|
+
return props.countries;
|
|
147
|
+
}
|
|
148
|
+
return config.countries;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const allRegions = computed((): Region[] => {
|
|
152
|
+
if (props.regions && isArray(props.regions) && props.regions.length) {
|
|
153
|
+
return props.regions;
|
|
154
|
+
}
|
|
155
|
+
return config.regions;
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
const regions = computed((): Country[] => {
|
|
159
|
+
return allRegions.value.filter(
|
|
160
|
+
(r) => r.country_id == normalizedModelValue.value.country
|
|
161
|
+
);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
const namePrefix = computed((): string => {
|
|
165
|
+
if (props.prefix) {
|
|
166
|
+
return props.prefix + '.';
|
|
167
|
+
}
|
|
168
|
+
return '';
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
function update(field: string, value: string) {
|
|
172
|
+
const newForm = cloneDeep(normalizedModelValue.value);
|
|
173
|
+
newForm[field] = value;
|
|
174
|
+
emit('update:model-value', newForm);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Autocomplete
|
|
178
|
+
|
|
179
|
+
const address1Ref = ref<InstanceType<typeof BaseInput> | null>(null);
|
|
180
|
+
const address1Input = computed(
|
|
181
|
+
() => address1Ref.value?.$refs.input ?? null
|
|
182
|
+
) as ComputedRef<HTMLInputElement | null>;
|
|
183
|
+
|
|
184
|
+
// eslint-disable-next-line no-undef
|
|
185
|
+
let autocomplete = null as google.maps.places.Autocomplete | null;
|
|
186
|
+
|
|
187
|
+
onMounted(() => {
|
|
188
|
+
if (!window.google) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
if (!address1Input.value) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
autocomplete = new window.google.maps.places.Autocomplete(
|
|
197
|
+
address1Input.value,
|
|
198
|
+
{
|
|
199
|
+
fields: ['address_components'],
|
|
200
|
+
types: ['address'],
|
|
201
|
+
componentRestrictions: { country: 'ca' },
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
autocomplete.addListener('place_changed', fillAddress);
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
function fillAddress() {
|
|
209
|
+
if (!autocomplete) {
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// Get the place details from the autocomplete object.
|
|
214
|
+
const place = autocomplete.getPlace();
|
|
215
|
+
let address1 = '';
|
|
216
|
+
let postcode = '';
|
|
217
|
+
|
|
218
|
+
const newForm = cloneDeep(props.modelValue);
|
|
219
|
+
|
|
220
|
+
if (!place.address_components) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// Get each component of the address from the place details,
|
|
225
|
+
// and then fill-in the corresponding field on the form.
|
|
226
|
+
// place.address_components are google.maps.GeocoderAddressComponent objects
|
|
227
|
+
// which are documented at http://goo.gle/3l5i5Mr
|
|
228
|
+
// eslint-disable-next-line no-undef
|
|
229
|
+
for (const component of place.address_components as google.maps.GeocoderAddressComponent[]) {
|
|
230
|
+
const componentType = component.types[0];
|
|
231
|
+
switch (componentType) {
|
|
232
|
+
case 'street_number': {
|
|
233
|
+
address1 = `${component.long_name} ${address1}`;
|
|
234
|
+
break;
|
|
235
|
+
}
|
|
236
|
+
case 'route': {
|
|
237
|
+
address1 += component.long_name;
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
case 'postal_code': {
|
|
241
|
+
postcode = `${component.long_name}${postcode}`;
|
|
242
|
+
break;
|
|
243
|
+
}
|
|
244
|
+
case 'postal_code_suffix': {
|
|
245
|
+
postcode = `${postcode}-${component.long_name}`;
|
|
246
|
+
break;
|
|
247
|
+
}
|
|
248
|
+
case 'locality':
|
|
249
|
+
newForm.city = component.long_name;
|
|
250
|
+
break;
|
|
251
|
+
case 'administrative_area_level_1': {
|
|
252
|
+
newForm.region = component.short_name.toLowerCase();
|
|
253
|
+
break;
|
|
254
|
+
}
|
|
255
|
+
case 'country':
|
|
256
|
+
newForm.country = component.short_name.toLowerCase();
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
nextTick(() => {
|
|
262
|
+
newForm.address_1 = address1;
|
|
263
|
+
|
|
264
|
+
// Force value change
|
|
265
|
+
if (address1Input.value) {
|
|
266
|
+
//address1Input.value.value = address1;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
newForm.postal_code = postcode;
|
|
270
|
+
|
|
271
|
+
emit('update:model-value', newForm);
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
</script>
|
|
275
|
+
|
|
276
|
+
<style lang="postcss">
|
|
277
|
+
.pac-container {
|
|
278
|
+
@apply rounded-lg border border-gray-200 font-sans shadow-md;
|
|
279
|
+
|
|
280
|
+
& .pac-item {
|
|
281
|
+
@apply flex cursor-pointer items-center py-2 pl-2;
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
& .pac-icon {
|
|
285
|
+
@apply m-0 mr-2;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
& .pac-item,
|
|
289
|
+
& .pac-item-query,
|
|
290
|
+
& .pac-matched {
|
|
291
|
+
@apply text-base;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
& .pac-matched {
|
|
295
|
+
@apply font-semibold;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
&:after {
|
|
299
|
+
background-image: none !important;
|
|
300
|
+
@apply h-0 p-0;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
</style>
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
@update:model-value="emitUpdate"
|
|
40
40
|
/>
|
|
41
41
|
<input
|
|
42
|
-
v-else
|
|
42
|
+
v-else-if="maskOptions"
|
|
43
43
|
ref="input"
|
|
44
44
|
v-maska:[maskOptions]
|
|
45
45
|
v-bind="bindings"
|
|
@@ -53,6 +53,20 @@
|
|
|
53
53
|
}"
|
|
54
54
|
@input="update"
|
|
55
55
|
/>
|
|
56
|
+
<input
|
|
57
|
+
v-else
|
|
58
|
+
ref="input"
|
|
59
|
+
v-bind="bindings"
|
|
60
|
+
:value="modelValue"
|
|
61
|
+
:type="type"
|
|
62
|
+
:autocomplete="autocomplete ? 'on' : 'off'"
|
|
63
|
+
:class="{
|
|
64
|
+
'rounded-l': emptyLeft,
|
|
65
|
+
'rounded-r': emptyRight,
|
|
66
|
+
'w-full border-none bg-white outline-none focus:z-[1] focus:ring-2 focus:ring-primary-600 focus:ring-offset-1 disabled:cursor-not-allowed disabled:text-slate-300': true,
|
|
67
|
+
}"
|
|
68
|
+
@input="update"
|
|
69
|
+
/>
|
|
56
70
|
<div
|
|
57
71
|
v-if="suffix"
|
|
58
72
|
class="flex shrink-0 items-center justify-center border-l px-4 transition-colors"
|
package/src/components/index.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import BaseActionItem from './BaseActionItem.vue';
|
|
2
|
+
import BaseAddressForm from './BaseAddressForm.vue';
|
|
2
3
|
import BaseAlert from './BaseAlert.vue';
|
|
3
4
|
import BaseApp from './BaseApp.vue';
|
|
4
5
|
import BaseAppDialogs from './BaseAppDialogs.vue';
|
|
@@ -88,6 +89,7 @@ import BaseLayoutSidebarConfigurable from './BaseLayoutSidebarConfigurable.vue';
|
|
|
88
89
|
|
|
89
90
|
export {
|
|
90
91
|
BaseActionItem,
|
|
92
|
+
BaseAddressForm,
|
|
91
93
|
BaseAlert,
|
|
92
94
|
BaseApp,
|
|
93
95
|
BaseAppDialogs,
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,8 @@ const messages = { en, fr };
|
|
|
15
15
|
|
|
16
16
|
import './assets/main.css';
|
|
17
17
|
import { Locales } from './types';
|
|
18
|
+
import { Country } from './types/Country';
|
|
19
|
+
import { Region } from './types/Region';
|
|
18
20
|
|
|
19
21
|
export interface Options {
|
|
20
22
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -24,6 +26,8 @@ export interface Options {
|
|
|
24
26
|
locales?: Locales;
|
|
25
27
|
formatQueryString?: (params: Record<string, any>) => string;
|
|
26
28
|
parseQueryString?: (params: string) => Record<string, any>;
|
|
29
|
+
countries?: Country[];
|
|
30
|
+
regions?: Region[];
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
const config = {
|
|
@@ -47,6 +51,8 @@ const config = {
|
|
|
47
51
|
parseQueryString(params: string): Record<string, any> {
|
|
48
52
|
return QueryString.parse(params);
|
|
49
53
|
},
|
|
54
|
+
countries: [] as Country[],
|
|
55
|
+
regions: [] as Region[],
|
|
50
56
|
};
|
|
51
57
|
|
|
52
58
|
function install(app: App, options?: Options) {
|
|
@@ -78,6 +84,14 @@ function install(app: App, options?: Options) {
|
|
|
78
84
|
if (options?.parseQueryString) {
|
|
79
85
|
config.parseQueryString = options.parseQueryString;
|
|
80
86
|
}
|
|
87
|
+
|
|
88
|
+
if (options?.countries) {
|
|
89
|
+
config.countries = options.countries;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
if (options?.regions) {
|
|
93
|
+
config.regions = options.regions;
|
|
94
|
+
}
|
|
81
95
|
}
|
|
82
96
|
|
|
83
97
|
export default { install };
|
package/src/lang/en.json
CHANGED
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"sui": {
|
|
3
|
+
"address": "Address",
|
|
4
|
+
"address_1_placeholder": "Postal address",
|
|
5
|
+
"address_2_description": "Apartment, suite, unit, building",
|
|
3
6
|
"and": "and",
|
|
4
7
|
"apply_filters": "Apply filters",
|
|
5
8
|
"autocomplete_placeholder": "Type to start your search",
|
|
6
9
|
"cancel": "Cancel",
|
|
10
|
+
"city": "City",
|
|
7
11
|
"clear": "Clear",
|
|
8
12
|
"click_or_select_date": "Click or select date",
|
|
9
13
|
"click_to_copy": "Click to copy",
|
|
10
14
|
"columns": "Columns",
|
|
11
15
|
"confirm": "Confirm",
|
|
12
16
|
"copied": "Copied",
|
|
17
|
+
"country": "Country",
|
|
13
18
|
"create_new": "Create new",
|
|
14
19
|
"day": "Day",
|
|
15
20
|
"delete_record": "Delete the record",
|
|
@@ -34,9 +39,11 @@
|
|
|
34
39
|
"or": "or",
|
|
35
40
|
"page": "Page",
|
|
36
41
|
"pagination_detail": "{page} records of {total}",
|
|
42
|
+
"postal_code_zip_code": "Postal Code / Zip Code",
|
|
37
43
|
"previous": "Previous",
|
|
38
44
|
"previous_month": "Previous month",
|
|
39
45
|
"read_more": "Read more",
|
|
46
|
+
"region": "State / Province",
|
|
40
47
|
"remove": "Remove",
|
|
41
48
|
"remove_file": "Remove file?",
|
|
42
49
|
"remove_file_description": "Are you sure you want to remove the file? This action is irreversible.",
|