@ternarytech-io/gears-ui 0.2.1 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,60 +1,60 @@
1
- <script setup lang="ts">
2
- // One level of a TSortableTree: its items, each with a list for its children under it (empty
3
- // ones open up while something is dragged, to drop into). Not used on its own.
4
- import { inject, onBeforeUnmount, onMounted, ref, watch, type FunctionalComponent } from 'vue'
5
- import type Sortable from 'sortablejs'
6
- import { treeKey, type TreeItemScope } from './sortableTree'
7
-
8
- defineOptions({ name: 'TSortableTreeList' })
9
-
10
- const props = defineProps<{ items: object[]; parent: object | null; depth: number }>()
11
- const tree = inject(treeKey)!
12
-
13
- const list = ref<HTMLElement>()
14
- let sortable: Sortable | null = null
15
-
16
- // An item's height: 1, plus its deepest child's.
17
- const heightOf = (item: object): number => 1 + Math.max(0, ...tree.childrenOf(item).map(heightOf))
18
-
19
- const Row: FunctionalComponent<TreeItemScope<object>> = scope => tree.render(scope)
20
-
21
- onMounted(async () => {
22
- const SortableClass = (await import('sortablejs')).default
23
- if (!list.value) return
24
- sortable = new SortableClass(list.value, {
25
- group: tree.group,
26
- animation: 150,
27
- draggable: '.t-tree-node',
28
- handle: tree.handle ? '.sortable-handle' : undefined,
29
- disabled: tree.disabled,
30
- // SortableJS's own dragging (not the browser's): the same in every browser and on touch screens.
31
- forceFallback: true,
32
- fallbackOnBody: true,
33
- swapThreshold: 0.65,
34
- onStart: () => { tree.dragging.value = true },
35
- // A drop may not take the item's deepest child past the tree's depth.
36
- onMove: event => Number(event.to.dataset.depth) - 1 + Number(event.dragged.dataset.height) <= tree.maxDepth,
37
- onEnd: ({ oldIndex, newIndex, item, from, to }) => {
38
- tree.dragging.value = false
39
- if (oldIndex == null || newIndex == null || (from === to && oldIndex === newIndex)) return
40
- // SortableJS moved the element; put it back and let Vue move it, so the lists stay right.
41
- to.removeChild(item)
42
- from.insertBefore(item, from.children[oldIndex] ?? null)
43
- tree.move(from.dataset.parent ?? '', oldIndex, to.dataset.parent ?? '', newIndex)
44
- }
45
- })
46
- })
47
-
48
- watch(() => tree.disabled, disabled => sortable?.option('disabled', !!disabled))
49
- onBeforeUnmount(() => sortable?.destroy())
50
- </script>
51
-
52
- <template>
53
- <div ref="list" :class="['t-tree-list', { 't-tree-children': depth > 1, 't-tree-empty': !items.length }]"
54
- :data-parent="parent ? tree.keyOf(parent) : ''" :data-depth="depth">
55
- <div v-for="item in items" :key="tree.keyOf(item)" class="t-tree-node" :data-height="heightOf(item)">
56
- <Row :item="item" :depth="depth" :parent="parent" />
57
- <TSortableTreeList v-if="depth < tree.maxDepth" :items="tree.childrenOf(item)" :parent="item" :depth="depth + 1" />
58
- </div>
59
- </div>
60
- </template>
1
+ <script setup lang="ts">
2
+ // One level of a TSortableTree: its items, each with a list for its children under it (empty
3
+ // ones open up while something is dragged, to drop into). Not used on its own.
4
+ import { inject, onBeforeUnmount, onMounted, ref, watch, type FunctionalComponent } from 'vue'
5
+ import type Sortable from 'sortablejs'
6
+ import { treeKey, type TreeItemScope } from './sortableTree'
7
+
8
+ defineOptions({ name: 'TSortableTreeList' })
9
+
10
+ const props = defineProps<{ items: object[]; parent: object | null; depth: number }>()
11
+ const tree = inject(treeKey)!
12
+
13
+ const list = ref<HTMLElement>()
14
+ let sortable: Sortable | null = null
15
+
16
+ // An item's height: 1, plus its deepest child's.
17
+ const heightOf = (item: object): number => 1 + Math.max(0, ...tree.childrenOf(item).map(heightOf))
18
+
19
+ const Row: FunctionalComponent<TreeItemScope<object>> = scope => tree.render(scope)
20
+
21
+ onMounted(async () => {
22
+ const SortableClass = (await import('sortablejs')).default
23
+ if (!list.value) return
24
+ sortable = new SortableClass(list.value, {
25
+ group: tree.group,
26
+ animation: 150,
27
+ draggable: '.t-tree-node',
28
+ handle: tree.handle ? '.sortable-handle' : undefined,
29
+ disabled: tree.disabled,
30
+ // SortableJS's own dragging (not the browser's): the same in every browser and on touch screens.
31
+ forceFallback: true,
32
+ fallbackOnBody: true,
33
+ swapThreshold: 0.65,
34
+ onStart: () => { tree.dragging.value = true },
35
+ // A drop may not take the item's deepest child past the tree's depth.
36
+ onMove: event => Number(event.to.dataset.depth) - 1 + Number(event.dragged.dataset.height) <= tree.maxDepth,
37
+ onEnd: ({ oldIndex, newIndex, item, from, to }) => {
38
+ tree.dragging.value = false
39
+ if (oldIndex == null || newIndex == null || (from === to && oldIndex === newIndex)) return
40
+ // SortableJS moved the element; put it back and let Vue move it, so the lists stay right.
41
+ to.removeChild(item)
42
+ from.insertBefore(item, from.children[oldIndex] ?? null)
43
+ tree.move(from.dataset.parent ?? '', oldIndex, to.dataset.parent ?? '', newIndex)
44
+ }
45
+ })
46
+ })
47
+
48
+ watch(() => tree.disabled, disabled => sortable?.option('disabled', !!disabled))
49
+ onBeforeUnmount(() => sortable?.destroy())
50
+ </script>
51
+
52
+ <template>
53
+ <div ref="list" :class="['t-tree-list', { 't-tree-children': depth > 1, 't-tree-empty': !items.length }]"
54
+ :data-parent="parent ? tree.keyOf(parent) : ''" :data-depth="depth">
55
+ <div v-for="item in items" :key="tree.keyOf(item)" class="t-tree-node" :data-height="heightOf(item)">
56
+ <Row :item="item" :depth="depth" :parent="parent" />
57
+ <TSortableTreeList v-if="depth < tree.maxDepth" :items="tree.childrenOf(item)" :parent="item" :depth="depth + 1" />
58
+ </div>
59
+ </div>
60
+ </template>
@@ -0,0 +1,34 @@
1
+ <script setup lang="ts">
2
+ // A tiny chart in a line of text or a stat card: Tabler's sparkline (an inline SVG, no library), as
3
+ // a line, bars, or a circle for one percentage. It takes the text color, so a color names it.
4
+ import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
5
+ import { Sparkline } from '@tabler/core'
6
+ import { toTabler, type Color } from '../types'
7
+
8
+ const props = withDefaults(defineProps<{
9
+ values: number[]
10
+ type?: 'line' | 'bar' | 'circle'
11
+ color?: Color
12
+ width?: number
13
+ height?: number
14
+ // Mark the last, highest or lowest value with a dot.
15
+ spot?: 'none' | 'last' | 'max' | 'min'
16
+ label?: string
17
+ }>(), { type: 'line', color: 'primary', width: 64, height: 24, spot: 'none' })
18
+
19
+ const el = ref<HTMLElement>()
20
+ let sparkline: InstanceType<typeof Sparkline> | null = null
21
+
22
+ onMounted(() => {
23
+ sparkline = new Sparkline(el.value!, {
24
+ type: props.type, values: props.values, width: props.width, height: props.height,
25
+ spot: props.spot, fill: props.type === 'line' ? 'auto' : 'none', animation: 0, label: false
26
+ })
27
+ })
28
+ watch(() => props.values, values => sparkline?.update(values), { deep: true })
29
+ onBeforeUnmount(() => sparkline?.dispose())
30
+ </script>
31
+
32
+ <template>
33
+ <span ref="el" :class="['sparkline', `text-${toTabler(color)}`]" role="img" :aria-label="label ?? `Trend: ${values.join(', ')}`" />
34
+ </template>
@@ -1,26 +1,56 @@
1
- <script setup lang="ts">
2
- // A figure on an overview page: label, value, a line under it, and an icon in a tinted square.
3
- import TIcon from './TIcon.vue'
4
- import { toTabler, type Color } from '../types'
5
-
6
- withDefaults(defineProps<{ label: string; value: string | number; detail?: string; icon: string; color?: Color }>(), { color: 'primary' })
7
- </script>
8
-
9
- <template>
10
- <div class="card">
11
- <div class="card-body">
12
- <div class="d-flex align-items-start justify-content-between gap-3">
13
- <div class="min-w-0">
14
- <div class="subheader">{{ label }}</div>
15
- <div class="h1 mb-0 mt-2">{{ value }}</div>
16
- <div v-if="detail || $slots.detail" class="text-secondary small mt-1">
17
- <slot name="detail">{{ detail }}</slot>
18
- </div>
19
- </div>
20
- <div :class="['t-stat-icon', `bg-${toTabler(color)}-lt`]">
21
- <TIcon :name="icon" />
22
- </div>
23
- </div>
24
- </div>
25
- </div>
26
- </template>
1
+ <script setup lang="ts">
2
+ // A figure on an overview page: label, value, a line under it, and an icon in a tinted square. A
3
+ // `trend` (the change, in percent) shows beside the value, green when it's good: up, unless
4
+ // `trendGood` is 'down' (costs, errors). `sparkline` draws the recent values under it.
5
+ import { computed } from 'vue'
6
+ import TIcon from './TIcon.vue'
7
+ import TSparkline from './TSparkline.vue'
8
+ import { toTabler, type Color } from '../types'
9
+
10
+ const props = withDefaults(defineProps<{
11
+ label: string
12
+ value: string | number
13
+ detail?: string
14
+ icon?: string
15
+ color?: Color
16
+ trend?: number | null
17
+ trendLabel?: string
18
+ trendGood?: 'up' | 'down'
19
+ sparkline?: number[]
20
+ sparklineType?: 'line' | 'bar'
21
+ }>(), { color: 'primary', trendGood: 'up', sparklineType: 'line' })
22
+
23
+ const trendText = computed(() => props.trend == null ? '' : `${Math.abs(Math.round(props.trend * 10) / 10)}%`)
24
+ const trendClass = computed(() => {
25
+ if (props.trend == null || props.trend === 0) return 'text-secondary'
26
+ return (props.trend > 0) === (props.trendGood === 'up') ? 'text-success' : 'text-danger'
27
+ })
28
+ const trendIcon = computed(() => !props.trend ? 'minus' : props.trend > 0 ? 'trending-up' : 'trending-down')
29
+ </script>
30
+
31
+ <template>
32
+ <div class="card">
33
+ <div class="card-body">
34
+ <div class="d-flex align-items-start justify-content-between gap-3">
35
+ <div class="min-w-0">
36
+ <div class="subheader">{{ label }}</div>
37
+ <div class="d-flex align-items-baseline gap-2 mt-2">
38
+ <div class="h1 mb-0">{{ value }}</div>
39
+ <span v-if="trend != null" :class="['d-inline-flex align-items-center gap-1 lh-1 small fw-medium', trendClass]"
40
+ :title="trendLabel">
41
+ {{ trendText }}<TIcon :name="trendIcon" />
42
+ </span>
43
+ </div>
44
+ <div v-if="detail || trendLabel || $slots.detail" class="text-secondary small mt-1">
45
+ <slot name="detail">{{ detail ?? trendLabel }}</slot>
46
+ </div>
47
+ </div>
48
+ <div v-if="icon" :class="['t-stat-icon', `bg-${toTabler(color)}-lt`]">
49
+ <TIcon :name="icon" />
50
+ </div>
51
+ </div>
52
+ <TSparkline v-if="sparkline?.length" :values="sparkline" :type="sparklineType" :color="color" :width="240" :height="36"
53
+ class="t-stat-sparkline mt-3" :label="`${label}: recent values`" />
54
+ </div>
55
+ </div>
56
+ </template>
@@ -1,134 +1,138 @@
1
- <script setup lang="ts" generic="Row extends Record<string, any>">
2
- // A table of rows. Columns name a key, a label and how to align; a `{key}-cell` slot draws a cell
3
- // (it gets the row and value), `{key}-header` a heading, and the `cell` slot any cell without its
4
- // own slot. Sortable columns sort the rows here, unless `manualSort` leaves it to the caller (who
5
- // watches v-model:sort); a `{key}-header` slot gets the column's sort and `toggleSort` to draw its
6
- // own sort button. `selectable` adds a checkbox to each row (Tabler's table-selectable) and one in
7
- // the header for every row; v-model:selected holds the chosen rows' keys. `card` fits it into a
8
- // flush TCard; `sticky` keeps the header in view while the table scrolls in its container.
9
- import { computed, ref, watchEffect } from 'vue'
10
- import TSpinner from './TSpinner.vue'
11
- import type { TableColumn, TableSort } from '../types'
12
-
13
- const props = withDefaults(defineProps<{
14
- columns: TableColumn<Row>[]
15
- rows: Row[]
16
- rowKey?: string | ((row: Row) => string | number)
17
- loading?: boolean
18
- empty?: string
19
- card?: boolean
20
- striped?: boolean
21
- hover?: boolean
22
- // Rows can be clicked; each click emits `select`.
23
- clickable?: boolean
24
- // A checkbox on each row; clicking a row (unless it's `clickable`) checks it too.
25
- selectable?: boolean
26
- manualSort?: boolean
27
- sticky?: boolean
28
- }>(), { rowKey: 'id', empty: 'Nothing to show.' })
29
-
30
- const emit = defineEmits<{ select: [row: Row] }>()
31
- const sort = defineModel<TableSort | null>('sort', { default: null })
32
- const selected = defineModel<(string | number)[]>('selected', { default: () => [] })
33
-
34
- const cell = (row: Row, column: TableColumn<Row>) => column.value ? column.value(row) : row[column.key]
35
- const key = (row: Row, index: number) => typeof props.rowKey === 'function' ? props.rowKey(row) : row[props.rowKey] ?? index
36
- const align = (column: TableColumn<Row>) => column.align === 'end' ? 'text-end' : column.align === 'center' ? 'text-center' : undefined
37
-
38
- const sorted = computed(() => {
39
- const by = sort.value
40
- const column = by && props.columns.find(c => c.key === by.key)
41
- if (!by || !column || props.manualSort) return props.rows
42
- const factor = by.direction === 'asc' ? 1 : -1
43
- return [...props.rows].sort((a, b) => {
44
- const x = cell(a, column) as any
45
- const y = cell(b, column) as any
46
- if (x == null) return y == null ? 0 : 1
47
- if (y == null) return -1
48
- return (typeof x === 'number' && typeof y === 'number' ? x - y : String(x).localeCompare(String(y), undefined, { numeric: true })) * factor
49
- })
50
- })
51
-
52
- function sortOf(column: TableColumn<Row>) {
53
- return sort.value?.key === column.key ? sort.value.direction : null
54
- }
55
-
56
- function toggleSort(column: TableColumn<Row>) {
57
- const current = sort.value?.key === column.key ? sort.value.direction : null
58
- sort.value = current === 'asc' ? { key: column.key, direction: 'desc' } : current === 'desc' ? null : { key: column.key, direction: 'asc' }
59
- }
60
-
61
- // ---- Selection ----
62
- const keys = computed(() => sorted.value.map((row, index) => key(row, index)))
63
- const isChecked = (row: Row, index: number) => selected.value.includes(key(row, index))
64
- const allChecked = computed(() => keys.value.length > 0 && keys.value.every(k => selected.value.includes(k)))
65
- const someChecked = computed(() => !allChecked.value && keys.value.some(k => selected.value.includes(k)))
66
- const allBox = ref<HTMLInputElement>()
67
- watchEffect(() => { if (allBox.value) allBox.value.indeterminate = someChecked.value })
68
-
69
- function check(row: Row, index: number) {
70
- const k = key(row, index)
71
- selected.value = selected.value.includes(k) ? selected.value.filter(x => x !== k) : [...selected.value, k]
72
- }
73
- // The header's box checks every row shown, or unchecks them (keeping rows not shown).
74
- function checkAll() {
75
- selected.value = allChecked.value
76
- ? selected.value.filter(k => !keys.value.includes(k))
77
- : [...new Set([...selected.value, ...keys.value])]
78
- }
79
- function clickRow(row: Row, index: number) {
80
- if (props.clickable) emit('select', row)
81
- else if (props.selectable) check(row, index)
82
- }
83
-
84
- const span = computed(() => props.columns.length + (props.selectable ? 1 : 0))
85
-
86
- function format(value: unknown) {
87
- if (value == null || value === '') return '—'
88
- if (typeof value === 'boolean') return value ? 'Yes' : 'No'
89
- return String(value)
90
- }
91
- </script>
92
-
93
- <template>
94
- <div :class="sticky ? 't-table-sticky' : 'table-responsive'">
95
- <table :class="['table table-vcenter mb-0', { 'card-table': card, 'table-striped': striped, 'table-hover': hover || clickable, 'table-selectable': selectable }]">
96
- <thead>
97
- <tr>
98
- <th v-if="selectable" class="w-1">
99
- <input ref="allBox" type="checkbox" class="form-check-input m-0 align-middle" :checked="allChecked" :disabled="!keys.length"
100
- aria-label="Select every row" @change="checkAll">
101
- </th>
102
- <th v-for="column in columns" :key="column.key" :class="align(column)" :style="column.width ? { width: column.width } : undefined"
103
- :aria-sort="sort?.key === column.key ? (sort.direction === 'asc' ? 'ascending' : 'descending') : undefined">
104
- <slot :name="`${column.key}-header`" :column="column" :sort="sortOf(column)" :toggle-sort="() => toggleSort(column)">
105
- <button v-if="column.sortable" type="button" :class="['table-sort', { asc: sort?.key === column.key && sort.direction === 'asc', desc: sort?.key === column.key && sort.direction === 'desc' }]"
106
- @click="toggleSort(column)">{{ column.label ?? column.key }}</button>
107
- <template v-else>{{ column.label ?? column.key }}</template>
108
- </slot>
109
- </th>
110
- </tr>
111
- </thead>
112
- <tbody>
113
- <tr v-if="loading && !rows.length">
114
- <td :colspan="span" class="text-center py-4"><TSpinner size="sm" show-label /></td>
115
- </tr>
116
- <tr v-else-if="!rows.length">
117
- <td :colspan="span" class="text-center text-secondary py-4"><slot name="empty">{{ empty }}</slot></td>
118
- </tr>
119
- <tr v-for="(row, index) in sorted" v-else :key="key(row, index)"
120
- :class="{ 'cursor-pointer': clickable || selectable, 'table-active': selectable && isChecked(row, index) }" @click="clickRow(row, index)">
121
- <td v-if="selectable" @click.stop>
122
- <input type="checkbox" class="form-check-input m-0 align-middle table-selectable-check" :checked="isChecked(row, index)"
123
- aria-label="Select the row" @change="check(row, index)">
124
- </td>
125
- <td v-for="column in columns" :key="column.key" :class="align(column)">
126
- <slot :name="`${column.key}-cell`" :row="row" :value="cell(row, column)">
127
- <slot name="cell" :row="row" :column="column" :value="cell(row, column)">{{ format(cell(row, column)) }}</slot>
128
- </slot>
129
- </td>
130
- </tr>
131
- </tbody>
132
- </table>
133
- </div>
134
- </template>
1
+ <script setup lang="ts" generic="Row extends Record<string, any>">
2
+ // A table of rows. Columns name a key, a label and how to align; a `{key}-cell` slot draws a cell
3
+ // (it gets the row and value), `{key}-header` a heading, and the `cell` slot any cell without its
4
+ // own slot. Sortable columns sort the rows here, unless `manualSort` leaves it to the caller (who
5
+ // watches v-model:sort); a `{key}-header` slot gets the column's sort and `toggleSort` to draw its
6
+ // own sort button. `selectable` adds a checkbox to each row (Tabler's table-selectable) and one in
7
+ // the header for every row; v-model:selected holds the chosen rows' keys. `card` fits it into a
8
+ // flush TCard; `sticky` keeps the header in view while the table scrolls in its container.
9
+ // `cellClickable` names cells that take a click of their own: the whole cell emits `cell-click`,
10
+ // instead of the row's click or check.
11
+ import { computed, ref, watchEffect } from 'vue'
12
+ import TSpinner from './TSpinner.vue'
13
+ import type { TableColumn, TableSort } from '../types'
14
+
15
+ const props = withDefaults(defineProps<{
16
+ columns: TableColumn<Row>[]
17
+ rows: Row[]
18
+ rowKey?: string | ((row: Row) => string | number)
19
+ loading?: boolean
20
+ empty?: string
21
+ card?: boolean
22
+ striped?: boolean
23
+ hover?: boolean
24
+ // Rows can be clicked; each click emits `select`.
25
+ clickable?: boolean
26
+ // A checkbox on each row; clicking a row (unless it's `clickable`) checks it too.
27
+ selectable?: boolean
28
+ manualSort?: boolean
29
+ sticky?: boolean
30
+ cellClickable?: (row: Row, column: TableColumn<Row>) => boolean
31
+ }>(), { rowKey: 'id', empty: 'Nothing to show.' })
32
+
33
+ const emit = defineEmits<{ select: [row: Row]; 'cell-click': [row: Row, column: TableColumn<Row>] }>()
34
+ const sort = defineModel<TableSort | null>('sort', { default: null })
35
+ const selected = defineModel<(string | number)[]>('selected', { default: () => [] })
36
+
37
+ const cell = (row: Row, column: TableColumn<Row>) => column.value ? column.value(row) : row[column.key]
38
+ const key = (row: Row, index: number) => typeof props.rowKey === 'function' ? props.rowKey(row) : row[props.rowKey] ?? index
39
+ const align = (column: TableColumn<Row>) => column.align === 'end' ? 'text-end' : column.align === 'center' ? 'text-center' : undefined
40
+
41
+ const sorted = computed(() => {
42
+ const by = sort.value
43
+ const column = by && props.columns.find(c => c.key === by.key)
44
+ if (!by || !column || props.manualSort) return props.rows
45
+ const factor = by.direction === 'asc' ? 1 : -1
46
+ return [...props.rows].sort((a, b) => {
47
+ const x = cell(a, column) as any
48
+ const y = cell(b, column) as any
49
+ if (x == null) return y == null ? 0 : 1
50
+ if (y == null) return -1
51
+ return (typeof x === 'number' && typeof y === 'number' ? x - y : String(x).localeCompare(String(y), undefined, { numeric: true })) * factor
52
+ })
53
+ })
54
+
55
+ function sortOf(column: TableColumn<Row>) {
56
+ return sort.value?.key === column.key ? sort.value.direction : null
57
+ }
58
+
59
+ function toggleSort(column: TableColumn<Row>) {
60
+ const current = sort.value?.key === column.key ? sort.value.direction : null
61
+ sort.value = current === 'asc' ? { key: column.key, direction: 'desc' } : current === 'desc' ? null : { key: column.key, direction: 'asc' }
62
+ }
63
+
64
+ // ---- Selection ----
65
+ const keys = computed(() => sorted.value.map((row, index) => key(row, index)))
66
+ const isChecked = (row: Row, index: number) => selected.value.includes(key(row, index))
67
+ const allChecked = computed(() => keys.value.length > 0 && keys.value.every(k => selected.value.includes(k)))
68
+ const someChecked = computed(() => !allChecked.value && keys.value.some(k => selected.value.includes(k)))
69
+ const allBox = ref<HTMLInputElement>()
70
+ watchEffect(() => { if (allBox.value) allBox.value.indeterminate = someChecked.value })
71
+
72
+ function check(row: Row, index: number) {
73
+ const k = key(row, index)
74
+ selected.value = selected.value.includes(k) ? selected.value.filter(x => x !== k) : [...selected.value, k]
75
+ }
76
+ // The header's box checks every row shown, or unchecks them (keeping rows not shown).
77
+ function checkAll() {
78
+ selected.value = allChecked.value
79
+ ? selected.value.filter(k => !keys.value.includes(k))
80
+ : [...new Set([...selected.value, ...keys.value])]
81
+ }
82
+ function clickRow(row: Row, index: number) {
83
+ if (props.clickable) emit('select', row)
84
+ else if (props.selectable) check(row, index)
85
+ }
86
+
87
+ const span = computed(() => props.columns.length + (props.selectable ? 1 : 0))
88
+
89
+ function format(value: unknown) {
90
+ if (value == null || value === '') return '—'
91
+ if (typeof value === 'boolean') return value ? 'Yes' : 'No'
92
+ return String(value)
93
+ }
94
+ </script>
95
+
96
+ <template>
97
+ <div :class="sticky ? 't-table-sticky' : 'table-responsive'">
98
+ <table :class="['table table-vcenter mb-0', { 'card-table': card, 'table-striped': striped, 'table-hover': hover || clickable, 'table-selectable': selectable }]">
99
+ <thead>
100
+ <tr>
101
+ <th v-if="selectable" class="w-1">
102
+ <input ref="allBox" type="checkbox" class="form-check-input m-0 align-middle" :checked="allChecked" :disabled="!keys.length"
103
+ aria-label="Select every row" @change="checkAll">
104
+ </th>
105
+ <th v-for="column in columns" :key="column.key" :class="align(column)" :style="column.width ? { width: column.width } : undefined"
106
+ :aria-sort="sort?.key === column.key ? (sort.direction === 'asc' ? 'ascending' : 'descending') : undefined">
107
+ <slot :name="`${column.key}-header`" :column="column" :sort="sortOf(column)" :toggle-sort="() => toggleSort(column)">
108
+ <button v-if="column.sortable" type="button" :class="['table-sort', { asc: sort?.key === column.key && sort.direction === 'asc', desc: sort?.key === column.key && sort.direction === 'desc' }]"
109
+ @click="toggleSort(column)">{{ column.label ?? column.key }}</button>
110
+ <template v-else>{{ column.label ?? column.key }}</template>
111
+ </slot>
112
+ </th>
113
+ </tr>
114
+ </thead>
115
+ <tbody>
116
+ <tr v-if="loading && !rows.length">
117
+ <td :colspan="span" class="text-center py-4"><TSpinner size="sm" show-label /></td>
118
+ </tr>
119
+ <tr v-else-if="!rows.length">
120
+ <td :colspan="span" class="text-center text-secondary py-4"><slot name="empty">{{ empty }}</slot></td>
121
+ </tr>
122
+ <tr v-for="(row, index) in sorted" v-else :key="key(row, index)"
123
+ :class="{ 'cursor-pointer': clickable || selectable, 'table-active': selectable && isChecked(row, index) }" @click="clickRow(row, index)">
124
+ <td v-if="selectable" @click.stop>
125
+ <input type="checkbox" class="form-check-input m-0 align-middle table-selectable-check" :checked="isChecked(row, index)"
126
+ aria-label="Select the row" @change="check(row, index)">
127
+ </td>
128
+ <td v-for="column in columns" :key="column.key" :class="[align(column), { 't-cell-clickable': cellClickable?.(row, column) }]"
129
+ @click="event => { if (cellClickable?.(row, column)) { event.stopPropagation(); emit('cell-click', row, column) } }">
130
+ <slot :name="`${column.key}-cell`" :row="row" :value="cell(row, column)">
131
+ <slot name="cell" :row="row" :column="column" :value="cell(row, column)">{{ format(cell(row, column)) }}</slot>
132
+ </slot>
133
+ </td>
134
+ </tr>
135
+ </tbody>
136
+ </table>
137
+ </div>
138
+ </template>
@@ -1,22 +1,22 @@
1
- <script setup lang="ts">
2
- // A theme's base: the grays behind every surface, border and muted text. Each tile shows five of
3
- // the base's shades, lightest to darkest.
4
- import TRadioGroup from './TRadioGroup.vue'
5
- import { themeBases } from '../theme'
6
- import type { ThemeBase } from '../types'
7
-
8
- defineProps<{ disabled?: boolean; legend?: string }>()
9
-
10
- const model = defineModel<ThemeBase | null | undefined>()
11
- const shades = [100, 300, 500, 700, 900]
12
- </script>
13
-
14
- <template>
15
- <TRadioGroup v-model="model" :items="themeBases" variant="tiles" :disabled="disabled" :legend="legend">
16
- <template #preview="{ item }">
17
- <span class="t-theme-swatches" :data-bs-theme-base="item.value">
18
- <span v-for="shade in shades" :key="shade" :style="{ background: `var(--tblr-gray-${shade})` }" />
19
- </span>
20
- </template>
21
- </TRadioGroup>
22
- </template>
1
+ <script setup lang="ts">
2
+ // A theme's base: the grays behind every surface, border and muted text. Each tile shows five of
3
+ // the base's shades, lightest to darkest.
4
+ import TRadioGroup from './TRadioGroup.vue'
5
+ import { themeBases } from '../theme'
6
+ import type { ThemeBase } from '../types'
7
+
8
+ defineProps<{ disabled?: boolean; legend?: string }>()
9
+
10
+ const model = defineModel<ThemeBase | null | undefined>()
11
+ const shades = [100, 300, 500, 700, 900]
12
+ </script>
13
+
14
+ <template>
15
+ <TRadioGroup v-model="model" :items="themeBases" variant="tiles" :disabled="disabled" :legend="legend">
16
+ <template #preview="{ item }">
17
+ <span class="t-theme-swatches" :data-bs-theme-base="item.value">
18
+ <span v-for="shade in shades" :key="shade" :style="{ background: `var(--tblr-gray-${shade})` }" />
19
+ </span>
20
+ </template>
21
+ </TRadioGroup>
22
+ </template>
@@ -1,19 +1,19 @@
1
- // What TSortableTree shares with its lists (TSortableTreeList), one per level.
2
- import type { InjectionKey, Ref, VNode } from 'vue'
3
-
4
- export interface TreeItemScope<T> { item: T; depth: number; parent: T | null }
5
-
6
- export interface TreeContext<T> {
7
- // The SortableJS group: items move between this tree's lists, and no other's.
8
- group: string
9
- handle?: boolean
10
- disabled?: boolean
11
- maxDepth: number
12
- dragging: Ref<boolean>
13
- keyOf(item: T): string
14
- childrenOf(item: T): T[]
15
- move(fromKey: string, oldIndex: number, toKey: string, newIndex: number): void
16
- render(scope: TreeItemScope<T>): VNode[] | undefined
17
- }
18
-
19
- export const treeKey: InjectionKey<TreeContext<object>> = Symbol('t-sortable-tree')
1
+ // What TSortableTree shares with its lists (TSortableTreeList), one per level.
2
+ import type { InjectionKey, Ref, VNode } from 'vue'
3
+
4
+ export interface TreeItemScope<T> { item: T; depth: number; parent: T | null }
5
+
6
+ export interface TreeContext<T> {
7
+ // The SortableJS group: items move between this tree's lists, and no other's.
8
+ group: string
9
+ handle?: boolean
10
+ disabled?: boolean
11
+ maxDepth: number
12
+ dragging: Ref<boolean>
13
+ keyOf(item: T): string
14
+ childrenOf(item: T): T[]
15
+ move(fromKey: string, oldIndex: number, toKey: string, newIndex: number): void
16
+ render(scope: TreeItemScope<T>): VNode[] | undefined
17
+ }
18
+
19
+ export const treeKey: InjectionKey<TreeContext<object>> = Symbol('t-sortable-tree')