@ternarytech-io/gears-ui 0.0.0-stage → 0.1.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/LICENSE +373 -0
- package/README.md +160 -2
- package/package.json +104 -6
- package/src/code-editor.ts +25 -0
- package/src/components/TAccentPicker.vue +41 -0
- package/src/components/TAdvancedSelect.vue +128 -0
- package/src/components/TAdvancedTable.vue +130 -0
- package/src/components/TAlert.vue +41 -0
- package/src/components/TAuthLayout.vue +32 -0
- package/src/components/TAvatar.vue +28 -0
- package/src/components/TBadge.vue +29 -0
- package/src/components/TButton.vue +60 -0
- package/src/components/TCard.vue +40 -0
- package/src/components/TCheckbox.vue +29 -0
- package/src/components/TCodeEditor.vue +128 -0
- package/src/components/TColorModeButton.vue +14 -0
- package/src/components/TColorPicker.vue +61 -0
- package/src/components/TCommandPalette.vue +109 -0
- package/src/components/TCopyButton.vue +72 -0
- package/src/components/TDatePicker.vue +83 -0
- package/src/components/TDropdown.vue +76 -0
- package/src/components/TDropzone.vue +76 -0
- package/src/components/TEmpty.vue +21 -0
- package/src/components/TFieldGroup.vue +11 -0
- package/src/components/TFileUpload.vue +92 -0
- package/src/components/TFontPicker.vue +23 -0
- package/src/components/TFormField.vue +40 -0
- package/src/components/TIcon.vue +12 -0
- package/src/components/TImageUpload.vue +131 -0
- package/src/components/TInput.vue +52 -0
- package/src/components/TInputMask.vue +70 -0
- package/src/components/TInputNumber.vue +62 -0
- package/src/components/TInputTags.vue +53 -0
- package/src/components/TLogView.vue +39 -0
- package/src/components/TModal.vue +54 -0
- package/src/components/TNav.vue +75 -0
- package/src/components/TPage.vue +48 -0
- package/src/components/TPagination.vue +44 -0
- package/src/components/TPanelList.vue +29 -0
- package/src/components/TProgress.vue +18 -0
- package/src/components/TRadioGroup.vue +68 -0
- package/src/components/TRadiusPicker.vue +21 -0
- package/src/components/TRangeSlider.vue +63 -0
- package/src/components/TRichEditor.vue +82 -0
- package/src/components/TSearchButton.vue +20 -0
- package/src/components/TSectionLayout.vue +37 -0
- package/src/components/TSelect.vue +60 -0
- package/src/components/TSelectMenu.vue +126 -0
- package/src/components/TSeparator.vue +10 -0
- package/src/components/TShell.vue +72 -0
- package/src/components/TSkeleton.vue +17 -0
- package/src/components/TSlideover.vue +47 -0
- package/src/components/TSortable.vue +61 -0
- package/src/components/TSpinner.vue +14 -0
- package/src/components/TSplitter.vue +85 -0
- package/src/components/TStatCard.vue +26 -0
- package/src/components/TSteps.vue +19 -0
- package/src/components/TSwitch.vue +18 -0
- package/src/components/TTable.vue +134 -0
- package/src/components/TTabs.vue +38 -0
- package/src/components/TTextarea.vue +42 -0
- package/src/components/TThemeBasePicker.vue +22 -0
- package/src/components/TThemeScope.vue +22 -0
- package/src/components/TToaster.vue +27 -0
- package/src/components/TTooltip.vue +33 -0
- package/src/components/TTopbar.vue +17 -0
- package/src/components/TVectorMap.vue +74 -0
- package/src/composables/useColorMode.ts +41 -0
- package/src/composables/useCommandPalette.ts +11 -0
- package/src/composables/useField.ts +26 -0
- package/src/composables/useOverlay.ts +55 -0
- package/src/composables/useToast.ts +33 -0
- package/src/index.ts +199 -0
- package/src/monaco.ts +27 -0
- package/src/plugins/coloris.ts +8 -0
- package/src/plugins/datepicker.ts +7 -0
- package/src/plugins/dropzone.ts +5 -0
- package/src/plugins/index.ts +49 -0
- package/src/plugins/inputMask.ts +7 -0
- package/src/plugins/once.ts +8 -0
- package/src/plugins/richEditor.ts +37 -0
- package/src/plugins/slider.ts +4 -0
- package/src/plugins/sortable.ts +7 -0
- package/src/plugins/tomSelect.ts +4 -0
- package/src/shims.d.ts +17 -0
- package/src/styles/gears.css +560 -0
- package/src/styles/plugins.css +10 -0
- package/src/theme.ts +28 -0
- package/src/types.ts +160 -0
- package/src/vectorMap.ts +14 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T">
|
|
2
|
+
// A select with a search box, for long lists, and for picking several (`multiple`, where the model
|
|
3
|
+
// is an array). Items are values or { label, value, group } objects; grouped items are listed
|
|
4
|
+
// under their group's name. The search filters the items; with `filter` off, the caller searches
|
|
5
|
+
// instead (v-model:search, showing `loading` meanwhile) and passes the items it found.
|
|
6
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
7
|
+
import { Dropdown } from '@tabler/core'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import { useField } from '../composables/useField'
|
|
10
|
+
import type { SelectItem } from '../types'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
items: (T | SelectItem<T>)[]
|
|
14
|
+
multiple?: boolean
|
|
15
|
+
placeholder?: string
|
|
16
|
+
searchable?: boolean
|
|
17
|
+
searchPlaceholder?: string
|
|
18
|
+
// Filter the items by the search; off when the caller searches.
|
|
19
|
+
filter?: boolean
|
|
20
|
+
loading?: boolean
|
|
21
|
+
size?: 'sm' | 'md' | 'lg'
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
invalid?: boolean
|
|
24
|
+
id?: string
|
|
25
|
+
}>(), { searchable: true, searchPlaceholder: 'Search…', filter: true, size: 'md' })
|
|
26
|
+
|
|
27
|
+
const model = defineModel<T | T[] | null | undefined>()
|
|
28
|
+
const query = defineModel<string>('search', { default: '' })
|
|
29
|
+
const field = useField(props)
|
|
30
|
+
|
|
31
|
+
const toggle = ref<HTMLButtonElement>()
|
|
32
|
+
const search = ref<HTMLInputElement>()
|
|
33
|
+
const list = ref<HTMLElement>()
|
|
34
|
+
const panel = ref<HTMLElement>()
|
|
35
|
+
let dropdown: Dropdown | null = null
|
|
36
|
+
|
|
37
|
+
const isItem = (item: unknown): item is SelectItem<T> =>
|
|
38
|
+
typeof item === 'object' && item !== null && 'label' in item && 'value' in item
|
|
39
|
+
const options = computed<SelectItem<T>[]>(() =>
|
|
40
|
+
props.items.map(item => isItem(item) ? item : { label: String(item), value: item as T }))
|
|
41
|
+
|
|
42
|
+
const chosen = computed<T[]>(() => props.multiple ? (Array.isArray(model.value) ? model.value : []) : model.value == null ? [] : [model.value as T])
|
|
43
|
+
const isChosen = (option: SelectItem<T>) => chosen.value.includes(option.value)
|
|
44
|
+
|
|
45
|
+
const summary = computed(() => {
|
|
46
|
+
const labels = options.value.filter(isChosen).map(o => o.label)
|
|
47
|
+
if (!labels.length) return ''
|
|
48
|
+
return labels.length > 2 ? `${labels.slice(0, 2).join(', ')} +${labels.length - 2}` : labels.join(', ')
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
// The matching options, in their groups (ungrouped options have an empty group name).
|
|
52
|
+
const groups = computed(() => {
|
|
53
|
+
const term = props.filter ? query.value.trim().toLowerCase() : ''
|
|
54
|
+
const result: { name: string; options: SelectItem<T>[] }[] = []
|
|
55
|
+
for (const option of options.value) {
|
|
56
|
+
if (term && !option.label.toLowerCase().includes(term)) continue
|
|
57
|
+
const name = option.group ?? ''
|
|
58
|
+
let group = result.find(g => g.name === name)
|
|
59
|
+
if (!group) result.push(group = { name, options: [] })
|
|
60
|
+
group.options.push(option)
|
|
61
|
+
}
|
|
62
|
+
return result
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
function pick(option: SelectItem<T>) {
|
|
66
|
+
if (!props.multiple) {
|
|
67
|
+
model.value = option.value
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
model.value = isChosen(option) ? chosen.value.filter(v => v !== option.value) : [...chosen.value, option.value]
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function firstItem() {
|
|
74
|
+
list.value?.querySelector<HTMLElement>('.dropdown-item')?.focus()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
onMounted(() => {
|
|
78
|
+
dropdown = new Dropdown(toggle.value!, {
|
|
79
|
+
autoClose: props.multiple ? 'outside' : true,
|
|
80
|
+
popperConfig: (config: object) => ({ ...config, strategy: 'fixed' })
|
|
81
|
+
})
|
|
82
|
+
// The menu is as wide as the select (it's positioned against the window, so 100% won't do).
|
|
83
|
+
toggle.value!.addEventListener('show.bs.dropdown', () => {
|
|
84
|
+
if (panel.value) panel.value.style.width = `${toggle.value!.offsetWidth}px`
|
|
85
|
+
})
|
|
86
|
+
toggle.value!.addEventListener('shown.bs.dropdown', () => nextTick(() => search.value?.focus()))
|
|
87
|
+
toggle.value!.addEventListener('hidden.bs.dropdown', () => { query.value = '' })
|
|
88
|
+
})
|
|
89
|
+
onBeforeUnmount(() => dropdown?.dispose())
|
|
90
|
+
</script>
|
|
91
|
+
|
|
92
|
+
<template>
|
|
93
|
+
<div class="dropdown t-select-menu">
|
|
94
|
+
<button :id="field.id.value" ref="toggle" type="button" :disabled="disabled" data-bs-toggle="dropdown" aria-haspopup="listbox"
|
|
95
|
+
:aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
|
|
96
|
+
:class="['form-select text-start text-truncate', size !== 'md' && `form-select-${size}`, { 'is-invalid': field.invalid.value }]">
|
|
97
|
+
<span v-if="summary">{{ summary }}</span>
|
|
98
|
+
<span v-else class="text-secondary">{{ placeholder ?? '' }} </span>
|
|
99
|
+
</button>
|
|
100
|
+
<div ref="panel" class="dropdown-menu p-0 t-select-menu-panel" role="listbox" :aria-multiselectable="multiple || undefined">
|
|
101
|
+
<div v-if="searchable" class="p-2 border-bottom">
|
|
102
|
+
<input ref="search" v-model="query" type="search" class="form-control form-control-sm" :placeholder="searchPlaceholder"
|
|
103
|
+
aria-label="Search the options" @keydown.down.prevent="firstItem">
|
|
104
|
+
</div>
|
|
105
|
+
<div ref="list" class="t-select-menu-items">
|
|
106
|
+
<template v-for="group in groups" :key="group.name">
|
|
107
|
+
<h6 v-if="group.name" class="dropdown-header">{{ group.name }}</h6>
|
|
108
|
+
<button v-for="(option, i) in group.options" :key="i" type="button" role="option" :aria-selected="isChosen(option)"
|
|
109
|
+
:disabled="option.disabled" :class="['dropdown-item', { active: !multiple && isChosen(option) }]" @click="pick(option)">
|
|
110
|
+
<input v-if="multiple" type="checkbox" class="form-check-input m-0 me-2 pe-none" tabindex="-1" :checked="isChosen(option)" aria-hidden="true">
|
|
111
|
+
<span class="min-w-0">
|
|
112
|
+
<span class="d-block text-truncate">{{ option.label }}</span>
|
|
113
|
+
<span v-if="option.description" class="d-block small text-secondary text-truncate">{{ option.description }}</span>
|
|
114
|
+
</span>
|
|
115
|
+
<TIcon v-if="!multiple && isChosen(option)" name="check" class="ms-auto ps-2" />
|
|
116
|
+
</button>
|
|
117
|
+
</template>
|
|
118
|
+
<div v-if="loading && !groups.length" class="dropdown-item-text text-secondary small">Loading…</div>
|
|
119
|
+
<div v-else-if="!groups.length" class="dropdown-item-text text-secondary small">No matches</div>
|
|
120
|
+
</div>
|
|
121
|
+
<div v-if="multiple && chosen.length" class="border-top p-1">
|
|
122
|
+
<button type="button" class="dropdown-item small text-secondary" @click="model = []">Clear the selection</button>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
</div>
|
|
126
|
+
</template>
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A dividing line, with an optional label in the middle; `vertical` separates items in a row.
|
|
3
|
+
defineProps<{ label?: string; orientation?: 'horizontal' | 'vertical' }>()
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<div v-if="orientation === 'vertical'" class="vr" role="separator" aria-orientation="vertical" />
|
|
8
|
+
<div v-else-if="label" class="hr-text" role="separator">{{ label }}</div>
|
|
9
|
+
<hr v-else class="my-3">
|
|
10
|
+
</template>
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// An app's frame: the sidebar (dark in both themes) with the brand, the links and a footer, and
|
|
3
|
+
// the page beside it. The sidebar folds to icons (remembered per `storageKey`); on small screens
|
|
4
|
+
// it's a top bar whose menu opens below it.
|
|
5
|
+
import { ref, watch } from 'vue'
|
|
6
|
+
import { RouterLink, useRoute } from 'vue-router'
|
|
7
|
+
import TIcon from './TIcon.vue'
|
|
8
|
+
import TNav from './TNav.vue'
|
|
9
|
+
import type { NavItem, Target } from '../types'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
nav: NavItem[]
|
|
13
|
+
footerNav?: NavItem[]
|
|
14
|
+
brand?: string
|
|
15
|
+
// A line under the brand name, in small capitals.
|
|
16
|
+
tagline?: string
|
|
17
|
+
logo?: string
|
|
18
|
+
brandTo?: Target
|
|
19
|
+
foldable?: boolean
|
|
20
|
+
storageKey?: string
|
|
21
|
+
}>(), { brandTo: '/', foldable: true, storageKey: 'gears-sidebar' })
|
|
22
|
+
|
|
23
|
+
function storedFold() {
|
|
24
|
+
try { return localStorage.getItem(props.storageKey) === 'folded' } catch { return false }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const folded = ref(props.foldable && storedFold())
|
|
28
|
+
const menuOpen = ref(false)
|
|
29
|
+
const route = useRoute()
|
|
30
|
+
|
|
31
|
+
watch(folded, value => {
|
|
32
|
+
try { localStorage.setItem(props.storageKey, value ? 'folded' : 'open') } catch { /* storage blocked */ }
|
|
33
|
+
})
|
|
34
|
+
watch(() => route.fullPath, () => { menuOpen.value = false })
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<div class="page t-shell">
|
|
39
|
+
<aside :class="['navbar navbar-vertical navbar-expand-lg', { 'navbar-folded': folded }]" data-bs-theme="dark">
|
|
40
|
+
<div class="container-fluid">
|
|
41
|
+
<button type="button" class="navbar-toggler" :aria-expanded="menuOpen" aria-label="Menu" @click="menuOpen = !menuOpen">
|
|
42
|
+
<span class="navbar-toggler-icon" />
|
|
43
|
+
</button>
|
|
44
|
+
<div class="navbar-brand">
|
|
45
|
+
<slot name="brand" :folded="folded">
|
|
46
|
+
<RouterLink :to="brandTo" class="d-flex align-items-center gap-2 text-reset text-decoration-none">
|
|
47
|
+
<img v-if="logo" :src="logo" alt="" class="navbar-brand-image" width="32" height="32">
|
|
48
|
+
<span v-if="!folded && brand" class="text-start lh-sm">
|
|
49
|
+
<span class="d-block fw-bold">{{ brand }}</span>
|
|
50
|
+
<span v-if="tagline" class="d-block text-secondary text-uppercase fw-medium" style="font-size: 0.625rem; letter-spacing: 0.18em">{{ tagline }}</span>
|
|
51
|
+
</span>
|
|
52
|
+
</RouterLink>
|
|
53
|
+
</slot>
|
|
54
|
+
</div>
|
|
55
|
+
<button v-if="foldable" type="button" class="t-fold-toggle d-none d-lg-grid"
|
|
56
|
+
:aria-label="folded ? 'Expand the menu' : 'Fold the menu'" @click="folded = !folded">
|
|
57
|
+
<TIcon :name="folded ? 'chevron-right' : 'chevron-left'" />
|
|
58
|
+
</button>
|
|
59
|
+
<div :class="['collapse navbar-collapse', { show: menuOpen }]">
|
|
60
|
+
<TNav :items="nav" :folded="folded" class="pt-lg-3" />
|
|
61
|
+
<div v-if="footerNav || $slots['sidebar-footer']" class="navbar-footer">
|
|
62
|
+
<TNav v-if="footerNav" :items="footerNav" :folded="folded" />
|
|
63
|
+
<slot name="sidebar-footer" :folded="folded" />
|
|
64
|
+
</div>
|
|
65
|
+
</div>
|
|
66
|
+
</div>
|
|
67
|
+
</aside>
|
|
68
|
+
<div class="page-wrapper">
|
|
69
|
+
<slot />
|
|
70
|
+
</div>
|
|
71
|
+
</div>
|
|
72
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Grey lines where content will appear once it loads.
|
|
3
|
+
withDefaults(defineProps<{ lines?: number; avatar?: boolean }>(), { lines: 3 })
|
|
4
|
+
|
|
5
|
+
// Lines vary in length, as text does; the last is the shortest.
|
|
6
|
+
const widths = ['col-12', 'col-10', 'col-11', 'col-8', 'col-9']
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<div class="placeholder-glow d-flex gap-3" aria-hidden="true">
|
|
11
|
+
<span v-if="avatar" class="avatar placeholder rounded-circle flex-shrink-0" />
|
|
12
|
+
<div class="flex-fill">
|
|
13
|
+
<div v-for="i in lines" :key="i"
|
|
14
|
+
:class="['placeholder d-block', i === lines && lines > 1 ? 'col-6' : widths[(i - 1) % widths.length], { 'mb-2': i < lines }]" />
|
|
15
|
+
</div>
|
|
16
|
+
</div>
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A panel that slides in from an edge, opened with v-model:open: details or a form beside the page.
|
|
3
|
+
import { ref } from 'vue'
|
|
4
|
+
import { Offcanvas } from '@tabler/core'
|
|
5
|
+
import { useOverlay } from '../composables/useOverlay'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
title?: string
|
|
9
|
+
description?: string
|
|
10
|
+
side?: 'start' | 'end' | 'top' | 'bottom'
|
|
11
|
+
dismissible?: boolean
|
|
12
|
+
}>(), { side: 'end', dismissible: true })
|
|
13
|
+
|
|
14
|
+
const open = defineModel<boolean>('open', { default: false })
|
|
15
|
+
const emit = defineEmits<{ 'after-leave': [] }>()
|
|
16
|
+
|
|
17
|
+
const el = ref<HTMLElement>()
|
|
18
|
+
const rendered = useOverlay(el, 'offcanvas', open,
|
|
19
|
+
element => new Offcanvas(element, { backdrop: props.dismissible ? true : 'static', keyboard: props.dismissible }),
|
|
20
|
+
() => emit('after-leave'))
|
|
21
|
+
|
|
22
|
+
const close = () => { open.value = false }
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<Teleport to="body">
|
|
27
|
+
<div ref="el" :class="['offcanvas', `offcanvas-${side}`]" tabindex="-1" :aria-label="title" role="dialog">
|
|
28
|
+
<template v-if="rendered">
|
|
29
|
+
<div v-if="title || $slots.header" class="offcanvas-header border-bottom">
|
|
30
|
+
<slot name="header">
|
|
31
|
+
<div class="min-w-0">
|
|
32
|
+
<h2 class="offcanvas-title">{{ title }}</h2>
|
|
33
|
+
<p v-if="description" class="text-secondary small mb-0 mt-1">{{ description }}</p>
|
|
34
|
+
</div>
|
|
35
|
+
</slot>
|
|
36
|
+
<button v-if="dismissible" type="button" class="btn-close" aria-label="Close" @click="close" />
|
|
37
|
+
</div>
|
|
38
|
+
<div class="offcanvas-body">
|
|
39
|
+
<slot :close="close" />
|
|
40
|
+
</div>
|
|
41
|
+
<div v-if="$slots.footer" class="border-top p-3 d-flex justify-content-end gap-2">
|
|
42
|
+
<slot name="footer" :close="close" />
|
|
43
|
+
</div>
|
|
44
|
+
</template>
|
|
45
|
+
</div>
|
|
46
|
+
</Teleport>
|
|
47
|
+
</template>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T">
|
|
2
|
+
// A list whose items can be dragged into a new order, with Tabler's sortable (SortableJS). v-model
|
|
3
|
+
// is the array; the `item` slot draws each item. With `handle`, items drag only by an element with
|
|
4
|
+
// the `sortable-handle` class (drawn in the slot). `tag` and `itemTag` choose the elements, such as
|
|
5
|
+
// "div" and "div" (the default) or "ul" and "li". SortableJS loads on first use.
|
|
6
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import type { Sortable } from '@tabler/core'
|
|
8
|
+
import { loadSortable } from '../plugins/sortable'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
itemKey?: string | ((item: T) => string | number)
|
|
12
|
+
tag?: string
|
|
13
|
+
itemTag?: string
|
|
14
|
+
itemClass?: string
|
|
15
|
+
handle?: boolean
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
animation?: number
|
|
18
|
+
}>(), { tag: 'div', itemTag: 'div', animation: 150 })
|
|
19
|
+
|
|
20
|
+
const model = defineModel<T[]>({ default: () => [] })
|
|
21
|
+
const emit = defineEmits<{ sort: [move: { from: number; to: number }] }>()
|
|
22
|
+
|
|
23
|
+
const list = ref<HTMLElement>()
|
|
24
|
+
let sortable: Sortable | null = null
|
|
25
|
+
|
|
26
|
+
const keyOf = (item: T, index: number) => typeof props.itemKey === 'function' ? props.itemKey(item)
|
|
27
|
+
: props.itemKey ? (item as Record<string, string | number>)[props.itemKey] : index
|
|
28
|
+
|
|
29
|
+
type SortEvent = { oldIndex?: number; newIndex?: number; item: HTMLElement; from: HTMLElement }
|
|
30
|
+
|
|
31
|
+
onMounted(async () => {
|
|
32
|
+
const SortableClass = await loadSortable()
|
|
33
|
+
if (!list.value) return
|
|
34
|
+
sortable = new SortableClass(list.value, {
|
|
35
|
+
animation: props.animation,
|
|
36
|
+
handle: props.handle ? '.sortable-handle' : undefined,
|
|
37
|
+
disabled: props.disabled,
|
|
38
|
+
onEnd: ({ oldIndex, newIndex, item, from }: SortEvent) => {
|
|
39
|
+
if (oldIndex == null || newIndex == null || oldIndex === newIndex) return
|
|
40
|
+
// SortableJS moved the element; put it back and let Vue move it, so its list stays right.
|
|
41
|
+
from.removeChild(item)
|
|
42
|
+
from.insertBefore(item, from.children[oldIndex] ?? null)
|
|
43
|
+
const next = [...model.value]
|
|
44
|
+
next.splice(newIndex, 0, ...next.splice(oldIndex, 1))
|
|
45
|
+
model.value = next
|
|
46
|
+
emit('sort', { from: oldIndex, to: newIndex })
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
watch(() => props.disabled, disabled => (sortable as unknown as { sortable?: { option(name: string, value: unknown): void } } | null)?.sortable?.option('disabled', disabled))
|
|
52
|
+
onBeforeUnmount(() => sortable?.dispose())
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<component :is="tag" ref="list" :class="['t-sortable', { 't-sortable-handles': handle }]">
|
|
57
|
+
<component :is="itemTag" v-for="(item, index) in model" :key="keyOf(item, index)" :class="itemClass">
|
|
58
|
+
<slot name="item" :item="item" :index="index" />
|
|
59
|
+
</component>
|
|
60
|
+
</component>
|
|
61
|
+
</template>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Something is loading. `label` is read by screen readers, and shown when `showLabel` is set.
|
|
3
|
+
import { toTabler, type Color } from '../types'
|
|
4
|
+
|
|
5
|
+
withDefaults(defineProps<{ size?: 'sm' | 'md'; color?: Color; label?: string; showLabel?: boolean }>(),
|
|
6
|
+
{ size: 'md', label: 'Loading…' })
|
|
7
|
+
</script>
|
|
8
|
+
|
|
9
|
+
<template>
|
|
10
|
+
<span class="d-inline-flex align-items-center gap-2" role="status">
|
|
11
|
+
<span :class="['spinner-border', size === 'sm' && 'spinner-border-sm', color && `text-${toTabler(color)}`]" aria-hidden="true" />
|
|
12
|
+
<span :class="showLabel ? 'text-secondary' : 'visually-hidden'">{{ label }}</span>
|
|
13
|
+
</span>
|
|
14
|
+
</template>
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Two panes with a handle between them to resize, by dragging or with the arrow keys: the `start`
|
|
3
|
+
// and `end` slots. `vertical` stacks them; otherwise they sit side by side. v-model:size is the
|
|
4
|
+
// start pane's share in percent, remembered per browser under `storageKey`. Panes are flex
|
|
5
|
+
// columns, so a card in one can fill it.
|
|
6
|
+
import { onMounted, ref, watch } from 'vue'
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(defineProps<{
|
|
9
|
+
orientation?: 'horizontal' | 'vertical'
|
|
10
|
+
defaultSize?: number
|
|
11
|
+
// The smallest each pane may get, in percent.
|
|
12
|
+
minStart?: number
|
|
13
|
+
minEnd?: number
|
|
14
|
+
storageKey?: string
|
|
15
|
+
}>(), { orientation: 'horizontal', defaultSize: 50, minStart: 10, minEnd: 10 })
|
|
16
|
+
|
|
17
|
+
const size = defineModel<number>('size')
|
|
18
|
+
const root = ref<HTMLElement>()
|
|
19
|
+
const dragging = ref(false)
|
|
20
|
+
|
|
21
|
+
const clamp = (value: number) => Math.min(100 - props.minEnd, Math.max(props.minStart, value))
|
|
22
|
+
|
|
23
|
+
onMounted(() => {
|
|
24
|
+
let saved: number | null = null
|
|
25
|
+
try { saved = props.storageKey ? Number(localStorage.getItem(`gears-split:${props.storageKey}`)) || null : null } catch { /* storage blocked */ }
|
|
26
|
+
size.value = clamp(size.value ?? saved ?? props.defaultSize)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
function save() {
|
|
30
|
+
if (!props.storageKey || size.value == null) return
|
|
31
|
+
try { localStorage.setItem(`gears-split:${props.storageKey}`, String(Math.round(size.value))) } catch { /* storage blocked */ }
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// A drag saves once, when it ends.
|
|
35
|
+
watch(size, () => { if (!dragging.value) save() })
|
|
36
|
+
|
|
37
|
+
function moveTo(event: PointerEvent) {
|
|
38
|
+
const box = root.value!.getBoundingClientRect()
|
|
39
|
+
size.value = clamp(props.orientation === 'vertical'
|
|
40
|
+
? (event.clientY - box.top) / box.height * 100
|
|
41
|
+
: (event.clientX - box.left) / box.width * 100)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function start(event: PointerEvent) {
|
|
45
|
+
dragging.value = true
|
|
46
|
+
const handle = event.currentTarget as HTMLElement
|
|
47
|
+
handle.setPointerCapture(event.pointerId)
|
|
48
|
+
const move = (e: PointerEvent) => moveTo(e)
|
|
49
|
+
const end = () => {
|
|
50
|
+
dragging.value = false
|
|
51
|
+
save()
|
|
52
|
+
handle.removeEventListener('pointermove', move)
|
|
53
|
+
handle.removeEventListener('pointerup', end)
|
|
54
|
+
handle.removeEventListener('pointercancel', end)
|
|
55
|
+
}
|
|
56
|
+
handle.addEventListener('pointermove', move)
|
|
57
|
+
handle.addEventListener('pointerup', end)
|
|
58
|
+
handle.addEventListener('pointercancel', end)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function key(event: KeyboardEvent) {
|
|
62
|
+
const back = props.orientation === 'vertical' ? 'ArrowUp' : 'ArrowLeft'
|
|
63
|
+
const forward = props.orientation === 'vertical' ? 'ArrowDown' : 'ArrowRight'
|
|
64
|
+
if (event.key !== back && event.key !== forward) return
|
|
65
|
+
event.preventDefault()
|
|
66
|
+
size.value = clamp((size.value ?? props.defaultSize) + (event.key === forward ? 5 : -5))
|
|
67
|
+
}
|
|
68
|
+
</script>
|
|
69
|
+
|
|
70
|
+
<template>
|
|
71
|
+
<div ref="root" :class="['t-splitter', `t-splitter-${orientation}`, { 't-splitter-dragging': dragging }]">
|
|
72
|
+
<div class="t-splitter-pane" :style="{ flexBasis: `${size ?? defaultSize}%` }">
|
|
73
|
+
<slot name="start" />
|
|
74
|
+
</div>
|
|
75
|
+
<div class="t-splitter-handle" role="separator" tabindex="0" aria-label="Resize"
|
|
76
|
+
:aria-orientation="orientation === 'vertical' ? 'horizontal' : 'vertical'"
|
|
77
|
+
:aria-valuenow="Math.round(size ?? defaultSize)" :aria-valuemin="minStart" :aria-valuemax="100 - minEnd"
|
|
78
|
+
@pointerdown.prevent="start" @keydown="key">
|
|
79
|
+
<span class="t-splitter-grip" />
|
|
80
|
+
</div>
|
|
81
|
+
<div class="t-splitter-pane t-splitter-pane-end">
|
|
82
|
+
<slot name="end" />
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
</template>
|
|
@@ -0,0 +1,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.
|
|
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>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A wizard's progress: the steps, with the current one bound by v-model (from 0). Steps already
|
|
3
|
+
// done can be clicked to go back to them.
|
|
4
|
+
import { toTabler, type Color, type StepItem } from '../types'
|
|
5
|
+
|
|
6
|
+
withDefaults(defineProps<{ items: StepItem[]; color?: Color; counter?: boolean }>(), { color: 'primary', counter: true })
|
|
7
|
+
|
|
8
|
+
const step = defineModel<number>({ default: 0 })
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<div :class="['steps', `steps-${toTabler(color)}`, { 'steps-counter': counter }]">
|
|
13
|
+
<component :is="i < step ? 'a' : 'span'" v-for="(item, i) in items" :key="i" :href="i < step ? '#' : undefined"
|
|
14
|
+
:class="['step-item', { active: i === step }]" :aria-current="i === step ? 'step' : undefined" @click.prevent="i < step && (step = i)">
|
|
15
|
+
<span class="d-block">{{ item.title }}</span>
|
|
16
|
+
<span v-if="item.description" class="d-block small text-secondary fw-normal">{{ item.description }}</span>
|
|
17
|
+
</component>
|
|
18
|
+
</div>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// An on/off switch, for settings that apply right away.
|
|
3
|
+
import { useField } from '../composables/useField'
|
|
4
|
+
|
|
5
|
+
const props = defineProps<{ label?: string; description?: string; disabled?: boolean; id?: string }>()
|
|
6
|
+
|
|
7
|
+
const model = defineModel<boolean>({ default: false })
|
|
8
|
+
const field = useField(props)
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<template>
|
|
12
|
+
<label class="form-check form-switch" :for="field.id.value">
|
|
13
|
+
<input :id="field.id.value" v-model="model" type="checkbox" role="switch" class="form-check-input" :disabled="disabled"
|
|
14
|
+
:aria-describedby="field.describedBy.value">
|
|
15
|
+
<span class="form-check-label"><slot>{{ label }}</slot></span>
|
|
16
|
+
<span v-if="description" class="form-check-description">{{ description }}</span>
|
|
17
|
+
</label>
|
|
18
|
+
</template>
|
|
@@ -0,0 +1,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
|
+
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>
|