@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,54 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A dialog over the page, opened with v-model:open. Its content renders only while it's open.
|
|
3
|
+
// Without `dismissible`, Esc and the backdrop don't close it (for a step that must be finished).
|
|
4
|
+
// `position="top"` places it near the top of the window instead of the middle (a search palette).
|
|
5
|
+
import { ref } from 'vue'
|
|
6
|
+
import { Modal } from '@tabler/core'
|
|
7
|
+
import { useOverlay } from '../composables/useOverlay'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
title?: string
|
|
11
|
+
description?: string
|
|
12
|
+
size?: 'sm' | 'md' | 'lg' | 'xl' | 'full'
|
|
13
|
+
dismissible?: boolean
|
|
14
|
+
scrollable?: boolean
|
|
15
|
+
position?: 'center' | 'top'
|
|
16
|
+
}>(), { size: 'md', dismissible: true, position: 'center' })
|
|
17
|
+
|
|
18
|
+
const open = defineModel<boolean>('open', { default: false })
|
|
19
|
+
const emit = defineEmits<{ 'after-enter': []; 'after-leave': [] }>()
|
|
20
|
+
|
|
21
|
+
const el = ref<HTMLElement>()
|
|
22
|
+
const rendered = useOverlay(el, 'modal', open,
|
|
23
|
+
element => new Modal(element, { backdrop: props.dismissible ? true : 'static', keyboard: props.dismissible }),
|
|
24
|
+
() => emit('after-leave'), () => emit('after-enter'))
|
|
25
|
+
|
|
26
|
+
const sizes = { sm: 'modal-sm', md: '', lg: 'modal-lg', xl: 'modal-xl', full: 'modal-full-width' }
|
|
27
|
+
const close = () => { open.value = false }
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<Teleport to="body">
|
|
32
|
+
<div ref="el" class="modal modal-blur fade" tabindex="-1" :aria-label="title" aria-modal="true" role="dialog">
|
|
33
|
+
<div :class="['modal-dialog', sizes[size], { 'modal-dialog-centered': position === 'center', 'modal-dialog-scrollable': scrollable }]">
|
|
34
|
+
<div v-if="rendered" class="modal-content">
|
|
35
|
+
<div v-if="title || $slots.header" class="modal-header">
|
|
36
|
+
<slot name="header">
|
|
37
|
+
<div class="min-w-0">
|
|
38
|
+
<h5 class="modal-title">{{ title }}</h5>
|
|
39
|
+
<p v-if="description" class="text-secondary small mb-0 mt-1">{{ description }}</p>
|
|
40
|
+
</div>
|
|
41
|
+
</slot>
|
|
42
|
+
<button v-if="dismissible" type="button" class="btn-close" aria-label="Close" @click="close" />
|
|
43
|
+
</div>
|
|
44
|
+
<div class="modal-body">
|
|
45
|
+
<slot :close="close" />
|
|
46
|
+
</div>
|
|
47
|
+
<div v-if="$slots.footer" class="modal-footer">
|
|
48
|
+
<slot name="footer" :close="close" />
|
|
49
|
+
</div>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
</Teleport>
|
|
54
|
+
</template>
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// The sidebar's links. An item with children is an accordion group, open at first when it holds
|
|
3
|
+
// the current page or says `defaultOpen`. In a folded sidebar a group opens as a flyout instead,
|
|
4
|
+
// and closes when a page is chosen.
|
|
5
|
+
import { reactive, watch } from 'vue'
|
|
6
|
+
import { RouterLink, useRoute, useRouter } from 'vue-router'
|
|
7
|
+
import TIcon from './TIcon.vue'
|
|
8
|
+
import { toTabler, type NavItem, type Target } from '../types'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{ items: NavItem[]; folded?: boolean }>()
|
|
11
|
+
|
|
12
|
+
const route = useRoute()
|
|
13
|
+
const router = useRouter()
|
|
14
|
+
|
|
15
|
+
function isActive(to: Target | undefined, exact?: boolean) {
|
|
16
|
+
if (!to) return false
|
|
17
|
+
const path = router.resolve(to as never).path
|
|
18
|
+
return exact ? route.path === path : route.path === path || route.path.startsWith(path.replace(/\/$/, '') + '/')
|
|
19
|
+
}
|
|
20
|
+
const groupActive = (item: NavItem) => item.children?.some(child => isActive(child.to, child.exact)) ?? false
|
|
21
|
+
|
|
22
|
+
const open = reactive(new Set<string>(props.items.filter(i => i.children && (i.defaultOpen || groupActive(i))).map(i => i.label)))
|
|
23
|
+
|
|
24
|
+
function toggle(item: NavItem) {
|
|
25
|
+
if (open.has(item.label)) {
|
|
26
|
+
open.delete(item.label)
|
|
27
|
+
} else {
|
|
28
|
+
// A folded sidebar shows one flyout at a time.
|
|
29
|
+
if (props.folded) open.clear()
|
|
30
|
+
open.add(item.label)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Going to a page opens its group (the route isn't known yet when the app first renders); in a
|
|
35
|
+
// folded sidebar it closes the flyout instead.
|
|
36
|
+
watch(() => route.fullPath, () => {
|
|
37
|
+
if (props.folded) open.clear()
|
|
38
|
+
else props.items.filter(groupActive).forEach(i => open.add(i.label))
|
|
39
|
+
})
|
|
40
|
+
watch(() => props.folded, folded => { if (folded) open.clear() })
|
|
41
|
+
|
|
42
|
+
// A badge is a label (shown in warning colors) or a label and color.
|
|
43
|
+
const badgeLabel = (item: NavItem) => typeof item.badge === 'string' ? item.badge : item.badge?.label
|
|
44
|
+
const badgeClass = (item: NavItem) => `badge badge-sm ms-auto bg-${toTabler((typeof item.badge === 'object' && item.badge.color) || 'warning')}-lt`
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<ul class="navbar-nav">
|
|
49
|
+
<template v-for="item in items" :key="item.label">
|
|
50
|
+
<li v-if="item.children" :class="['nav-item dropdown', { active: groupActive(item) }]">
|
|
51
|
+
<a href="#" :class="['nav-link dropdown-toggle', { show: open.has(item.label) }]" role="button" :aria-expanded="open.has(item.label)"
|
|
52
|
+
:title="folded ? item.label : undefined" @click.prevent="toggle(item)">
|
|
53
|
+
<span v-if="item.icon" class="nav-link-icon"><TIcon :name="item.icon" /></span>
|
|
54
|
+
<span class="nav-link-title">{{ item.label }}</span>
|
|
55
|
+
<span v-if="item.badge" :class="[badgeClass(item), 'me-2']">{{ badgeLabel(item) }}</span>
|
|
56
|
+
</a>
|
|
57
|
+
<div :class="['dropdown-menu', { show: open.has(item.label) }]">
|
|
58
|
+
<RouterLink v-for="child in item.children" :key="child.label" :to="child.to ?? '#'"
|
|
59
|
+
:class="['dropdown-item', { active: isActive(child.to, child.exact) }]">
|
|
60
|
+
<TIcon v-if="child.icon" :name="child.icon" class="me-2" />
|
|
61
|
+
{{ child.label }}
|
|
62
|
+
<span v-if="child.badge" :class="badgeClass(child)">{{ badgeLabel(child) }}</span>
|
|
63
|
+
</RouterLink>
|
|
64
|
+
</div>
|
|
65
|
+
</li>
|
|
66
|
+
<li v-else :class="['nav-item', { active: isActive(item.to, item.exact) }]">
|
|
67
|
+
<RouterLink :to="item.to ?? '#'" :class="['nav-link', { active: isActive(item.to, item.exact) }]" :title="folded ? item.label : undefined">
|
|
68
|
+
<span v-if="item.icon" class="nav-link-icon"><TIcon :name="item.icon" /></span>
|
|
69
|
+
<span class="nav-link-title">{{ item.label }}</span>
|
|
70
|
+
<span v-if="item.badge" :class="badgeClass(item)">{{ badgeLabel(item) }}</span>
|
|
71
|
+
</RouterLink>
|
|
72
|
+
</li>
|
|
73
|
+
</template>
|
|
74
|
+
</ul>
|
|
75
|
+
</template>
|
|
@@ -0,0 +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>
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A page's header (pretitle, title, description, actions on the right) and body. Bodies are capped
|
|
3
|
+
// in width; `narrow` suits forms and wizards, `wide` uses the whole width. `fill` pages take the
|
|
4
|
+
// height left and scroll inside their own panels; `flush` pages also drop the header and padding,
|
|
5
|
+
// for work sections that bring their own panels (TSectionLayout).
|
|
6
|
+
import { computed } from 'vue'
|
|
7
|
+
|
|
8
|
+
const props = defineProps<{
|
|
9
|
+
title?: string
|
|
10
|
+
pretitle?: string
|
|
11
|
+
description?: string
|
|
12
|
+
fill?: boolean
|
|
13
|
+
flush?: boolean
|
|
14
|
+
wide?: boolean
|
|
15
|
+
narrow?: boolean
|
|
16
|
+
}>()
|
|
17
|
+
|
|
18
|
+
const container = computed(() => props.narrow ? 'container-narrow' : props.wide || props.fill ? 'container-fluid' : 'container-xl')
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<div :class="['t-page', { 't-page-fill t-fill': fill || flush }]">
|
|
23
|
+
<div v-if="!flush && (title || $slots.header || $slots.actions)" class="page-header d-print-none">
|
|
24
|
+
<div :class="container">
|
|
25
|
+
<div class="row g-2 align-items-center">
|
|
26
|
+
<div class="col">
|
|
27
|
+
<slot name="header">
|
|
28
|
+
<div v-if="pretitle" class="page-pretitle">{{ pretitle }}</div>
|
|
29
|
+
<h2 class="page-title">{{ title }}</h2>
|
|
30
|
+
<div v-if="description" class="text-secondary mt-1">{{ description }}</div>
|
|
31
|
+
</slot>
|
|
32
|
+
</div>
|
|
33
|
+
<div v-if="$slots.actions" class="col-auto ms-auto d-print-none">
|
|
34
|
+
<div class="btn-list">
|
|
35
|
+
<slot name="actions" />
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
<slot v-if="flush" />
|
|
42
|
+
<div v-else :class="['page-body', { 't-fill': fill }]">
|
|
43
|
+
<div :class="[container, { 't-fill': fill }]">
|
|
44
|
+
<slot />
|
|
45
|
+
</div>
|
|
46
|
+
</div>
|
|
47
|
+
</div>
|
|
48
|
+
</template>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Page numbers for a long list, bound with v-model:page (from 1). Far pages fold into "…".
|
|
3
|
+
import { computed } from 'vue'
|
|
4
|
+
import TIcon from './TIcon.vue'
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(defineProps<{ total: number; itemsPerPage?: number; siblings?: number; size?: 'sm' | 'md' }>(),
|
|
7
|
+
{ itemsPerPage: 10, siblings: 1, size: 'md' })
|
|
8
|
+
|
|
9
|
+
const page = defineModel<number>('page', { default: 1 })
|
|
10
|
+
const count = computed(() => Math.max(1, Math.ceil(props.total / props.itemsPerPage)))
|
|
11
|
+
|
|
12
|
+
const pages = computed<(number | '…')[]>(() => {
|
|
13
|
+
const last = count.value
|
|
14
|
+
const from = Math.max(2, page.value - props.siblings)
|
|
15
|
+
const to = Math.min(last - 1, page.value + props.siblings)
|
|
16
|
+
const result: (number | '…')[] = [1]
|
|
17
|
+
if (from > 2) result.push('…')
|
|
18
|
+
for (let p = from; p <= to; p++) result.push(p)
|
|
19
|
+
if (to < last - 1) result.push('…')
|
|
20
|
+
if (last > 1) result.push(last)
|
|
21
|
+
return result
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const go = (p: number) => { page.value = Math.min(count.value, Math.max(1, p)) }
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<ul :class="['pagination m-0', size === 'sm' && 'pagination-sm']">
|
|
29
|
+
<li :class="['page-item', { disabled: page <= 1 }]">
|
|
30
|
+
<button type="button" class="page-link" aria-label="Previous page" :disabled="page <= 1" @click="go(page - 1)">
|
|
31
|
+
<TIcon name="chevron-left" />
|
|
32
|
+
</button>
|
|
33
|
+
</li>
|
|
34
|
+
<li v-for="(p, i) in pages" :key="i" :class="['page-item', { active: p === page, disabled: p === '…' }]">
|
|
35
|
+
<span v-if="p === '…'" class="page-link">…</span>
|
|
36
|
+
<button v-else type="button" class="page-link" :aria-current="p === page ? 'page' : undefined" @click="go(p)">{{ p }}</button>
|
|
37
|
+
</li>
|
|
38
|
+
<li :class="['page-item', { disabled: page >= count }]">
|
|
39
|
+
<button type="button" class="page-link" aria-label="Next page" :disabled="page >= count" @click="go(page + 1)">
|
|
40
|
+
<TIcon name="chevron-right" />
|
|
41
|
+
</button>
|
|
42
|
+
</li>
|
|
43
|
+
</ul>
|
|
44
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T">
|
|
2
|
+
// A compact list of things to choose from, for a section's side panel (TSectionLayout): files,
|
|
3
|
+
// saved queries, models. An optional heading above; v-model is the chosen item's value.
|
|
4
|
+
import TIcon from './TIcon.vue'
|
|
5
|
+
import type { PanelListItem } from '../types'
|
|
6
|
+
|
|
7
|
+
defineProps<{ items: PanelListItem<T>[]; heading?: string; empty?: string }>()
|
|
8
|
+
|
|
9
|
+
const model = defineModel<T>()
|
|
10
|
+
const emit = defineEmits<{ select: [item: PanelListItem<T>] }>()
|
|
11
|
+
|
|
12
|
+
function choose(item: PanelListItem<T>) {
|
|
13
|
+
model.value = item.value
|
|
14
|
+
emit('select', item)
|
|
15
|
+
}
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<div class="t-panel-list">
|
|
20
|
+
<div v-if="heading" class="t-panel-list-heading">{{ heading }}</div>
|
|
21
|
+
<p v-if="!items.length && empty" class="t-panel-list-empty">{{ empty }}</p>
|
|
22
|
+
<button v-for="(item, i) in items" :key="i" type="button" :title="item.title"
|
|
23
|
+
:class="['t-panel-list-item', { active: item.value === model, invalid: item.invalid }]" :aria-current="item.value === model || undefined" @click="choose(item)">
|
|
24
|
+
<TIcon v-if="item.icon" :name="item.icon" class="t-panel-list-icon" />
|
|
25
|
+
<span class="text-truncate flex-fill">{{ item.label }}</span>
|
|
26
|
+
<span v-if="item.trailing" class="t-panel-list-trailing">{{ item.trailing }}</span>
|
|
27
|
+
</button>
|
|
28
|
+
</div>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// How far along something is. Without a value it shows ongoing work of unknown length.
|
|
3
|
+
import { computed } from 'vue'
|
|
4
|
+
import { toTabler, type Color } from '../types'
|
|
5
|
+
|
|
6
|
+
const props = withDefaults(defineProps<{ value?: number | null; max?: number; color?: Color; size?: 'sm' | 'md'; label?: string }>(),
|
|
7
|
+
{ max: 100, color: 'primary', size: 'md' })
|
|
8
|
+
|
|
9
|
+
const percent = computed(() => props.value == null ? null : Math.min(100, Math.max(0, props.value / props.max * 100)))
|
|
10
|
+
</script>
|
|
11
|
+
|
|
12
|
+
<template>
|
|
13
|
+
<div :class="['progress', size === 'sm' && 'progress-sm']" role="progressbar" :aria-label="label"
|
|
14
|
+
aria-valuemin="0" :aria-valuemax="max" :aria-valuenow="value ?? undefined">
|
|
15
|
+
<div v-if="percent == null" :class="['progress-bar progress-bar-indeterminate', `bg-${toTabler(color)}`]" />
|
|
16
|
+
<div v-else :class="['progress-bar', `bg-${toTabler(color)}`]" :style="{ width: percent + '%' }" />
|
|
17
|
+
</div>
|
|
18
|
+
</template>
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T">
|
|
2
|
+
// One choice from a few, all shown. Items are values or { label, value, description } objects.
|
|
3
|
+
// `cards` shows each choice as a box (Tabler's select group), laid out in `columns` on wider
|
|
4
|
+
// screens: for choices that need their description, such as a project's database. `tiles` shows
|
|
5
|
+
// each choice as a picture with its label under it (the `preview` slot draws it), in a grid of
|
|
6
|
+
// tiles at least `tileWidth` wide: for choices you judge by eye, such as a theme's font.
|
|
7
|
+
import { computed, useId } from 'vue'
|
|
8
|
+
import type { SelectItem } from '../types'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
items: (T | SelectItem<T>)[]
|
|
12
|
+
orientation?: 'vertical' | 'horizontal'
|
|
13
|
+
variant?: 'list' | 'cards' | 'tiles'
|
|
14
|
+
columns?: 1 | 2 | 3
|
|
15
|
+
tileWidth?: string
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
legend?: string
|
|
18
|
+
}>(), { variant: 'list', columns: 2, tileWidth: '7rem' })
|
|
19
|
+
|
|
20
|
+
const model = defineModel<T | null | undefined>()
|
|
21
|
+
const name = useId()
|
|
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
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<div role="radiogroup" :aria-label="legend">
|
|
32
|
+
<div v-if="legend" class="form-label">{{ legend }}</div>
|
|
33
|
+
<div v-if="variant === 'cards'" class="form-selectgroup-boxes row g-3">
|
|
34
|
+
<label v-for="(option, i) in options" :key="i" :class="['form-selectgroup-item ps-0', columns > 1 && `col-sm-${12 / columns}`]">
|
|
35
|
+
<input type="radio" :name="name" class="form-selectgroup-input" :checked="option.value === model" :disabled="disabled || option.disabled"
|
|
36
|
+
@change="model = option.value">
|
|
37
|
+
<span class="form-selectgroup-label d-flex align-items-start gap-3 p-3 h-100 text-start">
|
|
38
|
+
<span class="form-selectgroup-check flex-shrink-0 mt-1" />
|
|
39
|
+
<span class="form-selectgroup-label-content">
|
|
40
|
+
<span class="d-block fw-medium text-body">{{ option.label }}</span>
|
|
41
|
+
<span v-if="option.description" class="d-block small text-secondary mt-1">{{ option.description }}</span>
|
|
42
|
+
</span>
|
|
43
|
+
</span>
|
|
44
|
+
</label>
|
|
45
|
+
</div>
|
|
46
|
+
<div v-else-if="variant === 'tiles'" class="t-radio-tiles" :style="{ '--t-tile-width': tileWidth }">
|
|
47
|
+
<label v-for="(option, i) in options" :key="i" :class="['t-radio-tile', { active: option.value === model, disabled: disabled || option.disabled }]">
|
|
48
|
+
<input type="radio" :name="name" class="t-radio-tile-input" :checked="option.value === model" :disabled="disabled || option.disabled"
|
|
49
|
+
@change="model = option.value">
|
|
50
|
+
<span class="t-radio-tile-check" aria-hidden="true" />
|
|
51
|
+
<span class="t-radio-tile-preview">
|
|
52
|
+
<slot name="preview" :item="option" :selected="option.value === model">
|
|
53
|
+
<span class="fw-medium">{{ option.label }}</span>
|
|
54
|
+
</slot>
|
|
55
|
+
</span>
|
|
56
|
+
<span class="t-radio-tile-label">{{ option.label }}</span>
|
|
57
|
+
</label>
|
|
58
|
+
</div>
|
|
59
|
+
<template v-else>
|
|
60
|
+
<label v-for="(option, i) in options" :key="i" :class="['form-check', { 'form-check-inline': orientation === 'horizontal' }]">
|
|
61
|
+
<input class="form-check-input" type="radio" :name="name" :checked="option.value === model" :disabled="disabled || option.disabled"
|
|
62
|
+
@change="model = option.value">
|
|
63
|
+
<span class="form-check-label">{{ option.label }}</span>
|
|
64
|
+
<span v-if="option.description" class="form-check-description">{{ option.description }}</span>
|
|
65
|
+
</label>
|
|
66
|
+
</template>
|
|
67
|
+
</div>
|
|
68
|
+
</template>
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A theme's corner radius, Tabler's scale from 0 (square corners) to 2 (round), as tiles showing a
|
|
3
|
+
// shape drawn with each.
|
|
4
|
+
import TRadioGroup from './TRadioGroup.vue'
|
|
5
|
+
import { themeRadii } from '../theme'
|
|
6
|
+
import type { ThemeRadius } from '../types'
|
|
7
|
+
|
|
8
|
+
defineProps<{ disabled?: boolean; legend?: string }>()
|
|
9
|
+
|
|
10
|
+
const model = defineModel<ThemeRadius | null | undefined>()
|
|
11
|
+
// At 2 the shape is a circle.
|
|
12
|
+
const radius = (scale: ThemeRadius) => `calc(1.125rem * ${scale} / 2)`
|
|
13
|
+
</script>
|
|
14
|
+
|
|
15
|
+
<template>
|
|
16
|
+
<TRadioGroup v-model="model" :items="themeRadii" variant="tiles" :disabled="disabled" :legend="legend">
|
|
17
|
+
<template #preview="{ item }">
|
|
18
|
+
<span class="t-theme-radius" :style="{ borderRadius: radius(item.value as ThemeRadius) }" />
|
|
19
|
+
</template>
|
|
20
|
+
</TRadioGroup>
|
|
21
|
+
</template>
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Tabler's range slider (noUiSlider): one handle for a number, or two for a range when v-model is
|
|
3
|
+
// [from, to]. Values snap to `step`; `tooltips` shows each handle's value above it. noUiSlider
|
|
4
|
+
// loads on first use.
|
|
5
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
6
|
+
import type { API } from 'nouislider'
|
|
7
|
+
import { loadSlider } from '../plugins/slider'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
min?: number
|
|
11
|
+
max?: number
|
|
12
|
+
step?: number
|
|
13
|
+
tooltips?: boolean
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
label?: string
|
|
16
|
+
}>(), { min: 0, max: 100, step: 1 })
|
|
17
|
+
|
|
18
|
+
const model = defineModel<number | [number, number] | null | undefined>()
|
|
19
|
+
const el = ref<HTMLElement>()
|
|
20
|
+
let slider: API | null = null
|
|
21
|
+
|
|
22
|
+
// As many decimals as the step has, so 0.1 steps show 0.3, not 0.30000000000000004.
|
|
23
|
+
const decimals = computed(() => (String(props.step).split('.')[1] ?? '').length)
|
|
24
|
+
const format = { to: (value: number) => Number(value.toFixed(decimals.value)), from: (value: string) => Number(value) }
|
|
25
|
+
|
|
26
|
+
const isRange = () => Array.isArray(model.value)
|
|
27
|
+
const values = () => isRange() ? [...(model.value as [number, number])] : [model.value as number ?? props.min]
|
|
28
|
+
const same = (a: number[], b: number[]) => a.length === b.length && a.every((v, i) => v === b[i])
|
|
29
|
+
|
|
30
|
+
onMounted(async () => {
|
|
31
|
+
const noUiSlider = await loadSlider()
|
|
32
|
+
if (!el.value) return
|
|
33
|
+
const start = values()
|
|
34
|
+
slider = noUiSlider.create(el.value, {
|
|
35
|
+
start,
|
|
36
|
+
connect: start.length === 2 ? true : 'lower',
|
|
37
|
+
step: props.step,
|
|
38
|
+
range: { min: props.min, max: props.max },
|
|
39
|
+
tooltips: props.tooltips ? start.map(() => format) : false,
|
|
40
|
+
format,
|
|
41
|
+
handleAttributes: start.map((_, i) => ({ 'aria-label': `${props.label ?? 'Value'}${start.length === 2 ? (i ? ' to' : ' from') : ''}` }))
|
|
42
|
+
})
|
|
43
|
+
if (props.disabled) slider.disable()
|
|
44
|
+
slider.on('update', (raw: (string | number)[]) => {
|
|
45
|
+
const next = raw.map(Number)
|
|
46
|
+
if (same(next, values())) return
|
|
47
|
+
model.value = isRange() ? [next[0], next[1]] : next[0]
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
watch(model, () => {
|
|
52
|
+
if (!slider) return
|
|
53
|
+
const current = ([] as (string | number)[]).concat(slider.get() as string | number | (string | number)[]).map(Number)
|
|
54
|
+
if (!same(current, values())) slider.set(values())
|
|
55
|
+
}, { deep: true })
|
|
56
|
+
watch(() => [props.min, props.max, props.step], () => slider?.updateOptions({ range: { min: props.min, max: props.max }, step: props.step }, true))
|
|
57
|
+
watch(() => props.disabled, disabled => disabled ? slider?.disable() : slider?.enable())
|
|
58
|
+
onBeforeUnmount(() => slider?.destroy())
|
|
59
|
+
</script>
|
|
60
|
+
|
|
61
|
+
<template>
|
|
62
|
+
<div ref="el" :class="['t-range-slider', { 't-range-slider-tooltips': tooltips }]" />
|
|
63
|
+
</template>
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A rich text editor with Tabler's WYSIWYG plugin (HugeRTE, an open-source fork of TinyMCE).
|
|
3
|
+
// v-model is the HTML. `toolbar` and `plugins` use HugeRTE's names; the plugins offered are those
|
|
4
|
+
// in src/plugins/richEditor.ts. It follows the light and dark theme (switching rebuilds the editor). Nothing
|
|
5
|
+
// is fetched: the editor, its skins and plugins are bundled and load on first use.
|
|
6
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import type { Editor } from 'hugerte'
|
|
8
|
+
import { useColorMode } from '../composables/useColorMode'
|
|
9
|
+
import { useField } from '../composables/useField'
|
|
10
|
+
import { loadRichEditor, type RichEditorPlugin } from '../plugins/richEditor'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
height?: number
|
|
14
|
+
toolbar?: string
|
|
15
|
+
plugins?: RichEditorPlugin[]
|
|
16
|
+
menubar?: boolean
|
|
17
|
+
statusbar?: boolean
|
|
18
|
+
placeholder?: string
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
id?: string
|
|
21
|
+
}>(), {
|
|
22
|
+
height: 300,
|
|
23
|
+
toolbar: 'undo redo | blocks | bold italic underline | bullist numlist | link image table | code',
|
|
24
|
+
plugins: () => ['advlist', 'autolink', 'lists', 'link', 'image', 'table', 'code']
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const model = defineModel<string>({ default: '' })
|
|
28
|
+
const field = useField(props)
|
|
29
|
+
const { isDark } = useColorMode()
|
|
30
|
+
const textarea = ref<HTMLTextAreaElement>()
|
|
31
|
+
const loading = ref(true)
|
|
32
|
+
let editor: Editor | null = null
|
|
33
|
+
let stopped = false
|
|
34
|
+
|
|
35
|
+
async function create() {
|
|
36
|
+
const hugerte = await loadRichEditor()
|
|
37
|
+
if (stopped || !textarea.value) return
|
|
38
|
+
editor?.remove()
|
|
39
|
+
textarea.value.value = model.value
|
|
40
|
+
const [created] = await hugerte.init({
|
|
41
|
+
target: textarea.value,
|
|
42
|
+
// The skins and content styles are bundled resources, named 'default' and 'dark'.
|
|
43
|
+
skin_url: isDark.value ? 'dark' : 'default',
|
|
44
|
+
content_css: isDark.value ? 'dark' : 'default',
|
|
45
|
+
// The page's font, and in the dark theme the card color rather than HugeRTE's navy.
|
|
46
|
+
content_style: 'body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; }'
|
|
47
|
+
+ (isDark.value ? ' body { background-color: #232525; color: #e6e7e9; }' : ''),
|
|
48
|
+
height: props.height,
|
|
49
|
+
menubar: props.menubar,
|
|
50
|
+
statusbar: props.statusbar,
|
|
51
|
+
plugins: props.plugins,
|
|
52
|
+
toolbar: props.toolbar,
|
|
53
|
+
placeholder: props.placeholder,
|
|
54
|
+
branding: false,
|
|
55
|
+
setup: (ed: Editor) => {
|
|
56
|
+
ed.on('input change undo redo ExecCommand', () => {
|
|
57
|
+
const html = ed.getContent()
|
|
58
|
+
if (html !== model.value) model.value = html
|
|
59
|
+
})
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
editor = created ?? null
|
|
63
|
+
if (editor && props.disabled) editor.mode.set('readonly')
|
|
64
|
+
loading.value = false
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
onMounted(create)
|
|
68
|
+
watch(model, html => { if (editor && html !== editor.getContent()) editor.setContent(html) })
|
|
69
|
+
watch(() => props.disabled, disabled => editor?.mode.set(disabled ? 'readonly' : 'design'))
|
|
70
|
+
watch(() => [isDark.value, props.toolbar, props.plugins, props.menubar, props.statusbar, props.height], create)
|
|
71
|
+
onBeforeUnmount(() => {
|
|
72
|
+
stopped = true
|
|
73
|
+
editor?.remove()
|
|
74
|
+
})
|
|
75
|
+
</script>
|
|
76
|
+
|
|
77
|
+
<template>
|
|
78
|
+
<!-- HugeRTE hides the textarea and adds its editor beside it, inside this wrapper. -->
|
|
79
|
+
<div class="t-rich-editor" :style="loading ? { minHeight: `${height}px` } : undefined">
|
|
80
|
+
<textarea :id="field.id.value" ref="textarea" class="form-control" :placeholder="placeholder" :aria-describedby="field.describedBy.value" />
|
|
81
|
+
</div>
|
|
82
|
+
</template>
|
|
@@ -0,0 +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>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Opens the TCommandPalette: a field-like button with the shortcut at its end, or with `collapsed`,
|
|
3
|
+
// a square icon button (for narrow top bars).
|
|
4
|
+
import TButton from './TButton.vue'
|
|
5
|
+
import TIcon from './TIcon.vue'
|
|
6
|
+
import { isMac, useCommandPalette } from '../composables/useCommandPalette'
|
|
7
|
+
|
|
8
|
+
withDefaults(defineProps<{ label?: string; collapsed?: boolean }>(), { label: 'Search…' })
|
|
9
|
+
|
|
10
|
+
const { open } = useCommandPalette()
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<TButton v-if="collapsed" icon="search" color="neutral" variant="ghost" :aria-label="label" @click="open = true" />
|
|
15
|
+
<button v-else type="button" class="t-search-button" aria-haspopup="dialog" @click="open = true">
|
|
16
|
+
<TIcon name="search" class="text-secondary" />
|
|
17
|
+
<span class="text-secondary text-truncate">{{ label }}</span>
|
|
18
|
+
<kbd class="ms-auto">{{ isMac ? '⌘' : 'Ctrl' }} K</kbd>
|
|
19
|
+
</button>
|
|
20
|
+
</template>
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A work section, Supabase-style: a secondary panel on the left (what the section works on:
|
|
3
|
+
// categories and models, saved queries, files) and a large work area. The panel can be hidden to
|
|
4
|
+
// give the work area the whole width. Use it in a `flush` TPage.
|
|
5
|
+
import { ref } from 'vue'
|
|
6
|
+
import TButton from './TButton.vue'
|
|
7
|
+
import TTooltip from './TTooltip.vue'
|
|
8
|
+
|
|
9
|
+
defineProps<{ title: string }>()
|
|
10
|
+
const open = ref(true)
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<div class="t-section">
|
|
15
|
+
<aside v-if="open" class="t-section-panel" :aria-label="title">
|
|
16
|
+
<div class="t-section-panel-header">
|
|
17
|
+
<h2 class="h3 mb-0 text-truncate">{{ title }}</h2>
|
|
18
|
+
<div class="d-flex align-items-center">
|
|
19
|
+
<slot name="panel-actions" />
|
|
20
|
+
<TTooltip text="Hide the panel">
|
|
21
|
+
<TButton icon="layout-sidebar-left-collapse" size="sm" color="neutral" variant="ghost" aria-label="Hide the panel" @click="open = false" />
|
|
22
|
+
</TTooltip>
|
|
23
|
+
</div>
|
|
24
|
+
</div>
|
|
25
|
+
<slot name="panel-header" />
|
|
26
|
+
<div class="flex-fill overflow-auto" style="min-height: 0">
|
|
27
|
+
<slot name="panel" />
|
|
28
|
+
</div>
|
|
29
|
+
</aside>
|
|
30
|
+
<div class="t-section-work">
|
|
31
|
+
<div v-if="!open" class="d-none d-md-block">
|
|
32
|
+
<TButton icon="layout-sidebar-left-expand" size="sm" color="neutral" variant="ghost" :label="title" @click="open = true" />
|
|
33
|
+
</div>
|
|
34
|
+
<slot />
|
|
35
|
+
</div>
|
|
36
|
+
</div>
|
|
37
|
+
</template>
|