@ternarytech-io/gears-ui 0.3.2 → 0.3.4

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/README.md CHANGED
@@ -102,7 +102,7 @@ add a page, add an entry to `preview/registry.ts` and a folder of examples.
102
102
  | Group | Components |
103
103
  | --- | --- |
104
104
  | Elements | `TButton`, `TBadge`, `TAvatar`, `TAlert`, `TCard`, `TIcon`, `TTooltip`, `TEmpty`, `TSpinner`, `TSkeleton`, `TProgress`, `TSeparator` |
105
- | Forms | `TFormField`, `TInput`, `TInputNumber`, `TTextarea`, `TSelect`, `TSelectMenu`, `TInputTags`, `TCheckbox`, `TSwitch`, `TRadioGroup` (list, cards or tiles with a picture), `TFieldGroup`, `TFileUpload`, `TImageUpload` (one image, checked for shape and size), `TIconPicker` (any Tabler icon, by name, with a search; the list is generated by `npm run icons`), `TCodeEditor` |
105
+ | Forms | `TFormField`, `TInput`, `TInputNumber`, `TTextarea`, `TSelect`, `TSelectMenu`, `TInputTags`, `TCheckbox`, `TSwitch`, `TRadioGroup` (list, cards or tiles with a picture), `TFieldGroup`, `TFileUpload`, `TImageUpload` (one image, checked for shape and size), `TIconPicker` (any Tabler icon, by name, with a search; the list is generated by `npm run icons`), `TRating` (stars, hearts or circles; no library), `TListBox` (always shown; one or several; a search), `TCheckboxTree` (parents check their children; partly checked; folding), `TCodeEditor` |
106
106
  | Theme | `TAccentPicker`, `TFontPicker`, `TRadiusPicker`, `TThemeBasePicker` (Tabler's theme settings as pickers), `TNavPositionPicker`, `TDensityPicker`, `TContainerPicker` (layout), `TThemeScope` (applies a `ThemeSettings`' look and density to what's inside it); `themeAccents`, `themeFonts`, `themeBases`, `themeRadii`, `themeNavs`, `themeDensities`, `themeContainers` |
107
107
  | Overlays | `TModal`, `TSlideover`, `TDropdown`, `TToaster` (with `useToast()`) |
108
108
  | Navigation | `TTabs`, `TPagination`, `TSteps`, `TNav`, `TPanelList`, `TCommandPalette`, `TSearchButton` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ternarytech-io/gears-ui",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "type": "module",
5
5
  "description": "Gears UI: Vue 3 components on Tabler, used by the Gears Studio and the applications it builds.",
6
6
  "license": "MPL-2.0",
@@ -0,0 +1,82 @@
1
+ <script setup lang="ts" generic="T">
2
+ // Checkboxes in a tree: a parent is checked when all its children are, partly checked (dash) when
3
+ // some are, and checking it checks them all. Parents fold and open with their arrow (`collapsible`,
4
+ // all open at first unless `collapsed`). v-model is the checked leaves' values.
5
+ import { computed, shallowRef } from 'vue'
6
+ import TIcon from './TIcon.vue'
7
+ import type { TreeItem } from '../types'
8
+
9
+ const props = withDefaults(defineProps<{
10
+ items: TreeItem<T>[]
11
+ collapsible?: boolean
12
+ collapsed?: boolean
13
+ disabled?: boolean
14
+ // The tree's accessible name.
15
+ label?: string
16
+ }>(), { collapsible: true, collapsed: false })
17
+
18
+ const model = defineModel<T[]>({ default: () => [] })
19
+ // The parents folded, by value.
20
+ const folded = shallowRef(new Set<T>())
21
+ if (props.collapsed) {
22
+ const walk = (items: TreeItem<T>[]) => items.forEach(i => { if (i.children?.length) { folded.value.add(i.value); walk(i.children) } })
23
+ walk(props.items)
24
+ }
25
+
26
+ const checked = computed(() => new Set(model.value))
27
+ const leaves = (item: TreeItem<T>): T[] => (item.children?.length ? item.children.flatMap(leaves) : [item.value])
28
+ function state(item: TreeItem<T>): 'on' | 'off' | 'some' {
29
+ const all = leaves(item)
30
+ const on = all.filter(v => checked.value.has(v)).length
31
+ return on === 0 ? 'off' : on === all.length ? 'on' : 'some'
32
+ }
33
+ function toggle(item: TreeItem<T>) {
34
+ if (props.disabled || item.disabled) return
35
+ const all = leaves(item)
36
+ const next = new Set(model.value)
37
+ if (state(item) === 'on') all.forEach(v => next.delete(v))
38
+ else all.forEach(v => next.add(v))
39
+ model.value = [...next]
40
+ }
41
+ function fold(item: TreeItem<T>) {
42
+ const next = new Set(folded.value)
43
+ if (next.has(item.value)) next.delete(item.value)
44
+ else next.add(item.value)
45
+ folded.value = next
46
+ }
47
+ // Rows to show, with their depth: what's under a folded parent is left out.
48
+ const rows = computed(() => {
49
+ const out: { item: TreeItem<T>; depth: number }[] = []
50
+ const walk = (items: TreeItem<T>[], depth: number) => items.forEach(item => {
51
+ out.push({ item, depth })
52
+ if (item.children?.length && !(props.collapsible && folded.value.has(item.value))) walk(item.children, depth + 1)
53
+ })
54
+ walk(props.items, 0)
55
+ return out
56
+ })
57
+ </script>
58
+
59
+ <template>
60
+ <div class="t-checkbox-tree" role="group" :aria-label="label">
61
+ <div v-for="{ item, depth } in rows" :key="String(item.value)" class="t-checkbox-tree-row" :style="{ paddingInlineStart: `${depth * 1.25}rem` }">
62
+ <button v-if="collapsible && item.children?.length" type="button" class="t-checkbox-tree-fold" :aria-expanded="!folded.has(item.value)"
63
+ :aria-label="`${folded.has(item.value) ? 'Open' : 'Fold'} ${item.label}`" @click="fold(item)">
64
+ <TIcon :name="folded.has(item.value) ? 'chevron-right' : 'chevron-down'" />
65
+ </button>
66
+ <span v-else-if="collapsible" class="t-checkbox-tree-fold" aria-hidden="true" />
67
+ <label class="form-check mb-0">
68
+ <input type="checkbox" class="form-check-input" :checked="state(item) === 'on'" :indeterminate.prop="state(item) === 'some'"
69
+ :aria-checked="state(item) === 'some' ? 'mixed' : state(item) === 'on'" :disabled="disabled || item.disabled" @change="toggle(item)">
70
+ <span class="form-check-label">{{ item.label }}</span>
71
+ </label>
72
+ </div>
73
+ </div>
74
+ </template>
75
+
76
+ <style scoped>
77
+ .t-checkbox-tree { display: flex; flex-direction: column; gap: 0.25rem; }
78
+ .t-checkbox-tree-row { display: flex; align-items: center; gap: 0.25rem; }
79
+ .t-checkbox-tree-row .form-check { min-height: 0; }
80
+ .t-checkbox-tree-fold { display: grid; place-items: center; flex-shrink: 0; width: 1.25rem; height: 1.25rem; padding: 0; border: 0; background: none; color: var(--tblr-secondary); }
81
+ button.t-checkbox-tree-fold:hover { color: var(--tblr-body-color); }
82
+ </style>
@@ -1,70 +1,73 @@
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>
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. `options` are IMask's own, for what a pattern can't say: a number with
6
+ // thousands separators and decimals, say ({ mask: '$num', blocks: { num: { mask: Number, scale: 2,
7
+ // thousandsSeparator: ',' } } }); they win over `mask`. IMask loads on first use.
8
+ import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
9
+ import type { InputMask } from '@tabler/core'
10
+ import TIcon from './TIcon.vue'
11
+ import { useField } from '../composables/useField'
12
+ import { loadInputMask } from '../plugins/inputMask'
13
+
14
+ type Mask = { value: string; unmaskedValue: string; on(event: 'accept', handler: () => void): void }
15
+
16
+ const props = withDefaults(defineProps<{
17
+ mask?: string
18
+ options?: Record<string, unknown>
19
+ unmasked?: boolean
20
+ showMask?: boolean
21
+ placeholder?: string
22
+ icon?: string
23
+ size?: 'sm' | 'md' | 'lg'
24
+ disabled?: boolean
25
+ invalid?: boolean
26
+ id?: string
27
+ }>(), { size: 'md' })
28
+
29
+ const model = defineModel<string | null | undefined>()
30
+ const field = useField(props)
31
+ const input = ref<HTMLInputElement>()
32
+ let instance: InputMask | null = null
33
+
34
+ const mask = () => (instance as unknown as { mask: Mask | null } | null)?.mask ?? null
35
+ const current = () => props.unmasked ? mask()?.unmaskedValue : mask()?.value
36
+
37
+ function write(value: string) {
38
+ const m = mask()
39
+ if (!m) return
40
+ if (props.unmasked) m.unmaskedValue = value
41
+ else m.value = value
42
+ }
43
+
44
+ async function create() {
45
+ const InputMaskClass = await loadInputMask()
46
+ if (!input.value) return
47
+ instance?.dispose()
48
+ instance = new InputMaskClass(input.value, { mask: props.mask ?? '', lazy: !props.showMask, ...props.options })
49
+ write(model.value ?? '')
50
+ mask()?.on('accept', () => {
51
+ const value = current() ?? ''
52
+ if (value !== (model.value ?? '')) model.value = value
53
+ })
54
+ }
55
+
56
+ onMounted(() => {
57
+ // Shown as is until IMask takes over.
58
+ if (input.value) input.value.value = model.value ?? ''
59
+ create()
60
+ })
61
+ watch(model, value => { if (mask() && (value ?? '') !== current()) write(value ?? '') })
62
+ watch(() => [props.mask, props.showMask, props.unmasked, props.options], create, { deep: true })
63
+ onBeforeUnmount(() => instance?.dispose())
64
+ </script>
65
+
66
+ <template>
67
+ <div :class="{ 'input-icon': icon }">
68
+ <span v-if="icon" class="input-icon-addon"><TIcon :name="icon" /></span>
69
+ <input :id="field.id.value" ref="input" type="text" :placeholder="placeholder" :disabled="disabled" autocomplete="off"
70
+ :aria-describedby="field.describedBy.value" :aria-invalid="field.invalid.value || undefined"
71
+ :class="['form-control', size !== 'md' && `form-control-${size}`, { 'is-invalid': field.invalid.value }]">
72
+ </div>
73
+ </template>
@@ -0,0 +1,111 @@
1
+ <script setup lang="ts" generic="T">
2
+ // A list of choices that's always shown (not a dropdown), to choose one or, with `multiple`,
3
+ // several; `searchable` adds a search above it. It's a listbox for assistive technology: the arrow
4
+ // keys, Home and End move through it, Space or Enter chooses. v-model is the chosen value (null for
5
+ // none), or with `multiple` the chosen values.
6
+ import { computed, ref, useId } from 'vue'
7
+ import TIcon from './TIcon.vue'
8
+ import { useField } from '../composables/useField'
9
+ import type { SelectItem } from '../types'
10
+
11
+ const props = withDefaults(defineProps<{
12
+ items: (T | SelectItem<T>)[]
13
+ multiple?: boolean
14
+ searchable?: boolean
15
+ searchPlaceholder?: string
16
+ // The list's tallest (CSS); it scrolls past that. `none` lets it fill the box it's in (give the
17
+ // TListBox a height, or put it in a flex column).
18
+ height?: string
19
+ disabled?: boolean
20
+ invalid?: boolean
21
+ // The list's accessible name, when no label points at it.
22
+ label?: string
23
+ id?: string
24
+ }>(), { searchPlaceholder: 'Search…', height: '12rem' })
25
+
26
+ const model = defineModel<T | T[] | null | undefined>()
27
+ const field = useField(props)
28
+ const listId = useId()
29
+ const query = ref('')
30
+ const active = ref(0)
31
+ const list = ref<HTMLElement>()
32
+
33
+ const options = computed(() => props.items.map(item => (item !== null && typeof item === 'object' && 'value' in (item as object) && 'label' in (item as object)
34
+ ? item as SelectItem<T>
35
+ : { label: String(item), value: item as T })))
36
+ const shown = computed(() => {
37
+ const term = query.value.trim().toLowerCase()
38
+ return term ? options.value.filter(o => o.label.toLowerCase().includes(term) || (o.description ?? '').toLowerCase().includes(term)) : options.value
39
+ })
40
+ const chosen = (value: T) => props.multiple ? Array.isArray(model.value) && model.value.includes(value) : model.value === value
41
+
42
+ function choose(option: SelectItem<T>) {
43
+ if (props.disabled || option.disabled) return
44
+ if (!props.multiple) {
45
+ model.value = option.value
46
+ return
47
+ }
48
+ const current = Array.isArray(model.value) ? model.value : []
49
+ model.value = current.includes(option.value) ? current.filter(v => v !== option.value) : [...current, option.value]
50
+ }
51
+ function key(event: KeyboardEvent) {
52
+ const last = shown.value.length - 1
53
+ if (last < 0) return
54
+ const moves: Record<string, number> = { ArrowDown: active.value + 1, ArrowUp: active.value - 1, Home: 0, End: last }
55
+ if (event.key in moves) {
56
+ event.preventDefault()
57
+ active.value = Math.max(0, Math.min(last, moves[event.key]!))
58
+ list.value?.querySelector<HTMLElement>(`[data-index="${active.value}"]`)?.scrollIntoView({ block: 'nearest' })
59
+ } else if (event.key === ' ' || event.key === 'Enter') {
60
+ event.preventDefault()
61
+ choose(shown.value[active.value]!)
62
+ }
63
+ }
64
+ </script>
65
+
66
+ <template>
67
+ <div :class="['t-list-box', { 'is-invalid': invalid || field.invalid.value, disabled }]">
68
+ <div v-if="searchable" class="t-list-box-search">
69
+ <input v-model="query" type="search" class="form-control form-control-sm" :placeholder="searchPlaceholder" :aria-label="searchPlaceholder"
70
+ :aria-controls="listId" :disabled="disabled" @input="active = 0">
71
+ </div>
72
+ <div :id="field.id.value === listId ? listId : field.id.value" ref="list" class="t-list-box-list" role="listbox" :tabindex="disabled ? -1 : 0"
73
+ :aria-multiselectable="multiple || undefined" :aria-disabled="disabled || undefined" :aria-label="label"
74
+ :aria-activedescendant="shown.length ? `${listId}-${active}` : undefined" :aria-describedby="field.describedBy.value" :style="{ maxHeight: height }"
75
+ @keydown="key">
76
+ <div v-for="(option, index) in shown" :id="`${listId}-${index}`" :key="index" :data-index="index" role="option"
77
+ :aria-selected="chosen(option.value)" :aria-disabled="option.disabled || undefined"
78
+ :class="['t-list-box-item', { selected: chosen(option.value), active: index === active, disabled: option.disabled }]"
79
+ @click="active = index; choose(option)">
80
+ <span v-if="multiple" class="t-list-box-check" aria-hidden="true"><TIcon v-if="chosen(option.value)" name="check" /></span>
81
+ <span class="min-w-0">
82
+ <span class="d-block text-truncate">{{ option.label }}</span>
83
+ <span v-if="option.description" class="d-block small text-secondary text-truncate">{{ option.description }}</span>
84
+ </span>
85
+ <TIcon v-if="!multiple && chosen(option.value)" name="check" class="ms-auto text-primary" />
86
+ </div>
87
+ <p v-if="!shown.length" class="t-list-box-empty">{{ query ? 'Nothing matches.' : 'Nothing to choose.' }}</p>
88
+ </div>
89
+ </div>
90
+ </template>
91
+
92
+ <style scoped>
93
+ .t-list-box { display: flex; flex-direction: column; min-height: 0; border: var(--tblr-border-width) solid var(--tblr-border-color); border-radius: var(--tblr-border-radius); background: var(--tblr-bg-forms, var(--tblr-bg-surface)); overflow: hidden; }
94
+ .t-list-box.is-invalid { border-color: var(--tblr-danger); }
95
+ .t-list-box.disabled { opacity: 0.65; }
96
+ .t-list-box-search { padding: 0.375rem; border-bottom: var(--tblr-border-width) solid var(--tblr-border-color); }
97
+ .t-list-box-list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 0.25rem; outline: none; }
98
+ .t-list-box-list:focus-visible { box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--tblr-primary) 40%, transparent); }
99
+ .t-list-box-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.5rem; border-radius: var(--tblr-border-radius-sm); cursor: pointer; user-select: none; }
100
+ .t-list-box-item:hover { background: var(--tblr-bg-surface-secondary); }
101
+ .t-list-box-list:focus-visible .t-list-box-item.active { background: var(--tblr-bg-surface-secondary); outline: 1px solid var(--tblr-border-color); }
102
+ .t-list-box-item.selected { background: color-mix(in srgb, var(--tblr-primary) 12%, transparent); }
103
+ .t-list-box-item.disabled { opacity: 0.5; cursor: default; }
104
+ .t-list-box-check {
105
+ display: grid; place-items: center; flex-shrink: 0; width: 1rem; height: 1rem; font-size: 0.75rem;
106
+ border: var(--tblr-border-width) solid var(--tblr-border-color-dark, var(--tblr-border-color)); border-radius: var(--tblr-border-radius-sm);
107
+ }
108
+ .t-list-box-check :deep(.icon) { width: auto; height: auto; font-size: 0.75rem; line-height: 1; vertical-align: 0; }
109
+ .selected > .t-list-box-check { background: var(--tblr-primary); border-color: var(--tblr-primary); color: var(--tblr-primary-fg, #fff); }
110
+ .t-list-box-empty { margin: 0.5rem; color: var(--tblr-secondary); font-size: 0.8125rem; }
111
+ </style>
@@ -0,0 +1,77 @@
1
+ <script setup lang="ts">
2
+ // A rating, from 1 to `max`, as a row of stars (or hearts, or circles): click one to choose it,
3
+ // click the chosen one again to clear it (with `clearable`). Pointing previews; the arrow keys,
4
+ // Home and End change it, as a radio group. Drawn with SVG, so nothing is loaded. v-model is the
5
+ // rating, or null for none.
6
+ import { computed, ref } from 'vue'
7
+ import { useField } from '../composables/useField'
8
+
9
+ const props = withDefaults(defineProps<{
10
+ max?: number
11
+ shape?: 'star' | 'heart' | 'circle'
12
+ // A Tabler color name (yellow, red, primary, …) or a CSS color.
13
+ color?: string
14
+ size?: 'sm' | 'md' | 'lg'
15
+ readonly?: boolean
16
+ disabled?: boolean
17
+ clearable?: boolean
18
+ // The group's accessible name.
19
+ label?: string
20
+ id?: string
21
+ }>(), { max: 5, shape: 'star', color: 'yellow', size: 'md', clearable: true, label: 'Rating' })
22
+
23
+ const model = defineModel<number | null | undefined>()
24
+ const field = useField(props)
25
+ const hover = ref<number | null>(null)
26
+ const shown = computed(() => hover.value ?? model.value ?? 0)
27
+ const items = computed(() => Array.from({ length: Math.max(1, Math.min(20, Math.round(props.max))) }, (_, i) => i + 1))
28
+ const locked = computed(() => props.readonly || props.disabled)
29
+ const fill = computed(() => (/^[a-z]+$/.test(props.color) ? `var(--tblr-${props.color})` : props.color))
30
+
31
+ const paths: Record<string, string> = {
32
+ star: 'M12 17.75l-6.172 3.245l1.179 -6.873l-5 -4.867l6.9 -1l3.086 -6.253l3.086 6.253l6.9 1l-5 4.867l1.179 6.873z',
33
+ heart: 'M19.5 12.572l-7.5 7.428l-7.5 -7.428a5 5 0 1 1 7.5 -6.566a5 5 0 1 1 7.5 6.572',
34
+ circle: 'M12 12m-9 0a9 9 0 1 0 18 0a9 9 0 1 0 -18 0'
35
+ }
36
+
37
+ function choose(value: number) {
38
+ if (locked.value) return
39
+ model.value = props.clearable && model.value === value ? null : value
40
+ }
41
+ function key(event: KeyboardEvent) {
42
+ if (locked.value) return
43
+ const current = model.value ?? 0
44
+ const next = event.key === 'ArrowRight' || event.key === 'ArrowUp' ? current + 1
45
+ : event.key === 'ArrowLeft' || event.key === 'ArrowDown' ? current - 1
46
+ : event.key === 'Home' ? 1 : event.key === 'End' ? items.value.length : null
47
+ if (next === null) return
48
+ event.preventDefault()
49
+ model.value = Math.max(props.clearable ? 0 : 1, Math.min(items.value.length, next)) || null
50
+ ;(event.currentTarget as HTMLElement).querySelector<HTMLElement>(`[data-value="${model.value ?? 1}"]`)?.focus()
51
+ }
52
+ </script>
53
+
54
+ <template>
55
+ <div :id="field.id.value" :class="['t-rating', `t-rating-${size}`, { 't-rating-locked': locked }]" role="radiogroup" :aria-label="label"
56
+ :aria-readonly="readonly || undefined" :aria-disabled="disabled || undefined" :aria-describedby="field.describedBy.value"
57
+ :style="{ '--t-rating-color': fill }" @keydown="key" @pointerleave="hover = null">
58
+ <button v-for="value in items" :key="value" type="button" role="radio" class="t-rating-item" :data-value="value"
59
+ :aria-checked="model === value" :aria-label="`${value} of ${items.length}`" :tabindex="(model ?? 1) === value ? 0 : -1" :disabled="disabled"
60
+ @click="choose(value)" @pointerenter="!locked && (hover = value)">
61
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path :d="paths[shape] ?? paths.star" :class="{ on: value <= shown }" /></svg>
62
+ </button>
63
+ </div>
64
+ </template>
65
+
66
+ <style scoped>
67
+ .t-rating { display: inline-flex; gap: 0.125rem; }
68
+ .t-rating-item { display: grid; place-items: center; padding: 0; border: 0; background: none; line-height: 0; cursor: pointer; border-radius: var(--tblr-border-radius-sm); }
69
+ .t-rating-locked .t-rating-item { cursor: default; }
70
+ .t-rating-item:disabled { opacity: 0.6; }
71
+ .t-rating-item:focus-visible { outline: 2px solid var(--tblr-primary); outline-offset: 1px; }
72
+ .t-rating svg { width: 1.5rem; height: 1.5rem; }
73
+ .t-rating-sm svg { width: 1.125rem; height: 1.125rem; }
74
+ .t-rating-lg svg { width: 2rem; height: 2rem; }
75
+ .t-rating path { fill: none; stroke: var(--tblr-border-color-dark, var(--tblr-secondary)); stroke-width: 1.5; stroke-linejoin: round; transition: fill 0.1s, stroke 0.1s; }
76
+ .t-rating path.on { fill: var(--t-rating-color); stroke: var(--t-rating-color); }
77
+ </style>
@@ -1,82 +1,86 @@
1
- <script setup lang="ts">
2
- // A rich text editor with Tabler's WYSIWYG plugin (HugeRTE, an open-source fork of TinyMCE).
3
- // v-model is the HTML. `toolbar` and `plugins` use HugeRTE's names; the plugins offered are those
4
- // in src/plugins/richEditor.ts. It follows the light and dark theme (switching rebuilds the editor). Nothing
5
- // is fetched: the editor, its skins and plugins are bundled and load on first use.
6
- import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
7
- import type { Editor } from 'hugerte'
8
- import { useColorMode } from '../composables/useColorMode'
9
- import { useField } from '../composables/useField'
10
- import { loadRichEditor, type RichEditorPlugin } from '../plugins/richEditor'
11
-
12
- const props = withDefaults(defineProps<{
13
- height?: number
14
- toolbar?: string
15
- plugins?: RichEditorPlugin[]
16
- menubar?: boolean
17
- statusbar?: boolean
18
- placeholder?: string
19
- disabled?: boolean
20
- id?: string
21
- }>(), {
22
- height: 300,
23
- toolbar: 'undo redo | blocks | bold italic underline | bullist numlist | link image table | code',
24
- plugins: () => ['advlist', 'autolink', 'lists', 'link', 'image', 'table', 'code']
25
- })
26
-
27
- const model = defineModel<string>({ default: '' })
28
- const field = useField(props)
29
- const { isDark } = useColorMode()
30
- const textarea = ref<HTMLTextAreaElement>()
31
- const loading = ref(true)
32
- let editor: Editor | null = null
33
- let stopped = false
34
-
35
- async function create() {
36
- const hugerte = await loadRichEditor()
37
- if (stopped || !textarea.value) return
38
- editor?.remove()
39
- textarea.value.value = model.value
40
- const [created] = await hugerte.init({
41
- target: textarea.value,
42
- // The skins and content styles are bundled resources, named 'default' and 'dark'.
43
- skin_url: isDark.value ? 'dark' : 'default',
44
- content_css: isDark.value ? 'dark' : 'default',
45
- // The page's font, and in the dark theme the card color rather than HugeRTE's navy.
46
- content_style: 'body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; }'
47
- + (isDark.value ? ' body { background-color: #232525; color: #e6e7e9; }' : ''),
48
- height: props.height,
49
- menubar: props.menubar,
50
- statusbar: props.statusbar,
51
- plugins: props.plugins,
52
- toolbar: props.toolbar,
53
- placeholder: props.placeholder,
54
- branding: false,
55
- setup: (ed: Editor) => {
56
- ed.on('input change undo redo ExecCommand', () => {
57
- const html = ed.getContent()
58
- if (html !== model.value) model.value = html
59
- })
60
- }
61
- })
62
- editor = created ?? null
63
- if (editor && props.disabled) editor.mode.set('readonly')
64
- loading.value = false
65
- }
66
-
67
- onMounted(create)
68
- watch(model, html => { if (editor && html !== editor.getContent()) editor.setContent(html) })
69
- watch(() => props.disabled, disabled => editor?.mode.set(disabled ? 'readonly' : 'design'))
70
- watch(() => [isDark.value, props.toolbar, props.plugins, props.menubar, props.statusbar, props.height], create)
71
- onBeforeUnmount(() => {
72
- stopped = true
73
- editor?.remove()
74
- })
75
- </script>
76
-
77
- <template>
78
- <!-- HugeRTE hides the textarea and adds its editor beside it, inside this wrapper. -->
79
- <div class="t-rich-editor" :style="loading ? { minHeight: `${height}px` } : undefined">
80
- <textarea :id="field.id.value" ref="textarea" class="form-control" :placeholder="placeholder" :aria-describedby="field.describedBy.value" />
81
- </div>
82
- </template>
1
+ <script setup lang="ts">
2
+ // A rich text editor with Tabler's WYSIWYG plugin (HugeRTE, an open-source fork of TinyMCE).
3
+ // v-model is the HTML. `toolbar` and `plugins` use HugeRTE's names; the plugins offered are those
4
+ // in src/plugins/richEditor.ts. It follows the light and dark theme (switching rebuilds the editor). Nothing
5
+ // is fetched: the editor, its skins and plugins are bundled and load on first use. It reports `focus`
6
+ // and `blur` (the editor is in an iframe, so the page's own focus events don't see it).
7
+ import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
8
+ import type { Editor } from 'hugerte'
9
+ import { useColorMode } from '../composables/useColorMode'
10
+ import { useField } from '../composables/useField'
11
+ import { loadRichEditor, type RichEditorPlugin } from '../plugins/richEditor'
12
+
13
+ const props = withDefaults(defineProps<{
14
+ height?: number
15
+ toolbar?: string
16
+ plugins?: RichEditorPlugin[]
17
+ menubar?: boolean
18
+ statusbar?: boolean
19
+ placeholder?: string
20
+ disabled?: boolean
21
+ id?: string
22
+ }>(), {
23
+ height: 300,
24
+ toolbar: 'undo redo | blocks | bold italic underline | bullist numlist | link image table | code',
25
+ plugins: () => ['advlist', 'autolink', 'lists', 'link', 'image', 'table', 'code']
26
+ })
27
+
28
+ const model = defineModel<string>({ default: '' })
29
+ const emit = defineEmits<{ focus: []; blur: [] }>()
30
+ const field = useField(props)
31
+ const { isDark } = useColorMode()
32
+ const textarea = ref<HTMLTextAreaElement>()
33
+ const loading = ref(true)
34
+ let editor: Editor | null = null
35
+ let stopped = false
36
+
37
+ async function create() {
38
+ const hugerte = await loadRichEditor()
39
+ if (stopped || !textarea.value) return
40
+ editor?.remove()
41
+ textarea.value.value = model.value
42
+ const [created] = await hugerte.init({
43
+ target: textarea.value,
44
+ // The skins and content styles are bundled resources, named 'default' and 'dark'.
45
+ skin_url: isDark.value ? 'dark' : 'default',
46
+ content_css: isDark.value ? 'dark' : 'default',
47
+ // The page's font, and in the dark theme the card color rather than HugeRTE's navy.
48
+ content_style: 'body { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; font-size: 14px; }'
49
+ + (isDark.value ? ' body { background-color: #232525; color: #e6e7e9; }' : ''),
50
+ height: props.height,
51
+ menubar: props.menubar,
52
+ statusbar: props.statusbar,
53
+ plugins: props.plugins,
54
+ toolbar: props.toolbar,
55
+ placeholder: props.placeholder,
56
+ branding: false,
57
+ setup: (ed: Editor) => {
58
+ ed.on('focus', () => emit('focus'))
59
+ ed.on('blur', () => emit('blur'))
60
+ ed.on('input change undo redo ExecCommand', () => {
61
+ const html = ed.getContent()
62
+ if (html !== model.value) model.value = html
63
+ })
64
+ }
65
+ })
66
+ editor = created ?? null
67
+ if (editor && props.disabled) editor.mode.set('readonly')
68
+ loading.value = false
69
+ }
70
+
71
+ onMounted(create)
72
+ watch(model, html => { if (editor && html !== editor.getContent()) editor.setContent(html) })
73
+ watch(() => props.disabled, disabled => editor?.mode.set(disabled ? 'readonly' : 'design'))
74
+ watch(() => [isDark.value, props.toolbar, props.plugins, props.menubar, props.statusbar, props.height], create)
75
+ onBeforeUnmount(() => {
76
+ stopped = true
77
+ editor?.remove()
78
+ })
79
+ </script>
80
+
81
+ <template>
82
+ <!-- HugeRTE hides the textarea and adds its editor beside it, inside this wrapper. -->
83
+ <div class="t-rich-editor" :style="loading ? { minHeight: `${height}px` } : undefined">
84
+ <textarea :id="field.id.value" ref="textarea" class="form-control" :placeholder="placeholder" :aria-describedby="field.describedBy.value" />
85
+ </div>
86
+ </template>
package/src/index.ts CHANGED
@@ -14,6 +14,7 @@ import TBadge from './components/TBadge.vue'
14
14
  import TButton from './components/TButton.vue'
15
15
  import TCard from './components/TCard.vue'
16
16
  import TCheckbox from './components/TCheckbox.vue'
17
+ import TCheckboxTree from './components/TCheckboxTree.vue'
17
18
  import TColorModeButton from './components/TColorModeButton.vue'
18
19
  import TCommandPalette from './components/TCommandPalette.vue'
19
20
  import TContainerPicker from './components/TContainerPicker.vue'
@@ -34,6 +35,7 @@ import TImageUpload from './components/TImageUpload.vue'
34
35
  import TInput from './components/TInput.vue'
35
36
  import TInputNumber from './components/TInputNumber.vue'
36
37
  import TInputTags from './components/TInputTags.vue'
38
+ import TListBox from './components/TListBox.vue'
37
39
  import TLogView from './components/TLogView.vue'
38
40
  import TModal from './components/TModal.vue'
39
41
  import TNav from './components/TNav.vue'
@@ -44,6 +46,7 @@ import TPanelList from './components/TPanelList.vue'
44
46
  import TProgress from './components/TProgress.vue'
45
47
  import TRadioGroup from './components/TRadioGroup.vue'
46
48
  import TRadiusPicker from './components/TRadiusPicker.vue'
49
+ import TRating from './components/TRating.vue'
47
50
  import TScaledFrame from './components/TScaledFrame.vue'
48
51
  import TSearchButton from './components/TSearchButton.vue'
49
52
  import TSectionLayout from './components/TSectionLayout.vue'
@@ -80,6 +83,7 @@ export {
80
83
  TButton,
81
84
  TCard,
82
85
  TCheckbox,
86
+ TCheckboxTree,
83
87
  TColorModeButton,
84
88
  TCommandPalette,
85
89
  TContainerPicker,
@@ -100,6 +104,7 @@ export {
100
104
  TInput,
101
105
  TInputNumber,
102
106
  TInputTags,
107
+ TListBox,
103
108
  TLogView,
104
109
  TModal,
105
110
  TNav,
@@ -110,6 +115,7 @@ export {
110
115
  TProgress,
111
116
  TRadioGroup,
112
117
  TRadiusPicker,
118
+ TRating,
113
119
  TScaledFrame,
114
120
  TSearchButton,
115
121
  TSectionLayout,
@@ -145,10 +151,10 @@ export { useToast, type Toast } from './composables/useToast'
145
151
 
146
152
  const components = {
147
153
  TAccentPicker, TAdvancedTable, TAlert, TAppLayout, TAuthLayout, TAvatar, TBadge, TButton, TCard,
148
- TCheckbox, TColorModeButton, TCommandPalette, TContainerPicker, TCopyButton, TDataGrid, TDataGridItem, TDensityPicker,
154
+ TCheckbox, TCheckboxTree, TColorModeButton, TCommandPalette, TContainerPicker, TCopyButton, TDataGrid, TDataGridItem, TDensityPicker,
149
155
  TDropdown, TEditableTable, TEmpty, TFieldGroup, TFileUpload, TFontPicker, TFormField, TIcon, TIconPicker, TImageUpload,
150
- TInput, TInputNumber, TInputTags, TLogView, TModal, TNav, TNavPositionPicker, TPage, TPagination,
151
- TPanelList, TProgress, TRadioGroup, TRadiusPicker, TScaledFrame, TSearchButton, TSectionLayout,
156
+ TInput, TInputNumber, TInputTags, TListBox, TLogView, TModal, TNav, TNavPositionPicker, TPage, TPagination,
157
+ TPanelList, TProgress, TRadioGroup, TRadiusPicker, TRating, TScaledFrame, TSearchButton, TSectionLayout,
152
158
  TSelect, TSelectMenu, TSeparator, TShell, TSkeleton, TSlideover, TSparkline, TSpinner, TSplitter, TStatCard,
153
159
  TSteps, TSwitch, TTable, TTabs, TTextarea, TThemeBasePicker, TThemeScope, TToaster, TTooltip,
154
160
  TTopbar, TVectorMap
@@ -172,6 +178,7 @@ declare module 'vue' {
172
178
  TButton: typeof TButton
173
179
  TCard: typeof TCard
174
180
  TCheckbox: typeof TCheckbox
181
+ TCheckboxTree: typeof TCheckboxTree
175
182
  TColorModeButton: typeof TColorModeButton
176
183
  TCommandPalette: typeof TCommandPalette
177
184
  TContainerPicker: typeof TContainerPicker
@@ -192,6 +199,7 @@ declare module 'vue' {
192
199
  TInput: typeof TInput
193
200
  TInputNumber: typeof TInputNumber
194
201
  TInputTags: typeof TInputTags
202
+ TListBox: typeof TListBox
195
203
  TLogView: typeof TLogView
196
204
  TModal: typeof TModal
197
205
  TNav: typeof TNav
@@ -202,6 +210,7 @@ declare module 'vue' {
202
210
  TProgress: typeof TProgress
203
211
  TRadioGroup: typeof TRadioGroup
204
212
  TRadiusPicker: typeof TRadiusPicker
213
+ TRating: typeof TRating
205
214
  TScaledFrame: typeof TScaledFrame
206
215
  TSearchButton: typeof TSearchButton
207
216
  TSectionLayout: typeof TSectionLayout
package/src/types.ts CHANGED
@@ -60,6 +60,14 @@ export interface AdvancedSelectItem<T = unknown> extends SelectItem<T> {
60
60
  avatar?: string
61
61
  }
62
62
 
63
+ /** An item of a TCheckboxTree: a leaf, or a parent with children. */
64
+ export interface TreeItem<T = string> {
65
+ label: string
66
+ value: T
67
+ children?: TreeItem<T>[]
68
+ disabled?: boolean
69
+ }
70
+
63
71
  export interface TabItem {
64
72
  label: string
65
73
  value: string