feat: add copy action indicator to color table

This commit is contained in:
Sebin Nyshkim 2023-01-18 18:35:52 +01:00
parent 5b16aae03c
commit e29a98f06d
2 changed files with 22 additions and 1 deletions

View file

@ -1,4 +1,6 @@
<script setup lang="ts">
import ClipboardIcon from "@/assets/icons/ClipboardIcon.vue";
interface ColorDict {
name: string;
value: string;
@ -8,6 +10,10 @@ interface Props {
colors: ColorDict[];
}
const copyToClipboard = (value: string) => {
navigator.clipboard.writeText(value);
};
defineProps<Props>();
</script>
@ -23,7 +29,13 @@ defineProps<Props>();
<tbody class="color-table__body">
<tr class="color-table__row" v-for="(color, idx) in colors" :key="idx">
<td class="color-table__cell name">{{ color.name }}</td>
<td class="color-table__cell value">{{ color.value }}</td>
<td
class="color-table__cell value"
@click.prevent="copyToClipboard(color.value)"
>
{{ color.value }}
<ClipboardIcon class="color-table__copy" />
</td>
<td
class="color-table__cell color"
:style="{ 'background-color': color.value }"
@ -49,11 +61,17 @@ defineProps<Props>();
&.value {
font-family: monospace;
text-align: center;
cursor: pointer;
}
&.color {
min-width: 10vw;
}
}
&__copy {
margin: 0 0 -0.25rem 0;
max-height: 1.25rem;
}
}
</style>