|  | 
| 1 | 1 | <template> | 
| 2 | 2 |   <dl | 
| 3 |  | -    v-for="(value, key, index) in map" | 
|  | 3 | +    v-for="(value, key, index) in filteredMap" | 
| 4 | 4 |     :key="key" | 
| 5 | 5 |     class="px-4 py-3 sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6" | 
| 6 | 6 |     :class="{ 'bg-white': index % 2 === 0, 'bg-gray-50': index % 2 !== 0 }" | 
|  | 
| 17 | 17 |   </dl> | 
| 18 | 18 | </template> | 
| 19 | 19 | 
 | 
| 20 |  | -<script> | 
| 21 |  | -export default { | 
| 22 |  | -  name: 'SbaKeyValueTable', | 
| 23 |  | -  props: { | 
| 24 |  | -    map: { | 
| 25 |  | -      type: Object, | 
| 26 |  | -      required: true, | 
| 27 |  | -    }, | 
| 28 |  | -  }, | 
| 29 |  | -  methods: { | 
| 30 |  | -    getSlotName(key, value) { | 
| 31 |  | -      return value?.id || key.replace(/[^a-zA-Z]/gi, '').toLowerCase(); | 
| 32 |  | -    }, | 
| 33 |  | -    getLabel(key, value) { | 
| 34 |  | -      return value?.label || key; | 
| 35 |  | -    }, | 
| 36 |  | -    getValue(value) { | 
| 37 |  | -      return value?.value || value; | 
| 38 |  | -    }, | 
| 39 |  | -  }, | 
|  | 20 | +<script setup lang="ts"> | 
|  | 21 | +import { computed } from 'vue'; | 
|  | 22 | +
 | 
|  | 23 | +const { map, skipNullValues = false } = defineProps<{ | 
|  | 24 | +  map: Record<string, any>; | 
|  | 25 | +  skipNullValues?: boolean; | 
|  | 26 | +}>(); | 
|  | 27 | +
 | 
|  | 28 | +const filteredMap = computed(() => { | 
|  | 29 | +  return Object.entries(map) | 
|  | 30 | +    .filter(([, value]) => { | 
|  | 31 | +      if (skipNullValues) { | 
|  | 32 | +        return value && value.value !== null; | 
|  | 33 | +      } | 
|  | 34 | +      return true; | 
|  | 35 | +    }) | 
|  | 36 | +    .reduce( | 
|  | 37 | +      (acc, [key, value]) => { | 
|  | 38 | +        acc[key] = value; | 
|  | 39 | +        return acc; | 
|  | 40 | +      }, | 
|  | 41 | +      {} as Record<string, any>, | 
|  | 42 | +    ); | 
|  | 43 | +}); | 
|  | 44 | +
 | 
|  | 45 | +const getSlotName = (key: string, value: any) => { | 
|  | 46 | +  return value?.id || key.replace(/[^a-zA-Z]/gi, '').toLowerCase(); | 
|  | 47 | +}; | 
|  | 48 | +
 | 
|  | 49 | +const getLabel = (key: string, value: any) => { | 
|  | 50 | +  return value?.label || key; | 
|  | 51 | +}; | 
|  | 52 | +
 | 
|  | 53 | +const getValue = (value: any) => { | 
|  | 54 | +  return value?.value || value; | 
| 40 | 55 | }; | 
| 41 | 56 | </script> | 
0 commit comments