@ternarytech-io/gears-ui 0.3.0 → 0.3.2
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 +1 -1
- package/package.json +2 -1
- package/src/components/TAccentPicker.vue +41 -41
- package/src/components/TContainerPicker.vue +22 -22
- package/src/components/TDensityPicker.vue +19 -19
- package/src/components/TEditableTable.vue +203 -203
- package/src/components/TFontPicker.vue +23 -23
- package/src/components/TIconPicker.vue +109 -0
- package/src/components/TNavPositionPicker.vue +22 -22
- package/src/components/TScaledFrame.vue +36 -36
- package/src/components/TShell.vue +82 -72
- package/src/components/TSortableTree.vue +73 -73
- package/src/components/TSortableTreeList.vue +60 -60
- package/src/components/TSparkline.vue +34 -34
- package/src/components/TStatCard.vue +56 -56
- package/src/components/TThemeBasePicker.vue +22 -22
- package/src/components/sortableTree.ts +19 -19
- package/src/data/tablerIcons.ts +5 -0
- package/src/index.ts +230 -227
- package/src/plugins/charts.ts +4 -4
- package/src/styles/gears.css +21 -12
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
// A theme's font, as tiles showing "Aa" in each typeface. `fonts` limits the choices; Comic is left
|
|
3
|
-
// out unless asked for.
|
|
4
|
-
import { computed } from 'vue'
|
|
5
|
-
import TRadioGroup from './TRadioGroup.vue'
|
|
6
|
-
import { themeFonts } from '../theme'
|
|
7
|
-
import type { ThemeFont } from '../types'
|
|
8
|
-
|
|
9
|
-
const props = withDefaults(defineProps<{ fonts?: ThemeFont[]; disabled?: boolean; legend?: string }>(),
|
|
10
|
-
{ fonts: () => ['sans-serif', 'serif', 'monospace'] })
|
|
11
|
-
|
|
12
|
-
const model = defineModel<ThemeFont | null | undefined>()
|
|
13
|
-
const items = computed(() => themeFonts.filter(f => props.fonts.includes(f.value)))
|
|
14
|
-
const family = (font: ThemeFont) => `var(--tblr-font-${font})`
|
|
15
|
-
</script>
|
|
16
|
-
|
|
17
|
-
<template>
|
|
18
|
-
<TRadioGroup v-model="model" :items="items" variant="tiles" :disabled="disabled" :legend="legend">
|
|
19
|
-
<template #preview="{ item }">
|
|
20
|
-
<span class="t-theme-font" :style="{ fontFamily: family(item.value as ThemeFont) }">Aa</span>
|
|
21
|
-
</template>
|
|
22
|
-
</TRadioGroup>
|
|
23
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A theme's font, as tiles showing "Aa" in each typeface. `fonts` limits the choices; Comic is left
|
|
3
|
+
// out unless asked for.
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
import TRadioGroup from './TRadioGroup.vue'
|
|
6
|
+
import { themeFonts } from '../theme'
|
|
7
|
+
import type { ThemeFont } from '../types'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{ fonts?: ThemeFont[]; disabled?: boolean; legend?: string }>(),
|
|
10
|
+
{ fonts: () => ['sans-serif', 'serif', 'monospace'] })
|
|
11
|
+
|
|
12
|
+
const model = defineModel<ThemeFont | null | undefined>()
|
|
13
|
+
const items = computed(() => themeFonts.filter(f => props.fonts.includes(f.value)))
|
|
14
|
+
const family = (font: ThemeFont) => `var(--tblr-font-${font})`
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<TRadioGroup v-model="model" :items="items" variant="tiles" :disabled="disabled" :legend="legend">
|
|
19
|
+
<template #preview="{ item }">
|
|
20
|
+
<span class="t-theme-font" :style="{ fontFamily: family(item.value as ThemeFont) }">Aa</span>
|
|
21
|
+
</template>
|
|
22
|
+
</TRadioGroup>
|
|
23
|
+
</template>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Chooses one of Tabler's icons, by name: a field showing the chosen icon that opens a panel with
|
|
3
|
+
// a search and a grid of every icon (generated from @tabler/icons-webfont; the list loads the first
|
|
4
|
+
// time the panel opens). v-model is the icon's name, such as "mail", or null for none.
|
|
5
|
+
import { computed, nextTick, onBeforeUnmount, ref, shallowRef, watch } from 'vue'
|
|
6
|
+
import TIcon from './TIcon.vue'
|
|
7
|
+
import { useField } from '../composables/useField'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
placeholder?: string
|
|
11
|
+
size?: 'sm' | 'md' | 'lg'
|
|
12
|
+
disabled?: boolean
|
|
13
|
+
// Offer "No icon".
|
|
14
|
+
clearable?: boolean
|
|
15
|
+
// How many matching icons the grid shows at once.
|
|
16
|
+
limit?: number
|
|
17
|
+
id?: string
|
|
18
|
+
}>(), { placeholder: 'Choose an icon', size: 'md', clearable: true, limit: 160 })
|
|
19
|
+
|
|
20
|
+
const model = defineModel<string | null | undefined>()
|
|
21
|
+
const field = useField(props)
|
|
22
|
+
const root = ref<HTMLElement>()
|
|
23
|
+
const search = ref<HTMLInputElement>()
|
|
24
|
+
const open = ref(false)
|
|
25
|
+
const query = ref('')
|
|
26
|
+
const icons = shallowRef<readonly string[]>([])
|
|
27
|
+
|
|
28
|
+
async function show() {
|
|
29
|
+
if (props.disabled) return
|
|
30
|
+
open.value = true
|
|
31
|
+
query.value = ''
|
|
32
|
+
if (!icons.value.length) icons.value = (await import('../data/tablerIcons')).tablerIcons
|
|
33
|
+
await nextTick()
|
|
34
|
+
search.value?.focus()
|
|
35
|
+
}
|
|
36
|
+
function close() {
|
|
37
|
+
open.value = false
|
|
38
|
+
}
|
|
39
|
+
function choose(name: string | null) {
|
|
40
|
+
model.value = name
|
|
41
|
+
close()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Matches: the name itself, then names starting with the search, then names containing it; words
|
|
45
|
+
// in the search can come in any order ("arrow up" finds arrow-big-up).
|
|
46
|
+
const matches = computed(() => {
|
|
47
|
+
const words = query.value.trim().toLowerCase().split(/[\s-]+/).filter(Boolean)
|
|
48
|
+
if (!words.length) return icons.value
|
|
49
|
+
const term = words.join('-')
|
|
50
|
+
const found = icons.value.filter(name => words.every(w => name.includes(w)))
|
|
51
|
+
const rank = (name: string) => (name === term ? 0 : name.startsWith(term) ? 1 : name.includes(term) ? 2 : 3)
|
|
52
|
+
return [...found].sort((a, b) => rank(a) - rank(b) || a.length - b.length || a.localeCompare(b))
|
|
53
|
+
})
|
|
54
|
+
const shown = computed(() => matches.value.slice(0, props.limit))
|
|
55
|
+
|
|
56
|
+
// A click outside, or Esc, closes it.
|
|
57
|
+
function outside(event: PointerEvent) {
|
|
58
|
+
if (root.value && !root.value.contains(event.target as Node)) close()
|
|
59
|
+
}
|
|
60
|
+
watch(open, value => {
|
|
61
|
+
if (value) document.addEventListener('pointerdown', outside, true)
|
|
62
|
+
else document.removeEventListener('pointerdown', outside, true)
|
|
63
|
+
})
|
|
64
|
+
onBeforeUnmount(() => document.removeEventListener('pointerdown', outside, true))
|
|
65
|
+
</script>
|
|
66
|
+
|
|
67
|
+
<template>
|
|
68
|
+
<div ref="root" class="t-icon-picker" @keydown.esc.stop="close">
|
|
69
|
+
<button :id="field.id.value" type="button" :class="['form-control t-icon-picker-field', size !== 'md' && `form-control-${size}`, { 'is-invalid': field.invalid.value }]"
|
|
70
|
+
:disabled="disabled" :aria-expanded="open" aria-haspopup="dialog" :aria-describedby="field.describedBy.value" @click="open ? close() : show()">
|
|
71
|
+
<TIcon v-if="model" :name="model" />
|
|
72
|
+
<span :class="['text-truncate', { 'text-secondary': !model }]">{{ model || placeholder }}</span>
|
|
73
|
+
<TIcon name="chevron-down" class="ms-auto text-secondary" />
|
|
74
|
+
</button>
|
|
75
|
+
|
|
76
|
+
<div v-if="open" class="t-icon-picker-panel dropdown-menu show" role="dialog" aria-label="Icons">
|
|
77
|
+
<div class="p-2 border-bottom">
|
|
78
|
+
<input ref="search" v-model="query" type="search" class="form-control form-control-sm" placeholder="Search icons" aria-label="Search icons">
|
|
79
|
+
</div>
|
|
80
|
+
<div class="t-icon-picker-grid" role="listbox" :aria-label="`${matches.length} icons`">
|
|
81
|
+
<button v-for="name in shown" :key="name" type="button" role="option" :aria-selected="name === model" :title="name" :aria-label="name"
|
|
82
|
+
:class="['t-icon-picker-icon', { active: name === model }]" @click="choose(name)">
|
|
83
|
+
<TIcon :name="name" />
|
|
84
|
+
</button>
|
|
85
|
+
<p v-if="icons.length && !matches.length" class="t-icon-picker-note">No icons match.</p>
|
|
86
|
+
<p v-else-if="!icons.length" class="t-icon-picker-note">Loading…</p>
|
|
87
|
+
</div>
|
|
88
|
+
<div class="d-flex align-items-center gap-2 px-2 py-1 border-top small text-secondary">
|
|
89
|
+
<span v-if="matches.length > shown.length">{{ shown.length }} of {{ matches.length.toLocaleString() }}: search to narrow them.</span>
|
|
90
|
+
<span v-else>{{ matches.length.toLocaleString() }} {{ matches.length === 1 ? 'icon' : 'icons' }}</span>
|
|
91
|
+
<button v-if="clearable && model" type="button" class="btn btn-sm btn-ghost-secondary ms-auto" @click="choose(null)">No icon</button>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
</template>
|
|
96
|
+
|
|
97
|
+
<style scoped>
|
|
98
|
+
.t-icon-picker { position: relative; }
|
|
99
|
+
.t-icon-picker-field { display: flex; align-items: center; gap: 0.5rem; text-align: start; }
|
|
100
|
+
.t-icon-picker-panel { position: absolute; inset-inline-start: 0; top: calc(100% + 0.25rem); z-index: 1060; width: min(20rem, 90vw); padding: 0; }
|
|
101
|
+
.t-icon-picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.25rem, 1fr)); gap: 0.125rem; max-height: 16rem; overflow-y: auto; padding: 0.5rem; }
|
|
102
|
+
.t-icon-picker-icon {
|
|
103
|
+
display: grid; place-items: center; aspect-ratio: 1; padding: 0; font-size: 1.25rem; border: 0; border-radius: var(--tblr-border-radius);
|
|
104
|
+
background: none; color: var(--tblr-body-color);
|
|
105
|
+
}
|
|
106
|
+
.t-icon-picker-icon:hover, .t-icon-picker-icon:focus-visible { background: var(--tblr-bg-surface-secondary); }
|
|
107
|
+
.t-icon-picker-icon.active { background: var(--tblr-primary); color: var(--tblr-primary-fg, #fff); }
|
|
108
|
+
.t-icon-picker-note { grid-column: 1 / -1; margin: 0.5rem; color: var(--tblr-secondary); font-size: 0.8125rem; }
|
|
109
|
+
</style>
|
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
// Where an application's navigation goes: down the left side or across the top. Each tile is a
|
|
3
|
-
// sketch of the page.
|
|
4
|
-
import TRadioGroup from './TRadioGroup.vue'
|
|
5
|
-
import { themeNavs } from '../theme'
|
|
6
|
-
import type { ThemeNav } from '../types'
|
|
7
|
-
|
|
8
|
-
defineProps<{ disabled?: boolean; legend?: string }>()
|
|
9
|
-
|
|
10
|
-
const model = defineModel<ThemeNav | null | undefined>()
|
|
11
|
-
</script>
|
|
12
|
-
|
|
13
|
-
<template>
|
|
14
|
-
<TRadioGroup v-model="model" :items="themeNavs" variant="tiles" tile-width="8rem" :disabled="disabled" :legend="legend">
|
|
15
|
-
<template #preview="{ item }">
|
|
16
|
-
<span :class="['t-sketch', item.value === 'top' ? 't-sketch-top' : 't-sketch-left']">
|
|
17
|
-
<span class="t-sketch-nav" />
|
|
18
|
-
<span class="t-sketch-page"><span /><span /><span /></span>
|
|
19
|
-
</span>
|
|
20
|
-
</template>
|
|
21
|
-
</TRadioGroup>
|
|
22
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Where an application's navigation goes: down the left side or across the top. Each tile is a
|
|
3
|
+
// sketch of the page.
|
|
4
|
+
import TRadioGroup from './TRadioGroup.vue'
|
|
5
|
+
import { themeNavs } from '../theme'
|
|
6
|
+
import type { ThemeNav } from '../types'
|
|
7
|
+
|
|
8
|
+
defineProps<{ disabled?: boolean; legend?: string }>()
|
|
9
|
+
|
|
10
|
+
const model = defineModel<ThemeNav | null | undefined>()
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<TRadioGroup v-model="model" :items="themeNavs" variant="tiles" tile-width="8rem" :disabled="disabled" :legend="legend">
|
|
15
|
+
<template #preview="{ item }">
|
|
16
|
+
<span :class="['t-sketch', item.value === 'top' ? 't-sketch-top' : 't-sketch-left']">
|
|
17
|
+
<span class="t-sketch-nav" />
|
|
18
|
+
<span class="t-sketch-page"><span /><span /><span /></span>
|
|
19
|
+
</span>
|
|
20
|
+
</template>
|
|
21
|
+
</TRadioGroup>
|
|
22
|
+
</template>
|
|
@@ -1,36 +1,36 @@
|
|
|
1
|
-
<script setup lang="ts">
|
|
2
|
-
// Shows its content at a screen's width (`width`, in pixels), scaled down to fit: a preview of a
|
|
3
|
-
// whole page, such as an application's layout, in a smaller space. It fills its parent's height;
|
|
4
|
-
// the content scrolls inside it, and fixed or sticky parts stay inside the frame.
|
|
5
|
-
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
6
|
-
|
|
7
|
-
const props = withDefaults(defineProps<{ width?: number }>(), { width: 1440 })
|
|
8
|
-
|
|
9
|
-
const frame = ref<HTMLElement>()
|
|
10
|
-
const size = ref({ width: 0, height: 0 })
|
|
11
|
-
let observer: ResizeObserver | undefined
|
|
12
|
-
|
|
13
|
-
onMounted(() => {
|
|
14
|
-
observer = new ResizeObserver(([entry]) => { size.value = { width: entry.contentRect.width, height: entry.contentRect.height } })
|
|
15
|
-
observer.observe(frame.value!)
|
|
16
|
-
})
|
|
17
|
-
onBeforeUnmount(() => observer?.disconnect())
|
|
18
|
-
|
|
19
|
-
// Never larger than life.
|
|
20
|
-
const scale = computed(() => size.value.width ? Math.min(1, size.value.width / props.width) : 1)
|
|
21
|
-
const screen = computed(() => ({
|
|
22
|
-
width: `${props.width}px`,
|
|
23
|
-
height: `${size.value.height / scale.value}px`,
|
|
24
|
-
transform: `scale(${scale.value})`
|
|
25
|
-
}))
|
|
26
|
-
</script>
|
|
27
|
-
|
|
28
|
-
<template>
|
|
29
|
-
<div ref="frame" class="t-scaled-frame">
|
|
30
|
-
<div class="t-scaled-screen" :style="screen">
|
|
31
|
-
<div class="t-scaled-scroll">
|
|
32
|
-
<slot :scale="scale" />
|
|
33
|
-
</div>
|
|
34
|
-
</div>
|
|
35
|
-
</div>
|
|
36
|
-
</template>
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Shows its content at a screen's width (`width`, in pixels), scaled down to fit: a preview of a
|
|
3
|
+
// whole page, such as an application's layout, in a smaller space. It fills its parent's height;
|
|
4
|
+
// the content scrolls inside it, and fixed or sticky parts stay inside the frame.
|
|
5
|
+
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{ width?: number }>(), { width: 1440 })
|
|
8
|
+
|
|
9
|
+
const frame = ref<HTMLElement>()
|
|
10
|
+
const size = ref({ width: 0, height: 0 })
|
|
11
|
+
let observer: ResizeObserver | undefined
|
|
12
|
+
|
|
13
|
+
onMounted(() => {
|
|
14
|
+
observer = new ResizeObserver(([entry]) => { size.value = { width: entry.contentRect.width, height: entry.contentRect.height } })
|
|
15
|
+
observer.observe(frame.value!)
|
|
16
|
+
})
|
|
17
|
+
onBeforeUnmount(() => observer?.disconnect())
|
|
18
|
+
|
|
19
|
+
// Never larger than life.
|
|
20
|
+
const scale = computed(() => size.value.width ? Math.min(1, size.value.width / props.width) : 1)
|
|
21
|
+
const screen = computed(() => ({
|
|
22
|
+
width: `${props.width}px`,
|
|
23
|
+
height: `${size.value.height / scale.value}px`,
|
|
24
|
+
transform: `scale(${scale.value})`
|
|
25
|
+
}))
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<div ref="frame" class="t-scaled-frame">
|
|
30
|
+
<div class="t-scaled-screen" :style="screen">
|
|
31
|
+
<div class="t-scaled-scroll">
|
|
32
|
+
<slot :scale="scale" />
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
</template>
|
|
@@ -1,72 +1,82 @@
|
|
|
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
|
-
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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. `fold` folds it for a while (a full-screen editor, say)
|
|
5
|
+
// without changing what's remembered; the toggle still opens it for the moment.
|
|
6
|
+
import { computed, ref, watch } from 'vue'
|
|
7
|
+
import { RouterLink, useRoute } from 'vue-router'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import TNav from './TNav.vue'
|
|
10
|
+
import type { NavItem, Target } from '../types'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
nav: NavItem[]
|
|
14
|
+
footerNav?: NavItem[]
|
|
15
|
+
brand?: string
|
|
16
|
+
// A line under the brand name, in small capitals.
|
|
17
|
+
tagline?: string
|
|
18
|
+
logo?: string
|
|
19
|
+
brandTo?: Target
|
|
20
|
+
foldable?: boolean
|
|
21
|
+
storageKey?: string
|
|
22
|
+
fold?: boolean
|
|
23
|
+
}>(), { brandTo: '/', foldable: true, storageKey: 'gears-sidebar', fold: false })
|
|
24
|
+
|
|
25
|
+
function storedFold() {
|
|
26
|
+
try { return localStorage.getItem(props.storageKey) === 'folded' } catch { return false }
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const remembered = ref(props.foldable && storedFold())
|
|
30
|
+
// While `fold` is on: folded unless the toggle opened it; null when `fold` is off.
|
|
31
|
+
const temporary = ref<boolean | null>(props.foldable && props.fold ? true : null)
|
|
32
|
+
const folded = computed(() => temporary.value ?? remembered.value)
|
|
33
|
+
const menuOpen = ref(false)
|
|
34
|
+
const route = useRoute()
|
|
35
|
+
|
|
36
|
+
watch(remembered, value => {
|
|
37
|
+
try { localStorage.setItem(props.storageKey, value ? 'folded' : 'open') } catch { /* storage blocked */ }
|
|
38
|
+
})
|
|
39
|
+
watch(() => props.fold, fold => { temporary.value = props.foldable && fold ? true : null })
|
|
40
|
+
function toggle() {
|
|
41
|
+
if (temporary.value !== null) temporary.value = !temporary.value
|
|
42
|
+
else remembered.value = !remembered.value
|
|
43
|
+
}
|
|
44
|
+
watch(() => route.fullPath, () => { menuOpen.value = false })
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<div class="page t-shell">
|
|
49
|
+
<aside :class="['navbar navbar-vertical navbar-expand-lg', { 'navbar-folded': folded }]" data-bs-theme="dark">
|
|
50
|
+
<div class="container-fluid">
|
|
51
|
+
<button type="button" class="navbar-toggler" :aria-expanded="menuOpen" aria-label="Menu" @click="menuOpen = !menuOpen">
|
|
52
|
+
<span class="navbar-toggler-icon" />
|
|
53
|
+
</button>
|
|
54
|
+
<div class="navbar-brand">
|
|
55
|
+
<slot name="brand" :folded="folded">
|
|
56
|
+
<RouterLink :to="brandTo" class="d-flex align-items-center gap-2 text-reset text-decoration-none">
|
|
57
|
+
<img v-if="logo" :src="logo" alt="" class="navbar-brand-image" width="32" height="32">
|
|
58
|
+
<span v-if="!folded && brand" class="text-start lh-sm">
|
|
59
|
+
<span class="d-block fw-bold">{{ brand }}</span>
|
|
60
|
+
<span v-if="tagline" class="d-block text-secondary text-uppercase fw-medium" style="font-size: 0.625rem; letter-spacing: 0.18em">{{ tagline }}</span>
|
|
61
|
+
</span>
|
|
62
|
+
</RouterLink>
|
|
63
|
+
</slot>
|
|
64
|
+
</div>
|
|
65
|
+
<button v-if="foldable" type="button" class="t-fold-toggle d-none d-lg-grid"
|
|
66
|
+
:aria-label="folded ? 'Expand the menu' : 'Fold the menu'" @click="toggle">
|
|
67
|
+
<TIcon :name="folded ? 'chevron-right' : 'chevron-left'" />
|
|
68
|
+
</button>
|
|
69
|
+
<div :class="['collapse navbar-collapse', { show: menuOpen }]">
|
|
70
|
+
<TNav :items="nav" :folded="folded" class="pt-lg-3" />
|
|
71
|
+
<div v-if="footerNav || $slots['sidebar-footer']" class="navbar-footer">
|
|
72
|
+
<TNav v-if="footerNav" :items="footerNav" :folded="folded" />
|
|
73
|
+
<slot name="sidebar-footer" :folded="folded" />
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</div>
|
|
77
|
+
</aside>
|
|
78
|
+
<div class="page-wrapper">
|
|
79
|
+
<slot />
|
|
80
|
+
</div>
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
@@ -1,73 +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>
|
|
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>
|