@kiva/kv-components 3.22.2 → 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 CHANGED
@@ -3,6 +3,25 @@
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
+
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)
18
+
19
+ **Note:** Version bump only for package @kiva/kv-components
20
+
21
+
22
+
23
+
24
+
6
25
  ## [3.22.2](https://github.com/kiva/kv-ui-elements/compare/@kiva/kv-components@3.22.1...@kiva/kv-components@3.22.2) (2023-05-29)
7
26
 
8
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kiva/kv-components",
3
- "version": "3.22.2",
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": "c29465a89a0cd252816abf35539038dfa0a6560d"
78
+ "gitHead": "097c378d83450baa4999ee5440a3862aa1496836"
79
79
  }
@@ -1,246 +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
71
- class="tw-text-link"
72
- @click="resetCountries"
73
- >
74
- Reset country selection
75
- </button>
76
-
77
- <kv-button
78
- @click="closeModal"
79
- >
80
- See {{ totalLoans }} loans
81
- </kv-button>
82
- </div>
83
- </form>
84
- </template>
85
-
86
- <script>
87
- import {
88
- ref,
89
- toRefs,
90
- watch,
91
- } from 'vue-demi';
92
- import { mdiChevronDown, mdiChevronRight } from '@mdi/js';
93
- import KvMaterialIcon from './KvMaterialIcon.vue';
94
- import KvCheckbox from './KvCheckbox.vue';
95
- import KvButton from './KvButton.vue';
96
-
97
- export default {
98
- components: {
99
- KvMaterialIcon,
100
- KvCheckbox,
101
- KvButton,
102
- },
103
- props: {
104
- /**
105
- * The regions with countries used to build the checkbox lists. Expected format:
106
- * [{
107
- * region: 'region',
108
- * numLoansFundraising: 1,
109
- * countries: [{
110
- * name: 'name',
111
- * isoCode: 'US',
112
- * numLoansFundraising: 1,
113
- * }]
114
- * }]
115
- */
116
- regions: {
117
- type: Array,
118
- default: undefined,
119
- },
120
- activeIsoCodes: {
121
- type: Array,
122
- default: () => [],
123
- },
124
- totalLoans: {
125
- type: Number,
126
- default: 0,
127
- },
128
- },
129
- emits: [
130
- 'updated',
131
- 'close-modal',
132
- ],
133
- setup(props, { emit }) {
134
- const { regions, activeIsoCodes } = toRefs(props);
135
- const displayedRegions = ref(regions);
136
- const openRegions = ref([]);
137
- const selected = ref(activeIsoCodes.value);
138
- const allSelectedModel = ref([]);
139
-
140
- const getItemLabel = (item) => {
141
- return `${item.name || item.region}`;
142
- };
143
-
144
- const getNumberLoans = (item) => {
145
- const countLabel = typeof item.numLoansFundraising !== 'undefined' ? ` (${item.numLoansFundraising})` : '';
146
-
147
- return `${countLabel}`;
148
- };
149
-
150
- const toggleRegion = (region) => {
151
- const existingIndex = openRegions.value.indexOf(region);
152
- if (existingIndex === -1) {
153
- openRegions.value.push(region);
154
- } else {
155
- openRegions.value.splice(existingIndex, 1);
156
- }
157
- };
158
-
159
- const isOpenRegion = (region) => {
160
- return openRegions.value.includes(region);
161
- };
162
-
163
- const getItems = (countries) => {
164
- // Disable checkboxes based on whether the current applied filters have loans fundraising for that country
165
- return countries.map((c) => ({
166
- value: c.isoCode,
167
- title: getItemLabel(c),
168
- numberLoans: c.numLoansFundraising,
169
- disabled: c.numLoansFundraising === 0,
170
- }));
171
- };
172
-
173
- const isAllSelected = (countries) => {
174
- return countries.every((country) => selected.value.includes(country.value));
175
- };
176
-
177
- const updateLocation = (evt) => {
178
- emit('updated', evt);
179
- };
180
-
181
- const toggleSelectAll = (countries) => {
182
- const isAll = isAllSelected(countries);
183
- countries.forEach((country) => {
184
- const index = selected.value.indexOf(country.value);
185
- const exists = index !== -1;
186
- if (isAll) {
187
- if (exists) selected.value.splice(index, 1);
188
- } else if (!exists) selected.value.push(country.value);
189
- });
190
- updateLocation(selected.value);
191
- };
192
-
193
- const resetCountries = () => {
194
- selected.value = [];
195
- updateLocation(selected.value);
196
- };
197
-
198
- const closeModal = () => {
199
- emit('close-modal');
200
- };
201
-
202
- const numberByRegion = (region) => {
203
- let total = 0;
204
- const regionData = regions.value.filter((regionItem) => {
205
- return regionItem.region === region;
206
- });
207
- const { countries } = regionData[0];
208
-
209
- for (let i = 0; i < countries.length; i += 1) {
210
- const country = countries[i];
211
- if (selected.value.includes(country.isoCode)) {
212
- total += 1;
213
- }
214
- }
215
-
216
- return total;
217
- };
218
-
219
- watch(activeIsoCodes, (val) => {
220
- if (selected.value.sort().toString() !== val.sort().toString()) {
221
- selected.value = val;
222
- updateLocation(selected.value);
223
- }
224
- });
225
-
226
- return {
227
- mdiChevronRight,
228
- mdiChevronDown,
229
- displayedRegions,
230
- getItemLabel,
231
- getNumberLoans,
232
- getItems,
233
- toggleSelectAll,
234
- toggleRegion,
235
- isOpenRegion,
236
- isAllSelected,
237
- selected,
238
- allSelectedModel,
239
- updateLocation,
240
- resetCountries,
241
- closeModal,
242
- numberByRegion,
243
- };
244
- },
245
- };
246
- </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
- };