@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,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A theme's accent color: Tabler's named colors as swatches (its color input). With `custom`, a
|
|
3
|
+
// last swatch picks any color (#rrggbb) with the browser's color picker; it shows the custom color
|
|
4
|
+
// while one is chosen. The `custom` slot goes after the swatches, for another picker.
|
|
5
|
+
import { computed, useId } from 'vue'
|
|
6
|
+
import TIcon from './TIcon.vue'
|
|
7
|
+
import { isCustomAccent, themeAccents } from '../theme'
|
|
8
|
+
import type { ThemeAccent } from '../types'
|
|
9
|
+
|
|
10
|
+
defineProps<{ custom?: boolean; disabled?: boolean; legend?: string }>()
|
|
11
|
+
|
|
12
|
+
const model = defineModel<ThemeAccent | null | undefined>()
|
|
13
|
+
const name = useId()
|
|
14
|
+
const customColor = computed(() => isCustomAccent(model.value ?? undefined) ? model.value! : null)
|
|
15
|
+
const label = (color: string) => color[0].toUpperCase() + color.slice(1)
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<template>
|
|
19
|
+
<div role="radiogroup" :aria-label="legend ?? 'Accent color'">
|
|
20
|
+
<div v-if="legend" class="form-label">{{ legend }}</div>
|
|
21
|
+
<div class="t-accent-swatches align-items-center">
|
|
22
|
+
<label v-for="color in themeAccents" :key="color" class="form-colorinput" :title="label(color)">
|
|
23
|
+
<input type="radio" :name="name" :value="color" class="form-colorinput-input" :checked="model === color" :disabled="disabled"
|
|
24
|
+
:aria-label="label(color)" @change="model = color">
|
|
25
|
+
<span :class="['form-colorinput-color', `bg-${color}`]" />
|
|
26
|
+
</label>
|
|
27
|
+
<label v-if="custom" :class="['form-colorinput t-accent-custom', { active: customColor }]" :title="customColor ? `Custom: ${customColor}` : 'Custom color'">
|
|
28
|
+
<input type="color" class="t-accent-custom-input" :value="customColor ?? '#3673d1'" :disabled="disabled" aria-label="Custom color"
|
|
29
|
+
@input="model = ($event.target as HTMLInputElement).value">
|
|
30
|
+
<span class="form-colorinput-color d-flex align-items-center justify-content-center" :style="customColor ? { background: customColor } : undefined">
|
|
31
|
+
<TIcon :name="customColor ? 'check' : 'color-picker'" :class="customColor ? 'text-white' : 'text-secondary'" />
|
|
32
|
+
</span>
|
|
33
|
+
</label>
|
|
34
|
+
<label v-else-if="customColor" class="form-colorinput" :title="customColor">
|
|
35
|
+
<input type="radio" :name="name" class="form-colorinput-input" checked :disabled="disabled" :aria-label="`Custom: ${customColor}`">
|
|
36
|
+
<span class="form-colorinput-color" :style="{ background: customColor }" />
|
|
37
|
+
</label>
|
|
38
|
+
<slot name="custom" />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T">
|
|
2
|
+
// Tabler's advanced select (Tom Select): type to filter, pick one or several (`multiple`, shown as
|
|
3
|
+
// removable chips), and with `create`, add values that aren't in the list. Items are values or
|
|
4
|
+
// { label, value, description, icon, avatar } objects; an icon or avatar initials show beside the
|
|
5
|
+
// label. Values keep their type; created values are strings. Tom Select loads on first use.
|
|
6
|
+
import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
|
7
|
+
import type TomSelect from 'tom-select'
|
|
8
|
+
import { useField } from '../composables/useField'
|
|
9
|
+
import { loadTomSelect } from '../plugins/tomSelect'
|
|
10
|
+
import type { AdvancedSelectItem } from '../types'
|
|
11
|
+
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
items: (T | AdvancedSelectItem<T>)[]
|
|
14
|
+
multiple?: boolean
|
|
15
|
+
// Allow values that aren't in the list.
|
|
16
|
+
create?: boolean
|
|
17
|
+
maxItems?: number
|
|
18
|
+
placeholder?: string
|
|
19
|
+
size?: 'sm' | 'md' | 'lg'
|
|
20
|
+
disabled?: boolean
|
|
21
|
+
invalid?: boolean
|
|
22
|
+
id?: string
|
|
23
|
+
}>(), { size: 'md' })
|
|
24
|
+
|
|
25
|
+
const model = defineModel<T | string | (T | string)[] | null | undefined>()
|
|
26
|
+
const field = useField(props)
|
|
27
|
+
const select = ref<HTMLSelectElement>()
|
|
28
|
+
let tom: TomSelect | null = null
|
|
29
|
+
let syncing = false
|
|
30
|
+
|
|
31
|
+
const isItem = (item: unknown): item is AdvancedSelectItem<T> =>
|
|
32
|
+
typeof item === 'object' && item !== null && 'label' in item && 'value' in item
|
|
33
|
+
const options = computed<AdvancedSelectItem<T>[]>(() =>
|
|
34
|
+
props.items.map(item => isItem(item) ? item : { label: String(item), value: item as T }))
|
|
35
|
+
|
|
36
|
+
// Tom Select works with string keys: an item's position, or "+" and the text of a created value.
|
|
37
|
+
const keyOf = (value: unknown) => {
|
|
38
|
+
const index = options.value.findIndex(o => o.value === value)
|
|
39
|
+
return index >= 0 ? String(index) : value == null ? null : `+${value}`
|
|
40
|
+
}
|
|
41
|
+
const valueOf = (key: string): T | string => key.startsWith('+') ? key.slice(1) : options.value[Number(key)].value
|
|
42
|
+
|
|
43
|
+
const keys = () => {
|
|
44
|
+
const value = model.value
|
|
45
|
+
const list = props.multiple ? (Array.isArray(value) ? value : []) : value == null ? [] : [value]
|
|
46
|
+
return list.map(keyOf).filter((k): k is string => k !== null)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const tomOptions = () => options.value.map((o, i) => ({
|
|
50
|
+
key: String(i), label: o.label, description: o.description ?? '', icon: o.icon ?? '', avatar: o.avatar ?? '', disabled: !!o.disabled, optgroup: o.group
|
|
51
|
+
}))
|
|
52
|
+
|
|
53
|
+
function escape(text: string) {
|
|
54
|
+
return text.replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]!)
|
|
55
|
+
}
|
|
56
|
+
function render(data: { label: string; description?: string; icon?: string; avatar?: string }, withDescription: boolean) {
|
|
57
|
+
const lead = data.icon ? `<i class="ti ti-${escape(data.icon)} icon me-2 text-secondary"></i>`
|
|
58
|
+
: data.avatar ? `<span class="avatar avatar-xs rounded-circle bg-primary-lt me-2">${escape(data.avatar)}</span>` : ''
|
|
59
|
+
const description = withDescription && data.description ? `<div class="small text-secondary">${escape(data.description)}</div>` : ''
|
|
60
|
+
return `<div class="d-flex align-items-center">${lead}<div>${escape(data.label)}${description}</div></div>`
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
onMounted(async () => {
|
|
64
|
+
const TomSelectClass = await loadTomSelect()
|
|
65
|
+
if (!select.value) return
|
|
66
|
+
const groups = [...new Set(options.value.map(o => o.group).filter(Boolean))] as string[]
|
|
67
|
+
tom = new TomSelectClass(select.value, {
|
|
68
|
+
valueField: 'key',
|
|
69
|
+
labelField: 'label',
|
|
70
|
+
searchField: ['label', 'description'],
|
|
71
|
+
options: tomOptions(),
|
|
72
|
+
optgroups: groups.map(g => ({ value: g, label: g })),
|
|
73
|
+
optgroupField: 'optgroup',
|
|
74
|
+
items: keys(),
|
|
75
|
+
maxItems: props.multiple ? (props.maxItems ?? null) : 1,
|
|
76
|
+
// Tom Select's typings expect a callback form; returning the new option works too.
|
|
77
|
+
create: props.create ? ((input: string) => ({ key: `+${input}`, label: input })) as never : false,
|
|
78
|
+
placeholder: props.placeholder,
|
|
79
|
+
copyClassesToDropdown: false,
|
|
80
|
+
dropdownParent: 'body',
|
|
81
|
+
plugins: props.multiple ? ['remove_button'] : [],
|
|
82
|
+
render: {
|
|
83
|
+
option: (data: never) => render(data, true),
|
|
84
|
+
item: (data: never) => render(data, false),
|
|
85
|
+
option_create: (data: { input: string }) => `<div class="create">Add <strong>${escape(data.input)}</strong>…</div>`,
|
|
86
|
+
no_results: () => '<div class="no-results">No matches</div>'
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
if (props.disabled) tom.disable()
|
|
90
|
+
tom.on('change', () => {
|
|
91
|
+
if (syncing || !tom) return
|
|
92
|
+
const value = tom.getValue()
|
|
93
|
+
const list = (Array.isArray(value) ? value : value ? [value] : []).map(valueOf)
|
|
94
|
+
model.value = props.multiple ? list : list[0] ?? null
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
// Changes from outside: new items, a new value, enabled or not.
|
|
99
|
+
watch(options, async () => {
|
|
100
|
+
if (!tom) return
|
|
101
|
+
syncing = true
|
|
102
|
+
tom.clearOptions()
|
|
103
|
+
tom.addOptions(tomOptions())
|
|
104
|
+
tom.setValue(keys(), true)
|
|
105
|
+
syncing = false
|
|
106
|
+
}, { deep: true })
|
|
107
|
+
watch(model, () => {
|
|
108
|
+
if (!tom) return
|
|
109
|
+
const current = tom.getValue()
|
|
110
|
+
const next = keys()
|
|
111
|
+
if (JSON.stringify(Array.isArray(current) ? current : current ? [current] : []) === JSON.stringify(next)) return
|
|
112
|
+
syncing = true
|
|
113
|
+
for (const key of next) if (key.startsWith('+') && !tom.options[key]) tom.addOption({ key, label: key.slice(1) })
|
|
114
|
+
tom.setValue(next, true)
|
|
115
|
+
syncing = false
|
|
116
|
+
}, { deep: true })
|
|
117
|
+
watch(() => props.disabled, disabled => nextTick(() => disabled ? tom?.disable() : tom?.enable()))
|
|
118
|
+
|
|
119
|
+
onBeforeUnmount(() => tom?.destroy())
|
|
120
|
+
</script>
|
|
121
|
+
|
|
122
|
+
<template>
|
|
123
|
+
<!-- Tom Select hides the select and adds its own control beside it, inside this wrapper. -->
|
|
124
|
+
<div class="t-advanced-select">
|
|
125
|
+
<select :id="field.id.value" ref="select" :multiple="multiple" :placeholder="placeholder" :aria-describedby="field.describedBy.value"
|
|
126
|
+
:class="['form-select', size !== 'md' && `form-select-${size}`, { 'is-invalid': field.invalid.value }]" />
|
|
127
|
+
</div>
|
|
128
|
+
</template>
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
<script setup lang="ts" generic="Row extends Record<string, any>">
|
|
2
|
+
// A TTable whose columns filter the rows it has (not a new query): a filter icon at the right of
|
|
3
|
+
// each heading opens a comparison (is, is not, contains, greater than, …) and a value under it.
|
|
4
|
+
// Filters combine (every one must match); a column keeps its filter when closed, and its icon shows
|
|
5
|
+
// it. v-model:filters holds them by column key. Everything else (sorting, selectable rows, cell
|
|
6
|
+
// and header slots, card, sticky) is TTable's.
|
|
7
|
+
import { computed, ref, useSlots } from 'vue'
|
|
8
|
+
import TButton from './TButton.vue'
|
|
9
|
+
import TInput from './TInput.vue'
|
|
10
|
+
import TSelect from './TSelect.vue'
|
|
11
|
+
import TTable from './TTable.vue'
|
|
12
|
+
import type { TableColumn, TableFilter, TableFilterOperator } from '../types'
|
|
13
|
+
|
|
14
|
+
defineOptions({ inheritAttrs: false })
|
|
15
|
+
|
|
16
|
+
const props = withDefaults(defineProps<{
|
|
17
|
+
columns: TableColumn<Row>[]
|
|
18
|
+
rows: Row[]
|
|
19
|
+
empty?: string
|
|
20
|
+
}>(), { empty: 'Nothing to show.' })
|
|
21
|
+
|
|
22
|
+
const filters = defineModel<Record<string, TableFilter>>('filters', { default: () => ({}) })
|
|
23
|
+
const slots = useSlots()
|
|
24
|
+
|
|
25
|
+
const operators: { label: string; value: TableFilterOperator }[] = [
|
|
26
|
+
{ label: 'Is', value: 'equals' },
|
|
27
|
+
{ label: 'Is not', value: 'notEquals' },
|
|
28
|
+
{ label: 'Contains', value: 'contains' },
|
|
29
|
+
{ label: 'Greater than', value: 'greaterThan' },
|
|
30
|
+
{ label: 'Less than', value: 'lessThan' },
|
|
31
|
+
{ label: 'At least', value: 'atLeast' },
|
|
32
|
+
{ label: 'At most', value: 'atMost' }
|
|
33
|
+
]
|
|
34
|
+
|
|
35
|
+
// Columns whose filter is open in the heading.
|
|
36
|
+
const open = ref(new Set<string>())
|
|
37
|
+
|
|
38
|
+
const filterable = (column: TableColumn<Row>) => column.filterable !== false && (column.label ?? column.key) !== ''
|
|
39
|
+
const cell = (row: Row, column: TableColumn<Row>) => column.value ? column.value(row) : row[column.key]
|
|
40
|
+
const active = (key: string) => !!filters.value[key]?.value.trim()
|
|
41
|
+
const activeCount = computed(() => Object.keys(filters.value).filter(active).length)
|
|
42
|
+
|
|
43
|
+
function toggle(column: TableColumn<Row>) {
|
|
44
|
+
const next = new Set(open.value)
|
|
45
|
+
if (next.has(column.key)) next.delete(column.key)
|
|
46
|
+
else {
|
|
47
|
+
next.add(column.key)
|
|
48
|
+
if (!filters.value[column.key]) filters.value = { ...filters.value, [column.key]: { operator: 'contains', value: '' } }
|
|
49
|
+
}
|
|
50
|
+
open.value = next
|
|
51
|
+
}
|
|
52
|
+
function set(key: string, change: Partial<TableFilter>) {
|
|
53
|
+
filters.value = { ...filters.value, [key]: { ...(filters.value[key] ?? { operator: 'contains', value: '' }), ...change } }
|
|
54
|
+
}
|
|
55
|
+
function clear(key: string) {
|
|
56
|
+
const { [key]: _, ...rest } = filters.value
|
|
57
|
+
filters.value = rest
|
|
58
|
+
const next = new Set(open.value)
|
|
59
|
+
next.delete(key)
|
|
60
|
+
open.value = next
|
|
61
|
+
}
|
|
62
|
+
function clearAll() {
|
|
63
|
+
filters.value = {}
|
|
64
|
+
open.value = new Set()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Text compares without case; numbers as numbers and dates as dates when both sides are one.
|
|
68
|
+
function matches(value: unknown, filter: TableFilter) {
|
|
69
|
+
const term = filter.value.trim()
|
|
70
|
+
if (!term) return true
|
|
71
|
+
if (value == null || value === '') return filter.operator === 'notEquals'
|
|
72
|
+
const text = typeof value === 'boolean' ? (value ? 'yes' : 'no') : value instanceof Date ? value.toISOString() : String(value)
|
|
73
|
+
const a = text.toLowerCase()
|
|
74
|
+
const b = term.toLowerCase()
|
|
75
|
+
let order: number
|
|
76
|
+
const x = typeof value === 'number' ? value : Number(text)
|
|
77
|
+
const y = Number(term)
|
|
78
|
+
if (Number.isFinite(x) && Number.isFinite(y) && text.trim() !== '') order = x - y
|
|
79
|
+
else if ((value instanceof Date || /^\d{4}-\d{2}-\d{2}/.test(text)) && Number.isFinite(Date.parse(term))) order = Date.parse(text) - Date.parse(term)
|
|
80
|
+
else order = a.localeCompare(b, undefined, { numeric: true })
|
|
81
|
+
switch (filter.operator) {
|
|
82
|
+
case 'equals': return order === 0 || a === b
|
|
83
|
+
case 'notEquals': return !(order === 0 || a === b)
|
|
84
|
+
case 'contains': return a.includes(b)
|
|
85
|
+
case 'greaterThan': return order > 0
|
|
86
|
+
case 'lessThan': return order < 0
|
|
87
|
+
case 'atLeast': return order >= 0
|
|
88
|
+
case 'atMost': return order <= 0
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const shown = computed(() => {
|
|
93
|
+
const applied = props.columns.filter(c => active(c.key)).map(c => ({ column: c, filter: filters.value[c.key] }))
|
|
94
|
+
return applied.length ? props.rows.filter(row => applied.every(({ column, filter }) => matches(cell(row, column), filter))) : props.rows
|
|
95
|
+
})
|
|
96
|
+
const emptyText = computed(() => props.rows.length && activeCount.value ? 'No rows match the filters.' : props.empty)
|
|
97
|
+
|
|
98
|
+
// TTable's slots, passed on; headings are drawn here, around a `{key}-header` slot when given.
|
|
99
|
+
const passed = computed(() => Object.keys(slots).filter(name => !name.endsWith('-header')))
|
|
100
|
+
|
|
101
|
+
defineExpose({ clearFilters: clearAll, shown })
|
|
102
|
+
</script>
|
|
103
|
+
|
|
104
|
+
<template>
|
|
105
|
+
<TTable v-bind="$attrs" :columns="columns" :rows="shown" :empty="emptyText">
|
|
106
|
+
<template v-for="column in columns" :key="column.key" #[`${column.key}-header`]="{ sort, toggleSort }">
|
|
107
|
+
<div class="t-table-heading">
|
|
108
|
+
<span class="t-table-heading-label">
|
|
109
|
+
<slot :name="`${column.key}-header`" :column="column">
|
|
110
|
+
<button v-if="column.sortable" type="button" :class="['table-sort', sort]" @click="toggleSort">{{ column.label ?? column.key }}</button>
|
|
111
|
+
<template v-else>{{ column.label ?? column.key }}</template>
|
|
112
|
+
</slot>
|
|
113
|
+
</span>
|
|
114
|
+
<TButton v-if="filterable(column)" size="xs" :color="active(column.key) ? 'primary' : 'neutral'" variant="ghost" square
|
|
115
|
+
:icon="active(column.key) ? 'filter-check' : 'filter'" :aria-label="`Filter by ${column.label ?? column.key}`"
|
|
116
|
+
:aria-expanded="open.has(column.key)" class="t-table-filter-toggle" @click="toggle(column)" />
|
|
117
|
+
</div>
|
|
118
|
+
<div v-if="filterable(column) && open.has(column.key)" class="t-table-filter">
|
|
119
|
+
<TSelect :model-value="filters[column.key]?.operator ?? 'contains'" :items="operators" size="sm" :aria-label="`How to compare ${column.label ?? column.key}`"
|
|
120
|
+
@update:model-value="v => v && set(column.key, { operator: v })" />
|
|
121
|
+
<TInput :model-value="filters[column.key]?.value ?? ''" size="sm" placeholder="Value" autofocus :aria-label="`Filter value for ${column.label ?? column.key}`"
|
|
122
|
+
@update:model-value="v => set(column.key, { value: String(v ?? '') })" @keydown.esc="clear(column.key)" />
|
|
123
|
+
<TButton size="xs" color="neutral" variant="ghost" square icon="x" :aria-label="`Clear the ${column.label ?? column.key} filter`" @click="clear(column.key)" />
|
|
124
|
+
</div>
|
|
125
|
+
</template>
|
|
126
|
+
<template v-for="name in passed" :key="name" #[name]="scope">
|
|
127
|
+
<slot :name="name" v-bind="scope ?? {}" />
|
|
128
|
+
</template>
|
|
129
|
+
</TTable>
|
|
130
|
+
</template>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A message on the page: what happened and, if needed, what to do. The icon follows the color
|
|
3
|
+
// unless one is given; `important` fills the alert with its color.
|
|
4
|
+
import { computed } from 'vue'
|
|
5
|
+
import TIcon from './TIcon.vue'
|
|
6
|
+
import { toTabler, type Color } from '../types'
|
|
7
|
+
|
|
8
|
+
const props = withDefaults(defineProps<{
|
|
9
|
+
title?: string
|
|
10
|
+
description?: string
|
|
11
|
+
color?: Color
|
|
12
|
+
variant?: 'soft' | 'important'
|
|
13
|
+
// An icon name; null for none. Without one, the color's own icon.
|
|
14
|
+
icon?: string | null
|
|
15
|
+
dismissible?: boolean
|
|
16
|
+
}>(), { color: 'info', variant: 'soft' })
|
|
17
|
+
|
|
18
|
+
const emit = defineEmits<{ close: [] }>()
|
|
19
|
+
|
|
20
|
+
const defaultIcons: Record<Color, string> = {
|
|
21
|
+
primary: 'info-circle', neutral: 'info-circle', info: 'info-circle',
|
|
22
|
+
success: 'circle-check', warning: 'alert-triangle', error: 'alert-circle'
|
|
23
|
+
}
|
|
24
|
+
const glyph = computed(() => props.icon === null ? null : props.icon ?? defaultIcons[props.color])
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<template>
|
|
28
|
+
<div :class="['alert', `alert-${toTabler(color)}`, { 'alert-important': variant === 'important', 'alert-dismissible': dismissible }]" role="alert">
|
|
29
|
+
<TIcon v-if="glyph" :name="glyph" class="alert-icon" />
|
|
30
|
+
<div>
|
|
31
|
+
<h4 v-if="title" class="alert-heading">{{ title }}</h4>
|
|
32
|
+
<div v-if="description || $slots.default" class="alert-description">
|
|
33
|
+
<slot>{{ description }}</slot>
|
|
34
|
+
</div>
|
|
35
|
+
<div v-if="$slots.actions" class="btn-list mt-2">
|
|
36
|
+
<slot name="actions" />
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
<button v-if="dismissible" type="button" class="btn-close" aria-label="Close" @click="emit('close')" />
|
|
40
|
+
</div>
|
|
41
|
+
</template>
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// An application's frame, laid out by a theme's layout settings (`theme`): the navigation down the
|
|
3
|
+
// left (it can fold to icons) or across the top (it can stay at the top as the page scrolls, and
|
|
4
|
+
// float apart from the edges), and the page boxed (centered, the background around it) or fluid.
|
|
5
|
+
// The brand is the logo and name, or the `brand` slot; the links are `items` (TNav), or the `nav`
|
|
6
|
+
// slot for links of your own. `actions` go at the top bar's end, or at the foot of the sidebar.
|
|
7
|
+
// Tabler's page, navbar and layout-boxed classes do the work, so it looks like Tabler's layouts.
|
|
8
|
+
import { computed } from 'vue'
|
|
9
|
+
import TIcon from './TIcon.vue'
|
|
10
|
+
import TNav from './TNav.vue'
|
|
11
|
+
import type { NavItem, ThemeSettings } from '../types'
|
|
12
|
+
|
|
13
|
+
const props = withDefaults(defineProps<{
|
|
14
|
+
theme?: ThemeSettings
|
|
15
|
+
items?: NavItem[]
|
|
16
|
+
brand?: string
|
|
17
|
+
logo?: string
|
|
18
|
+
}>(), { theme: () => ({}), items: () => [] })
|
|
19
|
+
|
|
20
|
+
const folded = defineModel<boolean>('folded', { default: false })
|
|
21
|
+
|
|
22
|
+
const top = computed(() => props.theme.nav === 'top')
|
|
23
|
+
const boxed = computed(() => props.theme.container === 'boxed')
|
|
24
|
+
const foldable = computed(() => !top.value && props.theme.navFoldable === true)
|
|
25
|
+
const container = computed(() => boxed.value ? 'container-xl' : 'container-fluid')
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<template>
|
|
29
|
+
<div :class="['t-app', { 'layout-boxed': boxed }]">
|
|
30
|
+
<div class="page">
|
|
31
|
+
<aside v-if="!top" :class="['navbar navbar-vertical navbar-expand-lg t-app-sidebar', { 'navbar-folded': foldable && folded }]">
|
|
32
|
+
<div class="container-fluid">
|
|
33
|
+
<div class="navbar-brand">
|
|
34
|
+
<slot name="brand" :folded="foldable && folded">
|
|
35
|
+
<img v-if="logo" :src="logo" alt="" class="t-app-logo">
|
|
36
|
+
<span v-if="brand && !(foldable && folded)" class="text-truncate">{{ brand }}</span>
|
|
37
|
+
</slot>
|
|
38
|
+
</div>
|
|
39
|
+
<button v-if="foldable" type="button" class="t-fold-toggle d-none d-lg-grid" :aria-label="folded ? 'Expand the menu' : 'Fold the menu'"
|
|
40
|
+
@click="folded = !folded">
|
|
41
|
+
<TIcon :name="folded ? 'chevron-right' : 'chevron-left'" />
|
|
42
|
+
</button>
|
|
43
|
+
<div class="collapse navbar-collapse">
|
|
44
|
+
<slot name="nav" orientation="vertical" :folded="foldable && folded">
|
|
45
|
+
<TNav :items="items" :folded="foldable && folded" class="pt-lg-3" />
|
|
46
|
+
</slot>
|
|
47
|
+
<div v-if="$slots.actions" class="navbar-footer"><slot name="actions" /></div>
|
|
48
|
+
</div>
|
|
49
|
+
</div>
|
|
50
|
+
</aside>
|
|
51
|
+
<header v-else :class="['navbar navbar-expand-md t-app-topbar', { 'sticky-top': theme.navSticky, 't-app-floating': theme.navFloating }]">
|
|
52
|
+
<div :class="[container, 'gap-3']">
|
|
53
|
+
<div class="navbar-brand">
|
|
54
|
+
<slot name="brand" :folded="false">
|
|
55
|
+
<img v-if="logo" :src="logo" alt="" class="t-app-logo">
|
|
56
|
+
<span v-if="brand" class="text-truncate">{{ brand }}</span>
|
|
57
|
+
</slot>
|
|
58
|
+
</div>
|
|
59
|
+
<div class="collapse navbar-collapse">
|
|
60
|
+
<slot name="nav" orientation="horizontal" :folded="false">
|
|
61
|
+
<TNav :items="items" />
|
|
62
|
+
</slot>
|
|
63
|
+
</div>
|
|
64
|
+
<div v-if="$slots.actions" class="ms-auto d-flex align-items-center gap-2"><slot name="actions" /></div>
|
|
65
|
+
</div>
|
|
66
|
+
</header>
|
|
67
|
+
<div class="page-wrapper">
|
|
68
|
+
<div class="page-body">
|
|
69
|
+
<div :class="container">
|
|
70
|
+
<slot />
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
</div>
|
|
76
|
+
</template>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A page with one centered card and the brand above it: sign-in, setup, a password change.
|
|
3
|
+
defineProps<{ title: string; subtitle?: string; brand?: string; logo?: string; wide?: boolean }>()
|
|
4
|
+
</script>
|
|
5
|
+
|
|
6
|
+
<template>
|
|
7
|
+
<div class="page page-center">
|
|
8
|
+
<div :class="['container py-4', wide ? 'container-narrow' : 'container-tight']">
|
|
9
|
+
<div v-if="brand || logo || $slots.brand" class="text-center mb-4">
|
|
10
|
+
<slot name="brand">
|
|
11
|
+
<span class="d-inline-flex align-items-center gap-2">
|
|
12
|
+
<img v-if="logo" :src="logo" alt="" width="36" height="36">
|
|
13
|
+
<span v-if="brand" class="h2 mb-0">{{ brand }}</span>
|
|
14
|
+
</span>
|
|
15
|
+
</slot>
|
|
16
|
+
</div>
|
|
17
|
+
<slot name="above" />
|
|
18
|
+
<div class="card card-md">
|
|
19
|
+
<div class="card-body">
|
|
20
|
+
<h1 class="h2 mb-1">{{ title }}</h1>
|
|
21
|
+
<p v-if="subtitle" class="text-secondary mb-0">{{ subtitle }}</p>
|
|
22
|
+
<div class="mt-4">
|
|
23
|
+
<slot />
|
|
24
|
+
</div>
|
|
25
|
+
</div>
|
|
26
|
+
</div>
|
|
27
|
+
<div v-if="$slots.footer" class="text-center text-secondary mt-3">
|
|
28
|
+
<slot name="footer" />
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
</div>
|
|
32
|
+
</template>
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A person or thing as a picture, or as initials (or an icon) on a tint when there's no picture.
|
|
3
|
+
import { computed } from 'vue'
|
|
4
|
+
import TIcon from './TIcon.vue'
|
|
5
|
+
import { toTabler, type Color } from '../types'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
text?: string
|
|
9
|
+
src?: string
|
|
10
|
+
icon?: string
|
|
11
|
+
alt?: string
|
|
12
|
+
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
13
|
+
color?: Color
|
|
14
|
+
shape?: 'circle' | 'square'
|
|
15
|
+
}>(), { size: 'md', color: 'primary', shape: 'circle' })
|
|
16
|
+
|
|
17
|
+
const classes = computed(() => ['avatar', props.size !== 'md' && `avatar-${props.size}`,
|
|
18
|
+
!props.src && `bg-${toTabler(props.color)}-lt`, props.shape === 'circle' && 'rounded-circle'])
|
|
19
|
+
</script>
|
|
20
|
+
|
|
21
|
+
<template>
|
|
22
|
+
<span :class="classes" :style="src ? { backgroundImage: `url(${src})` } : undefined" :role="alt ? 'img' : undefined" :aria-label="alt">
|
|
23
|
+
<template v-if="!src">
|
|
24
|
+
<TIcon v-if="icon" :name="icon" />
|
|
25
|
+
<slot v-else>{{ text }}</slot>
|
|
26
|
+
</template>
|
|
27
|
+
</span>
|
|
28
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A short status label. `soft` (tinted, the default) suits most statuses; `solid` draws the eye.
|
|
3
|
+
import { computed } from 'vue'
|
|
4
|
+
import TIcon from './TIcon.vue'
|
|
5
|
+
import { toTabler, type Color } from '../types'
|
|
6
|
+
|
|
7
|
+
const props = withDefaults(defineProps<{
|
|
8
|
+
label?: string | number
|
|
9
|
+
color?: Color
|
|
10
|
+
variant?: 'soft' | 'solid' | 'outline'
|
|
11
|
+
icon?: string
|
|
12
|
+
}>(), { color: 'primary', variant: 'soft' })
|
|
13
|
+
|
|
14
|
+
const classes = computed(() => {
|
|
15
|
+
const c = toTabler(props.color)
|
|
16
|
+
return ['badge', {
|
|
17
|
+
soft: `bg-${c}-lt`,
|
|
18
|
+
solid: `bg-${c} text-${c}-fg`,
|
|
19
|
+
outline: `badge-outline text-${c}`
|
|
20
|
+
}[props.variant]]
|
|
21
|
+
})
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<span :class="classes">
|
|
26
|
+
<TIcon v-if="icon" :name="icon" class="me-1" />
|
|
27
|
+
<slot>{{ label }}</slot>
|
|
28
|
+
</span>
|
|
29
|
+
</template>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A button, or a link that looks like one when given `to` (a route) or `href`. An icon with no
|
|
3
|
+
// label makes a square icon button; give it an aria-label.
|
|
4
|
+
import { computed, useSlots } from 'vue'
|
|
5
|
+
import { RouterLink } from 'vue-router'
|
|
6
|
+
import TIcon from './TIcon.vue'
|
|
7
|
+
import { toTabler, type Color, type Size, type Target } from '../types'
|
|
8
|
+
|
|
9
|
+
const props = withDefaults(defineProps<{
|
|
10
|
+
label?: string
|
|
11
|
+
icon?: string
|
|
12
|
+
trailingIcon?: string
|
|
13
|
+
color?: Color
|
|
14
|
+
variant?: 'solid' | 'outline' | 'ghost' | 'soft' | 'link'
|
|
15
|
+
size?: Size
|
|
16
|
+
loading?: boolean
|
|
17
|
+
disabled?: boolean
|
|
18
|
+
block?: boolean
|
|
19
|
+
square?: boolean
|
|
20
|
+
to?: Target
|
|
21
|
+
href?: string
|
|
22
|
+
target?: string
|
|
23
|
+
type?: 'button' | 'submit' | 'reset'
|
|
24
|
+
}>(), { color: 'primary', variant: 'solid', size: 'md', type: 'button' })
|
|
25
|
+
|
|
26
|
+
const slots = useSlots()
|
|
27
|
+
|
|
28
|
+
const look = computed(() => {
|
|
29
|
+
if (props.variant === 'link') return 'btn-link'
|
|
30
|
+
// Tabler's plain `btn` is the neutral solid button: the surface color with a border.
|
|
31
|
+
if (props.variant === 'solid') return props.color === 'neutral' ? '' : `btn-${toTabler(props.color)}`
|
|
32
|
+
const look = `btn-${props.variant}-${toTabler(props.color)}`
|
|
33
|
+
return props.variant === 'soft' ? `btn-soft ${look}` : look
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
const classes = computed(() => ['btn', look.value, {
|
|
37
|
+
'btn-xs': props.size === 'xs',
|
|
38
|
+
'btn-sm': props.size === 'sm',
|
|
39
|
+
'btn-lg': props.size === 'lg',
|
|
40
|
+
'btn-icon': props.square || (props.icon && !props.label && !slots.default),
|
|
41
|
+
'w-100': props.block,
|
|
42
|
+
'btn-loading': props.loading,
|
|
43
|
+
disabled: props.disabled && (props.to || props.href)
|
|
44
|
+
}])
|
|
45
|
+
|
|
46
|
+
const tag = computed(() => props.to && !props.disabled ? RouterLink : props.href ? 'a' : 'button')
|
|
47
|
+
const attrs = computed(() => {
|
|
48
|
+
if (tag.value === RouterLink) return { to: props.to }
|
|
49
|
+
if (tag.value === 'a') return { href: props.disabled ? undefined : props.href, target: props.target, 'aria-disabled': props.disabled || undefined }
|
|
50
|
+
return { type: props.type, disabled: props.disabled || props.loading }
|
|
51
|
+
})
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<component :is="tag" v-bind="attrs" :class="classes">
|
|
56
|
+
<TIcon v-if="icon" :name="icon" />
|
|
57
|
+
<slot>{{ label }}</slot>
|
|
58
|
+
<TIcon v-if="trailingIcon" :name="trailingIcon" class="icon-end" />
|
|
59
|
+
</component>
|
|
60
|
+
</template>
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A card: an optional header (title, subtitle, actions on the right), the body and a footer.
|
|
3
|
+
// `flush` drops the body's padding, for a table or list that runs to the card's edges.
|
|
4
|
+
import { toTabler, type Color } from '../types'
|
|
5
|
+
|
|
6
|
+
defineProps<{
|
|
7
|
+
title?: string
|
|
8
|
+
subtitle?: string
|
|
9
|
+
flush?: boolean
|
|
10
|
+
size?: 'sm' | 'md' | 'lg'
|
|
11
|
+
// A colored line along the top.
|
|
12
|
+
status?: Color
|
|
13
|
+
}>()
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<div :class="['card', size && `card-${size}`]">
|
|
18
|
+
<div v-if="status" :class="['card-status-top', `bg-${toTabler(status)}`]" />
|
|
19
|
+
<div v-if="title || $slots.header || $slots.actions" class="card-header">
|
|
20
|
+
<slot name="header">
|
|
21
|
+
<div class="min-w-0">
|
|
22
|
+
<h3 class="card-title">{{ title }}</h3>
|
|
23
|
+
<p v-if="subtitle" class="card-subtitle mb-0">{{ subtitle }}</p>
|
|
24
|
+
</div>
|
|
25
|
+
</slot>
|
|
26
|
+
<div v-if="$slots.actions" class="card-actions btn-list">
|
|
27
|
+
<slot name="actions" />
|
|
28
|
+
</div>
|
|
29
|
+
</div>
|
|
30
|
+
<template v-if="$slots.default">
|
|
31
|
+
<slot v-if="flush" />
|
|
32
|
+
<div v-else class="card-body">
|
|
33
|
+
<slot />
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
<div v-if="$slots.footer" class="card-footer">
|
|
37
|
+
<slot name="footer" />
|
|
38
|
+
</div>
|
|
39
|
+
</div>
|
|
40
|
+
</template>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
// A checkbox with its label and an optional line under it.
|
|
3
|
+
import { ref, watchEffect } from 'vue'
|
|
4
|
+
import { useField } from '../composables/useField'
|
|
5
|
+
|
|
6
|
+
const props = defineProps<{
|
|
7
|
+
label?: string
|
|
8
|
+
description?: string
|
|
9
|
+
disabled?: boolean
|
|
10
|
+
indeterminate?: boolean
|
|
11
|
+
invalid?: boolean
|
|
12
|
+
id?: string
|
|
13
|
+
}>()
|
|
14
|
+
|
|
15
|
+
const model = defineModel<boolean>({ default: false })
|
|
16
|
+
const field = useField(props)
|
|
17
|
+
const el = ref<HTMLInputElement>()
|
|
18
|
+
|
|
19
|
+
watchEffect(() => { if (el.value) el.value.indeterminate = !!props.indeterminate })
|
|
20
|
+
</script>
|
|
21
|
+
|
|
22
|
+
<template>
|
|
23
|
+
<label class="form-check" :for="field.id.value">
|
|
24
|
+
<input :id="field.id.value" ref="el" v-model="model" type="checkbox" :disabled="disabled"
|
|
25
|
+
:class="['form-check-input', { 'is-invalid': field.invalid.value }]" :aria-describedby="field.describedBy.value">
|
|
26
|
+
<span class="form-check-label"><slot>{{ label }}</slot></span>
|
|
27
|
+
<span v-if="description" class="form-check-description">{{ description }}</span>
|
|
28
|
+
</label>
|
|
29
|
+
</template>
|