aboutsummaryrefslogtreecommitdiff
path: root/src/ui/c-key-value-list/c-key-value-list.vue
blob: e3b19afd082ec6052c3ee384e76d788bfbf46584 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<script lang="ts" setup>
import _ from 'lodash';
import type { CKeyValueListItems } from './c-key-value-list.types';

const props = withDefaults(defineProps<{ items?: CKeyValueListItems }>(), { items: () => [] });
const { items } = toRefs(props);

const formattedItems = computed(() => items.value.filter(item => !_.isNil(item.value) || !item.hideOnNil));
</script>

<template>
  <table border-collapse table-fixed>
    <tr v-for="item in formattedItems" :key="item.label">
      <td py-1 pr-2 text-right font-bold>
        {{ item.label }}
      </td>

      <td v-if="_.isArray(item.value)">
        <div v-for="value in item.value" :key="value">
          <c-text-copyable :value="value" :show-icon="item.showCopyButton ?? true" />
        </div>
      </td>
      <td v-else-if="_.isBoolean(item.value)">
        <c-text-copyable :value="item.value ? 'true' : 'false'" :displayed-value="item.value ? 'Yes' : 'No'" :show-icon="item.showCopyButton ?? true" />
      </td>
      <td v-else-if="_.isNumber(item.value)" font-mono>
        <c-text-copyable :value="String(item.value)" :show-icon="item.showCopyButton ?? true" />
      </td>
      <td v-else-if="_.isNil(item.value) || item.value === ''" op-70>
        {{ item.placeholder ?? 'N/A' }}
      </td>
      <td v-else>
        <c-text-copyable :value="item.value" :show-icon="item.showCopyButton ?? true" />
      </td>
    </tr>
  </table>
</template>