@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.
- package/README.md +162 -161
- package/package.json +113 -111
- package/src/components/TAccentPicker.vue +41 -41
- package/src/components/TChart.vue +188 -0
- package/src/components/TContainerPicker.vue +22 -22
- package/src/components/TDataGrid.vue +41 -0
- package/src/components/TDataGridItem.vue +23 -0
- package/src/components/TDensityPicker.vue +19 -19
- package/src/components/TEditableTable.vue +203 -0
- package/src/components/TFontPicker.vue +23 -23
- package/src/components/TNavPositionPicker.vue +22 -22
- package/src/components/TRadiusPicker.vue +21 -21
- package/src/components/TScaledFrame.vue +36 -36
- package/src/components/TShell.vue +82 -72
- package/src/components/TSortableTree.vue +73 -73
- package/src/components/TSortableTreeList.vue +60 -60
- package/src/components/TSparkline.vue +34 -0
- package/src/components/TStatCard.vue +56 -26
- package/src/components/TTable.vue +138 -134
- package/src/components/TThemeBasePicker.vue +22 -22
- package/src/components/sortableTree.ts +19 -19
- package/src/index.ts +227 -215
- package/src/plugins/charts.ts +4 -0
- package/src/plugins/index.ts +55 -52
- package/src/styles/gears.css +666 -625
- package/src/theme.ts +50 -45
- package/src/types.ts +38 -1
|
@@ -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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
//
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
<tr v-
|
|
117
|
-
<td :colspan="span" class="text-center
|
|
118
|
-
</tr>
|
|
119
|
-
<tr v-
|
|
120
|
-
:class="
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
</
|
|
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')
|