@tak-ps/vue-tabler 5.9.0 → 5.11.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/CHANGELOG.md +10 -0
- package/components/Badge.vue +1 -1
- package/components/Dropdown.vue +10 -0
- package/components/IconButton.vue +36 -2
- package/components/Schema.vue +22 -2
- package/package.json +2 -2
- package/test/Badge.spec.ts +1 -1
- package/test/Dropdown.spec.ts +78 -0
- package/test/IconButton.spec.ts +27 -0
- package/test/Schema.spec.ts +32 -0
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
### Pending
|
|
14
14
|
|
|
15
|
+
### v5.11.0 - 2026-11-23
|
|
16
|
+
|
|
17
|
+
- :tada: `TablerIconButton` gains a `bordered` prop that draws it as an outlined button and an `active` prop that fills it with the primary color and sets `aria-pressed` for use as a toggle
|
|
18
|
+
- :bug: `TablerDropdown` handles `Escape` and arrow keys on the teleported menu and stops them propagating so Bootstrap's `.dropdown-menu` keydown handler never runs against a menu without a `data-bs-toggle` trigger (previously threw `this._element is undefined` when pressing `Escape` inside a dropdown input)
|
|
19
|
+
- :bug: `TablerBadge` text now defaults to `var(--tblr-body-color)` instead of white so badges stay legible in light mode
|
|
20
|
+
|
|
21
|
+
### v5.10.0 - 2026-10-18
|
|
22
|
+
|
|
23
|
+
- :tada: `TablerSchema` renders a property carrying an `@widget` hint through a `widget-<name>` scoped slot (`field`, `property`, `modelValue`, `disabled`, `update`) when the parent provides one, falling back to the input implied by the property type otherwise
|
|
24
|
+
|
|
15
25
|
### v5.9.0 - 2026-10-13
|
|
16
26
|
|
|
17
27
|
- :bug: `TablerSchema` renders an array of strings, numbers or booleans as a list of inline inputs with add & remove controls - previously each entry was an empty `Entry N` box as the item schema has no properties to recurse into
|
package/components/Badge.vue
CHANGED
|
@@ -27,7 +27,7 @@ const props = withDefaults(defineProps<BadgeProps>(), {
|
|
|
27
27
|
borderColor: undefined,
|
|
28
28
|
borderStyle: 'solid',
|
|
29
29
|
borderWidth: '1px',
|
|
30
|
-
textColor: '
|
|
30
|
+
textColor: 'var(--tblr-body-color)',
|
|
31
31
|
hoverBackgroundColor: undefined,
|
|
32
32
|
hoverBorderColor: undefined,
|
|
33
33
|
hoverBorderStyle: undefined,
|
package/components/Dropdown.vue
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
:style='floatingStyle'
|
|
23
23
|
:aria-labelledby='id'
|
|
24
24
|
@click='onMenuClick'
|
|
25
|
+
@keydown='onMenuKeydown'
|
|
25
26
|
>
|
|
26
27
|
<slot name='dropdown'>
|
|
27
28
|
Dropdown Content
|
|
@@ -168,6 +169,15 @@ function onEscape(e: KeyboardEvent) {
|
|
|
168
169
|
if (e.key === 'Escape') isOpen.value = false;
|
|
169
170
|
}
|
|
170
171
|
|
|
172
|
+
function onMenuKeydown(e: KeyboardEvent) {
|
|
173
|
+
if (e.key === 'Escape') {
|
|
174
|
+
e.stopPropagation();
|
|
175
|
+
isOpen.value = false;
|
|
176
|
+
} else if (e.key === 'ArrowUp' || e.key === 'ArrowDown') {
|
|
177
|
+
e.stopPropagation();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
171
181
|
onMounted(() => {
|
|
172
182
|
document.addEventListener('click', onOutsideClick, true);
|
|
173
183
|
document.addEventListener('keydown', onEscape);
|
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
:aria-label='props.title'
|
|
6
6
|
tabindex='0'
|
|
7
7
|
role='button'
|
|
8
|
+
:aria-pressed='props.active'
|
|
8
9
|
:class='{
|
|
9
10
|
"cursor-pointer": props.disabled === false,
|
|
10
11
|
"cursor-default disabled": props.disabled === true,
|
|
11
|
-
"custom-hover": props.hover && !props.color,
|
|
12
|
+
"custom-hover": props.hover && !props.color && !props.active,
|
|
13
|
+
"icon-button-bordered": props.bordered,
|
|
14
|
+
"icon-button-active": props.active === true,
|
|
12
15
|
}'
|
|
13
16
|
:style='iconButtonStyle'
|
|
14
17
|
class='rounded'
|
|
@@ -30,11 +33,15 @@ export interface IconButtonProps {
|
|
|
30
33
|
title: string;
|
|
31
34
|
hover?: boolean;
|
|
32
35
|
disabled?: boolean;
|
|
36
|
+
bordered?: boolean;
|
|
37
|
+
active?: boolean;
|
|
33
38
|
}
|
|
34
39
|
|
|
35
40
|
const props = withDefaults(defineProps<IconButtonProps>(), {
|
|
36
41
|
hover: true,
|
|
37
|
-
disabled: false
|
|
42
|
+
disabled: false,
|
|
43
|
+
bordered: false,
|
|
44
|
+
active: undefined
|
|
38
45
|
});
|
|
39
46
|
|
|
40
47
|
const iconButtonStyle = computed(() => {
|
|
@@ -69,4 +76,31 @@ const iconButtonStyle = computed(() => {
|
|
|
69
76
|
border-color: color-mix(in srgb, var(--tblr-light) 30%, transparent);
|
|
70
77
|
background: color-mix(in srgb, var(--tblr-light) 12%, transparent);
|
|
71
78
|
}
|
|
79
|
+
|
|
80
|
+
.icon-button-bordered {
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
align-items: center;
|
|
83
|
+
justify-content: center;
|
|
84
|
+
padding: 0.5rem;
|
|
85
|
+
border: var(--tblr-border-width) solid var(--tblr-border-color);
|
|
86
|
+
border-radius: var(--tblr-border-radius);
|
|
87
|
+
background: var(--tblr-bg-surface);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.icon-button-bordered.custom-hover:not(.disabled) {
|
|
91
|
+
border-color: var(--tblr-border-color);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.icon-button-active {
|
|
95
|
+
border: var(--tblr-border-width) solid var(--tblr-primary);
|
|
96
|
+
border-radius: var(--tblr-border-radius);
|
|
97
|
+
background: var(--tblr-primary);
|
|
98
|
+
color: var(--tblr-primary-fg, #ffffff);
|
|
99
|
+
transition: filter 0.15s ease;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.icon-button-active:not(.disabled):hover,
|
|
103
|
+
.icon-button-active:not(.disabled):focus-visible {
|
|
104
|
+
filter: brightness(1.1);
|
|
105
|
+
}
|
|
72
106
|
</style>
|
package/components/Schema.vue
CHANGED
|
@@ -7,7 +7,17 @@
|
|
|
7
7
|
:key='key'
|
|
8
8
|
class='py-2 floating-input'
|
|
9
9
|
>
|
|
10
|
-
<template v-if='
|
|
10
|
+
<template v-if='widgetSlot(key)'>
|
|
11
|
+
<slot
|
|
12
|
+
:name='widgetSlot(key)'
|
|
13
|
+
:field='key'
|
|
14
|
+
:property='s.properties[key]'
|
|
15
|
+
:model-value='data[key]'
|
|
16
|
+
:disabled='disabled'
|
|
17
|
+
:update='(value: unknown) => data[key] = value'
|
|
18
|
+
/>
|
|
19
|
+
</template>
|
|
20
|
+
<template v-else-if='isMultiEnum(s.properties[key])'>
|
|
11
21
|
<TablerMultiEnum
|
|
12
22
|
v-model='data[key]'
|
|
13
23
|
:label='key'
|
|
@@ -373,7 +383,7 @@
|
|
|
373
383
|
</template>
|
|
374
384
|
|
|
375
385
|
<script setup lang="ts">
|
|
376
|
-
import { ref, reactive, computed, watch, onMounted } from 'vue'
|
|
386
|
+
import { ref, reactive, computed, watch, onMounted, useSlots } from 'vue'
|
|
377
387
|
import TablerInput from './input/Input.vue';
|
|
378
388
|
import TablerToggle from './input/Toggle.vue';
|
|
379
389
|
import TablerEnum from './input/Enum.vue';
|
|
@@ -409,6 +419,8 @@ const emit = defineEmits<{
|
|
|
409
419
|
(e: 'update:modelValue', value: any): void;
|
|
410
420
|
}>();
|
|
411
421
|
|
|
422
|
+
const slots = useSlots();
|
|
423
|
+
|
|
412
424
|
const loading = ref(true);
|
|
413
425
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
414
426
|
const s = ref<any>({});
|
|
@@ -436,6 +448,14 @@ const csv = reactive({
|
|
|
436
448
|
/** Selected union variant index per property key */
|
|
437
449
|
const variant = reactive<Record<string, number>>({});
|
|
438
450
|
|
|
451
|
+
/** Name of the `widget-<name>` slot a property's `@widget` hint is rendered with, when the parent provides one */
|
|
452
|
+
const widgetSlot = (key: string): string | undefined => {
|
|
453
|
+
const widget = s.value.properties[key]['@widget'];
|
|
454
|
+
if (typeof widget !== 'string') return;
|
|
455
|
+
const name = `widget-${widget}`;
|
|
456
|
+
return slots[name] ? name : undefined;
|
|
457
|
+
}
|
|
458
|
+
|
|
439
459
|
/** Properties with a fixed const value are seeded but never rendered */
|
|
440
460
|
const visibleKeys = computed<string[]>(() => {
|
|
441
461
|
if (!s.value.properties) return [];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tak-ps/vue-tabler",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "5.
|
|
4
|
+
"version": "5.11.0",
|
|
5
5
|
"lib": "lib.ts",
|
|
6
6
|
"main": "lib.ts",
|
|
7
7
|
"module": "lib.ts",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"eslint": "^10.0.0",
|
|
50
50
|
"eslint-plugin-vue": "^10.0.0",
|
|
51
51
|
"globals": "^17.0.0",
|
|
52
|
-
"jsdom": "^
|
|
52
|
+
"jsdom": "^31.0.0",
|
|
53
53
|
"typescript": "^6.0.0",
|
|
54
54
|
"typescript-eslint": "^8.36.0",
|
|
55
55
|
"vite": "^8.0.0",
|
package/test/Badge.spec.ts
CHANGED
|
@@ -19,7 +19,7 @@ describe('TablerBadge', () => {
|
|
|
19
19
|
|
|
20
20
|
expect(badge.style.backgroundColor).toBe('rgba(34, 197, 94, 0.2)')
|
|
21
21
|
expect(badge.style.borderColor).toBe('rgba(27, 158, 75, 0.2)')
|
|
22
|
-
expect(badge.style.color).toBe('
|
|
22
|
+
expect(badge.style.color).toBe('var(--tblr-body-color)')
|
|
23
23
|
})
|
|
24
24
|
|
|
25
25
|
it('derives a darker border color from the provided background color', () => {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { mount, VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import Dropdown from '../components/Dropdown.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
|
|
8
|
+
const mountDropdown = async () => {
|
|
9
|
+
wrapper = mount(Dropdown, {
|
|
10
|
+
slots: {
|
|
11
|
+
default: '<button class="trigger">Open</button>',
|
|
12
|
+
dropdown: '<li><input class="search" /></li>',
|
|
13
|
+
},
|
|
14
|
+
attachTo: document.body,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
await wrapper.find('.trigger').trigger('click')
|
|
18
|
+
await nextTick()
|
|
19
|
+
|
|
20
|
+
return wrapper
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const menu = () => document.body.querySelector('.tabler-dropdown__menu')
|
|
24
|
+
|
|
25
|
+
describe('TablerDropdown', () => {
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
wrapper?.unmount()
|
|
28
|
+
wrapper = undefined
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
it('teleports the menu to body when opened', async () => {
|
|
32
|
+
await mountDropdown()
|
|
33
|
+
expect(menu()).not.toBeNull()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('closes on Escape from inside the menu without the event reaching document', async () => {
|
|
37
|
+
await mountDropdown()
|
|
38
|
+
|
|
39
|
+
let reachedDocument = false
|
|
40
|
+
const listener = () => { reachedDocument = true }
|
|
41
|
+
document.addEventListener('keydown', listener)
|
|
42
|
+
|
|
43
|
+
const input = menu()?.querySelector('.search') as HTMLInputElement
|
|
44
|
+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
|
45
|
+
await nextTick()
|
|
46
|
+
|
|
47
|
+
document.removeEventListener('keydown', listener)
|
|
48
|
+
|
|
49
|
+
expect(reachedDocument).toBe(false)
|
|
50
|
+
expect(menu()).toBeNull()
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('keeps arrow keys inside the menu open and away from document', async () => {
|
|
54
|
+
await mountDropdown()
|
|
55
|
+
|
|
56
|
+
let reachedDocument = false
|
|
57
|
+
const listener = () => { reachedDocument = true }
|
|
58
|
+
document.addEventListener('keydown', listener)
|
|
59
|
+
|
|
60
|
+
const input = menu()?.querySelector('.search') as HTMLInputElement
|
|
61
|
+
input.dispatchEvent(new KeyboardEvent('keydown', { key: 'ArrowDown', bubbles: true }))
|
|
62
|
+
await nextTick()
|
|
63
|
+
|
|
64
|
+
document.removeEventListener('keydown', listener)
|
|
65
|
+
|
|
66
|
+
expect(reachedDocument).toBe(false)
|
|
67
|
+
expect(menu()).not.toBeNull()
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('still closes on Escape pressed outside the menu', async () => {
|
|
71
|
+
await mountDropdown()
|
|
72
|
+
|
|
73
|
+
document.body.dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true }))
|
|
74
|
+
await nextTick()
|
|
75
|
+
|
|
76
|
+
expect(menu()).toBeNull()
|
|
77
|
+
})
|
|
78
|
+
})
|
package/test/IconButton.spec.ts
CHANGED
|
@@ -63,4 +63,31 @@ describe('TablerIconButton', () => {
|
|
|
63
63
|
expect(iconButtonSource).toContain('border-color: color-mix(in srgb, var(--tblr-light) 30%, transparent);')
|
|
64
64
|
expect(iconButtonSource).toContain('background: color-mix(in srgb, var(--tblr-light) 12%, transparent);')
|
|
65
65
|
})
|
|
66
|
+
|
|
67
|
+
it('omits aria-pressed unless used as a toggle', () => {
|
|
68
|
+
const plain = mount(IconButton, { props: { title: 'Toggle Panel' } })
|
|
69
|
+
expect(plain.get('div').attributes('aria-pressed')).toBeUndefined()
|
|
70
|
+
|
|
71
|
+
const off = mount(IconButton, { props: { title: 'Toggle Panel', active: false } })
|
|
72
|
+
expect(off.get('div').attributes('aria-pressed')).toBe('false')
|
|
73
|
+
expect(off.get('div').classes()).toContain('custom-hover')
|
|
74
|
+
expect(off.get('div').classes()).not.toContain('icon-button-active')
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('fills with the primary color when active', () => {
|
|
78
|
+
const wrapper = mount(IconButton, { props: { title: 'Toggle Panel', active: true } })
|
|
79
|
+
|
|
80
|
+
expect(wrapper.get('div').attributes('aria-pressed')).toBe('true')
|
|
81
|
+
expect(wrapper.get('div').classes()).toContain('icon-button-active')
|
|
82
|
+
expect(wrapper.get('div').classes()).not.toContain('custom-hover')
|
|
83
|
+
expect(iconButtonSource).toContain('background: var(--tblr-primary);')
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('draws a button outline when bordered', () => {
|
|
87
|
+
const wrapper = mount(IconButton, { props: { title: 'Toggle Panel', bordered: true } })
|
|
88
|
+
|
|
89
|
+
expect(wrapper.get('div').classes()).toContain('icon-button-bordered')
|
|
90
|
+
expect(wrapper.get('div').classes()).toContain('custom-hover')
|
|
91
|
+
expect(iconButtonSource).toContain('border: var(--tblr-border-width) solid var(--tblr-border-color);')
|
|
92
|
+
})
|
|
66
93
|
})
|
package/test/Schema.spec.ts
CHANGED
|
@@ -612,4 +612,36 @@ describe('TablerSchema applying default values', () => {
|
|
|
612
612
|
expect((wrapper.find('select').element as HTMLSelectElement).value).toBe('Team Account')
|
|
613
613
|
expect(lastEmitted(wrapper)).toEqual({ Source: { Mode: 'Team', TeamId: 't', Verbose: true } })
|
|
614
614
|
})
|
|
615
|
+
|
|
616
|
+
it('renders a property with an @widget hint through its slot and takes the slot update', async () => {
|
|
617
|
+
const wrapper = mount(Schema, {
|
|
618
|
+
props: {
|
|
619
|
+
modelValue: {},
|
|
620
|
+
schema: {
|
|
621
|
+
type: 'object',
|
|
622
|
+
properties: {
|
|
623
|
+
Type: { type: 'string', default: 'a-f-G', '@widget': 'type' },
|
|
624
|
+
Icon: { type: 'string', '@widget': 'icon' },
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
},
|
|
628
|
+
slots: {
|
|
629
|
+
'widget-type': `<template #widget-type='{ field, modelValue, update }'>
|
|
630
|
+
<button class='widget' :data-field='field' @click='update("a-h-G")'>{{ modelValue }}</button>
|
|
631
|
+
</template>`,
|
|
632
|
+
},
|
|
633
|
+
})
|
|
634
|
+
|
|
635
|
+
await flushPromises()
|
|
636
|
+
|
|
637
|
+
const widget = wrapper.get('button.widget')
|
|
638
|
+
expect(widget.attributes('data-field')).toBe('Type')
|
|
639
|
+
expect(widget.text()).toBe('a-f-G')
|
|
640
|
+
expect(wrapper.findAll('input').length).toBe(1)
|
|
641
|
+
|
|
642
|
+
await widget.trigger('click')
|
|
643
|
+
await flushPromises()
|
|
644
|
+
|
|
645
|
+
expect(lastEmitted(wrapper)).toEqual({ Type: 'a-h-G', Icon: '' })
|
|
646
|
+
})
|
|
615
647
|
})
|