@kiva/kv-components 3.48.0 → 3.48.2

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.
@@ -181,7 +181,7 @@
181
181
  >
182
182
  <kv-loan-progress-group
183
183
  id="loanProgress"
184
- :money-left="unreservedAmount"
184
+ :money-left="`${unreservedAmount}`"
185
185
  :progress-percent="fundraisingPercent"
186
186
  class="tw-text-black"
187
187
  />
@@ -220,7 +220,8 @@
220
220
  </template>
221
221
 
222
222
  <script>
223
- import { mdiMapMarker } from '@mdi/js';
223
+ import { loanCardComputedProperties, loanCardMethods } from '../utils/loanCard';
224
+
224
225
  import KvLoanUse from './KvLoanUse.vue';
225
226
  import KvBorrowerImage from './KvBorrowerImage.vue';
226
227
  import KvLoanProgressGroup from './KvLoanProgressGroup.vue';
@@ -231,12 +232,6 @@ import KvLoanTag from './KvLoanTag.vue';
231
232
  import KvMaterialIcon from './KvMaterialIcon.vue';
232
233
  import KvLoadingPlaceholder from './KvLoadingPlaceholder.vue';
233
234
 
234
- const LSE_LOAN_KEY = 'N/A';
235
- const ECO_FRIENDLY_KEY = 'ECO-FRIENDLY';
236
- const SUSTAINABLE_AG_KEY = 'SUSTAINABLE AG';
237
- const SINGLE_PARENT_KEY = 'SINGLE PARENT';
238
- const REFUGEE_KEY = 'REFUGEES/DISPLACED';
239
-
240
235
  export default {
241
236
  name: 'KvClassicLoanCard',
242
237
  components: {
@@ -263,10 +258,6 @@ export default {
263
258
  type: Boolean,
264
259
  default: false,
265
260
  },
266
- useFullWidth: {
267
- type: Boolean,
268
- default: false,
269
- },
270
261
  showTags: {
271
262
  type: Boolean,
272
263
  default: false,
@@ -279,10 +270,6 @@ export default {
279
270
  type: Boolean,
280
271
  default: false,
281
272
  },
282
- largeCard: {
283
- type: Boolean,
284
- default: false,
285
- },
286
273
  isAdding: {
287
274
  type: Boolean,
288
275
  default: false,
@@ -335,80 +322,77 @@ export default {
335
322
  type: Boolean,
336
323
  default: false,
337
324
  },
325
+ customCallouts: {
326
+ type: Array,
327
+ default: () => ([]),
328
+ },
329
+ useFullWidth: {
330
+ type: Boolean,
331
+ default: false,
332
+ },
333
+ largeCard: {
334
+ type: Boolean,
335
+ default: false,
336
+ },
338
337
  },
339
- data() {
338
+ setup(props) {
339
+ const {
340
+ allDataLoaded,
341
+ borrowerName,
342
+ city,
343
+ countryName,
344
+ distributionModel,
345
+ formattedLocation,
346
+ fundraisingPercent,
347
+ hasProgressData,
348
+ imageHash,
349
+ isLoading,
350
+ loanAmount,
351
+ loanBorrowerCount,
352
+ loanCallouts,
353
+ loanStatus,
354
+ loanUse,
355
+ mdiMapMarker,
356
+ readMorePath,
357
+ state,
358
+ tag,
359
+ unreservedAmount,
360
+ } = loanCardComputedProperties(props);
361
+
362
+ const {
363
+ clickReadMore,
364
+ showLoanDetails,
365
+ } = loanCardMethods(props);
366
+
340
367
  return {
368
+ allDataLoaded,
369
+ borrowerName,
370
+ city,
371
+ countryName,
372
+ distributionModel,
373
+ formattedLocation,
374
+ fundraisingPercent,
375
+ hasProgressData,
376
+ imageHash,
377
+ isLoading,
378
+ loanAmount,
379
+ loanBorrowerCount,
380
+ loanCallouts,
381
+ loanStatus,
382
+ loanUse,
341
383
  mdiMapMarker,
384
+ readMorePath,
385
+ state,
386
+ tag,
387
+ unreservedAmount,
388
+ clickReadMore,
389
+ showLoanDetails,
342
390
  };
343
391
  },
344
392
  computed: {
345
- tag() {
346
- return this.externalLinks ? 'a' : 'router-link';
347
- },
348
- readMorePath() {
349
- return this.customLoanDetails ? '' : `/lend/${this.loanId}`;
350
- },
351
- isLoading() {
352
- return !this.loanId || !this.loan;
353
- },
354
393
  cardWidth() {
355
394
  return this.useFullWidth ? '100%' : '374px';
356
395
  },
357
- borrowerName() {
358
- return this.loan?.name || '';
359
- },
360
- countryName() {
361
- return this.loan?.geocode?.country?.name || '';
362
- },
363
- city() {
364
- return this.loan?.geocode?.city || '';
365
- },
366
- state() {
367
- return this.loan?.geocode?.state || '';
368
- },
369
- distributionModel() {
370
- return this.loan?.distributionModel || '';
371
- },
372
- imageHash() {
373
- return this.loan?.image?.hash ?? '';
374
- },
375
- hasProgressData() {
376
- // Local resolver values for the progress bar load client-side
377
- return typeof this.loan?.unreservedAmount !== 'undefined'
378
- && typeof this.loan?.fundraisingPercent !== 'undefined';
379
- },
380
- allDataLoaded() {
381
- return !this.isLoading && this.hasProgressData;
382
- },
383
- fundraisingPercent() {
384
- return this.loan?.fundraisingPercent ?? 0;
385
- },
386
- unreservedAmount() {
387
- return this.loan?.unreservedAmount ?? '0';
388
- },
389
- formattedLocation() {
390
- if (this.distributionModel === 'direct') {
391
- const formattedString = `${this.city}, ${this.state}, ${this.countryName}`;
392
- return formattedString;
393
- }
394
- if (this.countryName === 'Puerto Rico') {
395
- const formattedString = `${this.city}, PR`;
396
- return formattedString;
397
- }
398
- return this.countryName;
399
- },
400
- loanUse() {
401
- return this.loan?.use ?? '';
402
- },
403
- loanStatus() {
404
- return this.loan?.status ?? '';
405
- },
406
- loanAmount() {
407
- return this.loan?.loanAmount ?? '0';
408
- },
409
- loanBorrowerCount() {
410
- return this.loan?.borrowerCount ?? 0;
411
- },
412
396
  imageAspectRatio() {
413
397
  if (this.largeCard) {
414
398
  return 5 / 8;
@@ -430,95 +414,12 @@ export default {
430
414
  { width: 335, viewSize: 375 },
431
415
  ];
432
416
  },
433
- loanCallouts() {
434
- const callouts = [];
435
- const activityName = this.loan?.activity?.name ?? '';
436
- const sectorName = this.loan?.sector?.name ?? '';
437
- const tags = this.loan?.tags?.filter((tag) => tag.charAt(0) === '#')
438
- .map((tag) => tag.substring(1)) ?? [];
439
- const themes = this.loan?.themes ?? [];
440
- const categories = {
441
- ecoFriendly: !!tags // eslint-disable-next-line max-len
442
- .filter((t) => t.toUpperCase() === ECO_FRIENDLY_KEY || t.toUpperCase() === SUSTAINABLE_AG_KEY).length,
443
- refugeesIdps: !!themes.filter((t) => t.toUpperCase() === REFUGEE_KEY).length,
444
- singleParents: !!tags.filter((t) => t.toUpperCase() === SINGLE_PARENT_KEY).length,
445
- };
446
-
447
- const isLseLoan = this.loan?.partnerName?.toUpperCase().includes(LSE_LOAN_KEY);
448
-
449
- // P1 Category
450
- // Exp limited to: Eco-friendly, Refugees and IDPs, Single Parents
451
- // Tag as first option for LSE loans
452
- if (isLseLoan && tags.length) {
453
- const position = Math.floor(Math.random() * tags.length);
454
- const tag = tags[position];
455
- callouts.push(tag);
456
- }
457
-
458
- if (!this.categoryPageName) {
459
- if (categories.ecoFriendly // eslint-disable-next-line max-len
460
- && !callouts.find((c) => c.toUpperCase() === ECO_FRIENDLY_KEY || c.toUpperCase() === SUSTAINABLE_AG_KEY)) {
461
- callouts.push('Eco-friendly');
462
- } else if (categories.refugeesIdps) {
463
- callouts.push('Refugees and IDPs');
464
- } else if (categories.singleParents
465
- && !callouts.find((c) => c.toUpperCase() === SINGLE_PARENT_KEY)) {
466
- callouts.push('Single Parent');
467
- }
468
- }
469
-
470
- // P2 Activity
471
- if (activityName && this.categoryPageName?.toUpperCase() !== activityName.toUpperCase()) {
472
- callouts.push(activityName);
473
- }
474
-
475
- // P3 Sector
476
- if (sectorName
477
- && (activityName.toUpperCase() !== sectorName.toUpperCase())
478
- && (sectorName.toUpperCase() !== this.categoryPageName?.toUpperCase())
479
- && callouts.length < 2) {
480
- callouts.push(sectorName);
481
- }
482
-
483
- // P4 Tag
484
- if (!!tags.length && callouts.length < 2) {
485
- const position = Math.floor(Math.random() * tags.length);
486
- const tag = tags[position];
487
- if (!callouts.filter((c) => c.toUpperCase() === tag.toUpperCase()).length) {
488
- callouts.push(tag);
489
- }
490
- }
491
-
492
- // P5 Theme
493
- if (!!themes.length && callouts.length < 2) {
494
- const position = Math.floor(Math.random() * themes.length);
495
- const theme = themes[position];
496
- if (!callouts.filter((c) => c.toUpperCase() === theme.toUpperCase()).length
497
- && theme.toUpperCase() !== this.categoryPageName?.toUpperCase()) {
498
- callouts.push(theme);
499
- }
500
- }
501
-
502
- // Only show one callout for LSE loans
503
- if (isLseLoan && callouts.length > 1) return [callouts.shift()];
504
- return callouts;
505
- },
506
- },
507
- methods: {
508
- showLoanDetails(e) {
509
- if (this.customLoanDetails) {
510
- e.preventDefault();
511
- this.$emit('show-loan-details');
512
- }
513
- },
514
- clickReadMore(target) {
515
- this.kvTrackFunction('Lending', 'click-Read more', target, this.loanId);
516
- },
517
417
  },
518
418
  };
519
419
  </script>
520
420
 
521
421
  <style lang="postcss" scoped>
422
+ /** Shared with KvWideLoanCard */
522
423
  .loan-card-use:hover,
523
424
  .loan-card-use:focus {
524
425
  @apply tw-text-primary;
@@ -218,10 +218,16 @@ export default {
218
218
  const kvLightboxBody = ref(null);
219
219
  const controlsRef = ref(null);
220
220
 
221
+ const trapElements = computed(() => [
222
+ kvLightbox.value, // This lightbox
223
+ '[role="alert"]', // Any open toasts/alerts on the page
224
+ ]);
221
225
  const {
222
226
  activate: activateFocusTrap,
223
227
  deactivate: deactivateFocusTrap,
224
- } = useFocusTrap(kvLightbox);
228
+ } = useFocusTrap(trapElements, {
229
+ allowOutsideClick: true, // allow clicking outside the lightbox to close it
230
+ });
225
231
 
226
232
  let makePageInertCallback = null;
227
233
  let onKeyUp = null;