feat: copy table button
This commit is contained in:
@@ -10,7 +10,7 @@
|
|||||||
- [x] Empty project from template
|
- [x] Empty project from template
|
||||||
- [x] Configuration
|
- [x] Configuration
|
||||||
- [x] Generate table
|
- [x] Generate table
|
||||||
- [ ] Copy table option
|
- [x] Copy table option
|
||||||
- [x] Save last state in cookies
|
- [x] Save last state in cookies
|
||||||
- [ ] Other format: raw text
|
- [ ] Other format: raw text
|
||||||
- [ ] Other format: SVG
|
- [ ] Other format: SVG
|
||||||
|
|||||||
+9
-2
@@ -95,7 +95,7 @@
|
|||||||
</table>
|
</table>
|
||||||
<template v-if="table.length">
|
<template v-if="table.length">
|
||||||
<h2>Output Table</h2>
|
<h2>Output Table</h2>
|
||||||
<table class="output">
|
<table id="output" class="output">
|
||||||
<colgroup>
|
<colgroup>
|
||||||
<col style="width: 25%">
|
<col style="width: 25%">
|
||||||
<col>
|
<col>
|
||||||
@@ -104,9 +104,16 @@
|
|||||||
<td v-for="item in row">{{item}}</td>
|
<td v-for="item in row">{{item}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<br>
|
||||||
|
<p>
|
||||||
|
<button @click="copyTable">
|
||||||
|
<i icon="table"></i>
|
||||||
|
<span v-if="copyTableOverride">{{copyTableOverride}}</span>
|
||||||
|
<span v-else>Copy table</span>
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
</template>
|
</template>
|
||||||
<h2 v-else>Add more vegetables !</h2>
|
<h2 v-else>Add more vegetables !</h2>
|
||||||
<br />
|
|
||||||
<small class="footer">
|
<small class="footer">
|
||||||
<i icon="at-sign"></i> <a href="https://github.com/klemek" target="_blank">klemek</a>
|
<i icon="at-sign"></i> <a href="https://github.com/klemek" target="_blank">klemek</a>
|
||||||
-
|
-
|
||||||
|
|||||||
@@ -231,6 +231,7 @@ const app = createApp({
|
|||||||
mix: 25,
|
mix: 25,
|
||||||
},
|
},
|
||||||
table: [],
|
table: [],
|
||||||
|
copyTableOverride: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
@@ -333,6 +334,7 @@ const app = createApp({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
generateData() {
|
generateData() {
|
||||||
|
this.table.splice(0, this.table.length);
|
||||||
if (this.candidates.length <= 2) {
|
if (this.candidates.length <= 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -360,9 +362,21 @@ const app = createApp({
|
|||||||
table[table.length - 1][1] = "🥗 SALAD 🥗";
|
table[table.length - 1][1] = "🥗 SALAD 🥗";
|
||||||
}
|
}
|
||||||
|
|
||||||
this.table.splice(0, this.table.length);
|
|
||||||
this.table.push(...table);
|
this.table.push(...table);
|
||||||
},
|
},
|
||||||
|
async copyTable() {
|
||||||
|
const csvTable = this.table.map((row) => row.join("\t")).join("\n");
|
||||||
|
try {
|
||||||
|
await navigator.clipboard.writeText(csvTable);
|
||||||
|
this.copyTableOverride = "Table Copied";
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error.message);
|
||||||
|
this.copyTableOverride = "Error";
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
this.copyTableOverride = null;
|
||||||
|
}, 1000);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user