@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,92 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Choose files by dropping them on the area or clicking it, with no upload: v-model holds them
|
|
3
|
+
// (one File, or an array with `multiple`) for the page to read or send. Chosen files are listed
|
|
4
|
+
// under it with their size, and can be removed. `accept` limits the kinds (".txt,image/*"); files
|
|
5
|
+
// that don't match are left out, and `rejected` says which. For uploading with previews, see
|
|
6
|
+
// TDropzone.
|
|
7
|
+
import { computed, ref } from 'vue'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import { useField } from '../composables/useField'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
accept?: string
|
|
13
|
+
multiple?: boolean
|
|
14
|
+
label?: string
|
|
15
|
+
description?: string
|
|
16
|
+
icon?: string
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
invalid?: boolean
|
|
19
|
+
id?: string
|
|
20
|
+
}>(), { label: 'Drop a file here or click to choose', icon: 'upload' })
|
|
21
|
+
|
|
22
|
+
const model = defineModel<File | File[] | null | undefined>()
|
|
23
|
+
const emit = defineEmits<{ rejected: [files: File[]] }>()
|
|
24
|
+
const field = useField(props)
|
|
25
|
+
|
|
26
|
+
const input = ref<HTMLInputElement>()
|
|
27
|
+
const over = ref(false)
|
|
28
|
+
|
|
29
|
+
const files = computed<File[]>(() => Array.isArray(model.value) ? model.value : model.value ? [model.value] : [])
|
|
30
|
+
|
|
31
|
+
// Does the file match `accept`: extensions (".txt"), types ("text/plain") or families ("image/*").
|
|
32
|
+
function accepted(file: File) {
|
|
33
|
+
if (!props.accept) return true
|
|
34
|
+
return props.accept.split(',').map(a => a.trim().toLowerCase()).filter(Boolean).some(rule =>
|
|
35
|
+
rule.startsWith('.') ? file.name.toLowerCase().endsWith(rule)
|
|
36
|
+
: rule.endsWith('/*') ? file.type.toLowerCase().startsWith(rule.slice(0, -1))
|
|
37
|
+
: file.type.toLowerCase() === rule)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function add(list: FileList | null) {
|
|
41
|
+
if (!list?.length || props.disabled) return
|
|
42
|
+
const all = [...list]
|
|
43
|
+
const good = all.filter(accepted)
|
|
44
|
+
const bad = all.filter(f => !accepted(f))
|
|
45
|
+
if (bad.length) emit('rejected', bad)
|
|
46
|
+
if (!good.length) return
|
|
47
|
+
model.value = props.multiple ? [...files.value, ...good] : good[0]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function remove(file: File) {
|
|
51
|
+
model.value = props.multiple ? files.value.filter(f => f !== file) : null
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function drop(event: DragEvent) {
|
|
55
|
+
over.value = false
|
|
56
|
+
add(event.dataTransfer?.files ?? null)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function chosen() {
|
|
60
|
+
add(input.value!.files)
|
|
61
|
+
// The same file can be chosen again after it's removed.
|
|
62
|
+
input.value!.value = ''
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function size(bytes: number) {
|
|
66
|
+
if (bytes < 1024) return `${bytes} B`
|
|
67
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
|
|
68
|
+
return `${(bytes / 1024 / 1024).toFixed(1)} MB`
|
|
69
|
+
}
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<template>
|
|
73
|
+
<div class="t-file-upload">
|
|
74
|
+
<label :for="field.id.value" :class="['t-file-upload-area', { over, disabled, 'is-invalid': field.invalid.value }]"
|
|
75
|
+
@dragover.prevent="over = !disabled" @dragleave="over = false" @drop.prevent="drop">
|
|
76
|
+
<TIcon :name="icon" class="fs-2 text-secondary" />
|
|
77
|
+
<span class="fw-medium">{{ label }}</span>
|
|
78
|
+
<span v-if="description" class="small text-secondary">{{ description }}</span>
|
|
79
|
+
<input :id="field.id.value" ref="input" type="file" class="visually-hidden" :accept="accept" :multiple="multiple" :disabled="disabled"
|
|
80
|
+
:aria-describedby="field.describedBy.value" @change="chosen">
|
|
81
|
+
</label>
|
|
82
|
+
<ul v-if="files.length" class="list-group mt-2">
|
|
83
|
+
<li v-for="(file, i) in files" :key="`${i}-${file.name}`" class="list-group-item d-flex align-items-center gap-2 py-2">
|
|
84
|
+
<TIcon name="file" class="text-secondary" />
|
|
85
|
+
<span class="text-truncate">{{ file.name }}</span>
|
|
86
|
+
<span class="small text-secondary flex-shrink-0">{{ size(file.size) }}</span>
|
|
87
|
+
<button type="button" class="btn btn-ghost-secondary btn-icon btn-sm ms-auto" :aria-label="`Remove ${file.name}`" :disabled="disabled"
|
|
88
|
+
@click="remove(file)"><TIcon name="x" /></button>
|
|
89
|
+
</li>
|
|
90
|
+
</ul>
|
|
91
|
+
</div>
|
|
92
|
+
</template>
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A theme's font, as tiles showing "Aa" in each typeface. `fonts` limits the choices; Comic is left
|
|
3
|
+
// out unless asked for.
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
import TRadioGroup from './TRadioGroup.vue'
|
|
6
|
+
import { themeFonts } from '../theme'
|
|
7
|
+
import type { ThemeFont } from '../types'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{ fonts?: ThemeFont[]; disabled?: boolean; legend?: string }>(),
|
|
10
|
+
{ fonts: () => ['sans-serif', 'serif', 'monospace'] })
|
|
11
|
+
|
|
12
|
+
const model = defineModel<ThemeFont | null | undefined>()
|
|
13
|
+
const items = computed(() => themeFonts.filter(f => props.fonts.includes(f.value)))
|
|
14
|
+
const family = (font: ThemeFont) => `var(--tblr-font-${font})`
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<TRadioGroup v-model="model" :items="items" variant="tiles" :disabled="disabled" :legend="legend">
|
|
19
|
+
<template #preview="{ item }">
|
|
20
|
+
<span class="t-theme-font" :style="{ fontFamily: family(item.value as ThemeFont) }">Aa</span>
|
|
21
|
+
</template>
|
|
22
|
+
</TRadioGroup>
|
|
23
|
+
</template>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A labelled form field around one control (TInput, TSelect, …). The label points at the control;
|
|
3
|
+
// `hint` sits at the label's right, `description` under the control, and an error replaces it.
|
|
4
|
+
import { computed, useId } from 'vue'
|
|
5
|
+
import { provideField } from '../composables/useField'
|
|
6
|
+
|
|
7
|
+
const props = defineProps<{
|
|
8
|
+
label?: string
|
|
9
|
+
hint?: string
|
|
10
|
+
description?: string
|
|
11
|
+
// A message, or `true` to mark the control invalid without one.
|
|
12
|
+
error?: string | boolean
|
|
13
|
+
required?: boolean
|
|
14
|
+
id?: string
|
|
15
|
+
}>()
|
|
16
|
+
|
|
17
|
+
const generated = useId()
|
|
18
|
+
const id = computed(() => props.id ?? generated)
|
|
19
|
+
const message = computed(() => typeof props.error === 'string' && props.error ? props.error : null)
|
|
20
|
+
|
|
21
|
+
provideField({
|
|
22
|
+
id: id.value,
|
|
23
|
+
invalid: computed(() => !!props.error),
|
|
24
|
+
describedBy: computed(() => message.value || props.description ? `${id.value}-help` : undefined)
|
|
25
|
+
})
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<div>
|
|
30
|
+
<label v-if="label || $slots.label" :for="id" :class="['form-label', { required }]">
|
|
31
|
+
<slot name="label">{{ label }}</slot>
|
|
32
|
+
<span v-if="hint" class="form-label-description">{{ hint }}</span>
|
|
33
|
+
</label>
|
|
34
|
+
<slot />
|
|
35
|
+
<div v-if="message" :id="`${id}-help`" class="invalid-feedback d-block">{{ message }}</div>
|
|
36
|
+
<small v-else-if="description || $slots.description" :id="`${id}-help`" class="form-hint">
|
|
37
|
+
<slot name="description">{{ description }}</slot>
|
|
38
|
+
</small>
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A Tabler icon from the webfont, by name ("plus", "player-play"; a "ti-" prefix is allowed). It
|
|
3
|
+
// takes the size and color of the text around it. Browse names at https://tabler.io/icons.
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{ name: string; spin?: boolean }>()
|
|
7
|
+
const glyph = computed(() => 'ti-' + props.name.replace(/^ti-/, ''))
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<template>
|
|
11
|
+
<i :class="['ti', glyph, 'icon', { 'ti-spin': spin }]" aria-hidden="true" />
|
|
12
|
+
</template>
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// One image, such as a logo: drop it or click to choose, see it, replace or remove it. The image is
|
|
3
|
+
// checked before it's taken: its type (`accept`), that it's `square` when asked, and that its
|
|
4
|
+
// sides are between `minSize` and `maxSize` pixels. A refused image says why, under the area, and
|
|
5
|
+
// in a `rejected` event. v-model holds the File chosen, or the address of the current image (a
|
|
6
|
+
// string); nothing uploads.
|
|
7
|
+
import { computed, onBeforeUnmount, ref, watch } from 'vue'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import { useField } from '../composables/useField'
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
accept?: string
|
|
13
|
+
square?: boolean
|
|
14
|
+
minSize?: number
|
|
15
|
+
maxSize?: number
|
|
16
|
+
label?: string
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
invalid?: boolean
|
|
19
|
+
id?: string
|
|
20
|
+
}>(), { accept: 'image/png,image/jpeg,image/webp', label: 'Drop an image here or click to choose' })
|
|
21
|
+
|
|
22
|
+
const model = defineModel<File | string | null | undefined>()
|
|
23
|
+
const emit = defineEmits<{ rejected: [reason: string, file: File] }>()
|
|
24
|
+
const field = useField(props)
|
|
25
|
+
|
|
26
|
+
const input = ref<HTMLInputElement>()
|
|
27
|
+
const over = ref(false)
|
|
28
|
+
const problem = ref('')
|
|
29
|
+
const dimensions = ref<{ width: number; height: number } | null>(null)
|
|
30
|
+
|
|
31
|
+
// What the area shows: the chosen file through an object URL, or the address it was given.
|
|
32
|
+
const objectUrl = ref<string | null>(null)
|
|
33
|
+
watch(model, value => {
|
|
34
|
+
if (objectUrl.value) URL.revokeObjectURL(objectUrl.value)
|
|
35
|
+
objectUrl.value = value instanceof File ? URL.createObjectURL(value) : null
|
|
36
|
+
}, { immediate: true })
|
|
37
|
+
onBeforeUnmount(() => { if (objectUrl.value) URL.revokeObjectURL(objectUrl.value) })
|
|
38
|
+
const src = computed(() => objectUrl.value ?? (typeof model.value === 'string' ? model.value : null))
|
|
39
|
+
const chosenFile = computed(() => model.value instanceof File ? model.value : null)
|
|
40
|
+
|
|
41
|
+
const rules = computed(() => {
|
|
42
|
+
const parts: string[] = []
|
|
43
|
+
if (props.square) parts.push('Square')
|
|
44
|
+
if (props.minSize && props.maxSize) parts.push(`${props.minSize}×${props.minSize} to ${props.maxSize}×${props.maxSize} pixels`)
|
|
45
|
+
else if (props.minSize) parts.push(`at least ${props.minSize}×${props.minSize} pixels`)
|
|
46
|
+
else if (props.maxSize) parts.push(`at most ${props.maxSize}×${props.maxSize} pixels`)
|
|
47
|
+
const types = props.accept.split(',').map(t => t.trim().replace(/^image\//, '').replace(/^\./, '').toUpperCase()).filter(Boolean)
|
|
48
|
+
if (types.length) parts.push(types.join(', ').replace('JPEG', 'JPG'))
|
|
49
|
+
return parts.join(' · ')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
function accepted(file: File) {
|
|
53
|
+
return props.accept.split(',').map(a => a.trim().toLowerCase()).filter(Boolean).some(rule =>
|
|
54
|
+
rule.startsWith('.') ? file.name.toLowerCase().endsWith(rule)
|
|
55
|
+
: rule.endsWith('/*') ? file.type.toLowerCase().startsWith(rule.slice(0, -1))
|
|
56
|
+
: file.type.toLowerCase() === rule)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function measure(file: File) {
|
|
60
|
+
return new Promise<{ width: number; height: number } | null>(resolve => {
|
|
61
|
+
const url = URL.createObjectURL(file)
|
|
62
|
+
const image = new Image()
|
|
63
|
+
image.onload = () => { resolve({ width: image.naturalWidth, height: image.naturalHeight }); URL.revokeObjectURL(url) }
|
|
64
|
+
image.onerror = () => { resolve(null); URL.revokeObjectURL(url) }
|
|
65
|
+
image.src = url
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function refuse(reason: string, file: File) {
|
|
70
|
+
problem.value = reason
|
|
71
|
+
emit('rejected', reason, file)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async function take(file: File | undefined) {
|
|
75
|
+
if (!file || props.disabled) return
|
|
76
|
+
problem.value = ''
|
|
77
|
+
if (!accepted(file)) return refuse(`${file.name} isn't an image of a type this takes (${rules.value}).`, file)
|
|
78
|
+
const size = await measure(file)
|
|
79
|
+
if (!size) return refuse(`${file.name} couldn't be read as an image.`, file)
|
|
80
|
+
const { width, height } = size
|
|
81
|
+
if (props.square && width !== height) return refuse(`The image is ${width}×${height}; it must be square.`, file)
|
|
82
|
+
if (props.minSize && (width < props.minSize || height < props.minSize))
|
|
83
|
+
return refuse(`The image is ${width}×${height}; it must be at least ${props.minSize}×${props.minSize}.`, file)
|
|
84
|
+
if (props.maxSize && (width > props.maxSize || height > props.maxSize))
|
|
85
|
+
return refuse(`The image is ${width}×${height}; it must be at most ${props.maxSize}×${props.maxSize}.`, file)
|
|
86
|
+
dimensions.value = size
|
|
87
|
+
model.value = file
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function chosen() {
|
|
91
|
+
take(input.value!.files?.[0])
|
|
92
|
+
// The same file can be chosen again after it's removed.
|
|
93
|
+
input.value!.value = ''
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function drop(event: DragEvent) {
|
|
97
|
+
over.value = false
|
|
98
|
+
take(event.dataTransfer?.files?.[0])
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function remove() {
|
|
102
|
+
model.value = null
|
|
103
|
+
dimensions.value = null
|
|
104
|
+
problem.value = ''
|
|
105
|
+
}
|
|
106
|
+
</script>
|
|
107
|
+
|
|
108
|
+
<template>
|
|
109
|
+
<div class="t-image-upload">
|
|
110
|
+
<label :for="field.id.value" :class="['t-file-upload-area t-image-upload-area', { over, disabled, 'is-invalid': field.invalid.value || !!problem }]"
|
|
111
|
+
@dragover.prevent="over = !disabled" @dragleave="over = false" @drop.prevent="drop">
|
|
112
|
+
<span :class="['t-image-upload-preview', { square }]">
|
|
113
|
+
<img v-if="src" :src="src" alt="">
|
|
114
|
+
<TIcon v-else name="photo" class="fs-1 text-secondary" />
|
|
115
|
+
</span>
|
|
116
|
+
<span class="d-flex flex-column align-items-start text-start gap-1 min-w-0">
|
|
117
|
+
<span class="fw-medium">{{ src ? 'Drop or click to replace' : label }}</span>
|
|
118
|
+
<span class="small text-secondary">{{ rules }}</span>
|
|
119
|
+
<span v-if="chosenFile" class="small text-secondary text-truncate mw-100">
|
|
120
|
+
{{ chosenFile.name }}<template v-if="dimensions"> · {{ dimensions.width }}×{{ dimensions.height }}</template>
|
|
121
|
+
</span>
|
|
122
|
+
</span>
|
|
123
|
+
<input :id="field.id.value" ref="input" type="file" class="visually-hidden" :accept="accept" :disabled="disabled"
|
|
124
|
+
:aria-describedby="field.describedBy.value" @change="chosen">
|
|
125
|
+
</label>
|
|
126
|
+
<div v-if="problem" class="invalid-feedback d-block" role="alert">{{ problem }}</div>
|
|
127
|
+
<button v-if="src && !disabled" type="button" class="btn btn-link btn-sm px-0 text-danger" @click="remove">
|
|
128
|
+
<TIcon name="trash" class="me-1" />Remove image
|
|
129
|
+
</button>
|
|
130
|
+
</div>
|
|
131
|
+
</template>
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A text input. Attributes (name, autocomplete, min, …) go to the <input>. `type="number"` gives
|
|
3
|
+
// back numbers, and null when it's empty. Icons sit inside the input; the `trailing` slot can hold
|
|
4
|
+
// a small button. `autofocus` focuses it when it appears (the HTML attribute only works on page load).
|
|
5
|
+
import { computed, onMounted, ref } from 'vue'
|
|
6
|
+
import TIcon from './TIcon.vue'
|
|
7
|
+
import { useField } from '../composables/useField'
|
|
8
|
+
|
|
9
|
+
defineOptions({ inheritAttrs: false })
|
|
10
|
+
|
|
11
|
+
const props = withDefaults(defineProps<{
|
|
12
|
+
type?: string
|
|
13
|
+
placeholder?: string
|
|
14
|
+
icon?: string
|
|
15
|
+
trailingIcon?: string
|
|
16
|
+
size?: 'sm' | 'md' | 'lg'
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
readonly?: boolean
|
|
19
|
+
invalid?: boolean
|
|
20
|
+
autofocus?: boolean
|
|
21
|
+
id?: string
|
|
22
|
+
}>(), { type: 'text', size: 'md' })
|
|
23
|
+
|
|
24
|
+
const model = defineModel<string | number | null | undefined>()
|
|
25
|
+
const field = useField(props)
|
|
26
|
+
const el = ref<HTMLInputElement>()
|
|
27
|
+
|
|
28
|
+
onMounted(() => { if (props.autofocus) el.value?.focus() })
|
|
29
|
+
|
|
30
|
+
const value = computed(() => model.value ?? '')
|
|
31
|
+
|
|
32
|
+
function input(event: Event) {
|
|
33
|
+
const raw = (event.target as HTMLInputElement).value
|
|
34
|
+
model.value = props.type === 'number' ? (raw === '' ? null : Number(raw)) : raw
|
|
35
|
+
}
|
|
36
|
+
</script>
|
|
37
|
+
|
|
38
|
+
<template>
|
|
39
|
+
<div :class="{ 'input-icon': icon || trailingIcon || $slots.trailing }">
|
|
40
|
+
<span v-if="icon" class="input-icon-addon">
|
|
41
|
+
<TIcon :name="icon" />
|
|
42
|
+
</span>
|
|
43
|
+
<input v-bind="$attrs" :id="field.id.value" ref="el" :type="type" :value="value" :placeholder="placeholder" :disabled="disabled" :readonly="readonly"
|
|
44
|
+
:aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
|
|
45
|
+
:class="['form-control', size !== 'md' && `form-control-${size}`, { 'is-invalid': field.invalid.value }]" @input="input">
|
|
46
|
+
<span v-if="trailingIcon || $slots.trailing" class="input-icon-addon" :style="$slots.trailing ? { pointerEvents: 'auto' } : undefined">
|
|
47
|
+
<slot name="trailing">
|
|
48
|
+
<TIcon :name="trailingIcon!" />
|
|
49
|
+
</slot>
|
|
50
|
+
</span>
|
|
51
|
+
</div>
|
|
52
|
+
</template>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A text input that follows a pattern, with Tabler's input mask (IMask): `0` is a digit, `a` a
|
|
3
|
+
// letter, `*` either, and other characters are written for you, as in "(000) 000-0000".
|
|
4
|
+
// `showMask` shows the pattern before typing. v-model is the text as shown, or with `unmasked`,
|
|
5
|
+
// only what was typed. IMask loads on first use.
|
|
6
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import type { InputMask } from '@tabler/core'
|
|
8
|
+
import TIcon from './TIcon.vue'
|
|
9
|
+
import { useField } from '../composables/useField'
|
|
10
|
+
import { loadInputMask } from '../plugins/inputMask'
|
|
11
|
+
|
|
12
|
+
type Mask = { value: string; unmaskedValue: string; on(event: 'accept', handler: () => void): void }
|
|
13
|
+
|
|
14
|
+
const props = withDefaults(defineProps<{
|
|
15
|
+
mask: string
|
|
16
|
+
unmasked?: boolean
|
|
17
|
+
showMask?: boolean
|
|
18
|
+
placeholder?: string
|
|
19
|
+
icon?: string
|
|
20
|
+
size?: 'sm' | 'md' | 'lg'
|
|
21
|
+
disabled?: boolean
|
|
22
|
+
invalid?: boolean
|
|
23
|
+
id?: string
|
|
24
|
+
}>(), { size: 'md' })
|
|
25
|
+
|
|
26
|
+
const model = defineModel<string | null | undefined>()
|
|
27
|
+
const field = useField(props)
|
|
28
|
+
const input = ref<HTMLInputElement>()
|
|
29
|
+
let instance: InputMask | null = null
|
|
30
|
+
|
|
31
|
+
const mask = () => (instance as unknown as { mask: Mask | null } | null)?.mask ?? null
|
|
32
|
+
const current = () => props.unmasked ? mask()?.unmaskedValue : mask()?.value
|
|
33
|
+
|
|
34
|
+
function write(value: string) {
|
|
35
|
+
const m = mask()
|
|
36
|
+
if (!m) return
|
|
37
|
+
if (props.unmasked) m.unmaskedValue = value
|
|
38
|
+
else m.value = value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function create() {
|
|
42
|
+
const InputMaskClass = await loadInputMask()
|
|
43
|
+
if (!input.value) return
|
|
44
|
+
instance?.dispose()
|
|
45
|
+
instance = new InputMaskClass(input.value, { mask: props.mask, lazy: !props.showMask })
|
|
46
|
+
write(model.value ?? '')
|
|
47
|
+
mask()?.on('accept', () => {
|
|
48
|
+
const value = current() ?? ''
|
|
49
|
+
if (value !== (model.value ?? '')) model.value = value
|
|
50
|
+
})
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
onMounted(() => {
|
|
54
|
+
// Shown as is until IMask takes over.
|
|
55
|
+
if (input.value) input.value.value = model.value ?? ''
|
|
56
|
+
create()
|
|
57
|
+
})
|
|
58
|
+
watch(model, value => { if (mask() && (value ?? '') !== current()) write(value ?? '') })
|
|
59
|
+
watch(() => [props.mask, props.showMask, props.unmasked], create)
|
|
60
|
+
onBeforeUnmount(() => instance?.dispose())
|
|
61
|
+
</script>
|
|
62
|
+
|
|
63
|
+
<template>
|
|
64
|
+
<div :class="{ 'input-icon': icon }">
|
|
65
|
+
<span v-if="icon" class="input-icon-addon"><TIcon :name="icon" /></span>
|
|
66
|
+
<input :id="field.id.value" ref="input" type="text" :placeholder="placeholder" :disabled="disabled" autocomplete="off"
|
|
67
|
+
:aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
|
|
68
|
+
:class="['form-control', size !== 'md' && `form-control-${size}`, { 'is-invalid': field.invalid.value }]">
|
|
69
|
+
</div>
|
|
70
|
+
</template>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A number field with minus and plus buttons, on Tabler's number input: the buttons (held down,
|
|
3
|
+
// they repeat), the arrow keys, Home and End all step within `min` and `max`, rounded to `step`.
|
|
4
|
+
// v-model is a number, or null when the field is empty.
|
|
5
|
+
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
6
|
+
import { NumberInput } from '@tabler/core'
|
|
7
|
+
import TIcon from './TIcon.vue'
|
|
8
|
+
import { useField } from '../composables/useField'
|
|
9
|
+
|
|
10
|
+
const props = withDefaults(defineProps<{
|
|
11
|
+
min?: number
|
|
12
|
+
max?: number
|
|
13
|
+
step?: number
|
|
14
|
+
placeholder?: string
|
|
15
|
+
size?: 'sm' | 'md' | 'lg'
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
invalid?: boolean
|
|
18
|
+
id?: string
|
|
19
|
+
}>(), { size: 'md' })
|
|
20
|
+
|
|
21
|
+
const model = defineModel<number | null | undefined>()
|
|
22
|
+
const field = useField(props)
|
|
23
|
+
const wrapper = ref<HTMLElement>()
|
|
24
|
+
const input = ref<HTMLInputElement>()
|
|
25
|
+
let numberInput: NumberInput | null = null
|
|
26
|
+
|
|
27
|
+
const text = (value: number | null | undefined) => value == null ? '' : String(value)
|
|
28
|
+
|
|
29
|
+
function create() {
|
|
30
|
+
numberInput?.dispose()
|
|
31
|
+
numberInput = new NumberInput(wrapper.value!, { min: props.min ?? null, max: props.max ?? null, step: props.step ?? null })
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Typing, the buttons and the keys all end in the input's own input event.
|
|
35
|
+
function read() {
|
|
36
|
+
const raw = input.value!.value.trim()
|
|
37
|
+
const value = raw === '' || isNaN(Number(raw)) ? null : Number(raw)
|
|
38
|
+
if (value !== (model.value ?? null)) model.value = value
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onMounted(() => {
|
|
42
|
+
input.value!.value = text(model.value)
|
|
43
|
+
create()
|
|
44
|
+
})
|
|
45
|
+
watch(model, value => { if (input.value && input.value.value !== text(value) && Number(input.value.value) !== value) input.value.value = text(value) })
|
|
46
|
+
watch(() => [props.min, props.max, props.step], create)
|
|
47
|
+
onBeforeUnmount(() => numberInput?.dispose())
|
|
48
|
+
</script>
|
|
49
|
+
|
|
50
|
+
<template>
|
|
51
|
+
<div ref="wrapper" :class="['number-input', size !== 'md' && `number-input-${size}`]">
|
|
52
|
+
<button type="button" class="btn btn-icon" data-bs-number-input-action="decrement" aria-label="Decrease" :disabled="disabled">
|
|
53
|
+
<TIcon name="minus" />
|
|
54
|
+
</button>
|
|
55
|
+
<input :id="field.id.value" ref="input" type="text" inputmode="decimal" :placeholder="placeholder" :disabled="disabled" autocomplete="off"
|
|
56
|
+
:aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
|
|
57
|
+
:class="['form-control', size !== 'md' && `form-control-${size}`, { 'is-invalid': field.invalid.value }]" @input="read">
|
|
58
|
+
<button type="button" class="btn btn-icon" data-bs-number-input-action="increment" aria-label="Increase" :disabled="disabled">
|
|
59
|
+
<TIcon name="plus" />
|
|
60
|
+
</button>
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A list of short values typed one at a time: Enter or a comma adds one, Backspace in the empty
|
|
3
|
+
// box removes the last. The model is an array of strings.
|
|
4
|
+
import { ref } from 'vue'
|
|
5
|
+
import { useField } from '../composables/useField'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
placeholder?: string
|
|
9
|
+
size?: 'sm' | 'md' | 'lg'
|
|
10
|
+
disabled?: boolean
|
|
11
|
+
invalid?: boolean
|
|
12
|
+
// Allow the same value twice.
|
|
13
|
+
duplicates?: boolean
|
|
14
|
+
id?: string
|
|
15
|
+
}>(), { size: 'md' })
|
|
16
|
+
|
|
17
|
+
const model = defineModel<string[]>({ default: () => [] })
|
|
18
|
+
const field = useField(props)
|
|
19
|
+
const input = ref<HTMLInputElement>()
|
|
20
|
+
const draft = ref('')
|
|
21
|
+
|
|
22
|
+
function add() {
|
|
23
|
+
const value = draft.value.trim()
|
|
24
|
+
draft.value = ''
|
|
25
|
+
if (!value || (!props.duplicates && model.value.includes(value))) return
|
|
26
|
+
model.value = [...model.value, value]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function remove(index: number) {
|
|
30
|
+
model.value = model.value.filter((_, i) => i !== index)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function key(event: KeyboardEvent) {
|
|
34
|
+
if (event.key === 'Enter' || event.key === ',') {
|
|
35
|
+
event.preventDefault()
|
|
36
|
+
add()
|
|
37
|
+
} else if (event.key === 'Backspace' && !draft.value && model.value.length) {
|
|
38
|
+
remove(model.value.length - 1)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
</script>
|
|
42
|
+
|
|
43
|
+
<template>
|
|
44
|
+
<div :class="['form-control t-tags', size !== 'md' && `form-control-${size}`, { 'is-invalid': field.invalid.value, disabled }]"
|
|
45
|
+
@click="input?.focus()">
|
|
46
|
+
<span v-for="(tag, i) in model" :key="`${i}-${tag}`" class="badge bg-secondary-lt t-tag">
|
|
47
|
+
{{ tag }}
|
|
48
|
+
<button v-if="!disabled" type="button" class="btn-close" :aria-label="`Remove ${tag}`" @click.stop="remove(i)" />
|
|
49
|
+
</span>
|
|
50
|
+
<input :id="field.id.value" ref="input" v-model="draft" class="t-tags-input" :disabled="disabled"
|
|
51
|
+
:placeholder="model.length ? '' : placeholder" :aria-describedby="field.describedBy.value" @keydown="key" @blur="add">
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// Log output: either one block of `text` (a build log) or `lines` with times and levels (an app's
|
|
3
|
+
// output). It follows the end as output arrives, unless the reader scrolls up, which turns
|
|
4
|
+
// v-model:follow off; scrolling back to the end turns it on again. `fill` takes the height it's
|
|
5
|
+
// given instead of a capped scroll box.
|
|
6
|
+
import { nextTick, ref, watch } from 'vue'
|
|
7
|
+
import type { LogLine } from '../types'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{ text?: string; lines?: LogLine[]; fill?: boolean; maxHeight?: string; empty?: string }>(),
|
|
10
|
+
{ maxHeight: '20rem', empty: 'No output yet.' })
|
|
11
|
+
|
|
12
|
+
const follow = defineModel<boolean>('follow', { default: true })
|
|
13
|
+
const box = ref<HTMLElement>()
|
|
14
|
+
|
|
15
|
+
const levels = { error: 'text-danger', warning: 'text-warning', highlight: 'text-primary', muted: 'text-secondary' }
|
|
16
|
+
|
|
17
|
+
function toEnd() {
|
|
18
|
+
if (box.value) box.value.scrollTop = box.value.scrollHeight
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function scrolled() {
|
|
22
|
+
if (!box.value) return
|
|
23
|
+
follow.value = box.value.scrollHeight - box.value.scrollTop - box.value.clientHeight < 24
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
watch(() => [props.text, props.lines?.length, props.lines?.at(-1)], () => { if (follow.value) nextTick(toEnd) }, { immediate: true })
|
|
27
|
+
watch(follow, value => { if (value) nextTick(toEnd) })
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<pre v-if="!lines" ref="box" :class="['t-log', { 't-fill': fill }]" :style="fill ? undefined : { maxHeight }" @scroll="scrolled">{{ text || empty }}</pre>
|
|
32
|
+
<div v-else ref="box" :class="['t-log', { 't-fill': fill }]" :style="fill ? undefined : { maxHeight }" role="log" @scroll="scrolled">
|
|
33
|
+
<p v-if="!lines.length" class="text-secondary m-0">{{ empty }}</p>
|
|
34
|
+
<div v-for="(line, i) in lines" :key="line.id ?? i" class="t-log-line">
|
|
35
|
+
<span v-if="line.time" class="t-log-time">{{ line.time }}</span>
|
|
36
|
+
<span :class="line.level && levels[line.level]">{{ line.text }}</span>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
</template>
|
|
@@ -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>
|