@kiva/kv-components 3.22.3 → 3.23.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.
- package/CHANGELOG.md +11 -0
- package/package.json +2 -2
- package/vue/KvLocationSelector.vue +0 -243
- package/vue/stories/KvLocationSelector.stories.js +0 -140
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [3.23.0](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.22.3...@kiva/kv-components@3.23.0) (2023-06-09)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* location selector no longer being used ([bdf5452](https://github.com/kiva/kv-ui-elements/commit/bdf5452ec359b040cd7a904678422c3ae540889c))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
## [3.22.3](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.22.2...@kiva/kv-components@3.22.3) (2023-06-02)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @kiva/kv-components
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kiva/kv-components",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.23.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -75,5 +75,5 @@
|
|
|
75
75
|
"optional": true
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
|
-
"gitHead": "
|
|
78
|
+
"gitHead": "097c378d83450baa4999ee5440a3862aa1496836"
|
|
79
79
|
}
|
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<form
|
|
3
|
-
class="tw-grid tw-gap-1.5 tw-mb-2"
|
|
4
|
-
@submit.prevent
|
|
5
|
-
>
|
|
6
|
-
<div class="tw-text-right tw-hidden md:tw-block tw-mb-1 tw-pr-2">
|
|
7
|
-
Locations
|
|
8
|
-
</div>
|
|
9
|
-
<fieldset
|
|
10
|
-
v-for="option in displayedRegions"
|
|
11
|
-
:key="option.region"
|
|
12
|
-
class="md:tw-border-b tw-border-tertiary md:tw-pb-1 md:tw-mb-1"
|
|
13
|
-
>
|
|
14
|
-
<legend class="tw-w-full md:tw-mb-1">
|
|
15
|
-
<button
|
|
16
|
-
class="tw-transition-all tw-flex tw-items-center md:tw-justify-between tw-w-full"
|
|
17
|
-
@click="toggleRegion(option.region)"
|
|
18
|
-
>
|
|
19
|
-
<kv-material-icon
|
|
20
|
-
:icon="isOpenRegion(option.region) ? mdiChevronDown : mdiChevronRight"
|
|
21
|
-
class="tw-h-1.5 tw-w-1.5 md:tw-h-3 md:tw-w-3 tw-mr-1 tw-transition-all md:tw-order-2"
|
|
22
|
-
/>
|
|
23
|
-
<span class="md:tw-order-1 md:tw-text-subhead md:tw-flex tw-items-center">
|
|
24
|
-
<span class="tw-w-4 tw-text-action tw-text-base tw-text-right tw-mr-1 tw-hidden md:tw-inline">
|
|
25
|
-
{{ numberByRegion(option.region) !== 0 ? `(${numberByRegion(option.region)})` :'' }}
|
|
26
|
-
</span>
|
|
27
|
-
{{ getItemLabel(option) }} <span class="md:tw-hidden">{{ getNumberLoans(option) }}</span>
|
|
28
|
-
</span>
|
|
29
|
-
</button>
|
|
30
|
-
</legend>
|
|
31
|
-
<menu
|
|
32
|
-
v-if="isOpenRegion(option.region)"
|
|
33
|
-
class="tw-flex tw-flex-col tw-gap-1.5 tw-my-1.5"
|
|
34
|
-
>
|
|
35
|
-
<li class="md:tw-hidden">
|
|
36
|
-
<button
|
|
37
|
-
class="tw-text-link"
|
|
38
|
-
@click="toggleSelectAll(getItems(option.countries))"
|
|
39
|
-
>
|
|
40
|
-
{{ isAllSelected(getItems(option.countries)) ? 'Deselect' : 'Select' }} all
|
|
41
|
-
</button>
|
|
42
|
-
</li>
|
|
43
|
-
<div class="tw-grid tw-grid-cols-1 md:tw-grid-cols-3 tw-gap-1.5 md:tw-gap-2.5 md:tw-pl-5">
|
|
44
|
-
<li class="tw-hidden md:tw-block">
|
|
45
|
-
<kv-checkbox
|
|
46
|
-
v-model="allSelectedModel"
|
|
47
|
-
:value="`selected-all-${option.region}`"
|
|
48
|
-
@change="toggleSelectAll(getItems(option.countries))"
|
|
49
|
-
>
|
|
50
|
-
{{ isAllSelected(getItems(option.countries)) ? 'Deselect' : 'Select' }} all
|
|
51
|
-
</kv-checkbox>
|
|
52
|
-
</li>
|
|
53
|
-
<li
|
|
54
|
-
v-for="(item, i) in getItems(option.countries)"
|
|
55
|
-
:key="i"
|
|
56
|
-
>
|
|
57
|
-
<kv-checkbox
|
|
58
|
-
v-model="selected"
|
|
59
|
-
:value="item.value"
|
|
60
|
-
:disabled="item.disabled"
|
|
61
|
-
@change="updateLocation"
|
|
62
|
-
>
|
|
63
|
-
{{ item.title }} ({{ item.numberLoans }})
|
|
64
|
-
</kv-checkbox>
|
|
65
|
-
</li>
|
|
66
|
-
</div>
|
|
67
|
-
</menu>
|
|
68
|
-
</fieldset>
|
|
69
|
-
<div class="tw-hidden md:tw-flex tw-gap-2 tw-justify-end tw-mt-1.5">
|
|
70
|
-
<button @click="resetCountries">
|
|
71
|
-
Reset country selection
|
|
72
|
-
</button>
|
|
73
|
-
|
|
74
|
-
<kv-button
|
|
75
|
-
@click="closeModal"
|
|
76
|
-
>
|
|
77
|
-
See {{ totalLoans }} loans
|
|
78
|
-
</kv-button>
|
|
79
|
-
</div>
|
|
80
|
-
</form>
|
|
81
|
-
</template>
|
|
82
|
-
|
|
83
|
-
<script>
|
|
84
|
-
import {
|
|
85
|
-
ref,
|
|
86
|
-
toRefs,
|
|
87
|
-
watch,
|
|
88
|
-
} from 'vue-demi';
|
|
89
|
-
import { mdiChevronDown, mdiChevronRight } from '@mdi/js';
|
|
90
|
-
import KvMaterialIcon from './KvMaterialIcon.vue';
|
|
91
|
-
import KvCheckbox from './KvCheckbox.vue';
|
|
92
|
-
import KvButton from './KvButton.vue';
|
|
93
|
-
|
|
94
|
-
export default {
|
|
95
|
-
components: {
|
|
96
|
-
KvMaterialIcon,
|
|
97
|
-
KvCheckbox,
|
|
98
|
-
KvButton,
|
|
99
|
-
},
|
|
100
|
-
props: {
|
|
101
|
-
/**
|
|
102
|
-
* The regions with countries used to build the checkbox lists. Expected format:
|
|
103
|
-
* [{
|
|
104
|
-
* region: 'region',
|
|
105
|
-
* numLoansFundraising: 1,
|
|
106
|
-
* countries: [{
|
|
107
|
-
* name: 'name',
|
|
108
|
-
* isoCode: 'US',
|
|
109
|
-
* numLoansFundraising: 1,
|
|
110
|
-
* }]
|
|
111
|
-
* }]
|
|
112
|
-
*/
|
|
113
|
-
regions: {
|
|
114
|
-
type: Array,
|
|
115
|
-
default: undefined,
|
|
116
|
-
},
|
|
117
|
-
activeIsoCodes: {
|
|
118
|
-
type: Array,
|
|
119
|
-
default: () => [],
|
|
120
|
-
},
|
|
121
|
-
totalLoans: {
|
|
122
|
-
type: Number,
|
|
123
|
-
default: 0,
|
|
124
|
-
},
|
|
125
|
-
},
|
|
126
|
-
emits: [
|
|
127
|
-
'updated',
|
|
128
|
-
'close-modal',
|
|
129
|
-
],
|
|
130
|
-
setup(props, { emit }) {
|
|
131
|
-
const { regions, activeIsoCodes } = toRefs(props);
|
|
132
|
-
const displayedRegions = ref(regions);
|
|
133
|
-
const openRegions = ref([]);
|
|
134
|
-
const selected = ref(activeIsoCodes.value);
|
|
135
|
-
const allSelectedModel = ref([]);
|
|
136
|
-
|
|
137
|
-
const getItemLabel = (item) => {
|
|
138
|
-
return `${item.name || item.region}`;
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const getNumberLoans = (item) => {
|
|
142
|
-
const countLabel = typeof item.numLoansFundraising !== 'undefined' ? ` (${item.numLoansFundraising})` : '';
|
|
143
|
-
|
|
144
|
-
return `${countLabel}`;
|
|
145
|
-
};
|
|
146
|
-
|
|
147
|
-
const toggleRegion = (region) => {
|
|
148
|
-
const existingIndex = openRegions.value.indexOf(region);
|
|
149
|
-
if (existingIndex === -1) {
|
|
150
|
-
openRegions.value.push(region);
|
|
151
|
-
} else {
|
|
152
|
-
openRegions.value.splice(existingIndex, 1);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
const isOpenRegion = (region) => {
|
|
157
|
-
return openRegions.value.includes(region);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const getItems = (countries) => {
|
|
161
|
-
// Disable checkboxes based on whether the current applied filters have loans fundraising for that country
|
|
162
|
-
return countries.map((c) => ({
|
|
163
|
-
value: c.isoCode,
|
|
164
|
-
title: getItemLabel(c),
|
|
165
|
-
numberLoans: c.numLoansFundraising,
|
|
166
|
-
disabled: c.numLoansFundraising === 0,
|
|
167
|
-
}));
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
const isAllSelected = (countries) => {
|
|
171
|
-
return countries.every((country) => selected.value.includes(country.value));
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
const updateLocation = (evt) => {
|
|
175
|
-
emit('updated', evt);
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
const toggleSelectAll = (countries) => {
|
|
179
|
-
const isAll = isAllSelected(countries);
|
|
180
|
-
countries.forEach((country) => {
|
|
181
|
-
const index = selected.value.indexOf(country.value);
|
|
182
|
-
const exists = index !== -1;
|
|
183
|
-
if (isAll) {
|
|
184
|
-
if (exists) selected.value.splice(index, 1);
|
|
185
|
-
} else if (!exists) selected.value.push(country.value);
|
|
186
|
-
});
|
|
187
|
-
updateLocation(selected.value);
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
const resetCountries = () => {
|
|
191
|
-
selected.value = [];
|
|
192
|
-
updateLocation(selected.value);
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
const closeModal = () => {
|
|
196
|
-
emit('close-modal');
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const numberByRegion = (region) => {
|
|
200
|
-
let total = 0;
|
|
201
|
-
const regionData = regions.value.filter((regionItem) => {
|
|
202
|
-
return regionItem.region === region;
|
|
203
|
-
});
|
|
204
|
-
const { countries } = regionData[0];
|
|
205
|
-
|
|
206
|
-
for (let i = 0; i < countries.length; i += 1) {
|
|
207
|
-
const country = countries[i];
|
|
208
|
-
if (selected.value.includes(country.isoCode)) {
|
|
209
|
-
total += 1;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return total;
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
watch(activeIsoCodes, (val) => {
|
|
217
|
-
if (selected.value.sort().toString() !== val.sort().toString()) {
|
|
218
|
-
selected.value = val;
|
|
219
|
-
updateLocation(selected.value);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
return {
|
|
224
|
-
mdiChevronRight,
|
|
225
|
-
mdiChevronDown,
|
|
226
|
-
displayedRegions,
|
|
227
|
-
getItemLabel,
|
|
228
|
-
getNumberLoans,
|
|
229
|
-
getItems,
|
|
230
|
-
toggleSelectAll,
|
|
231
|
-
toggleRegion,
|
|
232
|
-
isOpenRegion,
|
|
233
|
-
isAllSelected,
|
|
234
|
-
selected,
|
|
235
|
-
allSelectedModel,
|
|
236
|
-
updateLocation,
|
|
237
|
-
resetCountries,
|
|
238
|
-
closeModal,
|
|
239
|
-
numberByRegion,
|
|
240
|
-
};
|
|
241
|
-
},
|
|
242
|
-
};
|
|
243
|
-
</script>
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import KvLocationSelector from '../KvLocationSelector.vue';
|
|
2
|
-
|
|
3
|
-
const regions = [
|
|
4
|
-
{
|
|
5
|
-
region: 'Africa',
|
|
6
|
-
countries: [
|
|
7
|
-
{
|
|
8
|
-
__typename: 'Country',
|
|
9
|
-
name: 'Burkina Faso',
|
|
10
|
-
region: 'Africa',
|
|
11
|
-
isoCode: 'BF',
|
|
12
|
-
numLoansFundraising: 43,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
__typename: 'Country',
|
|
16
|
-
name: 'Congo (DRC)',
|
|
17
|
-
region: 'Africa',
|
|
18
|
-
isoCode: 'CD',
|
|
19
|
-
numLoansFundraising: 42,
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
__typename: 'Country',
|
|
23
|
-
name: 'Egypt',
|
|
24
|
-
region: 'Africa',
|
|
25
|
-
isoCode: 'EG',
|
|
26
|
-
numLoansFundraising: 13,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
__typename: 'Country',
|
|
30
|
-
name: 'Ghana',
|
|
31
|
-
region: 'Africa',
|
|
32
|
-
isoCode: 'GH',
|
|
33
|
-
numLoansFundraising: 54,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
__typename: 'Country',
|
|
37
|
-
name: 'Kenya',
|
|
38
|
-
region: 'Africa',
|
|
39
|
-
isoCode: 'KE',
|
|
40
|
-
numLoansFundraising: 1046,
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
__typename: 'Country',
|
|
44
|
-
name: 'Liberia',
|
|
45
|
-
region: 'Africa',
|
|
46
|
-
isoCode: 'LR',
|
|
47
|
-
numLoansFundraising: 117,
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
numLoansFundraising: 2095,
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
region: 'North America',
|
|
54
|
-
countries: [
|
|
55
|
-
{
|
|
56
|
-
__typename: 'Country',
|
|
57
|
-
name: 'Dominican Republic',
|
|
58
|
-
region: 'North America',
|
|
59
|
-
isoCode: 'DO',
|
|
60
|
-
numLoansFundraising: 14,
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
__typename: 'Country',
|
|
64
|
-
name: 'Mexico',
|
|
65
|
-
region: 'North America',
|
|
66
|
-
isoCode: 'MX',
|
|
67
|
-
numLoansFundraising: 7,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
__typename: 'Country',
|
|
71
|
-
name: 'Puerto Rico',
|
|
72
|
-
region: 'North America',
|
|
73
|
-
isoCode: 'PR',
|
|
74
|
-
numLoansFundraising: 2,
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
__typename: 'Country',
|
|
78
|
-
name: 'United States',
|
|
79
|
-
region: 'North America',
|
|
80
|
-
isoCode: 'US',
|
|
81
|
-
numLoansFundraising: 8,
|
|
82
|
-
},
|
|
83
|
-
],
|
|
84
|
-
numLoansFundraising: 31,
|
|
85
|
-
},
|
|
86
|
-
];
|
|
87
|
-
|
|
88
|
-
export default {
|
|
89
|
-
title: 'KvLocationSelector',
|
|
90
|
-
component: KvLocationSelector,
|
|
91
|
-
argTypes: {
|
|
92
|
-
regions: {
|
|
93
|
-
control: {
|
|
94
|
-
type: 'select',
|
|
95
|
-
options: regions,
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
activeIsoCodes: {
|
|
99
|
-
control: {
|
|
100
|
-
type: 'select',
|
|
101
|
-
options: [],
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
totalLoans: {
|
|
105
|
-
control: {
|
|
106
|
-
type: 'number',
|
|
107
|
-
options: '',
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const Template = (args, {
|
|
114
|
-
argTypes,
|
|
115
|
-
}) => ({
|
|
116
|
-
props: Object.keys(argTypes),
|
|
117
|
-
components: {
|
|
118
|
-
KvLocationSelector,
|
|
119
|
-
},
|
|
120
|
-
template: `
|
|
121
|
-
<kv-location-selector
|
|
122
|
-
:regions="regions"
|
|
123
|
-
:active-iso-codes="activeIsoCodes"
|
|
124
|
-
:total-loans="totalLoans"
|
|
125
|
-
/>
|
|
126
|
-
`,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
export const Default = Template.bind({});
|
|
130
|
-
Default.args = {
|
|
131
|
-
regions,
|
|
132
|
-
totalLoans: 320,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
export const DefinedIsoCodes = Template.bind({});
|
|
136
|
-
DefinedIsoCodes.args = {
|
|
137
|
-
regions,
|
|
138
|
-
totalLoans: 320,
|
|
139
|
-
activeIsoCodes: ['BF', 'EG', 'KE', 'US', 'MX'],
|
|
140
|
-
};
|