@ternarytech-io/gears-ui 0.0.0-stage → 0.2.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 +161 -3
- package/package.json +111 -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/TAppLayout.vue +76 -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/TContainerPicker.vue +22 -0
- package/src/components/TCopyButton.vue +72 -0
- package/src/components/TDatePicker.vue +83 -0
- package/src/components/TDensityPicker.vue +19 -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/TNavPositionPicker.vue +22 -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/TScaledFrame.vue +36 -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/TSortableTree.vue +73 -0
- package/src/components/TSortableTreeList.vue +60 -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 +23 -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/components/sortableTree.ts +19 -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 +215 -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 +52 -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 +625 -0
- package/src/styles/plugins.css +10 -0
- package/src/theme.ts +45 -0
- package/src/types.ts +177 -0
- package/src/vectorMap.ts +14 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T">
|
|
2
|
+
// A native select. Items are values or { label, value, group } objects; values keep their type (a
|
|
3
|
+
// number stays a number), since options are matched by position. Grouped items are listed under
|
|
4
|
+
// their group's name.
|
|
5
|
+
import { computed } from 'vue'
|
|
6
|
+
import { useField } from '../composables/useField'
|
|
7
|
+
import type { SelectItem } from '../types'
|
|
8
|
+
|
|
9
|
+
defineOptions({ inheritAttrs: false })
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
items: (T | SelectItem<T>)[]
|
|
13
|
+
placeholder?: string
|
|
14
|
+
size?: 'sm' | 'md' | 'lg'
|
|
15
|
+
disabled?: boolean
|
|
16
|
+
invalid?: boolean
|
|
17
|
+
id?: string
|
|
18
|
+
}>(), { size: 'md' })
|
|
19
|
+
|
|
20
|
+
const model = defineModel<T | null | undefined>()
|
|
21
|
+
const field = useField(props)
|
|
22
|
+
|
|
23
|
+
const isItem = (item: unknown): item is SelectItem<T> =>
|
|
24
|
+
typeof item === 'object' && item !== null && 'label' in item && 'value' in item
|
|
25
|
+
|
|
26
|
+
const options = computed<SelectItem<T>[]>(() =>
|
|
27
|
+
props.items.map(item => isItem(item) ? item : { label: String(item), value: item as T }))
|
|
28
|
+
|
|
29
|
+
const selected = computed(() => String(options.value.findIndex(o => o.value === model.value)))
|
|
30
|
+
|
|
31
|
+
// Options in runs of the same group, keeping their positions.
|
|
32
|
+
const runs = computed(() => {
|
|
33
|
+
const result: { group?: string; options: { option: SelectItem<T>; index: number }[] }[] = []
|
|
34
|
+
options.value.forEach((option, index) => {
|
|
35
|
+
const last = result.at(-1)
|
|
36
|
+
if (last && last.group === option.group) last.options.push({ option, index })
|
|
37
|
+
else result.push({ group: option.group, options: [{ option, index }] })
|
|
38
|
+
})
|
|
39
|
+
return result
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
function change(event: Event) {
|
|
43
|
+
const index = Number((event.target as HTMLSelectElement).value)
|
|
44
|
+
model.value = index >= 0 ? options.value[index].value : null
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<select v-bind="$attrs" :id="field.id.value" :value="selected" :disabled="disabled"
|
|
50
|
+
:aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
|
|
51
|
+
:class="['form-select', size !== 'md' && `form-select-${size}`, { 'is-invalid': field.invalid.value }]" @change="change">
|
|
52
|
+
<option v-if="placeholder || selected === '-1'" value="-1" disabled>{{ placeholder ?? '' }}</option>
|
|
53
|
+
<template v-for="(run, r) in runs" :key="r">
|
|
54
|
+
<optgroup v-if="run.group" :label="run.group">
|
|
55
|
+
<option v-for="{ option, index } in run.options" :key="index" :value="String(index)" :disabled="option.disabled">{{ option.label }}</option>
|
|
56
|
+
</optgroup>
|
|
57
|
+
<option v-for="{ option, index } in run.options" v-else :key="index" :value="String(index)" :disabled="option.disabled">{{ option.label }}</option>
|
|
58
|
+
</template>
|
|
59
|
+
</select>
|
|
60
|
+
</template>
|
|
@@ -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,73 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T extends object">
|
|
2
|
+
// A tree whose items can be dragged into a new order, and into or out of each other, with
|
|
3
|
+
// SortableJS: a menu of pages and sub-pages, say. v-model is the top level; each item keeps its
|
|
4
|
+
// children in `childrenKey` ("children"). The `item` slot draws an item's row (it gets the item,
|
|
5
|
+
// its depth from 1, and its parent). `maxDepth` limits how deep the tree goes (2: items and their
|
|
6
|
+
// children); a drop that would go deeper is refused. With `handle`, rows drag only by an element
|
|
7
|
+
// with the `sortable-handle` class. `move` reports each move. SortableJS loads on first use.
|
|
8
|
+
import { provide, ref, useId } from 'vue'
|
|
9
|
+
import TSortableTreeList from './TSortableTreeList.vue'
|
|
10
|
+
import { treeKey, type TreeContext } from './sortableTree'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
itemKey: string | ((item: T) => string | number)
|
|
14
|
+
childrenKey?: string
|
|
15
|
+
maxDepth?: number
|
|
16
|
+
handle?: boolean
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
}>(), { childrenKey: 'children', maxDepth: 2 })
|
|
19
|
+
|
|
20
|
+
const model = defineModel<T[]>({ default: () => [] })
|
|
21
|
+
const emit = defineEmits<{ move: [move: { item: T; from: { parent: T | null; index: number }; to: { parent: T | null; index: number } }] }>()
|
|
22
|
+
const slots = defineSlots<{ item?(scope: { item: T; depth: number; parent: T | null }): unknown }>()
|
|
23
|
+
const dragging = ref(false)
|
|
24
|
+
|
|
25
|
+
const keyOf = (item: T) => String(typeof props.itemKey === 'function' ? props.itemKey(item) : (item as Record<string, unknown>)[props.itemKey])
|
|
26
|
+
const childrenOf = (item: T): T[] => ((item as Record<string, unknown>)[props.childrenKey] as T[] | undefined) ?? []
|
|
27
|
+
|
|
28
|
+
function find(key: string, items: T[] = model.value): T | null {
|
|
29
|
+
for (const item of items) {
|
|
30
|
+
if (keyOf(item) === key) return item
|
|
31
|
+
const found = find(key, childrenOf(item))
|
|
32
|
+
if (found) return found
|
|
33
|
+
}
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The list a parent's children are in, made when it has none yet.
|
|
38
|
+
function listOf(parent: T | null): T[] {
|
|
39
|
+
if (!parent) return model.value
|
|
40
|
+
const record = parent as Record<string, unknown>
|
|
41
|
+
if (!Array.isArray(record[props.childrenKey])) record[props.childrenKey] = []
|
|
42
|
+
return record[props.childrenKey] as T[]
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function move(fromKey: string, oldIndex: number, toKey: string, newIndex: number) {
|
|
46
|
+
const from = fromKey ? find(fromKey) : null
|
|
47
|
+
const to = toKey ? find(toKey) : null
|
|
48
|
+
const [item] = listOf(from).splice(oldIndex, 1)
|
|
49
|
+
if (!item) return
|
|
50
|
+
listOf(to).splice(newIndex, 0, item)
|
|
51
|
+
model.value = [...model.value]
|
|
52
|
+
emit('move', { item, from: { parent: from, index: oldIndex }, to: { parent: to, index: newIndex } })
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const context: TreeContext<T> = {
|
|
56
|
+
group: useId(),
|
|
57
|
+
get handle() { return props.handle },
|
|
58
|
+
get disabled() { return props.disabled },
|
|
59
|
+
get maxDepth() { return props.maxDepth },
|
|
60
|
+
dragging,
|
|
61
|
+
keyOf,
|
|
62
|
+
childrenOf,
|
|
63
|
+
move,
|
|
64
|
+
render: scope => slots.item?.(scope as { item: T; depth: number; parent: T | null }) as ReturnType<TreeContext<T>['render']>
|
|
65
|
+
}
|
|
66
|
+
provide(treeKey, context as unknown as TreeContext<object>)
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<div :class="['t-tree', { 't-tree-dragging': dragging, 't-sortable-handles': handle }]">
|
|
71
|
+
<TSortableTreeList :items="model" :parent="null" :depth="1" />
|
|
72
|
+
</div>
|
|
73
|
+
</template>
|
|
@@ -0,0 +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>
|
|
@@ -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>
|