Files
legume/src/components/OutputTable.vue
T
klemek fc77ebf185
Deploy / Deploy to Stapler (push) Has been cancelled
Deploy / Build (push) Has been cancelled
Lint / ESLint (push) Has been cancelled
Lint / TypeScript (push) Has been cancelled
refactor: refresh from template
2026-05-02 21:46:11 +02:00

64 lines
1.4 KiB
Vue

<script setup lang="ts">
import { updateIcons } from "@/lib/icons";
import { ref, onUpdated } from "vue";
const table = defineModel<[string, string][]>({ required: true });
const copyTableOverride = ref<string | null>(null);
async function copyTable() {
const csvTable = table.value.map((row) => row.join("\t")).join("\n");
try {
await navigator.clipboard.writeText(csvTable);
copyTableOverride.value = "Table Copied";
} catch {
copyTableOverride.value = "Error";
}
setTimeout(() => {
copyTableOverride.value = null;
}, 1000);
}
onUpdated(updateIcons);
</script>
<template>
<table id="output" class="output">
<colgroup>
<col style="width: 25%" />
<col />
</colgroup>
<tr v-for="(row, index) in table" :key="`out-row-${index}`">
<td v-for="(item, index2) in row" :key="`out-cell-${index}-${index2}`">
{{ item }}
</td>
</tr>
</table>
<br />
<p>
<button @click="copyTable">
<i icon="table"></i>&nbsp;
<span v-if="copyTableOverride">{{ copyTableOverride }}</span>
<span v-else>Copy table</span>
</button>
</p>
</template>
<style scoped>
table.output,
table.output th,
table.output td {
border: 1px solid var(--text-secondary);
}
table.output td {
text-align: center;
font-size: 1.1em;
padding: 0.25em 0.5em;
}
table.output td:first-child {
text-align: right;
}
</style>