@ternarytech-io/gears-ui 0.2.0 → 0.3.0

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 CHANGED
@@ -106,9 +106,9 @@ add a page, add an entry to `preview/registry.ts` and a folder of examples.
106
106
  | Theme | `TAccentPicker`, `TFontPicker`, `TRadiusPicker`, `TThemeBasePicker` (Tabler's theme settings as pickers), `TNavPositionPicker`, `TDensityPicker`, `TContainerPicker` (layout), `TThemeScope` (applies a `ThemeSettings`' look and density to what's inside it); `themeAccents`, `themeFonts`, `themeBases`, `themeRadii`, `themeNavs`, `themeDensities`, `themeContainers` |
107
107
  | Overlays | `TModal`, `TSlideover`, `TDropdown`, `TToaster` (with `useToast()`) |
108
108
  | Navigation | `TTabs`, `TPagination`, `TSteps`, `TNav`, `TPanelList`, `TCommandPalette`, `TSearchButton` |
109
- | Data | `TTable` (sorting, `selectable` rows), `TAdvancedTable` (filters by column), `TStatCard`, `TLogView` |
110
- | Layout | `TAppLayout` (an application's frame, laid out by its theme), `TScaledFrame` (a whole screen scaled to fit), `TShell`, `TTopbar`, `TPage`, `TSectionLayout`, `TSplitter`, `TAuthLayout`, `TColorModeButton` |
111
- | Plugins | `TAdvancedSelect`, `TCopyButton`, `TColorPicker`, `TDatePicker`, `TDropzone`, `TInputMask`, `TRangeSlider`, `TSortable`, `TSortableTree`, `TVectorMap`, `TRichEditor` |
109
+ | Data | `TTable` (sorting, `selectable` rows), `TAdvancedTable` (filters by column), `TEditableTable` (editing in place, bulk actions, search, pages, column kinds; client-side or `manual`), `TDataGrid` and `TDataGridItem` (Tabler's datagrid: labels and values for detail panels), `TStatCard` (with a trend and a sparkline), `TSparkline` (Tabler's, no library), `TLogView` |
110
+ | Layout | `TAppLayout` (an application's frame, laid out by its theme, with a menu button on small screens), `TScaledFrame` (a whole screen scaled to fit), `TShell`, `TTopbar`, `TPage`, `TSectionLayout`, `TSplitter`, `TAuthLayout`, `TColorModeButton` |
111
+ | Plugins | `TAdvancedSelect`, `TChart`, `TCopyButton`, `TColorPicker`, `TDatePicker`, `TDropzone`, `TInputMask`, `TRangeSlider`, `TSortable`, `TSortableTree`, `TVectorMap`, `TRichEditor` |
112
112
 
113
113
  ### Plugins
114
114
 
@@ -120,6 +120,7 @@ Tabler's restyling of them (`tabler-vendors.css`), which must come after.
120
120
  | Component | Library | Notes |
121
121
  | --- | --- | --- |
122
122
  | `TAdvancedSelect` | Tom Select | One or several (`multiple`, as chips); `create` adds new values; icons and avatars beside labels. Overlaps `TSelectMenu`, which has no dependency. |
123
+ | `TChart` | ApexCharts | `line`, `area`, `bar` (across), `column`, `pie`, `donut`; `series` along `categories`, `stacked`, `format`. Colors follow the theme (and a `TThemeScope`), light or dark; `options` passes anything else to ApexCharts. |
123
124
  | `TCopyButton` | Tabler's clipboard | Copies `text`, or the field `target` selects. Needs https or localhost. |
124
125
  | `TColorPicker` | Coloris | `format`, `alpha`, `swatches`, `swatchesOnly`. The field isn't wrapped by Coloris (Vue owns it); the swatch is ours. |
125
126
  | `TDatePicker` | Tabler's date picker, on Vanilla Calendar Pro | `single`, `multiple` or `range`; `inline`; the model is `YYYY-MM-DD`, `format` only changes the display. |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ternarytech-io/gears-ui",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "type": "module",
5
5
  "description": "Gears UI: Vue 3 components on Tabler, used by the Gears Studio and the applications it builds.",
6
6
  "license": "MPL-2.0",
@@ -55,7 +55,8 @@
55
55
  "imask": "^7.6.0",
56
56
  "nouislider": "^15.8.0",
57
57
  "sortablejs": "^1.15.0",
58
- "hugerte": "^1.0.0"
58
+ "hugerte": "^1.0.0",
59
+ "apexcharts": "^7.0.0"
59
60
  },
60
61
  "dependencies": {
61
62
  "@tabler/core": "1.7.1",
@@ -65,6 +66,7 @@
65
66
  "@melloware/coloris": "0.25.0",
66
67
  "@types/sortablejs": "1.15.9",
67
68
  "@vitejs/plugin-vue": "6.0.10",
69
+ "apexcharts": "7.0.0",
68
70
  "dropzone": "6.3.5",
69
71
  "hugerte": "1.0.14",
70
72
  "imask": "7.6.1",
@@ -1,76 +1,88 @@
1
- <script setup lang="ts">
2
- // An application's frame, laid out by a theme's layout settings (`theme`): the navigation down the
3
- // left (it can fold to icons) or across the top (it can stay at the top as the page scrolls, and
4
- // float apart from the edges), and the page boxed (centered, the background around it) or fluid.
5
- // The brand is the logo and name, or the `brand` slot; the links are `items` (TNav), or the `nav`
6
- // slot for links of your own. `actions` go at the top bar's end, or at the foot of the sidebar.
7
- // Tabler's page, navbar and layout-boxed classes do the work, so it looks like Tabler's layouts.
8
- import { computed } from 'vue'
9
- import TIcon from './TIcon.vue'
10
- import TNav from './TNav.vue'
11
- import type { NavItem, ThemeSettings } from '../types'
12
-
13
- const props = withDefaults(defineProps<{
14
- theme?: ThemeSettings
15
- items?: NavItem[]
16
- brand?: string
17
- logo?: string
18
- }>(), { theme: () => ({}), items: () => [] })
19
-
20
- const folded = defineModel<boolean>('folded', { default: false })
21
-
22
- const top = computed(() => props.theme.nav === 'top')
23
- const boxed = computed(() => props.theme.container === 'boxed')
24
- const foldable = computed(() => !top.value && props.theme.navFoldable === true)
25
- const container = computed(() => boxed.value ? 'container-xl' : 'container-fluid')
26
- </script>
27
-
28
- <template>
29
- <div :class="['t-app', { 'layout-boxed': boxed }]">
30
- <div class="page">
31
- <aside v-if="!top" :class="['navbar navbar-vertical navbar-expand-lg t-app-sidebar', { 'navbar-folded': foldable && folded }]">
32
- <div class="container-fluid">
33
- <div class="navbar-brand">
34
- <slot name="brand" :folded="foldable && folded">
35
- <img v-if="logo" :src="logo" alt="" class="t-app-logo">
36
- <span v-if="brand && !(foldable && folded)" class="text-truncate">{{ brand }}</span>
37
- </slot>
38
- </div>
39
- <button v-if="foldable" type="button" class="t-fold-toggle d-none d-lg-grid" :aria-label="folded ? 'Expand the menu' : 'Fold the menu'"
40
- @click="folded = !folded">
41
- <TIcon :name="folded ? 'chevron-right' : 'chevron-left'" />
42
- </button>
43
- <div class="collapse navbar-collapse">
44
- <slot name="nav" orientation="vertical" :folded="foldable && folded">
45
- <TNav :items="items" :folded="foldable && folded" class="pt-lg-3" />
46
- </slot>
47
- <div v-if="$slots.actions" class="navbar-footer"><slot name="actions" /></div>
48
- </div>
49
- </div>
50
- </aside>
51
- <header v-else :class="['navbar navbar-expand-md t-app-topbar', { 'sticky-top': theme.navSticky, 't-app-floating': theme.navFloating }]">
52
- <div :class="[container, 'gap-3']">
53
- <div class="navbar-brand">
54
- <slot name="brand" :folded="false">
55
- <img v-if="logo" :src="logo" alt="" class="t-app-logo">
56
- <span v-if="brand" class="text-truncate">{{ brand }}</span>
57
- </slot>
58
- </div>
59
- <div class="collapse navbar-collapse">
60
- <slot name="nav" orientation="horizontal" :folded="false">
61
- <TNav :items="items" />
62
- </slot>
63
- </div>
64
- <div v-if="$slots.actions" class="ms-auto d-flex align-items-center gap-2"><slot name="actions" /></div>
65
- </div>
66
- </header>
67
- <div class="page-wrapper">
68
- <div class="page-body">
69
- <div :class="container">
70
- <slot />
71
- </div>
72
- </div>
73
- </div>
74
- </div>
75
- </div>
76
- </template>
1
+ <script setup lang="ts">
2
+ // An application's frame, laid out by a theme's layout settings (`theme`): the navigation down the
3
+ // left (it can fold to icons) or across the top (it can stay at the top as the page scrolls, and
4
+ // float apart from the edges), and the page boxed (centered, the background around it) or fluid.
5
+ // The brand is the logo and name, or the `brand` slot; the links are `items` (TNav), or the `nav`
6
+ // slot for links of your own. `actions` go at the top bar's end, or at the foot of the sidebar.
7
+ // Tabler's page, navbar and layout-boxed classes do the work, so it looks like Tabler's layouts.
8
+ // On small screens the links fold away behind a menu button, and close again on navigating.
9
+ import { computed, ref, watch } from 'vue'
10
+ import { useRoute } from 'vue-router'
11
+ import TIcon from './TIcon.vue'
12
+ import TNav from './TNav.vue'
13
+ import type { NavItem, ThemeSettings } from '../types'
14
+
15
+ const props = withDefaults(defineProps<{
16
+ theme?: ThemeSettings
17
+ items?: NavItem[]
18
+ brand?: string
19
+ logo?: string
20
+ }>(), { theme: () => ({}), items: () => [] })
21
+
22
+ const folded = defineModel<boolean>('folded', { default: false })
23
+
24
+ const top = computed(() => props.theme.nav === 'top')
25
+ const boxed = computed(() => props.theme.container === 'boxed')
26
+ const foldable = computed(() => !top.value && props.theme.navFoldable === true)
27
+ const container = computed(() => boxed.value ? 'container-xl' : 'container-fluid')
28
+
29
+ const menuOpen = ref(false)
30
+ const route = useRoute()
31
+ watch(() => route.fullPath, () => { menuOpen.value = false })
32
+ </script>
33
+
34
+ <template>
35
+ <div :class="['t-app', { 'layout-boxed': boxed }]">
36
+ <div class="page">
37
+ <aside v-if="!top" :class="['navbar navbar-vertical navbar-expand-lg t-app-sidebar', { 'navbar-folded': foldable && folded }]">
38
+ <div class="container-fluid">
39
+ <button type="button" class="navbar-toggler" :aria-expanded="menuOpen" aria-label="Menu" @click="menuOpen = !menuOpen">
40
+ <span class="navbar-toggler-icon" />
41
+ </button>
42
+ <div class="navbar-brand">
43
+ <slot name="brand" :folded="foldable && folded">
44
+ <img v-if="logo" :src="logo" alt="" class="t-app-logo">
45
+ <span v-if="brand && !(foldable && folded)" class="text-truncate">{{ brand }}</span>
46
+ </slot>
47
+ </div>
48
+ <button v-if="foldable" type="button" class="t-fold-toggle d-none d-lg-grid" :aria-label="folded ? 'Expand the menu' : 'Fold the menu'"
49
+ @click="folded = !folded">
50
+ <TIcon :name="folded ? 'chevron-right' : 'chevron-left'" />
51
+ </button>
52
+ <div :class="['collapse navbar-collapse', { show: menuOpen }]">
53
+ <slot name="nav" orientation="vertical" :folded="foldable && folded">
54
+ <TNav :items="items" :folded="foldable && folded" class="pt-lg-3" />
55
+ </slot>
56
+ <div v-if="$slots.actions" class="navbar-footer"><slot name="actions" /></div>
57
+ </div>
58
+ </div>
59
+ </aside>
60
+ <header v-else :class="['navbar navbar-expand-md t-app-topbar', { 'sticky-top': theme.navSticky, 't-app-floating': theme.navFloating }]">
61
+ <div :class="[container, 'gap-3']">
62
+ <button type="button" class="navbar-toggler" :aria-expanded="menuOpen" aria-label="Menu" @click="menuOpen = !menuOpen">
63
+ <span class="navbar-toggler-icon" />
64
+ </button>
65
+ <div class="navbar-brand">
66
+ <slot name="brand" :folded="false">
67
+ <img v-if="logo" :src="logo" alt="" class="t-app-logo">
68
+ <span v-if="brand" class="text-truncate">{{ brand }}</span>
69
+ </slot>
70
+ </div>
71
+ <div :class="['collapse navbar-collapse', { show: menuOpen }]">
72
+ <slot name="nav" orientation="horizontal" :folded="false">
73
+ <TNav :items="items" />
74
+ </slot>
75
+ </div>
76
+ <div v-if="$slots.actions" class="ms-auto d-flex align-items-center gap-2"><slot name="actions" /></div>
77
+ </div>
78
+ </header>
79
+ <div class="page-wrapper">
80
+ <div class="page-body">
81
+ <div :class="container">
82
+ <slot />
83
+ </div>
84
+ </div>
85
+ </div>
86
+ </div>
87
+ </div>
88
+ </template>
@@ -0,0 +1,188 @@
1
+ <script setup lang="ts">
2
+ // A chart, as Tabler draws them with ApexCharts: a line, area, bar (across), column (up), pie or
3
+ // donut. `series` are named lists of numbers along `categories` (a pie or donut uses the first
4
+ // series, one slice per category). Colors come from the theme (the accent first), or `colors`
5
+ // (named colors such as 'success', or any CSS color); they follow light and dark mode and a
6
+ // TThemeScope around the chart. `format` writes values in the axis and tooltips; `options` is
7
+ // merged over everything for whatever else ApexCharts does. ApexCharts loads on first use.
8
+ import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
9
+ import type ApexCharts from 'apexcharts'
10
+ import type { ApexOptions } from 'apexcharts'
11
+ import { loadApexCharts } from '../plugins/charts'
12
+ import type { ChartSeries, ChartType, Color } from '../types'
13
+ import { toTabler } from '../types'
14
+
15
+ const props = withDefaults(defineProps<{
16
+ type?: ChartType
17
+ series: ChartSeries[]
18
+ categories?: (string | number)[]
19
+ height?: number | string
20
+ stacked?: boolean
21
+ // Shown by default with more than one series, and for pies and donuts.
22
+ legend?: boolean
23
+ colors?: (Color | string)[]
24
+ format?: (value: number) => string
25
+ // No axes, grid or legend: a small chart inside a card or a stat.
26
+ sparkline?: boolean
27
+ label?: string
28
+ options?: ApexOptions
29
+ // Vue makes a missing boolean false; undefined keeps the legend's default.
30
+ }>(), { type: 'line', categories: () => [], height: 240, label: 'Chart', legend: undefined })
31
+
32
+ const emit = defineEmits<{ 'point-click': [point: { series: number; index: number; category: string | number | undefined }] }>()
33
+
34
+ const el = ref<HTMLElement>()
35
+ let chart: ApexCharts | null = null
36
+
37
+ // Tabler's chart colors after the accent: its named colors, in an order that keeps neighbors apart.
38
+ const palette = ['primary', 'green', 'orange', 'purple', 'cyan', 'pink', 'yellow', 'red', 'teal', 'indigo']
39
+ const named = new Set(['primary', 'neutral', 'success', 'warning', 'error', 'info'])
40
+
41
+ const round = computed(() => props.type === 'pie' || props.type === 'donut')
42
+
43
+ /** A CSS color as the browser resolves it here, inside any theme scope: `var(--tblr-primary)` → rgb(…). */
44
+ function resolve(color: string): string {
45
+ if (!el.value) return color
46
+ const probe = document.createElement('span')
47
+ probe.style.display = 'none'
48
+ probe.style.color = color
49
+ el.value.appendChild(probe)
50
+ const value = getComputedStyle(probe).color
51
+ probe.remove()
52
+ return value ? rgb(value) : color
53
+ }
54
+
55
+ // ApexCharts makes fills see-through only for hex and rgb() colors, and Tabler's theme colors can
56
+ // come back as oklch(…); painting one pixel gives any color as rgb().
57
+ let pixel: CanvasRenderingContext2D | null = null
58
+ function rgb(color: string): string {
59
+ if (/^(rgb|#)/i.test(color)) return color
60
+ pixel ??= document.createElement('canvas').getContext('2d', { willReadFrequently: true })
61
+ if (!pixel) return color
62
+ pixel.clearRect(0, 0, 1, 1)
63
+ pixel.fillStyle = color
64
+ pixel.fillRect(0, 0, 1, 1)
65
+ const [r, g, b, a] = pixel.getImageData(0, 0, 1, 1).data
66
+ return a === 255 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${Math.round(a / 255 * 100) / 100})`
67
+ }
68
+ const cssColor = (color: string) => named.has(color) ? `var(--tblr-${toTabler(color as Color)})`
69
+ : /^[a-z]+$/.test(color) && palette.includes(color) ? `var(--tblr-${color})` : color
70
+
71
+ function themed(): ApexOptions {
72
+ const count = round.value ? props.categories.length : props.series.length
73
+ const colors = Array.from({ length: Math.max(count, 1) }, (_, i) =>
74
+ resolve(cssColor(props.series[i]?.color ?? props.colors?.[i] ?? palette[i % palette.length])))
75
+ const text = resolve('var(--tblr-secondary)')
76
+ const border = resolve('var(--tblr-border-color)')
77
+ return {
78
+ colors,
79
+ chart: { foreColor: text, background: 'transparent' },
80
+ grid: { borderColor: border },
81
+ stroke: { colors: round.value ? [resolve('var(--tblr-bg-surface)')] : undefined },
82
+ theme: { mode: el.value?.closest('[data-bs-theme]')?.getAttribute('data-bs-theme') === 'dark' ? 'dark' : 'light' }
83
+ }
84
+ }
85
+
86
+ function options(): ApexOptions {
87
+ const apexType = props.type === 'column' ? 'bar' : props.type
88
+ const formatter = props.format ? (value: number) => (value == null ? '' : props.format!(value)) : undefined
89
+ const base: ApexOptions = {
90
+ chart: {
91
+ type: apexType,
92
+ height: props.height,
93
+ fontFamily: 'inherit',
94
+ parentHeightOffset: 0,
95
+ toolbar: { show: false },
96
+ zoom: { enabled: false },
97
+ animations: { enabled: false },
98
+ stacked: props.stacked,
99
+ sparkline: { enabled: props.sparkline ?? false },
100
+ events: {
101
+ dataPointSelection: (_event, _chart, config) => {
102
+ if (config) emit('point-click', { series: config.seriesIndex, index: config.dataPointIndex, category: props.categories[config.dataPointIndex] })
103
+ }
104
+ }
105
+ },
106
+ series: round.value
107
+ ? (props.series[0]?.data ?? []).map(v => v ?? 0)
108
+ : props.series.map(s => ({ name: s.name, data: s.data })),
109
+ labels: round.value ? props.categories.map(String) : undefined,
110
+ xaxis: round.value ? undefined : {
111
+ categories: props.categories,
112
+ tooltip: { enabled: false },
113
+ axisBorder: { show: false },
114
+ axisTicks: { show: false },
115
+ labels: { formatter: props.type === 'bar' ? formatter as never : undefined }
116
+ },
117
+ yaxis: round.value ? undefined : { labels: { formatter: props.type === 'bar' ? undefined : formatter, padding: 4 } },
118
+ plotOptions: {
119
+ bar: { horizontal: props.type === 'bar', columnWidth: '50%', barHeight: '60%', borderRadius: 2 },
120
+ pie: { donut: { size: '70%' } }
121
+ },
122
+ dataLabels: { enabled: false },
123
+ fill: { opacity: props.type === 'area' ? 0.16 : 1, type: 'solid' },
124
+ stroke: { width: props.type === 'line' || props.type === 'area' ? 2 : round.value ? 2 : 0, curve: 'smooth', lineCap: 'round' },
125
+ // Bars across need room for their labels on the left.
126
+ grid: { strokeDashArray: 4, padding: { top: -16, right: 0, left: props.type === 'bar' ? 8 : -4, bottom: -4 } },
127
+ legend: {
128
+ show: props.legend ?? (round.value || props.series.length > 1),
129
+ position: 'bottom',
130
+ offsetY: 8,
131
+ markers: { size: 6, shape: 'circle', strokeWidth: 0 },
132
+ itemMargin: { horizontal: 8, vertical: 4 }
133
+ },
134
+ tooltip: { theme: 'dark', y: { formatter } },
135
+ noData: { text: 'No data' }
136
+ }
137
+ return defined(merge(merge(base, themed()), props.options ?? {}))
138
+ }
139
+
140
+ /** Without keys set to undefined: ApexCharts takes them as values, over its defaults (labels: undefined breaks it). */
141
+ function defined<T>(value: T): T {
142
+ if (!isObject(value)) return value
143
+ return Object.fromEntries(Object.entries(value).filter(([, v]) => v !== undefined).map(([k, v]) => [k, defined(v)])) as T
144
+ }
145
+
146
+ /** Objects merged deeply; arrays and values replaced. */
147
+ function merge<T>(target: T, source: unknown): T {
148
+ if (!isObject(target) || !isObject(source)) return (source === undefined ? target : source) as T
149
+ const result: Record<string, unknown> = { ...target }
150
+ for (const [key, value] of Object.entries(source)) {
151
+ if (value === undefined) continue
152
+ result[key] = isObject(value) && isObject(result[key]) ? merge(result[key], value) : value
153
+ }
154
+ return result as T
155
+ }
156
+ function isObject(value: unknown): value is Record<string, unknown> {
157
+ return typeof value === 'object' && value !== null && !Array.isArray(value) && typeof value !== 'function'
158
+ }
159
+
160
+ // The theme can change around the chart: light and dark, or a theme scope's accent and grays.
161
+ let observer: MutationObserver | null = null
162
+ function watchTheme() {
163
+ observer = new MutationObserver(() => chart?.updateOptions(options(), true))
164
+ const themedAncestors = new Set<Element>([document.documentElement])
165
+ for (let node = el.value?.parentElement; node; node = node.parentElement)
166
+ if ([...node.attributes].some(a => a.name.startsWith('data-bs-theme') || a.name === 'data-t-density')) themedAncestors.add(node)
167
+ for (const node of themedAncestors) observer.observe(node, { attributes: true, attributeFilter: ['data-bs-theme', 'data-bs-theme-primary', 'data-bs-theme-base', 'style', 'class'] })
168
+ }
169
+
170
+ onMounted(async () => {
171
+ const ApexCharts = await loadApexCharts()
172
+ if (!el.value) return
173
+ chart = new ApexCharts(el.value, options())
174
+ await chart.render()
175
+ watchTheme()
176
+ })
177
+ watch(() => [props.type, props.series, props.categories, props.stacked, props.legend, props.colors, props.height, props.options, props.sparkline],
178
+ () => chart?.updateOptions(options(), true), { deep: true })
179
+ onBeforeUnmount(() => {
180
+ observer?.disconnect()
181
+ chart?.destroy()
182
+ chart = null
183
+ })
184
+ </script>
185
+
186
+ <template>
187
+ <div ref="el" class="t-chart" role="img" :aria-label="label" />
188
+ </template>
@@ -0,0 +1,41 @@
1
+ <script setup lang="ts">
2
+ // Tabler's datagrid: labels and their values, for detail panels and summaries, in a grid that fits
3
+ // as many columns as there's room for. `horizontal` puts each label beside its value; `cols` fixes
4
+ // the columns (1 to 4); `itemWidth`, `titleWidth` and `gap` set Tabler's datagrid variables. The
5
+ // pairs come from `items` (a slot named by an item's `key` draws its value; `copy` adds a copy
6
+ // button; an empty value is a dash) or from TDataGridItem children. It's a description list, so
7
+ // screen readers keep each label with its value.
8
+ import { computed } from 'vue'
9
+ import TDataGridItem from './TDataGridItem.vue'
10
+ import type { DataGridItem } from '../types'
11
+
12
+ const props = defineProps<{
13
+ items?: DataGridItem[]
14
+ horizontal?: boolean
15
+ cols?: 1 | 2 | 3 | 4
16
+ // The narrowest a column gets (Tabler's default is 15rem); lower fits more short values in a row.
17
+ itemWidth?: string
18
+ // The label's width when `horizontal` (Tabler's default is 10rem).
19
+ titleWidth?: string
20
+ // Between items, across and down (Tabler's default is 1.5rem).
21
+ gap?: string
22
+ }>()
23
+
24
+ const style = computed(() => ({
25
+ '--tblr-datagrid-item-width': props.itemWidth,
26
+ '--tblr-datagrid-title-width': props.titleWidth,
27
+ '--tblr-datagrid-padding': props.gap
28
+ }))
29
+ </script>
30
+
31
+ <template>
32
+ <dl :class="['datagrid mb-0', { 'datagrid-horizontal': horizontal }, cols && `datagrid-cols-${cols}`]" :style="style">
33
+ <template v-for="(item, i) in items ?? []" :key="item.key ?? `${i}-${item.label}`">
34
+ <TDataGridItem v-if="item.key && $slots[item.key]" :label="item.label" :copy="item.copy">
35
+ <slot :name="item.key" :item="item" />
36
+ </TDataGridItem>
37
+ <TDataGridItem v-else :label="item.label" :value="item.value" :copy="item.copy" />
38
+ </template>
39
+ <slot />
40
+ </dl>
41
+ </template>
@@ -0,0 +1,23 @@
1
+ <script setup lang="ts">
2
+ // One label and its value in a TDataGrid. The value is `value`, or the slot for anything else (a
3
+ // status, a badge, avatars, a progress bar, a field); empty, it's written as a dash so it doesn't
4
+ // look missing. `copy` adds a button that copies the value.
5
+ import { computed } from 'vue'
6
+ import TCopyButton from './TCopyButton.vue'
7
+
8
+ const props = defineProps<{ label: string; value?: string | number | boolean | null; copy?: boolean }>()
9
+
10
+ const text = computed(() => props.value == null || props.value === '' ? '' : typeof props.value === 'boolean' ? (props.value ? 'Yes' : 'No') : String(props.value))
11
+ </script>
12
+
13
+ <template>
14
+ <div class="datagrid-item">
15
+ <dt class="datagrid-title">{{ label }}</dt>
16
+ <dd :class="['datagrid-content mb-0', { 'd-flex align-items-center gap-2': copy }]">
17
+ <slot v-if="$slots.default" />
18
+ <template v-else-if="copy && text"><code class="text-break">{{ text }}</code></template>
19
+ <template v-else>{{ text || '–' }}</template>
20
+ <TCopyButton v-if="copy && text" :text="text" icon-only size="sm" variant="ghost" :label="`Copy the ${label.toLowerCase()}`" />
21
+ </dd>
22
+ </div>
23
+ </template>