-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
/
Copy pathDocTable.vue
76 lines (69 loc) · 1.88 KB
/
DocTable.vue
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<template>
<div>
<q-table
:rows="rows"
:columns="validatedColumns"
row-key="name"
flat
bordered
hide-bottom
:rows-per-page-options="[0]"
style="width: fit-content;"
>
<template v-slot:body-cell-name="props">
<q-td :props="props">
<q-badge
color="brand-primary cursor-pointer"
outline
:label="props.row.name"
@click="copy(props.row.name)"
class="text-subtitle1"
/>
</q-td>
</template>
<template v-slot:body-cell-description="props">
<q-td :props="props" class="text-body1" style="font-size: 1rem;">
<span v-html="formatDescription(props.row.description)"></span>
</q-td>
</template>
</q-table>
</div>
</template>
<script setup>
import { ref, computed } from 'vue'
import { copyToClipboard, useQuasar } from 'quasar'
const props = defineProps({
rows: {
type: Array,
required: true
},
additionalColumns: {
type: Array,
required: false,
default: () => []
}
})
const $q = useQuasar()
const requiredColumns = ref([
{ name: 'name', label: 'Class Name', align: 'left', field: row => row.name, headerStyle: 'font-weight: bold; font-size: 1rem;' },
{ name: 'description', label: 'Description', align: 'left', field: row => row.description, headerStyle: 'font-weight: bold; font-size: 1rem;' }
])
const validatedColumns = computed(() => {
return [ ...requiredColumns.value, ...props.additionalColumns ]
})
const copy = (text) => {
copyToClipboard(text)
.then(() => {
$q.notify('Copied to clipboard')
})
.catch(() => {
$q.notify({
color: 'negative',
message: 'Failed to copy to clipboard'
})
})
}
const formatDescription = (description) => {
return description.replace(/`([^`]+)`/g, '<code class="doc-token">$1</code>')
}
</script>