refactor(c-key-value-list): got rid of table for layout (#611)

This commit is contained in:
Corentin THOMASSET 2023-09-03 18:12:22 +02:00 committed by GitHub
parent c7d4562d3b
commit 7ab9204e96
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 49 additions and 33 deletions

View file

@ -0,0 +1,27 @@
<script lang="ts" setup>
import _ from 'lodash';
import type { CKeyValueListItem } from './c-key-value-list.types';
const props = defineProps<{ item: CKeyValueListItem }>();
const { item } = toRefs(props);
</script>
<template>
<div 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>
</div>
<div 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" />
</div>
<div v-else-if="_.isNumber(item.value)" font-mono>
<c-text-copyable :value="String(item.value)" :show-icon="item.showCopyButton ?? true" />
</div>
<div v-else-if="_.isNil(item.value) || item.value === ''" op-70>
{{ item.placeholder ?? 'N/A' }}
</div>
<div v-else>
<c-text-copyable :value="item.value" :show-icon="item.showCopyButton ?? true" />
</div>
</template>

View file

@ -9,29 +9,13 @@ const formattedItems = computed(() => items.value.filter(item => !_.isNil(item.v
</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>
<div my-5>
<div v-for="item in formattedItems" :key="item.label" flex gap-2 py-1 class="c-key-value-list__item">
<div flex-basis-180px text-right font-bold class="c-key-value-list__key">
{{ item.label }}
</td>
</div>
<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>
<c-key-value-list-item :item="item" class="c-key-value-list__value" />
</div>
</div>
</template>

View file

@ -19,7 +19,10 @@ const isTargetHovered = useElementHover(targetRef);
'op-100 scale-100': isTargetHovered,
}"
>
<slot name="tooltip">
<slot
v-if="isTargetHovered"
name="tooltip"
>
{{ tooltip }}
</slot>
</div>