@ternarytech-io/gears-ui 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +373 -0
- package/README.md +160 -2
- package/package.json +104 -6
- package/src/code-editor.ts +25 -0
- package/src/components/TAccentPicker.vue +41 -0
- package/src/components/TAdvancedSelect.vue +128 -0
- package/src/components/TAdvancedTable.vue +130 -0
- package/src/components/TAlert.vue +41 -0
- package/src/components/TAuthLayout.vue +32 -0
- package/src/components/TAvatar.vue +28 -0
- package/src/components/TBadge.vue +29 -0
- package/src/components/TButton.vue +60 -0
- package/src/components/TCard.vue +40 -0
- package/src/components/TCheckbox.vue +29 -0
- package/src/components/TCodeEditor.vue +128 -0
- package/src/components/TColorModeButton.vue +14 -0
- package/src/components/TColorPicker.vue +61 -0
- package/src/components/TCommandPalette.vue +109 -0
- package/src/components/TCopyButton.vue +72 -0
- package/src/components/TDatePicker.vue +83 -0
- package/src/components/TDropdown.vue +76 -0
- package/src/components/TDropzone.vue +76 -0
- package/src/components/TEmpty.vue +21 -0
- package/src/components/TFieldGroup.vue +11 -0
- package/src/components/TFileUpload.vue +92 -0
- package/src/components/TFontPicker.vue +23 -0
- package/src/components/TFormField.vue +40 -0
- package/src/components/TIcon.vue +12 -0
- package/src/components/TImageUpload.vue +131 -0
- package/src/components/TInput.vue +52 -0
- package/src/components/TInputMask.vue +70 -0
- package/src/components/TInputNumber.vue +62 -0
- package/src/components/TInputTags.vue +53 -0
- package/src/components/TLogView.vue +39 -0
- package/src/components/TModal.vue +54 -0
- package/src/components/TNav.vue +75 -0
- package/src/components/TPage.vue +48 -0
- package/src/components/TPagination.vue +44 -0
- package/src/components/TPanelList.vue +29 -0
- package/src/components/TProgress.vue +18 -0
- package/src/components/TRadioGroup.vue +68 -0
- package/src/components/TRadiusPicker.vue +21 -0
- package/src/components/TRangeSlider.vue +63 -0
- package/src/components/TRichEditor.vue +82 -0
- package/src/components/TSearchButton.vue +20 -0
- package/src/components/TSectionLayout.vue +37 -0
- package/src/components/TSelect.vue +60 -0
- package/src/components/TSelectMenu.vue +126 -0
- package/src/components/TSeparator.vue +10 -0
- package/src/components/TShell.vue +72 -0
- package/src/components/TSkeleton.vue +17 -0
- package/src/components/TSlideover.vue +47 -0
- package/src/components/TSortable.vue +61 -0
- package/src/components/TSpinner.vue +14 -0
- package/src/components/TSplitter.vue +85 -0
- package/src/components/TStatCard.vue +26 -0
- package/src/components/TSteps.vue +19 -0
- package/src/components/TSwitch.vue +18 -0
- package/src/components/TTable.vue +134 -0
- package/src/components/TTabs.vue +38 -0
- package/src/components/TTextarea.vue +42 -0
- package/src/components/TThemeBasePicker.vue +22 -0
- package/src/components/TThemeScope.vue +22 -0
- package/src/components/TToaster.vue +27 -0
- package/src/components/TTooltip.vue +33 -0
- package/src/components/TTopbar.vue +17 -0
- package/src/components/TVectorMap.vue +74 -0
- package/src/composables/useColorMode.ts +41 -0
- package/src/composables/useCommandPalette.ts +11 -0
- package/src/composables/useField.ts +26 -0
- package/src/composables/useOverlay.ts +55 -0
- package/src/composables/useToast.ts +33 -0
- package/src/index.ts +199 -0
- package/src/monaco.ts +27 -0
- package/src/plugins/coloris.ts +8 -0
- package/src/plugins/datepicker.ts +7 -0
- package/src/plugins/dropzone.ts +5 -0
- package/src/plugins/index.ts +49 -0
- package/src/plugins/inputMask.ts +7 -0
- package/src/plugins/once.ts +8 -0
- package/src/plugins/richEditor.ts +37 -0
- package/src/plugins/slider.ts +4 -0
- package/src/plugins/sortable.ts +7 -0
- package/src/plugins/tomSelect.ts +4 -0
- package/src/shims.d.ts +17 -0
- package/src/styles/gears.css +560 -0
- package/src/styles/plugins.css +10 -0
- package/src/theme.ts +28 -0
- package/src/types.ts +160 -0
- package/src/vectorMap.ts +14 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Tabs, bound with v-model to the chosen item's value (the first item's when unset). Each tab's
|
|
3
|
+
// content goes in a slot named after its value; the default slot gets the chosen item. `segmented`
|
|
4
|
+
// is a compact switch between modes (it usually has no content slots); `card` fits the tabs into a
|
|
5
|
+
// TCard's header slot.
|
|
6
|
+
import { computed } from 'vue'
|
|
7
|
+
import TIcon from './TIcon.vue'
|
|
8
|
+
import type { TabItem } from '../types'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
items: TabItem[]
|
|
12
|
+
variant?: 'tabs' | 'pills' | 'segmented'
|
|
13
|
+
size?: 'sm' | 'md'
|
|
14
|
+
card?: boolean
|
|
15
|
+
}>(), { variant: 'tabs', size: 'md' })
|
|
16
|
+
|
|
17
|
+
const model = defineModel<string>()
|
|
18
|
+
const current = computed(() => model.value ?? props.items[0]?.value)
|
|
19
|
+
const item = computed(() => props.items.find(i => i.value === current.value))
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<div>
|
|
24
|
+
<nav :class="['nav', `nav-${variant}`, { 'card-header-tabs': card, 'nav-segmented-sm': variant === 'segmented' && size === 'sm' }]" role="tablist">
|
|
25
|
+
<button v-for="tab in items" :key="tab.value" type="button" role="tab" :class="['nav-link', { active: tab.value === current }]"
|
|
26
|
+
:aria-selected="tab.value === current" :disabled="tab.disabled" @click="model = tab.value">
|
|
27
|
+
<TIcon v-if="tab.icon" :name="tab.icon" :class="variant === 'segmented' ? 'me-1' : 'me-2'" />
|
|
28
|
+
{{ tab.label }}
|
|
29
|
+
<span v-if="tab.badge != null" class="badge bg-secondary-lt ms-2">{{ tab.badge }}</span>
|
|
30
|
+
</button>
|
|
31
|
+
</nav>
|
|
32
|
+
<div v-if="item && ($slots[item.value] || $slots.default)" class="pt-3" role="tabpanel">
|
|
33
|
+
<slot :name="item.value" :item="item">
|
|
34
|
+
<slot :item="item" />
|
|
35
|
+
</slot>
|
|
36
|
+
</div>
|
|
37
|
+
</div>
|
|
38
|
+
</template>
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A multi-line text input. `autoresize` grows it with its text instead of scrolling; `autofocus`
|
|
3
|
+
// focuses it when it appears.
|
|
4
|
+
import { nextTick, onMounted, ref, watch } from 'vue'
|
|
5
|
+
import { useField } from '../composables/useField'
|
|
6
|
+
|
|
7
|
+
defineOptions({ inheritAttrs: false })
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
placeholder?: string
|
|
11
|
+
rows?: number
|
|
12
|
+
autoresize?: boolean
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
readonly?: boolean
|
|
15
|
+
invalid?: boolean
|
|
16
|
+
autofocus?: boolean
|
|
17
|
+
id?: string
|
|
18
|
+
}>(), { rows: 3 })
|
|
19
|
+
|
|
20
|
+
const model = defineModel<string | null | undefined>()
|
|
21
|
+
const field = useField(props)
|
|
22
|
+
const el = ref<HTMLTextAreaElement>()
|
|
23
|
+
|
|
24
|
+
function resize() {
|
|
25
|
+
if (!props.autoresize || !el.value) return
|
|
26
|
+
el.value.style.height = 'auto'
|
|
27
|
+
el.value.style.height = `${el.value.scrollHeight + 2}px`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onMounted(() => {
|
|
31
|
+
resize()
|
|
32
|
+
if (props.autofocus) el.value?.focus()
|
|
33
|
+
})
|
|
34
|
+
watch(model, () => nextTick(resize))
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<template>
|
|
38
|
+
<textarea v-bind="$attrs" :id="field.id.value" ref="el" :value="model ?? ''" :rows="rows" :placeholder="placeholder" :disabled="disabled" :readonly="readonly"
|
|
39
|
+
:aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
|
|
40
|
+
:class="['form-control', { 'is-invalid': field.invalid.value }]" :style="autoresize ? { resize: 'none', overflow: 'hidden' } : undefined"
|
|
41
|
+
@input="model = ($event.target as HTMLTextAreaElement).value" />
|
|
42
|
+
</template>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A theme's base: the grays behind every surface, border and muted text. Each tile shows five of
|
|
3
|
+
// the base's shades, lightest to darkest.
|
|
4
|
+
import TRadioGroup from './TRadioGroup.vue'
|
|
5
|
+
import { themeBases } from '../theme'
|
|
6
|
+
import type { ThemeBase } from '../types'
|
|
7
|
+
|
|
8
|
+
defineProps<{ disabled?: boolean; legend?: string }>()
|
|
9
|
+
|
|
10
|
+
const model = defineModel<ThemeBase | null | undefined>()
|
|
11
|
+
const shades = [100, 300, 500, 700, 900]
|
|
12
|
+
</script>
|
|
13
|
+
|
|
14
|
+
<template>
|
|
15
|
+
<TRadioGroup v-model="model" :items="themeBases" variant="tiles" :disabled="disabled" :legend="legend">
|
|
16
|
+
<template #preview="{ item }">
|
|
17
|
+
<span class="t-theme-swatches" :data-bs-theme-base="item.value">
|
|
18
|
+
<span v-for="shade in shades" :key="shade" :style="{ background: `var(--tblr-gray-${shade})` }" />
|
|
19
|
+
</span>
|
|
20
|
+
</template>
|
|
21
|
+
</TRadioGroup>
|
|
22
|
+
</template>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Tabler's theme settings for part of a page: what's inside takes the theme's accent color, font,
|
|
3
|
+
// base grays, corner radius and light or dark mode, whatever the page around it uses. For previews
|
|
4
|
+
// of an application's theme. A custom accent (#rrggbb) is set as the primary color directly.
|
|
5
|
+
import { computed } from 'vue'
|
|
6
|
+
import { useColorMode } from '../composables/useColorMode'
|
|
7
|
+
import { isCustomAccent } from '../theme'
|
|
8
|
+
import type { ThemeSettings } from '../types'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{ theme: ThemeSettings }>()
|
|
11
|
+
const { resolved } = useColorMode()
|
|
12
|
+
|
|
13
|
+
const custom = computed(() => isCustomAccent(props.theme.accent))
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<div class="t-theme-scope" :data-bs-theme="theme.mode ?? resolved" :data-bs-theme-base="theme.base"
|
|
18
|
+
:data-bs-theme-font="theme.font" :data-bs-theme-radius="theme.radius"
|
|
19
|
+
:data-bs-theme-primary="custom ? undefined : theme.accent" :style="custom ? { '--tblr-primary': theme.accent } : undefined">
|
|
20
|
+
<slot />
|
|
21
|
+
</div>
|
|
22
|
+
</template>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Shows the toasts added with useToast(), stacked in the bottom corner. Put one in the app's frame.
|
|
3
|
+
import TIcon from './TIcon.vue'
|
|
4
|
+
import { useToast } from '../composables/useToast'
|
|
5
|
+
import { toTabler } from '../types'
|
|
6
|
+
|
|
7
|
+
const { toasts, remove } = useToast()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<Teleport to="body">
|
|
12
|
+
<div class="toast-container position-fixed bottom-0 end-0 p-3" aria-live="polite">
|
|
13
|
+
<TransitionGroup name="t-toast">
|
|
14
|
+
<div v-for="toast in toasts" :key="toast.id" class="toast show t-toast" role="status">
|
|
15
|
+
<div class="toast-body d-flex align-items-start gap-2">
|
|
16
|
+
<TIcon v-if="toast.icon" :name="toast.icon" :class="['mt-1', toast.color && toast.color !== 'neutral' ? `text-${toTabler(toast.color)}` : 'text-secondary']" />
|
|
17
|
+
<div class="flex-fill min-w-0">
|
|
18
|
+
<div class="fw-medium">{{ toast.title }}</div>
|
|
19
|
+
<div v-if="toast.description" class="text-secondary small mt-1">{{ toast.description }}</div>
|
|
20
|
+
</div>
|
|
21
|
+
<button type="button" class="btn-close ms-2" aria-label="Close" @click="remove(toast.id)" />
|
|
22
|
+
</div>
|
|
23
|
+
</div>
|
|
24
|
+
</TransitionGroup>
|
|
25
|
+
</div>
|
|
26
|
+
</Teleport>
|
|
27
|
+
</template>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A short hint on hover or focus, around whatever is in the slot. The text is read when the
|
|
3
|
+
// tooltip shows, so it can change; with no text it doesn't show.
|
|
4
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
5
|
+
import { Tooltip } from '@tabler/core'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{ text?: string; placement?: 'top' | 'bottom' | 'start' | 'end'; disabled?: boolean }>(),
|
|
8
|
+
{ placement: 'top' })
|
|
9
|
+
|
|
10
|
+
const el = ref<HTMLElement>()
|
|
11
|
+
let tooltip: Tooltip | null = null
|
|
12
|
+
|
|
13
|
+
const placements = { top: 'top', bottom: 'bottom', start: 'left', end: 'right' } as const
|
|
14
|
+
|
|
15
|
+
onMounted(() => {
|
|
16
|
+
tooltip = new Tooltip(el.value!, {
|
|
17
|
+
title: () => props.text ?? '',
|
|
18
|
+
placement: placements[props.placement],
|
|
19
|
+
trigger: 'hover focus',
|
|
20
|
+
delay: { show: 150, hide: 0 }
|
|
21
|
+
})
|
|
22
|
+
el.value!.addEventListener('show.bs.tooltip', event => { if (!props.text || props.disabled) event.preventDefault() })
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
watch(() => props.disabled, disabled => { if (disabled) tooltip?.hide() })
|
|
26
|
+
onBeforeUnmount(() => tooltip?.dispose())
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<template>
|
|
30
|
+
<span ref="el" class="d-inline-flex">
|
|
31
|
+
<slot />
|
|
32
|
+
</span>
|
|
33
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// The bar along the top of a page: things on the left (a switcher, breadcrumbs) and on the right
|
|
3
|
+
// (search, actions, the theme and user menus).
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<header class="navbar navbar-expand d-print-none border-bottom t-topbar">
|
|
8
|
+
<div class="container-fluid gap-2 flex-nowrap">
|
|
9
|
+
<div class="d-flex align-items-center gap-2 min-w-0">
|
|
10
|
+
<slot name="left" />
|
|
11
|
+
</div>
|
|
12
|
+
<div class="d-flex align-items-center gap-2 ms-auto">
|
|
13
|
+
<slot name="right" />
|
|
14
|
+
</div>
|
|
15
|
+
</div>
|
|
16
|
+
</header>
|
|
17
|
+
</template>
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A world map with Tabler's vector map: countries shaded by `values` (a number per ISO code, such
|
|
3
|
+
// as { US: 120, DE: 80 }), places as `markers`, `lines` between markers, a `legend` for the scale,
|
|
4
|
+
// and selecting countries (`select`, with v-model:selected). `zoom` adds zoom buttons and dragging.
|
|
5
|
+
// The map and its data load on first use.
|
|
6
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import type VectorMap from '@tabler/core/dist/types/src/vector-map'
|
|
8
|
+
import type { VectorMapLine, VectorMapMarker, VectorMapTooltipItem } from '@tabler/core/dist/types/src/vector-map'
|
|
9
|
+
import { loadVectorMap } from '../vectorMap'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
values?: Record<string, number>
|
|
13
|
+
min?: number
|
|
14
|
+
max?: number
|
|
15
|
+
// Two to five colors for the scale, low to high.
|
|
16
|
+
colors?: string[]
|
|
17
|
+
markers?: VectorMapMarker[]
|
|
18
|
+
lines?: VectorMapLine[]
|
|
19
|
+
tooltip?: boolean | ((item: VectorMapTooltipItem) => string)
|
|
20
|
+
legend?: boolean | ((value: number) => string)
|
|
21
|
+
select?: 'none' | 'single' | 'multiple'
|
|
22
|
+
zoom?: boolean
|
|
23
|
+
label?: string
|
|
24
|
+
height?: string
|
|
25
|
+
}>(), { values: () => ({}), colors: () => [], markers: () => [], lines: () => [], tooltip: true, legend: false, select: 'none', label: 'World map', height: '20rem' })
|
|
26
|
+
|
|
27
|
+
const selected = defineModel<string[]>('selected', { default: () => [] })
|
|
28
|
+
const emit = defineEmits<{ 'region-click': [code: string] }>()
|
|
29
|
+
|
|
30
|
+
const el = ref<HTMLElement>()
|
|
31
|
+
let map: VectorMap | null = null
|
|
32
|
+
|
|
33
|
+
async function create() {
|
|
34
|
+
const VectorMapClass = await loadVectorMap()
|
|
35
|
+
if (!el.value) return
|
|
36
|
+
map?.dispose()
|
|
37
|
+
el.value.replaceChildren()
|
|
38
|
+
map = new VectorMapClass(el.value, {
|
|
39
|
+
values: props.values,
|
|
40
|
+
min: props.min ?? null,
|
|
41
|
+
max: props.max ?? null,
|
|
42
|
+
colors: props.colors,
|
|
43
|
+
markers: props.markers,
|
|
44
|
+
lines: props.lines,
|
|
45
|
+
tooltip: props.tooltip,
|
|
46
|
+
legend: props.legend,
|
|
47
|
+
select: props.select,
|
|
48
|
+
selected: selected.value,
|
|
49
|
+
zoom: props.zoom,
|
|
50
|
+
label: props.label
|
|
51
|
+
})
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
onMounted(() => {
|
|
55
|
+
create()
|
|
56
|
+
el.value!.addEventListener('selected.bs.vector-map', event => {
|
|
57
|
+
selected.value = [...((event as Event & { selected: string[] }).selected ?? [])]
|
|
58
|
+
})
|
|
59
|
+
el.value!.addEventListener('regionclick.bs.vector-map', event => {
|
|
60
|
+
emit('region-click', (event as Event & { code: string }).code)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
watch(() => props.values, values => map?.update(values), { deep: true })
|
|
65
|
+
watch(() => [props.min, props.max, props.colors, props.markers, props.lines, props.tooltip, props.legend, props.select, props.zoom, props.label], create, { deep: true })
|
|
66
|
+
watch(selected, codes => {
|
|
67
|
+
if (map && JSON.stringify(map.getSelected()) !== JSON.stringify(codes)) map.setSelected(codes)
|
|
68
|
+
})
|
|
69
|
+
onBeforeUnmount(() => map?.dispose())
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<template>
|
|
73
|
+
<div ref="el" class="vector-map" :style="{ height }" />
|
|
74
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// The color theme: light, dark or the system's. Tabler reads `data-bs-theme` on <html>; the choice
|
|
2
|
+
// is remembered in localStorage (the browser may refuse, so that's best effort).
|
|
3
|
+
import { computed, ref, watchEffect } from 'vue'
|
|
4
|
+
|
|
5
|
+
export type ColorMode = 'light' | 'dark' | 'system'
|
|
6
|
+
|
|
7
|
+
const storageKey = 'gears-color-mode'
|
|
8
|
+
const media = typeof window !== 'undefined' ? window.matchMedia('(prefers-color-scheme: dark)') : null
|
|
9
|
+
|
|
10
|
+
function stored(): ColorMode {
|
|
11
|
+
try {
|
|
12
|
+
const value = localStorage.getItem(storageKey)
|
|
13
|
+
if (value === 'light' || value === 'dark' || value === 'system') return value
|
|
14
|
+
} catch { /* storage blocked */ }
|
|
15
|
+
return 'system'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const preference = ref<ColorMode>(stored())
|
|
19
|
+
const systemDark = ref(media?.matches ?? false)
|
|
20
|
+
media?.addEventListener('change', e => { systemDark.value = e.matches })
|
|
21
|
+
|
|
22
|
+
const resolved = computed<'light' | 'dark'>(() =>
|
|
23
|
+
preference.value === 'system' ? (systemDark.value ? 'dark' : 'light') : preference.value)
|
|
24
|
+
|
|
25
|
+
let applied = false
|
|
26
|
+
|
|
27
|
+
export function useColorMode() {
|
|
28
|
+
if (!applied && typeof document !== 'undefined') {
|
|
29
|
+
applied = true
|
|
30
|
+
watchEffect(() => {
|
|
31
|
+
document.documentElement.setAttribute('data-bs-theme', resolved.value)
|
|
32
|
+
try { localStorage.setItem(storageKey, preference.value) } catch { /* storage blocked */ }
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
preference,
|
|
37
|
+
resolved,
|
|
38
|
+
isDark: computed(() => resolved.value === 'dark'),
|
|
39
|
+
toggle: () => { preference.value = resolved.value === 'dark' ? 'light' : 'dark' }
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// The command palette's open state, shared: TSearchButton opens it, TCommandPalette shows it, and
|
|
2
|
+
// Ctrl+K (⌘K on a Mac) toggles it from anywhere.
|
|
3
|
+
import { ref } from 'vue'
|
|
4
|
+
|
|
5
|
+
const open = ref(false)
|
|
6
|
+
|
|
7
|
+
export const isMac = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/.test(navigator.platform)
|
|
8
|
+
|
|
9
|
+
export function useCommandPalette() {
|
|
10
|
+
return { open, toggle: () => { open.value = !open.value } }
|
|
11
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// A form field shares its id and state with the control inside it, so the label points at the
|
|
2
|
+
// control and an error marks it invalid without wiring each one by hand.
|
|
3
|
+
import { computed, inject, provide, useId, type ComputedRef, type InjectionKey } from 'vue'
|
|
4
|
+
|
|
5
|
+
export interface FieldContext {
|
|
6
|
+
id: string
|
|
7
|
+
invalid: ComputedRef<boolean>
|
|
8
|
+
describedBy: ComputedRef<string | undefined>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const fieldKey: InjectionKey<FieldContext> = Symbol('t-field')
|
|
12
|
+
|
|
13
|
+
export function provideField(context: FieldContext) {
|
|
14
|
+
provide(fieldKey, context)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// The control's id (its own, its field's or a new one), whether it's invalid, and what describes it.
|
|
18
|
+
export function useField(props: { id?: string; invalid?: boolean }) {
|
|
19
|
+
const field = inject(fieldKey, null)
|
|
20
|
+
const fallback = useId()
|
|
21
|
+
return {
|
|
22
|
+
id: computed(() => props.id ?? field?.id ?? fallback),
|
|
23
|
+
invalid: computed(() => props.invalid || (field?.invalid.value ?? false)),
|
|
24
|
+
describedBy: computed(() => field?.describedBy.value)
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Drives a Bootstrap modal or offcanvas from a v-model: opening the model shows it, and closing it
|
|
2
|
+
// any way (the close button, Esc, the backdrop) sets the model back. Content renders while it's
|
|
3
|
+
// open and until it has faded out. `afterEnter` runs once it has opened (and taken focus).
|
|
4
|
+
import { onBeforeUnmount, onMounted, ref, watch, type Ref } from 'vue'
|
|
5
|
+
|
|
6
|
+
interface Overlay {
|
|
7
|
+
show(): void
|
|
8
|
+
hide(): void
|
|
9
|
+
dispose(): void
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useOverlay(el: Ref<HTMLElement | undefined>, kind: 'modal' | 'offcanvas', open: Ref<boolean>,
|
|
13
|
+
create: (el: HTMLElement) => Overlay, afterLeave: () => void, afterEnter?: () => void) {
|
|
14
|
+
const rendered = ref(open.value)
|
|
15
|
+
let overlay: Overlay | null = null
|
|
16
|
+
let shown = false
|
|
17
|
+
|
|
18
|
+
onMounted(() => {
|
|
19
|
+
const element = el.value!
|
|
20
|
+
overlay = create(element)
|
|
21
|
+
element.addEventListener(`show.bs.${kind}`, () => { shown = true })
|
|
22
|
+
element.addEventListener(`shown.bs.${kind}`, () => afterEnter?.())
|
|
23
|
+
element.addEventListener(`hide.bs.${kind}`, () => {
|
|
24
|
+
shown = false
|
|
25
|
+
if (open.value) open.value = false
|
|
26
|
+
})
|
|
27
|
+
element.addEventListener(`hidden.bs.${kind}`, () => {
|
|
28
|
+
if (!open.value) rendered.value = false
|
|
29
|
+
afterLeave()
|
|
30
|
+
})
|
|
31
|
+
if (open.value) overlay.show()
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
watch(open, value => {
|
|
35
|
+
if (value) {
|
|
36
|
+
rendered.value = true
|
|
37
|
+
overlay?.show()
|
|
38
|
+
} else {
|
|
39
|
+
overlay?.hide()
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
onBeforeUnmount(() => {
|
|
44
|
+
overlay?.dispose()
|
|
45
|
+
// Bootstrap leaves its backdrop and scroll lock behind when an open overlay is disposed.
|
|
46
|
+
if (shown) {
|
|
47
|
+
document.querySelectorAll(`.${kind}-backdrop`).forEach(backdrop => backdrop.remove())
|
|
48
|
+
document.body.classList.remove('modal-open')
|
|
49
|
+
document.body.style.removeProperty('overflow')
|
|
50
|
+
document.body.style.removeProperty('padding-right')
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
return rendered
|
|
55
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Short notices in the corner ("Saved.", "Deleted."), shown by a TToaster in the app's frame:
|
|
2
|
+
// `useToast().add({ title, description, color, icon })`. They close by themselves after
|
|
3
|
+
// `duration` milliseconds (5 seconds; 0 keeps one until it's closed).
|
|
4
|
+
import { ref } from 'vue'
|
|
5
|
+
import type { Color } from '../types'
|
|
6
|
+
|
|
7
|
+
export interface Toast {
|
|
8
|
+
id: number
|
|
9
|
+
title: string
|
|
10
|
+
description?: string
|
|
11
|
+
color?: Color
|
|
12
|
+
icon?: string
|
|
13
|
+
duration?: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const toasts = ref<Toast[]>([])
|
|
17
|
+
let nextId = 1
|
|
18
|
+
|
|
19
|
+
function remove(id: number) {
|
|
20
|
+
toasts.value = toasts.value.filter(t => t.id !== id)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function add(toast: Omit<Toast, 'id'>) {
|
|
24
|
+
const id = nextId++
|
|
25
|
+
toasts.value = [...toasts.value, { ...toast, id }]
|
|
26
|
+
const duration = toast.duration ?? 5000
|
|
27
|
+
if (duration > 0) setTimeout(() => remove(id), duration)
|
|
28
|
+
return id
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useToast() {
|
|
32
|
+
return { toasts, add, remove }
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
// Gears UI: Vue components on Tabler. Import the styles once (`@ternarytech-io/gears-ui/styles.css`), then either
|
|
2
|
+
// install the plugin (registers every component globally) or import components one by one.
|
|
3
|
+
// Components that need an optional library have their own entry points, so apps that don't use
|
|
4
|
+
// them don't need the library: `@ternarytech-io/gears-ui/code-editor` (Monaco) and `@ternarytech-io/gears-ui/plugins` (Tom
|
|
5
|
+
// Select, Coloris, Vanilla Calendar Pro, Dropzone, IMask, noUiSlider, SortableJS, HugeRTE).
|
|
6
|
+
import type { App } from 'vue'
|
|
7
|
+
import TAccentPicker from './components/TAccentPicker.vue'
|
|
8
|
+
import TAdvancedTable from './components/TAdvancedTable.vue'
|
|
9
|
+
import TAlert from './components/TAlert.vue'
|
|
10
|
+
import TAuthLayout from './components/TAuthLayout.vue'
|
|
11
|
+
import TAvatar from './components/TAvatar.vue'
|
|
12
|
+
import TBadge from './components/TBadge.vue'
|
|
13
|
+
import TButton from './components/TButton.vue'
|
|
14
|
+
import TCard from './components/TCard.vue'
|
|
15
|
+
import TCheckbox from './components/TCheckbox.vue'
|
|
16
|
+
import TColorModeButton from './components/TColorModeButton.vue'
|
|
17
|
+
import TCommandPalette from './components/TCommandPalette.vue'
|
|
18
|
+
import TCopyButton from './components/TCopyButton.vue'
|
|
19
|
+
import TDropdown from './components/TDropdown.vue'
|
|
20
|
+
import TEmpty from './components/TEmpty.vue'
|
|
21
|
+
import TFieldGroup from './components/TFieldGroup.vue'
|
|
22
|
+
import TFileUpload from './components/TFileUpload.vue'
|
|
23
|
+
import TFontPicker from './components/TFontPicker.vue'
|
|
24
|
+
import TFormField from './components/TFormField.vue'
|
|
25
|
+
import TIcon from './components/TIcon.vue'
|
|
26
|
+
import TImageUpload from './components/TImageUpload.vue'
|
|
27
|
+
import TInput from './components/TInput.vue'
|
|
28
|
+
import TInputNumber from './components/TInputNumber.vue'
|
|
29
|
+
import TInputTags from './components/TInputTags.vue'
|
|
30
|
+
import TLogView from './components/TLogView.vue'
|
|
31
|
+
import TModal from './components/TModal.vue'
|
|
32
|
+
import TNav from './components/TNav.vue'
|
|
33
|
+
import TPage from './components/TPage.vue'
|
|
34
|
+
import TPagination from './components/TPagination.vue'
|
|
35
|
+
import TPanelList from './components/TPanelList.vue'
|
|
36
|
+
import TProgress from './components/TProgress.vue'
|
|
37
|
+
import TRadioGroup from './components/TRadioGroup.vue'
|
|
38
|
+
import TRadiusPicker from './components/TRadiusPicker.vue'
|
|
39
|
+
import TSearchButton from './components/TSearchButton.vue'
|
|
40
|
+
import TSectionLayout from './components/TSectionLayout.vue'
|
|
41
|
+
import TSelect from './components/TSelect.vue'
|
|
42
|
+
import TSelectMenu from './components/TSelectMenu.vue'
|
|
43
|
+
import TSeparator from './components/TSeparator.vue'
|
|
44
|
+
import TShell from './components/TShell.vue'
|
|
45
|
+
import TSkeleton from './components/TSkeleton.vue'
|
|
46
|
+
import TSlideover from './components/TSlideover.vue'
|
|
47
|
+
import TSpinner from './components/TSpinner.vue'
|
|
48
|
+
import TSplitter from './components/TSplitter.vue'
|
|
49
|
+
import TStatCard from './components/TStatCard.vue'
|
|
50
|
+
import TSteps from './components/TSteps.vue'
|
|
51
|
+
import TSwitch from './components/TSwitch.vue'
|
|
52
|
+
import TTable from './components/TTable.vue'
|
|
53
|
+
import TTabs from './components/TTabs.vue'
|
|
54
|
+
import TTextarea from './components/TTextarea.vue'
|
|
55
|
+
import TThemeBasePicker from './components/TThemeBasePicker.vue'
|
|
56
|
+
import TThemeScope from './components/TThemeScope.vue'
|
|
57
|
+
import TToaster from './components/TToaster.vue'
|
|
58
|
+
import TTooltip from './components/TTooltip.vue'
|
|
59
|
+
import TTopbar from './components/TTopbar.vue'
|
|
60
|
+
import TVectorMap from './components/TVectorMap.vue'
|
|
61
|
+
|
|
62
|
+
export {
|
|
63
|
+
TAccentPicker,
|
|
64
|
+
TAdvancedTable,
|
|
65
|
+
TAlert,
|
|
66
|
+
TAuthLayout,
|
|
67
|
+
TAvatar,
|
|
68
|
+
TBadge,
|
|
69
|
+
TButton,
|
|
70
|
+
TCard,
|
|
71
|
+
TCheckbox,
|
|
72
|
+
TColorModeButton,
|
|
73
|
+
TCommandPalette,
|
|
74
|
+
TCopyButton,
|
|
75
|
+
TDropdown,
|
|
76
|
+
TEmpty,
|
|
77
|
+
TFieldGroup,
|
|
78
|
+
TFileUpload,
|
|
79
|
+
TFontPicker,
|
|
80
|
+
TFormField,
|
|
81
|
+
TIcon,
|
|
82
|
+
TImageUpload,
|
|
83
|
+
TInput,
|
|
84
|
+
TInputNumber,
|
|
85
|
+
TInputTags,
|
|
86
|
+
TLogView,
|
|
87
|
+
TModal,
|
|
88
|
+
TNav,
|
|
89
|
+
TPage,
|
|
90
|
+
TPagination,
|
|
91
|
+
TPanelList,
|
|
92
|
+
TProgress,
|
|
93
|
+
TRadioGroup,
|
|
94
|
+
TRadiusPicker,
|
|
95
|
+
TSearchButton,
|
|
96
|
+
TSectionLayout,
|
|
97
|
+
TSelect,
|
|
98
|
+
TSelectMenu,
|
|
99
|
+
TSeparator,
|
|
100
|
+
TShell,
|
|
101
|
+
TSkeleton,
|
|
102
|
+
TSlideover,
|
|
103
|
+
TSpinner,
|
|
104
|
+
TSplitter,
|
|
105
|
+
TStatCard,
|
|
106
|
+
TSteps,
|
|
107
|
+
TSwitch,
|
|
108
|
+
TTable,
|
|
109
|
+
TTabs,
|
|
110
|
+
TTextarea,
|
|
111
|
+
TThemeBasePicker,
|
|
112
|
+
TThemeScope,
|
|
113
|
+
TToaster,
|
|
114
|
+
TTooltip,
|
|
115
|
+
TTopbar,
|
|
116
|
+
TVectorMap
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export * from './types'
|
|
120
|
+
export { isCustomAccent, themeAccents, themeBases, themeFonts, themeRadii } from './theme'
|
|
121
|
+
export { useColorMode, type ColorMode } from './composables/useColorMode'
|
|
122
|
+
export { useCommandPalette } from './composables/useCommandPalette'
|
|
123
|
+
export { useField } from './composables/useField'
|
|
124
|
+
export { useToast, type Toast } from './composables/useToast'
|
|
125
|
+
|
|
126
|
+
const components = {
|
|
127
|
+
TAccentPicker, TAdvancedTable, TAlert, TAuthLayout, TAvatar, TBadge, TButton, TCard, TCheckbox,
|
|
128
|
+
TColorModeButton, TCommandPalette, TCopyButton, TDropdown, TEmpty, TFieldGroup, TFileUpload,
|
|
129
|
+
TFontPicker, TFormField, TIcon, TImageUpload, TInput, TInputNumber, TInputTags, TLogView, TModal,
|
|
130
|
+
TNav, TPage, TPagination, TPanelList, TProgress, TRadioGroup, TRadiusPicker, TSearchButton,
|
|
131
|
+
TSectionLayout, TSelect, TSelectMenu, TSeparator, TShell, TSkeleton, TSlideover, TSpinner,
|
|
132
|
+
TSplitter, TStatCard, TSteps, TSwitch, TTable, TTabs, TTextarea, TThemeBasePicker, TThemeScope,
|
|
133
|
+
TToaster, TTooltip, TTopbar, TVectorMap
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
export default {
|
|
137
|
+
install(app: App) {
|
|
138
|
+
for (const [name, component] of Object.entries(components)) app.component(name, component)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
declare module 'vue' {
|
|
143
|
+
export interface GlobalComponents {
|
|
144
|
+
TAccentPicker: typeof TAccentPicker
|
|
145
|
+
TAdvancedTable: typeof TAdvancedTable
|
|
146
|
+
TAlert: typeof TAlert
|
|
147
|
+
TAuthLayout: typeof TAuthLayout
|
|
148
|
+
TAvatar: typeof TAvatar
|
|
149
|
+
TBadge: typeof TBadge
|
|
150
|
+
TButton: typeof TButton
|
|
151
|
+
TCard: typeof TCard
|
|
152
|
+
TCheckbox: typeof TCheckbox
|
|
153
|
+
TColorModeButton: typeof TColorModeButton
|
|
154
|
+
TCommandPalette: typeof TCommandPalette
|
|
155
|
+
TCopyButton: typeof TCopyButton
|
|
156
|
+
TDropdown: typeof TDropdown
|
|
157
|
+
TEmpty: typeof TEmpty
|
|
158
|
+
TFieldGroup: typeof TFieldGroup
|
|
159
|
+
TFileUpload: typeof TFileUpload
|
|
160
|
+
TFontPicker: typeof TFontPicker
|
|
161
|
+
TFormField: typeof TFormField
|
|
162
|
+
TIcon: typeof TIcon
|
|
163
|
+
TImageUpload: typeof TImageUpload
|
|
164
|
+
TInput: typeof TInput
|
|
165
|
+
TInputNumber: typeof TInputNumber
|
|
166
|
+
TInputTags: typeof TInputTags
|
|
167
|
+
TLogView: typeof TLogView
|
|
168
|
+
TModal: typeof TModal
|
|
169
|
+
TNav: typeof TNav
|
|
170
|
+
TPage: typeof TPage
|
|
171
|
+
TPagination: typeof TPagination
|
|
172
|
+
TPanelList: typeof TPanelList
|
|
173
|
+
TProgress: typeof TProgress
|
|
174
|
+
TRadioGroup: typeof TRadioGroup
|
|
175
|
+
TRadiusPicker: typeof TRadiusPicker
|
|
176
|
+
TSearchButton: typeof TSearchButton
|
|
177
|
+
TSectionLayout: typeof TSectionLayout
|
|
178
|
+
TSelect: typeof TSelect
|
|
179
|
+
TSelectMenu: typeof TSelectMenu
|
|
180
|
+
TSeparator: typeof TSeparator
|
|
181
|
+
TShell: typeof TShell
|
|
182
|
+
TSkeleton: typeof TSkeleton
|
|
183
|
+
TSlideover: typeof TSlideover
|
|
184
|
+
TSpinner: typeof TSpinner
|
|
185
|
+
TSplitter: typeof TSplitter
|
|
186
|
+
TStatCard: typeof TStatCard
|
|
187
|
+
TSteps: typeof TSteps
|
|
188
|
+
TSwitch: typeof TSwitch
|
|
189
|
+
TTable: typeof TTable
|
|
190
|
+
TTabs: typeof TTabs
|
|
191
|
+
TTextarea: typeof TTextarea
|
|
192
|
+
TThemeBasePicker: typeof TThemeBasePicker
|
|
193
|
+
TThemeScope: typeof TThemeScope
|
|
194
|
+
TToaster: typeof TToaster
|
|
195
|
+
TTooltip: typeof TTooltip
|
|
196
|
+
TTopbar: typeof TTopbar
|
|
197
|
+
TVectorMap: typeof TVectorMap
|
|
198
|
+
}
|
|
199
|
+
}
|