@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,128 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A code editor (Monaco) for any language: queries, generated code, settings, JSON. It follows the
|
|
3
|
+
// light and dark theme, offers the completions it's given, and emits `run` on Ctrl+Enter. Monaco
|
|
4
|
+
// loads the first time an editor is shown. Give it a height (a class, or flex in a column);
|
|
5
|
+
// `flush` drops the border, for an editor that fills a card.
|
|
6
|
+
import { onBeforeUnmount, onMounted, ref, shallowRef, watch } from 'vue'
|
|
7
|
+
import type * as Monaco from 'monaco-editor'
|
|
8
|
+
import TSpinner from './TSpinner.vue'
|
|
9
|
+
import { useColorMode } from '../composables/useColorMode'
|
|
10
|
+
import type { CodeCompletion } from '../types'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
language: string
|
|
14
|
+
readOnly?: boolean
|
|
15
|
+
completions?: CodeCompletion[]
|
|
16
|
+
// The editor's accessible name.
|
|
17
|
+
label?: string
|
|
18
|
+
flush?: boolean
|
|
19
|
+
lineNumbers?: boolean
|
|
20
|
+
}>(), { completions: () => [], label: 'Code editor', lineNumbers: true })
|
|
21
|
+
|
|
22
|
+
const value = defineModel<string>({ default: '' })
|
|
23
|
+
const emit = defineEmits<{ run: [] }>()
|
|
24
|
+
|
|
25
|
+
const host = ref<HTMLDivElement>()
|
|
26
|
+
const loading = ref(true)
|
|
27
|
+
const { isDark } = useColorMode()
|
|
28
|
+
let monaco: typeof Monaco | undefined
|
|
29
|
+
const editor = shallowRef<Monaco.editor.IStandaloneCodeEditor>()
|
|
30
|
+
let completionProvider: Monaco.IDisposable | undefined
|
|
31
|
+
|
|
32
|
+
const theme = () => isDark.value ? 'gears-dark' : 'gears-light'
|
|
33
|
+
|
|
34
|
+
onMounted(async () => {
|
|
35
|
+
monaco = (await import('../monaco')).default
|
|
36
|
+
if (!host.value) return
|
|
37
|
+
editor.value = monaco.editor.create(host.value, {
|
|
38
|
+
value: value.value,
|
|
39
|
+
language: props.language,
|
|
40
|
+
readOnly: props.readOnly,
|
|
41
|
+
theme: theme(),
|
|
42
|
+
automaticLayout: true,
|
|
43
|
+
minimap: { enabled: false },
|
|
44
|
+
overviewRulerLanes: 0,
|
|
45
|
+
hideCursorInOverviewRuler: true,
|
|
46
|
+
scrollBeyondLastLine: false,
|
|
47
|
+
lineNumbers: props.lineNumbers ? 'on' : 'off',
|
|
48
|
+
fontSize: 13,
|
|
49
|
+
fontFamily: "ui-monospace, 'Cascadia Code', Consolas, monospace",
|
|
50
|
+
tabSize: 2,
|
|
51
|
+
wordWrap: 'on',
|
|
52
|
+
ariaLabel: props.label,
|
|
53
|
+
padding: { top: 8, bottom: 8 }
|
|
54
|
+
})
|
|
55
|
+
editor.value.onDidChangeModelContent(() => {
|
|
56
|
+
const text = editor.value!.getValue()
|
|
57
|
+
if (text !== value.value) value.value = text
|
|
58
|
+
})
|
|
59
|
+
editor.value.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => emit('run'))
|
|
60
|
+
registerCompletions()
|
|
61
|
+
loading.value = false
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
// The editor goes before its model: a model disposed under a live editor throws "Model is disposed!".
|
|
65
|
+
onBeforeUnmount(() => {
|
|
66
|
+
completionProvider?.dispose()
|
|
67
|
+
const model = editor.value?.getModel()
|
|
68
|
+
editor.value?.dispose()
|
|
69
|
+
model?.dispose()
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
watch(value, text => {
|
|
73
|
+
if (editor.value && text !== editor.value.getValue()) editor.value.setValue(text)
|
|
74
|
+
})
|
|
75
|
+
watch(() => props.readOnly, readOnly => editor.value?.updateOptions({ readOnly }))
|
|
76
|
+
watch(() => props.language, language => {
|
|
77
|
+
const model = editor.value?.getModel()
|
|
78
|
+
if (monaco && model) monaco.editor.setModelLanguage(model, language)
|
|
79
|
+
registerCompletions()
|
|
80
|
+
})
|
|
81
|
+
watch(isDark, () => monaco?.editor.setTheme(theme()))
|
|
82
|
+
watch(() => props.completions, registerCompletions)
|
|
83
|
+
|
|
84
|
+
// Offers this editor's completions, only in this editor's model.
|
|
85
|
+
function registerCompletions() {
|
|
86
|
+
completionProvider?.dispose()
|
|
87
|
+
completionProvider = undefined
|
|
88
|
+
if (!monaco || !editor.value || props.completions.length === 0) return
|
|
89
|
+
const m = monaco
|
|
90
|
+
const kinds = {
|
|
91
|
+
keyword: m.languages.CompletionItemKind.Keyword, table: m.languages.CompletionItemKind.Class,
|
|
92
|
+
field: m.languages.CompletionItemKind.Field, function: m.languages.CompletionItemKind.Function,
|
|
93
|
+
value: m.languages.CompletionItemKind.Value, snippet: m.languages.CompletionItemKind.Snippet
|
|
94
|
+
}
|
|
95
|
+
const own = editor.value.getModel()
|
|
96
|
+
completionProvider = m.languages.registerCompletionItemProvider(props.language, {
|
|
97
|
+
provideCompletionItems(model, position) {
|
|
98
|
+
if (model !== own) return { suggestions: [] }
|
|
99
|
+
const word = model.getWordUntilPosition(position)
|
|
100
|
+
const range = { startLineNumber: position.lineNumber, endLineNumber: position.lineNumber, startColumn: word.startColumn, endColumn: word.endColumn }
|
|
101
|
+
return {
|
|
102
|
+
suggestions: props.completions.map(c => ({
|
|
103
|
+
label: c.label,
|
|
104
|
+
kind: kinds[c.kind ?? 'keyword'],
|
|
105
|
+
insertText: c.insertText ?? c.label,
|
|
106
|
+
detail: c.detail,
|
|
107
|
+
range
|
|
108
|
+
}))
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Focuses the editor.
|
|
115
|
+
function focus() {
|
|
116
|
+
editor.value?.focus()
|
|
117
|
+
}
|
|
118
|
+
defineExpose({ focus })
|
|
119
|
+
</script>
|
|
120
|
+
|
|
121
|
+
<template>
|
|
122
|
+
<div :class="['t-code-editor', { 't-code-editor-flush': flush }]">
|
|
123
|
+
<div ref="host" class="t-code-editor-host" />
|
|
124
|
+
<div v-if="loading" class="t-code-editor-loading">
|
|
125
|
+
<TSpinner size="sm" show-label label="Loading the editor…" />
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Switches between the light and dark themes.
|
|
3
|
+
import TButton from './TButton.vue'
|
|
4
|
+
import TTooltip from './TTooltip.vue'
|
|
5
|
+
import { useColorMode } from '../composables/useColorMode'
|
|
6
|
+
|
|
7
|
+
const { isDark, toggle } = useColorMode()
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<TTooltip :text="isDark ? 'Light theme' : 'Dark theme'">
|
|
12
|
+
<TButton :icon="isDark ? 'sun' : 'moon'" color="neutral" variant="ghost" :aria-label="isDark ? 'Use the light theme' : 'Use the dark theme'" @click="toggle" />
|
|
13
|
+
</TTooltip>
|
|
14
|
+
</template>
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A color field with Tabler's color picker (Coloris): a swatch of the color, the value as text, and
|
|
3
|
+
// a picker on focus. `format` is how the value is written (hex by default); `alpha` allows
|
|
4
|
+
// transparency; `swatches` offers preset colors, and `swatchesOnly` limits the choice to them.
|
|
5
|
+
// Coloris loads on first use.
|
|
6
|
+
import { computed, onBeforeUnmount, onMounted, watch } from 'vue'
|
|
7
|
+
import { useColorMode } from '../composables/useColorMode'
|
|
8
|
+
import { useField } from '../composables/useField'
|
|
9
|
+
import { loadColoris } from '../plugins/coloris'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
format?: 'hex' | 'rgb' | 'hsl' | 'auto' | 'mixed'
|
|
13
|
+
alpha?: boolean
|
|
14
|
+
swatches?: string[]
|
|
15
|
+
swatchesOnly?: boolean
|
|
16
|
+
placeholder?: string
|
|
17
|
+
size?: 'sm' | 'md' | 'lg'
|
|
18
|
+
disabled?: boolean
|
|
19
|
+
invalid?: boolean
|
|
20
|
+
id?: string
|
|
21
|
+
}>(), { format: 'hex', size: 'md' })
|
|
22
|
+
|
|
23
|
+
const model = defineModel<string | null | undefined>()
|
|
24
|
+
const field = useField(props)
|
|
25
|
+
const { isDark } = useColorMode()
|
|
26
|
+
let coloris: Awaited<ReturnType<typeof loadColoris>> | null = null
|
|
27
|
+
|
|
28
|
+
const selector = computed(() => `#${CSS.escape(field.id.value)}`)
|
|
29
|
+
|
|
30
|
+
function configure() {
|
|
31
|
+
coloris?.setInstance(selector.value, {
|
|
32
|
+
format: props.format,
|
|
33
|
+
alpha: props.alpha,
|
|
34
|
+
swatches: props.swatches ?? [],
|
|
35
|
+
swatchesOnly: props.swatchesOnly,
|
|
36
|
+
themeMode: isDark.value ? 'dark' : 'light'
|
|
37
|
+
})
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
onMounted(async () => {
|
|
41
|
+
coloris = await loadColoris()
|
|
42
|
+
// Coloris listens for fields by selector; ours are marked with a class and left unwrapped
|
|
43
|
+
// (wrapping would move the input out of Vue's hands), so the swatch here is our own.
|
|
44
|
+
coloris({ el: '.t-color-input', wrap: false, selectInput: false, theme: 'default' })
|
|
45
|
+
configure()
|
|
46
|
+
})
|
|
47
|
+
watch(() => [props.format, props.alpha, props.swatches, props.swatchesOnly, isDark.value], configure, { deep: true })
|
|
48
|
+
onBeforeUnmount(() => coloris?.removeInstance(selector.value))
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<template>
|
|
52
|
+
<div :class="['input-group t-color-picker', size !== 'md' && `input-group-${size}`]">
|
|
53
|
+
<span class="input-group-text p-1">
|
|
54
|
+
<span class="t-color-swatch" :style="{ background: model || 'transparent' }" />
|
|
55
|
+
</span>
|
|
56
|
+
<input :id="field.id.value" type="text" :value="model ?? ''" :placeholder="placeholder ?? (format === 'hex' ? '#3673d1' : '')"
|
|
57
|
+
:disabled="disabled" autocomplete="off" spellcheck="false" :aria-describedby="field.describedBy.value"
|
|
58
|
+
:class="['form-control t-color-input font-monospace', { 'is-invalid': field.invalid.value }]"
|
|
59
|
+
@input="model = ($event.target as HTMLInputElement).value">
|
|
60
|
+
</div>
|
|
61
|
+
</template>
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Search over pages and things, opened with Ctrl+K (⌘K on a Mac) or a TSearchButton: type to
|
|
3
|
+
// filter the groups' items by label, suffix and keywords; arrow keys move, Enter opens. An item
|
|
4
|
+
// goes to its `to` or runs its `onSelect`. Put one in the app's frame. v-model:open is optional
|
|
5
|
+
// (the state is shared with TSearchButton); watch it to load items when it opens.
|
|
6
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import { useRouter } from 'vue-router'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import TModal from './TModal.vue'
|
|
10
|
+
import { useCommandPalette } from '../composables/useCommandPalette'
|
|
11
|
+
import type { CommandGroup, CommandItem } from '../types'
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(defineProps<{
|
|
14
|
+
groups: CommandGroup[]
|
|
15
|
+
placeholder?: string
|
|
16
|
+
empty?: string
|
|
17
|
+
// Toggle it with Ctrl+K / ⌘K.
|
|
18
|
+
shortcut?: boolean
|
|
19
|
+
}>(), { placeholder: 'Search…', empty: 'No matches', shortcut: true })
|
|
20
|
+
|
|
21
|
+
const model = defineModel<boolean>('open', { default: false })
|
|
22
|
+
const { open, toggle } = useCommandPalette()
|
|
23
|
+
const router = useRouter()
|
|
24
|
+
|
|
25
|
+
const query = ref('')
|
|
26
|
+
const active = ref(0)
|
|
27
|
+
const input = ref<HTMLInputElement>()
|
|
28
|
+
const list = ref<HTMLElement>()
|
|
29
|
+
|
|
30
|
+
// The model and the shared state follow each other.
|
|
31
|
+
watch(open, value => { model.value = value })
|
|
32
|
+
watch(model, value => { open.value = value })
|
|
33
|
+
|
|
34
|
+
const matches = (item: CommandItem, term: string) =>
|
|
35
|
+
[item.label, item.suffix ?? '', ...(item.keywords ?? [])].some(text => text.toLowerCase().includes(term))
|
|
36
|
+
|
|
37
|
+
const shown = computed(() => {
|
|
38
|
+
const term = query.value.trim().toLowerCase()
|
|
39
|
+
return props.groups
|
|
40
|
+
.map(group => ({ ...group, items: term ? group.items.filter(item => matches(item, term)) : group.items }))
|
|
41
|
+
.filter(group => group.items.length)
|
|
42
|
+
})
|
|
43
|
+
const flat = computed(() => shown.value.flatMap(group => group.items))
|
|
44
|
+
|
|
45
|
+
watch(query, () => { active.value = 0 })
|
|
46
|
+
watch(open, value => { if (!value) query.value = '' })
|
|
47
|
+
|
|
48
|
+
function move(by: number) {
|
|
49
|
+
if (!flat.value.length) return
|
|
50
|
+
active.value = (active.value + by + flat.value.length) % flat.value.length
|
|
51
|
+
nextTick(() => list.value?.querySelector('.active')?.scrollIntoView({ block: 'nearest' }))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function choose(item: CommandItem | undefined) {
|
|
55
|
+
if (!item) return
|
|
56
|
+
open.value = false
|
|
57
|
+
if (item.onSelect) item.onSelect()
|
|
58
|
+
else if (item.to) router.push(item.to as never)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function key(event: KeyboardEvent) {
|
|
62
|
+
if (event.key === 'ArrowDown') { event.preventDefault(); move(1) }
|
|
63
|
+
else if (event.key === 'ArrowUp') { event.preventDefault(); move(-1) }
|
|
64
|
+
else if (event.key === 'Enter') { event.preventDefault(); choose(flat.value[active.value]) }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function shortcutKey(event: KeyboardEvent) {
|
|
68
|
+
if (props.shortcut && event.key.toLowerCase() === 'k' && (event.ctrlKey || event.metaKey) && !event.altKey && !event.shiftKey) {
|
|
69
|
+
event.preventDefault()
|
|
70
|
+
toggle()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
onMounted(() => window.addEventListener('keydown', shortcutKey))
|
|
74
|
+
onBeforeUnmount(() => window.removeEventListener('keydown', shortcutKey))
|
|
75
|
+
|
|
76
|
+
// Where each item sits in the flat list, for the highlight.
|
|
77
|
+
const indexOf = (item: CommandItem) => flat.value.indexOf(item)
|
|
78
|
+
</script>
|
|
79
|
+
|
|
80
|
+
<template>
|
|
81
|
+
<TModal v-model:open="open" position="top" size="lg" @after-enter="input?.focus()">
|
|
82
|
+
<div class="t-command">
|
|
83
|
+
<div class="input-icon">
|
|
84
|
+
<span class="input-icon-addon"><TIcon name="search" /></span>
|
|
85
|
+
<input ref="input" v-model="query" type="search" class="form-control form-control-lg border-0 shadow-none" :placeholder="placeholder"
|
|
86
|
+
role="combobox" aria-expanded="true" aria-controls="t-command-list" aria-autocomplete="list" :aria-label="placeholder" @keydown="key">
|
|
87
|
+
</div>
|
|
88
|
+
<div id="t-command-list" ref="list" class="t-command-list" role="listbox">
|
|
89
|
+
<template v-for="group in shown" :key="group.id">
|
|
90
|
+
<div v-if="group.label" class="t-command-group">{{ group.label }}</div>
|
|
91
|
+
<button v-for="item in group.items" :key="`${group.id}-${item.label}-${item.suffix ?? ''}`" type="button" role="option"
|
|
92
|
+
:aria-selected="indexOf(item) === active" :class="['t-command-item', { active: indexOf(item) === active }]"
|
|
93
|
+
@click="choose(item)" @mousemove="active = indexOf(item)">
|
|
94
|
+
<TIcon v-if="item.icon" :name="item.icon" class="text-secondary" />
|
|
95
|
+
<span class="text-truncate">{{ item.label }}</span>
|
|
96
|
+
<span v-if="item.suffix" class="small text-secondary text-truncate">{{ item.suffix }}</span>
|
|
97
|
+
<TIcon v-if="indexOf(item) === active" name="corner-down-left" class="ms-auto text-secondary" />
|
|
98
|
+
</button>
|
|
99
|
+
</template>
|
|
100
|
+
<p v-if="!flat.length" class="text-secondary text-center py-4 mb-0">{{ empty }}</p>
|
|
101
|
+
</div>
|
|
102
|
+
<div class="t-command-footer">
|
|
103
|
+
<span><kbd>↑</kbd> <kbd>↓</kbd> to move</span>
|
|
104
|
+
<span><kbd>Enter</kbd> to open</span>
|
|
105
|
+
<span><kbd>Esc</kbd> to close</span>
|
|
106
|
+
</div>
|
|
107
|
+
</div>
|
|
108
|
+
</TModal>
|
|
109
|
+
</template>
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Whether an application's page sits in a box, centered on wide screens with the background
|
|
3
|
+
// around it, or fills the width. Each tile is a sketch of the page.
|
|
4
|
+
import TRadioGroup from './TRadioGroup.vue'
|
|
5
|
+
import { themeContainers } from '../theme'
|
|
6
|
+
import type { ThemeContainer } from '../types'
|
|
7
|
+
|
|
8
|
+
defineProps<{ disabled?: boolean; legend?: string }>()
|
|
9
|
+
|
|
10
|
+
const model = defineModel<ThemeContainer | null | undefined>()
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<TRadioGroup v-model="model" :items="themeContainers" variant="tiles" tile-width="8rem" :disabled="disabled" :legend="legend">
|
|
15
|
+
<template #preview="{ item }">
|
|
16
|
+
<span :class="['t-sketch t-sketch-left', { 't-sketch-boxed': item.value === 'boxed' }]">
|
|
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,72 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Copies text with Tabler's clipboard plugin: the `text` given, or the value (or text) of the
|
|
3
|
+
// element `target` selects. It says "Copied" for a moment after. Without a label it's a square
|
|
4
|
+
// icon button; its tooltip carries the label. Emits `copied`, or `error` when the browser refuses
|
|
5
|
+
// (the clipboard needs https or localhost).
|
|
6
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import { Clipboard } from '@tabler/core'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import TTooltip from './TTooltip.vue'
|
|
10
|
+
import { toTabler, type Color, type Size } from '../types'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
text?: string
|
|
14
|
+
target?: string
|
|
15
|
+
label?: string
|
|
16
|
+
copiedLabel?: string
|
|
17
|
+
// Show only the icon.
|
|
18
|
+
iconOnly?: boolean
|
|
19
|
+
color?: Color
|
|
20
|
+
variant?: 'solid' | 'outline' | 'ghost' | 'soft'
|
|
21
|
+
size?: Size
|
|
22
|
+
delay?: number
|
|
23
|
+
}>(), { label: 'Copy', copiedLabel: 'Copied', color: 'neutral', variant: 'solid', size: 'md', delay: 2000 })
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits<{ copied: []; error: [] }>()
|
|
26
|
+
|
|
27
|
+
const button = ref<HTMLButtonElement>()
|
|
28
|
+
const copied = ref(false)
|
|
29
|
+
let clipboard: Clipboard | null = null
|
|
30
|
+
|
|
31
|
+
const classes = computed(() => {
|
|
32
|
+
const c = toTabler(props.color)
|
|
33
|
+
const look = props.variant === 'solid' ? (props.color === 'neutral' ? '' : `btn-${c}`)
|
|
34
|
+
: props.variant === 'soft' ? `btn-soft btn-soft-${c}` : `btn-${props.variant}-${c}`
|
|
35
|
+
return ['btn', look, {
|
|
36
|
+
'btn-xs': props.size === 'xs', 'btn-sm': props.size === 'sm', 'btn-lg': props.size === 'lg', 'btn-icon': props.iconOnly,
|
|
37
|
+
'btn-success': copied.value && props.variant === 'solid' && props.color === 'neutral'
|
|
38
|
+
}]
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
function create() {
|
|
42
|
+
clipboard?.dispose()
|
|
43
|
+
clipboard = new Clipboard(button.value!, { text: props.text ?? null, target: props.target ?? null, delay: props.delay })
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
onMounted(() => {
|
|
47
|
+
create()
|
|
48
|
+
button.value!.addEventListener('copied.bs.clipboard', () => {
|
|
49
|
+
copied.value = true
|
|
50
|
+
emit('copied')
|
|
51
|
+
setTimeout(() => { copied.value = false }, props.delay)
|
|
52
|
+
})
|
|
53
|
+
button.value!.addEventListener('error.bs.clipboard', () => emit('error'))
|
|
54
|
+
})
|
|
55
|
+
watch(() => [props.text, props.target, props.delay], create)
|
|
56
|
+
onBeforeUnmount(() => clipboard?.dispose())
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<template>
|
|
60
|
+
<TTooltip :text="iconOnly ? (copied ? copiedLabel : label) : undefined">
|
|
61
|
+
<button ref="button" type="button" :class="classes" :aria-label="iconOnly ? label : undefined" @click="clipboard?.copy()">
|
|
62
|
+
<span class="clipboard-label t-copy-part">
|
|
63
|
+
<TIcon name="copy" :class="{ 'me-2': !iconOnly }" />
|
|
64
|
+
<template v-if="!iconOnly">{{ label }}</template>
|
|
65
|
+
</span>
|
|
66
|
+
<span class="clipboard-feedback t-copy-part" hidden>
|
|
67
|
+
<TIcon name="check" :class="iconOnly ? 'text-success' : 'me-2'" />
|
|
68
|
+
<template v-if="!iconOnly">{{ copiedLabel }}</template>
|
|
69
|
+
</span>
|
|
70
|
+
</button>
|
|
71
|
+
</TTooltip>
|
|
72
|
+
</template>
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A date field with Tabler's date picker (Vanilla Calendar Pro underneath). Dates are `YYYY-MM-DD`
|
|
3
|
+
// strings: one for `single`, or an array for `multiple` and `range` (from and to). `inline` shows
|
|
4
|
+
// the calendar in place instead of a field. `format` is how dates show in the field ('DD.MM.YYYY',
|
|
5
|
+
// 'iso', …); the model keeps `YYYY-MM-DD`. The calendar loads on first use.
|
|
6
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import type { Datepicker } from '@tabler/core'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import { useField } from '../composables/useField'
|
|
10
|
+
import { loadDatepicker } from '../plugins/datepicker'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
mode?: 'single' | 'multiple' | 'range'
|
|
14
|
+
inline?: boolean
|
|
15
|
+
min?: string
|
|
16
|
+
max?: string
|
|
17
|
+
// Months shown side by side.
|
|
18
|
+
months?: number
|
|
19
|
+
// 0 for Sunday, 1 for Monday.
|
|
20
|
+
firstWeekday?: 0 | 1
|
|
21
|
+
weekNumbers?: boolean
|
|
22
|
+
format?: string
|
|
23
|
+
placeholder?: string
|
|
24
|
+
size?: 'sm' | 'md' | 'lg'
|
|
25
|
+
disabled?: boolean
|
|
26
|
+
invalid?: boolean
|
|
27
|
+
id?: string
|
|
28
|
+
}>(), { mode: 'single', months: 1, size: 'md' })
|
|
29
|
+
|
|
30
|
+
const model = defineModel<string | string[] | null | undefined>()
|
|
31
|
+
const field = useField(props)
|
|
32
|
+
const el = ref<HTMLElement>()
|
|
33
|
+
let picker: Datepicker | null = null
|
|
34
|
+
|
|
35
|
+
// Tabler types dates as `YYYY-MM-DD` template strings and months as 1 to 12; props are plain.
|
|
36
|
+
type IsoDate = `${number}-${string}-${string}`
|
|
37
|
+
type MonthsCount = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12
|
|
38
|
+
|
|
39
|
+
const dates = () => Array.isArray(model.value) ? model.value : model.value ? [model.value] : []
|
|
40
|
+
const same = (a: string[], b: string[]) => a.length === b.length && a.every((d, i) => d === b[i])
|
|
41
|
+
|
|
42
|
+
async function create() {
|
|
43
|
+
const DatepickerClass = await loadDatepicker()
|
|
44
|
+
if (!el.value) return
|
|
45
|
+
picker?.dispose()
|
|
46
|
+
picker = new DatepickerClass(el.value, {
|
|
47
|
+
selectionMode: props.mode === 'range' ? 'multiple-ranged' : props.mode,
|
|
48
|
+
inline: props.inline,
|
|
49
|
+
dateMin: (props.min ?? null) as IsoDate | null,
|
|
50
|
+
dateMax: (props.max ?? null) as IsoDate | null,
|
|
51
|
+
displayMonthsCount: props.months as MonthsCount,
|
|
52
|
+
...(props.firstWeekday != null ? { firstWeekday: props.firstWeekday } : {}),
|
|
53
|
+
weekNumbers: props.weekNumbers,
|
|
54
|
+
...(props.format ? { dateFormat: props.format } : {}),
|
|
55
|
+
selectedDates: dates()
|
|
56
|
+
})
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
onMounted(() => {
|
|
60
|
+
create()
|
|
61
|
+
el.value!.addEventListener('change.bs.datepicker', event => {
|
|
62
|
+
const picked = (event as Event & { dates: string[] }).dates ?? []
|
|
63
|
+
if (same(picked, dates())) return
|
|
64
|
+
model.value = props.mode === 'single' ? picked[0] ?? null : picked
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
watch(model, () => {
|
|
69
|
+
if (picker && !same(picker.getSelectedDates(), dates())) picker.setSelectedDates(dates())
|
|
70
|
+
}, { deep: true })
|
|
71
|
+
watch(() => [props.mode, props.inline, props.min, props.max, props.months, props.firstWeekday, props.weekNumbers, props.format], create, { flush: 'post' })
|
|
72
|
+
onBeforeUnmount(() => picker?.dispose())
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<template>
|
|
76
|
+
<div v-if="inline" ref="el" class="t-datepicker-inline" :aria-label="placeholder ?? 'Calendar'" />
|
|
77
|
+
<div v-else class="input-icon">
|
|
78
|
+
<span class="input-icon-addon"><TIcon name="calendar" /></span>
|
|
79
|
+
<input :id="field.id.value" ref="el" type="text" :placeholder="placeholder" :disabled="disabled" autocomplete="off"
|
|
80
|
+
:aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
|
|
81
|
+
:class="['form-control', size !== 'md' && `form-control-${size}`, { 'is-invalid': field.invalid.value }]">
|
|
82
|
+
</div>
|
|
83
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// How much room an application's content gets: padding inside cards, tables, buttons and fields,
|
|
3
|
+
// and the gaps between them. Each tile shows rows at that spacing.
|
|
4
|
+
import TRadioGroup from './TRadioGroup.vue'
|
|
5
|
+
import { themeDensities } from '../theme'
|
|
6
|
+
import type { ThemeDensity } from '../types'
|
|
7
|
+
|
|
8
|
+
defineProps<{ disabled?: boolean; legend?: string }>()
|
|
9
|
+
|
|
10
|
+
const model = defineModel<ThemeDensity | null | undefined>()
|
|
11
|
+
</script>
|
|
12
|
+
|
|
13
|
+
<template>
|
|
14
|
+
<TRadioGroup v-model="model" :items="themeDensities" variant="tiles" tile-width="8rem" :disabled="disabled" :legend="legend">
|
|
15
|
+
<template #preview="{ item }">
|
|
16
|
+
<span :class="['t-sketch-rows', `t-sketch-${item.value}`]"><span /><span /><span /><span /></span>
|
|
17
|
+
</template>
|
|
18
|
+
</TRadioGroup>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A menu under a button. Items come in groups (an array of arrays), split by dividers; an item is
|
|
3
|
+
// a link (`to`, `href`), an action (`onSelect`) or a `label` heading. The slot replaces the button.
|
|
4
|
+
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
|
|
5
|
+
import { RouterLink } from 'vue-router'
|
|
6
|
+
import { Dropdown } from '@tabler/core'
|
|
7
|
+
import TButton from './TButton.vue'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import { toTabler, type Color, type DropdownItem, type Size } from '../types'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
items: DropdownItem[] | DropdownItem[][]
|
|
13
|
+
align?: 'start' | 'end'
|
|
14
|
+
label?: string
|
|
15
|
+
icon?: string
|
|
16
|
+
color?: Color
|
|
17
|
+
variant?: 'solid' | 'outline' | 'ghost' | 'soft'
|
|
18
|
+
size?: Size
|
|
19
|
+
menuClass?: string
|
|
20
|
+
}>(), { align: 'start', color: 'neutral', variant: 'solid', size: 'md' })
|
|
21
|
+
|
|
22
|
+
const emit = defineEmits<{ 'update:open': [open: boolean] }>()
|
|
23
|
+
|
|
24
|
+
const toggle = ref<HTMLElement>()
|
|
25
|
+
let dropdown: Dropdown | null = null
|
|
26
|
+
|
|
27
|
+
const groups = computed(() => (Array.isArray(props.items[0]) ? props.items : [props.items]) as DropdownItem[][])
|
|
28
|
+
|
|
29
|
+
function tag(item: DropdownItem) {
|
|
30
|
+
return item.to && !item.disabled ? RouterLink : item.href ? 'a' : 'button'
|
|
31
|
+
}
|
|
32
|
+
function attrs(item: DropdownItem) {
|
|
33
|
+
if (item.to && !item.disabled) return { to: item.to }
|
|
34
|
+
if (item.href) return { href: item.disabled ? undefined : item.href }
|
|
35
|
+
return { type: 'button', disabled: item.disabled }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
onMounted(() => {
|
|
39
|
+
// A fixed popper escapes containers that clip (cards, tables, the sidebar).
|
|
40
|
+
dropdown = new Dropdown(toggle.value!, { popperConfig: (config: object) => ({ ...config, strategy: 'fixed' }) })
|
|
41
|
+
toggle.value!.addEventListener('show.bs.dropdown', () => emit('update:open', true))
|
|
42
|
+
toggle.value!.addEventListener('hide.bs.dropdown', () => emit('update:open', false))
|
|
43
|
+
})
|
|
44
|
+
onBeforeUnmount(() => dropdown?.dispose())
|
|
45
|
+
</script>
|
|
46
|
+
|
|
47
|
+
<template>
|
|
48
|
+
<div class="dropdown d-inline-flex">
|
|
49
|
+
<span ref="toggle" class="d-inline-flex" data-bs-toggle="dropdown" aria-haspopup="menu">
|
|
50
|
+
<slot>
|
|
51
|
+
<TButton :label="label" :icon="icon" :color="color" :variant="variant" :size="size" trailing-icon="chevron-down" />
|
|
52
|
+
</slot>
|
|
53
|
+
</span>
|
|
54
|
+
<div :class="['dropdown-menu', align === 'end' && 'dropdown-menu-end', menuClass]" role="menu">
|
|
55
|
+
<template v-for="(group, g) in groups" :key="g">
|
|
56
|
+
<div v-if="g > 0 && group.length" class="dropdown-divider" />
|
|
57
|
+
<template v-for="(item, i) in group" :key="`${g}-${i}`">
|
|
58
|
+
<div v-if="item.type === 'label'" class="dropdown-header d-block">
|
|
59
|
+
<div class="text-body fw-medium text-truncate">{{ item.label }}</div>
|
|
60
|
+
<div v-if="item.description" class="text-secondary text-truncate fw-normal">{{ item.description }}</div>
|
|
61
|
+
</div>
|
|
62
|
+
<component :is="tag(item)" v-else v-bind="attrs(item)" role="menuitem"
|
|
63
|
+
:class="['dropdown-item', { disabled: item.disabled }, item.color && `text-${toTabler(item.color)}`]"
|
|
64
|
+
@click="item.onSelect?.($event)">
|
|
65
|
+
<TIcon v-if="item.icon" :name="item.icon" class="dropdown-item-icon" />
|
|
66
|
+
<span class="min-w-0">
|
|
67
|
+
<span class="d-block text-truncate">{{ item.label }}</span>
|
|
68
|
+
<span v-if="item.description" class="d-block small text-secondary text-truncate">{{ item.description }}</span>
|
|
69
|
+
</span>
|
|
70
|
+
<TIcon v-if="item.trailingIcon" :name="item.trailingIcon" class="ms-auto ps-2" />
|
|
71
|
+
</component>
|
|
72
|
+
</template>
|
|
73
|
+
</template>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Tabler's file drop area (Dropzone): drop files or click to choose them, with previews. With a
|
|
3
|
+
// `url`, files upload there as they're added (`uploaded` or `error` follows each); without one,
|
|
4
|
+
// they're only collected, and v-model holds the accepted files for the form to send. `accept` is
|
|
5
|
+
// a list like "image/*,.pdf"; `maxFilesize` is in MB. Dropzone loads on first use.
|
|
6
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import type Dropzone from 'dropzone'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import { loadDropzone } from '../plugins/dropzone'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
url?: string
|
|
13
|
+
accept?: string
|
|
14
|
+
maxFiles?: number
|
|
15
|
+
maxFilesize?: number
|
|
16
|
+
paramName?: string
|
|
17
|
+
headers?: Record<string, string>
|
|
18
|
+
title?: string
|
|
19
|
+
hint?: string
|
|
20
|
+
}>(), { paramName: 'file', title: 'Drop files here or click to choose' })
|
|
21
|
+
|
|
22
|
+
const model = defineModel<File[]>({ default: () => [] })
|
|
23
|
+
const emit = defineEmits<{ uploaded: [file: File, response: unknown]; error: [file: File, message: string] }>()
|
|
24
|
+
|
|
25
|
+
const el = ref<HTMLElement>()
|
|
26
|
+
let dropzone: Dropzone | null = null
|
|
27
|
+
|
|
28
|
+
function sync() {
|
|
29
|
+
if (dropzone) model.value = dropzone.getAcceptedFiles()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onMounted(async () => {
|
|
33
|
+
const DropzoneClass = await loadDropzone()
|
|
34
|
+
if (!el.value) return
|
|
35
|
+
dropzone = new DropzoneClass(el.value, {
|
|
36
|
+
url: props.url ?? '/',
|
|
37
|
+
autoProcessQueue: !!props.url,
|
|
38
|
+
acceptedFiles: props.accept,
|
|
39
|
+
maxFiles: props.maxFiles,
|
|
40
|
+
maxFilesize: props.maxFilesize,
|
|
41
|
+
paramName: props.paramName,
|
|
42
|
+
headers: props.headers,
|
|
43
|
+
addRemoveLinks: true,
|
|
44
|
+
dictRemoveFile: 'Remove',
|
|
45
|
+
dictCancelUpload: 'Cancel',
|
|
46
|
+
dictInvalidFileType: 'This kind of file isn\'t allowed here.',
|
|
47
|
+
dictFileTooBig: 'The file is {{filesize}} MB; the limit is {{maxFilesize}} MB.',
|
|
48
|
+
dictMaxFilesExceeded: 'No more files can be added.'
|
|
49
|
+
})
|
|
50
|
+
// A file is accepted (or rejected) right after it's added.
|
|
51
|
+
dropzone.on('addedfile', () => setTimeout(sync))
|
|
52
|
+
dropzone.on('removedfile', sync)
|
|
53
|
+
dropzone.on('success', (file: File, response: unknown) => emit('uploaded', file, response))
|
|
54
|
+
dropzone.on('error', (file: File, message: string | { error?: string }) => {
|
|
55
|
+
emit('error', file, typeof message === 'string' ? message : message?.error ?? 'The file couldn\'t be added.')
|
|
56
|
+
sync()
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
// Clearing the model from outside clears the area.
|
|
61
|
+
watch(model, files => { if (dropzone && !files.length && dropzone.files.length) dropzone.removeAllFiles(true) })
|
|
62
|
+
onBeforeUnmount(() => dropzone?.destroy())
|
|
63
|
+
|
|
64
|
+
// Uploads the queued files, for a dropzone with a `url`.
|
|
65
|
+
defineExpose({ upload: () => dropzone?.processQueue() })
|
|
66
|
+
</script>
|
|
67
|
+
|
|
68
|
+
<template>
|
|
69
|
+
<div ref="el" class="dropzone t-dropzone">
|
|
70
|
+
<div class="dz-message">
|
|
71
|
+
<TIcon name="cloud-upload" class="d-block mx-auto mb-2 fs-1 text-secondary" />
|
|
72
|
+
<h3 class="dropzone-msg-title">{{ title }}</h3>
|
|
73
|
+
<span v-if="hint" class="dropzone-msg-desc text-secondary">{{ hint }}</span>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|