@m3ui-vue/m3ui-vue 0.9.1 → 0.9.3
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 +43 -0
- package/dist/API.md +266 -60
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-pJU1vFaR.js → MTextField-DKtgPymd.js} +422 -206
- package/dist/MTextField-DKtgPymd.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.md +547 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MBox.vue.d.ts +3 -3
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MColorPicker.vue.d.ts +13 -1
- package/dist/components/MColorPickerModal.vue.d.ts +14 -2
- package/dist/components/MDragHandle.vue.d.ts +12 -0
- package/dist/components/MEmojiSelector.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +5 -3
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MOverlay.vue.d.ts +1 -1
- package/dist/components/MScrollField.vue.d.ts +40 -0
- package/dist/components/MScrollable.vue.d.ts +9 -0
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MSplitter.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTimePickerModal.vue.d.ts +3 -0
- package/dist/components/MTimeScroll.vue.d.ts +22 -0
- package/dist/components/MToggleButton.vue.d.ts +2 -0
- package/dist/components/MTransition.vue.d.ts +34 -0
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/components/_MColorPanel.vue.d.ts +18 -0
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_colorUtils.d.ts +34 -0
- package/dist/composables/_themeColor.d.ts +1 -0
- package/dist/composables/_useSpring.d.ts +17 -0
- package/dist/composables/dynamicColor.d.ts +18 -0
- package/dist/composables/useColorPalette.d.ts +27 -0
- package/dist/composables/useLocale.d.ts +16 -0
- package/dist/directives/vRipple.d.ts +16 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/locales/index.js +112 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7443 -6150
- package/dist/m3ui.js.map +1 -1
- package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
- package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/palettes.css +546 -0
- package/dist/styles/theme.css +90 -0
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-Drihe5G2.js → useLocale-Cn9MVIdw.js} +17 -1
- package/dist/useLocale-Cn9MVIdw.js.map +1 -0
- package/package.json +3 -2
- package/src/__tests__/MButtonGroup.test.ts +51 -0
- package/src/__tests__/MColorPicker.test.ts +141 -0
- package/src/__tests__/MDragHandle.test.ts +57 -0
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MListItemShape.test.ts +76 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MScrollField.test.ts +69 -0
- package/src/__tests__/MScrollable.test.ts +42 -0
- package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
- package/src/__tests__/MTabs.test.ts +39 -0
- package/src/__tests__/MTimePickerModal.test.ts +52 -0
- package/src/__tests__/MTimeScroll.test.ts +44 -0
- package/src/__tests__/MTransition.test.ts +27 -0
- package/src/__tests__/dynamicColor.test.ts +191 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MBox.vue +4 -2
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +118 -44
- package/src/components/MColorPicker.vue +114 -210
- package/src/components/MColorPickerModal.vue +50 -251
- package/src/components/MDragHandle.vue +54 -0
- package/src/components/MFab.vue +8 -15
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MList.vue +33 -3
- package/src/components/MListItem.vue +75 -5
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MScrollField.vue +310 -0
- package/src/components/MScrollable.vue +160 -5
- package/src/components/MSplitButton.vue +5 -12
- package/src/components/MSplitter.vue +33 -10
- package/src/components/MSwipeToDismiss.vue +247 -0
- package/src/components/MTabs.vue +16 -5
- package/src/components/MTimePickerModal.vue +48 -8
- package/src/components/MTimeScroll.vue +161 -0
- package/src/components/MToggleButton.vue +5 -12
- package/src/components/MTransition.vue +149 -0
- package/src/components/_MColorPanel.vue +478 -0
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_colorUtils.ts +107 -0
- package/src/composables/_themeColor.ts +33 -0
- package/src/composables/_useSpring.ts +91 -0
- package/src/composables/dynamicColor.ts +85 -0
- package/src/composables/useColorPalette.ts +171 -25
- package/src/composables/useFieldBg.ts +6 -0
- package/src/composables/useLocale.ts +34 -0
- package/src/data/emoji-names/emoji-names-de.ts +1 -0
- package/src/data/emoji-names/emoji-names-en.ts +1 -0
- package/src/data/emoji-names/emoji-names-es.ts +1 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1 -0
- package/src/data/emojis.ts +1 -0
- package/src/directives/vRipple.ts +73 -0
- package/src/index.ts +14 -1
- package/src/locales/de.ts +16 -0
- package/src/locales/es.ts +16 -0
- package/src/locales/fr.ts +16 -0
- package/src/locales/ja.ts +16 -0
- package/src/locales/ko.ts +16 -0
- package/src/locales/pt.ts +16 -0
- package/src/locales/zh.ts +16 -0
- package/src/plugin.ts +30 -7
- package/src/styles/palettes.css +546 -0
- package/src/styles/theme.css +90 -0
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-pJU1vFaR.js.map +0 -1
- package/dist/useLocale-Drihe5G2.js.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MIconButton from '../components/MIconButton.vue'
|
|
4
|
+
|
|
5
|
+
describe('MIconButton', () => {
|
|
6
|
+
it('is a plain button without checked', async () => {
|
|
7
|
+
const w = mount(MIconButton, { props: { icon: 'favorite' } })
|
|
8
|
+
expect(w.attributes('aria-pressed')).toBeUndefined()
|
|
9
|
+
await w.trigger('click')
|
|
10
|
+
expect(w.emitted('update:checked')).toBeUndefined()
|
|
11
|
+
expect(w.find('.material-symbols-outlined').attributes('style')).not.toContain('FILL')
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
it('toggles through v-model:checked', async () => {
|
|
15
|
+
const w = mount(MIconButton, { props: { icon: 'favorite', checked: false } })
|
|
16
|
+
expect(w.attributes('aria-pressed')).toBe('false')
|
|
17
|
+
await w.trigger('click')
|
|
18
|
+
expect(w.emitted('update:checked')).toEqual([[true]])
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('does not toggle while disabled', async () => {
|
|
22
|
+
const w = mount(MIconButton, { props: { icon: 'favorite', checked: false, disabled: true } })
|
|
23
|
+
await w.trigger('click')
|
|
24
|
+
expect(w.emitted('update:checked')).toBeUndefined()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('fills the icon and swaps to checkedIcon when checked', () => {
|
|
28
|
+
const w = mount(MIconButton, { props: { icon: 'play_arrow', checkedIcon: 'pause', checked: true } })
|
|
29
|
+
const icon = w.find('.material-symbols-outlined')
|
|
30
|
+
expect(icon.text()).toBe('pause')
|
|
31
|
+
expect(icon.attributes('style')).toContain("'FILL' 1")
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('uses the selected colors of each variant', () => {
|
|
35
|
+
const cases: [string, string, string][] = [
|
|
36
|
+
['standard', 'text-on-surface-variant', 'text-primary'],
|
|
37
|
+
['filled', 'bg-surface-container', 'bg-primary'],
|
|
38
|
+
['tonal', 'bg-secondary-container', 'bg-secondary'],
|
|
39
|
+
['outlined', 'border-current', 'bg-inverse-surface'],
|
|
40
|
+
]
|
|
41
|
+
for (const [variant, off, on] of cases) {
|
|
42
|
+
expect(mount(MIconButton, { props: { icon: 'x', variant: variant as any, checked: false } }).classes()).toContain(off)
|
|
43
|
+
expect(mount(MIconButton, { props: { icon: 'x', variant: variant as any, checked: true } }).classes()).toContain(on)
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
it('renders a button, not a link, when it is a toggle', () => {
|
|
48
|
+
const w = mount(MIconButton, { props: { icon: 'x', checked: false, to: '/somewhere' } })
|
|
49
|
+
expect(w.element.tagName).toBe('BUTTON')
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('sets the toggle shape on mount: round squares off when checked', () => {
|
|
53
|
+
const off = mount(MIconButton, { props: { icon: 'x', checked: false } })
|
|
54
|
+
expect((off.element as HTMLElement).style.borderRadius).toBe('20px')
|
|
55
|
+
const on = mount(MIconButton, { props: { icon: 'x', checked: true } })
|
|
56
|
+
expect((on.element as HTMLElement).style.borderRadius).toBe('12px')
|
|
57
|
+
const square = mount(MIconButton, { props: { icon: 'x', checked: true, shape: 'squared' } })
|
|
58
|
+
expect((square.element as HTMLElement).style.borderRadius).toBe('20px')
|
|
59
|
+
})
|
|
60
|
+
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MList from '../components/MList.vue'
|
|
5
|
+
import MListItem from '../components/MListItem.vue'
|
|
6
|
+
import MListSubheader from '../components/MListSubheader.vue'
|
|
7
|
+
|
|
8
|
+
let wrapper: VueWrapper | undefined
|
|
9
|
+
afterEach(() => {
|
|
10
|
+
wrapper?.unmount()
|
|
11
|
+
wrapper = undefined
|
|
12
|
+
document.body.innerHTML = ''
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// Springs run on rAF; give them time to settle
|
|
16
|
+
const settle = () => new Promise((r) => setTimeout(r, 600))
|
|
17
|
+
const radius = (el: Element) => (el as HTMLElement).style.borderRadius
|
|
18
|
+
|
|
19
|
+
describe('MListItem shape morph', () => {
|
|
20
|
+
it('rests at 4px and grows on hover and press when clickable', async () => {
|
|
21
|
+
wrapper = mount(MListItem, { props: { title: 'A', clickable: true }, attachTo: document.body })
|
|
22
|
+
const row = wrapper.element
|
|
23
|
+
await settle()
|
|
24
|
+
expect(radius(row)).toBe('4px')
|
|
25
|
+
row.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
26
|
+
await settle()
|
|
27
|
+
expect(radius(row)).toBe('8px')
|
|
28
|
+
row.dispatchEvent(new PointerEvent('pointerdown', { button: 0, pointerType: 'mouse' }))
|
|
29
|
+
await settle()
|
|
30
|
+
expect(radius(row)).toBe('16px')
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('ignores hover when not interactive, but morphs when selected', async () => {
|
|
34
|
+
wrapper = mount(MListItem, { props: { title: 'A' }, attachTo: document.body })
|
|
35
|
+
wrapper.element.dispatchEvent(new PointerEvent('pointerenter', { pointerType: 'mouse' }))
|
|
36
|
+
await settle()
|
|
37
|
+
expect(radius(wrapper.element)).toBe('4px')
|
|
38
|
+
await wrapper.setProps({ active: true })
|
|
39
|
+
await settle()
|
|
40
|
+
expect(radius(wrapper.element)).toBe('16px')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('rounds the outer corners of each segmented run', async () => {
|
|
44
|
+
wrapper = mount(MList, {
|
|
45
|
+
props: { segmented: true },
|
|
46
|
+
slots: {
|
|
47
|
+
default: () => [
|
|
48
|
+
h(MListItem, { title: 'A' }),
|
|
49
|
+
h(MListItem, { title: 'B' }),
|
|
50
|
+
h(MListItem, { title: 'C' }),
|
|
51
|
+
h(MListSubheader, { title: 'More' }),
|
|
52
|
+
h(MListItem, { title: 'D' }),
|
|
53
|
+
],
|
|
54
|
+
},
|
|
55
|
+
attachTo: document.body,
|
|
56
|
+
})
|
|
57
|
+
await settle()
|
|
58
|
+
const rows = wrapper.findAll('[role="listitem"]').map((w) => w.element)
|
|
59
|
+
expect(rows.map(radius)).toEqual([
|
|
60
|
+
'16px 16px 4px 4px',
|
|
61
|
+
'4px',
|
|
62
|
+
'4px 4px 16px 16px',
|
|
63
|
+
'16px',
|
|
64
|
+
])
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('keeps the pill in nav lists', async () => {
|
|
68
|
+
wrapper = mount(MList, {
|
|
69
|
+
props: { nav: true },
|
|
70
|
+
slots: { default: () => h(MListItem, { title: 'A', clickable: true }) },
|
|
71
|
+
attachTo: document.body,
|
|
72
|
+
})
|
|
73
|
+
await settle()
|
|
74
|
+
expect(radius(wrapper.find('[role="listitem"]').element)).toBe('')
|
|
75
|
+
})
|
|
76
|
+
})
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, provide } from 'vue'
|
|
4
|
+
import MMenuItem from '../components/MMenuItem.vue'
|
|
5
|
+
|
|
6
|
+
// Mounts the item inside a stand-in for MMenu that records close() calls
|
|
7
|
+
function inMenu(props: Record<string, unknown>) {
|
|
8
|
+
const closes: number[] = []
|
|
9
|
+
const Host = defineComponent({
|
|
10
|
+
setup() {
|
|
11
|
+
provide('m-menu-close', () => closes.push(1))
|
|
12
|
+
return () => h(MMenuItem, props, () => 'Item')
|
|
13
|
+
},
|
|
14
|
+
})
|
|
15
|
+
const w = mount(Host)
|
|
16
|
+
return { item: w.findComponent(MMenuItem), button: w.find('button'), closes }
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
describe('MMenuItem', () => {
|
|
20
|
+
it('stays a plain item without selected or checked', () => {
|
|
21
|
+
const { button } = inMenu({})
|
|
22
|
+
expect(button.attributes('role')).toBeUndefined()
|
|
23
|
+
expect(button.attributes('aria-checked')).toBeUndefined()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('is a radio item with selected, closing the menu on click', async () => {
|
|
27
|
+
const { button, closes } = inMenu({ selected: true })
|
|
28
|
+
expect(button.attributes('role')).toBe('menuitemradio')
|
|
29
|
+
expect(button.attributes('aria-checked')).toBe('true')
|
|
30
|
+
expect(button.classes()).toContain('bg-tertiary-container')
|
|
31
|
+
await button.trigger('click')
|
|
32
|
+
expect(closes).toHaveLength(1)
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
it('is a checkbox item with checked, toggling v-model:checked and keeping the menu open', async () => {
|
|
36
|
+
const { item, button, closes } = inMenu({ checked: false })
|
|
37
|
+
expect(button.attributes('role')).toBe('menuitemcheckbox')
|
|
38
|
+
expect(button.attributes('aria-checked')).toBe('false')
|
|
39
|
+
await button.trigger('click')
|
|
40
|
+
expect(item.emitted('update:checked')).toEqual([[true]])
|
|
41
|
+
expect(item.emitted('click')).toHaveLength(1)
|
|
42
|
+
expect(closes).toHaveLength(0)
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
it('closes after a checked item when keepOpen is false', async () => {
|
|
46
|
+
const { button, closes } = inMenu({ checked: true, keepOpen: false })
|
|
47
|
+
await button.trigger('click')
|
|
48
|
+
expect(closes).toHaveLength(1)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('rounds the outer corners of a run of selectable items, and all corners of the selected one', async () => {
|
|
52
|
+
const w = mount(defineComponent({
|
|
53
|
+
setup: () => () => h('div', [
|
|
54
|
+
h(MMenuItem, { selected: false }, () => 'A'),
|
|
55
|
+
h(MMenuItem, { selected: true }, () => 'B'),
|
|
56
|
+
h(MMenuItem, { selected: false }, () => 'C'),
|
|
57
|
+
h(MMenuItem, { selected: false }, () => 'D'),
|
|
58
|
+
h('hr'),
|
|
59
|
+
h(MMenuItem, { checked: false }, () => 'E'),
|
|
60
|
+
h(MMenuItem, {}, () => 'Plain'),
|
|
61
|
+
]),
|
|
62
|
+
}), { attachTo: document.body })
|
|
63
|
+
await nextTick()
|
|
64
|
+
// (the DOM shortens four equal corners to one value)
|
|
65
|
+
const radius = w.findAll('button').map((b) => b.element.style.borderRadius)
|
|
66
|
+
expect(radius).toEqual([
|
|
67
|
+
'12px 12px 4px 4px', // first
|
|
68
|
+
'12px', // selected
|
|
69
|
+
'4px', // middle
|
|
70
|
+
'4px 4px 12px 12px', // last
|
|
71
|
+
'4px', // alone after the divider
|
|
72
|
+
'', // plain items keep their own shape
|
|
73
|
+
])
|
|
74
|
+
w.unmount()
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('shows a sliding check without an icon, and swaps or fills the icon with one', () => {
|
|
78
|
+
expect(inMenu({ checked: true }).button.find('span.overflow-hidden').text()).toBe('check')
|
|
79
|
+
const swapped = inMenu({ selected: true, icon: 'play_arrow', selectedIcon: 'pause' }).button
|
|
80
|
+
expect(swapped.text()).toContain('pause')
|
|
81
|
+
const filled = inMenu({ selected: true, icon: 'star' }).button.find('.material-symbols-outlined')
|
|
82
|
+
expect(filled.attributes('style')).toContain('FILL')
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import MScrollField from '../components/MScrollField.vue'
|
|
4
|
+
|
|
5
|
+
let wrapper: VueWrapper | undefined
|
|
6
|
+
afterEach(() => {
|
|
7
|
+
wrapper?.unmount()
|
|
8
|
+
wrapper = undefined
|
|
9
|
+
document.body.innerHTML = ''
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
13
|
+
|
|
14
|
+
describe('MScrollField', () => {
|
|
15
|
+
it('formats with two digits and moves with the arrow keys, wrapping around', async () => {
|
|
16
|
+
wrapper = mount(MScrollField, {
|
|
17
|
+
props: { modelValue: 0, count: 60, label: 'Minute', 'onUpdate:modelValue': (v: number) => wrapper!.setProps({ modelValue: v }) },
|
|
18
|
+
attachTo: document.body,
|
|
19
|
+
})
|
|
20
|
+
const field = wrapper.find('[role="slider"]')
|
|
21
|
+
expect(field.attributes('aria-valuetext')).toBe('00')
|
|
22
|
+
await field.trigger('keydown', { key: 'ArrowUp' })
|
|
23
|
+
await wait()
|
|
24
|
+
expect(wrapper.emitted('update:modelValue')?.at(-1)).toEqual([59])
|
|
25
|
+
expect(field.attributes('aria-valuetext')).toBe('59')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('follows an outside change the short way around', async () => {
|
|
29
|
+
wrapper = mount(MScrollField, { props: { modelValue: 58, count: 60 }, attachTo: document.body })
|
|
30
|
+
await wrapper.setProps({ modelValue: 1 })
|
|
31
|
+
await wait()
|
|
32
|
+
// 58 → 59 → 0 → 1, never back through 57…2
|
|
33
|
+
const seen = wrapper.emitted<[number]>('update:modelValue')!.map((e) => e[0])
|
|
34
|
+
expect(seen).toEqual([59, 0, 1])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
// Regression: the wheel took its own value, handed back through v-model mid-flight, for an outside change
|
|
38
|
+
// and retargeted toward it, so it stopped short (and on a 4-item wheel scrolled back and forth forever)
|
|
39
|
+
it('ignores its own value coming back through v-model while it is still moving (wheel)', async () => {
|
|
40
|
+
wrapper = mount(MScrollField, {
|
|
41
|
+
props: { modelValue: 0, count: 4, 'onUpdate:modelValue': (v: number) => wrapper!.setProps({ modelValue: v }) },
|
|
42
|
+
attachTo: document.body,
|
|
43
|
+
})
|
|
44
|
+
const field = wrapper.find('[role="slider"]')
|
|
45
|
+
// 120px = 3 steps in one go: 0 → 3
|
|
46
|
+
await field.trigger('wheel', { deltaY: 120 })
|
|
47
|
+
await wait(1000)
|
|
48
|
+
const seen = wrapper.emitted<[number]>('update:modelValue')!.map((e) => e[0])
|
|
49
|
+
expect(seen).toEqual([1, 2, 3])
|
|
50
|
+
expect(field.attributes('aria-valuetext')).toBe('03')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('ignores its own value coming back through v-model while it is still moving (keys)', async () => {
|
|
54
|
+
wrapper = mount(MScrollField, {
|
|
55
|
+
props: { modelValue: 10, count: 60, 'onUpdate:modelValue': (v: number) => wrapper!.setProps({ modelValue: v }) },
|
|
56
|
+
attachTo: document.body,
|
|
57
|
+
})
|
|
58
|
+
const field = wrapper.find('[role="slider"]')
|
|
59
|
+
for (let i = 0; i < 4; i++) await field.trigger('keydown', { key: 'ArrowDown' })
|
|
60
|
+
await wait(1000)
|
|
61
|
+
expect(wrapper.emitted<[number]>('update:modelValue')!.at(-1)).toEqual([14])
|
|
62
|
+
expect(field.attributes('aria-valuetext')).toBe('14')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('uses a custom format', () => {
|
|
66
|
+
wrapper = mount(MScrollField, { props: { modelValue: 1, count: 2, format: (i: number) => ['L', 'oz'][i]! } })
|
|
67
|
+
expect(wrapper.find('[role="slider"]').attributes('aria-valuetext')).toBe('oz')
|
|
68
|
+
})
|
|
69
|
+
})
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { h } from 'vue'
|
|
4
|
+
import MScrollable from '../components/MScrollable.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
describe('MScrollable indicator', () => {
|
|
15
|
+
it('hides the native scrollbar and sizes the thumb to the visible fraction', async () => {
|
|
16
|
+
wrapper = mount(MScrollable, {
|
|
17
|
+
props: { scrollbar: 'indicator', scrollbarFade: false },
|
|
18
|
+
slots: { default: () => h('div', 'Long content') },
|
|
19
|
+
attachTo: document.body,
|
|
20
|
+
})
|
|
21
|
+
const el = wrapper.element as HTMLElement
|
|
22
|
+
expect(el.className).toContain('m3-scrollable-hidden')
|
|
23
|
+
Object.defineProperty(el, 'clientHeight', { value: 200, configurable: true })
|
|
24
|
+
Object.defineProperty(el, 'scrollHeight', { value: 800, configurable: true })
|
|
25
|
+
el.scrollTop = 300
|
|
26
|
+
el.dispatchEvent(new Event('scroll'))
|
|
27
|
+
const thumb = wrapper.find('.m3-scrollable-thumb-v').element as HTMLElement
|
|
28
|
+
// Track 196px (2px inset at each end), thumb 196 × 200/800 = 49px, offset 2 + 300/600 × (196 − 49)
|
|
29
|
+
expect(thumb.style.height).toBe('49px')
|
|
30
|
+
expect(thumb.style.transform).toBe('translate(0px, 375.5px)')
|
|
31
|
+
expect(thumb.style.opacity).toBe('1')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('draws nothing when the content fits', async () => {
|
|
35
|
+
wrapper = mount(MScrollable, { props: { scrollbar: 'indicator' }, slots: { default: () => h('div', 'Short') } })
|
|
36
|
+
const el = wrapper.element as HTMLElement
|
|
37
|
+
Object.defineProperty(el, 'clientHeight', { value: 200, configurable: true })
|
|
38
|
+
Object.defineProperty(el, 'scrollHeight', { value: 200, configurable: true })
|
|
39
|
+
el.dispatchEvent(new Event('scroll'))
|
|
40
|
+
expect((wrapper.find('.m3-scrollable-thumb-v').element as HTMLElement).style.display).toBe('none')
|
|
41
|
+
})
|
|
42
|
+
})
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MSwipeToDismiss from '../components/MSwipeToDismiss.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
14
|
+
|
|
15
|
+
describe('MSwipeToDismiss', () => {
|
|
16
|
+
function setup(props: Record<string, unknown> = {}) {
|
|
17
|
+
wrapper = mount(MSwipeToDismiss, {
|
|
18
|
+
props,
|
|
19
|
+
slots: { default: () => h('div', 'Row'), background: ({ target }: { target: string }) => h('span', { class: 'bg' }, target) },
|
|
20
|
+
attachTo: document.body,
|
|
21
|
+
})
|
|
22
|
+
Object.defineProperty(wrapper.element, 'offsetWidth', { value: 300, configurable: true })
|
|
23
|
+
return wrapper
|
|
24
|
+
}
|
|
25
|
+
function drag(el: Element, dx: number, durationMs: number) {
|
|
26
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, pointerId: 1, bubbles: true }))
|
|
27
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + dx / 2, clientY: 10, pointerId: 1, timeStamp: 0 } as PointerEventInit))
|
|
28
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
29
|
+
return new Promise<void>((r) => setTimeout(() => {
|
|
30
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
31
|
+
r()
|
|
32
|
+
}, durationMs))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Slowly (under the 125px/s fling velocity) and still moving when released, so the 56px threshold decides
|
|
36
|
+
async function slowDrag(el: Element, dx: number) {
|
|
37
|
+
el.dispatchEvent(new PointerEvent('pointerdown', { clientX: 100, clientY: 10, button: 0, pointerId: 1, bubbles: true }))
|
|
38
|
+
const steps = 10
|
|
39
|
+
for (let i = 1; i <= steps; i++) {
|
|
40
|
+
await wait(60)
|
|
41
|
+
window.dispatchEvent(new PointerEvent('pointermove', { clientX: 100 + (dx * i) / steps, clientY: 10, pointerId: 1 }))
|
|
42
|
+
}
|
|
43
|
+
window.dispatchEvent(new PointerEvent('pointerup', { clientX: 100 + dx, clientY: 10, pointerId: 1 }))
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
it('dismisses past the 56px threshold', async () => {
|
|
47
|
+
const w = setup()
|
|
48
|
+
await slowDrag(w.element, -80)
|
|
49
|
+
await nextTick()
|
|
50
|
+
expect(w.find('.bg').text()).toBe('end-to-start')
|
|
51
|
+
await wait(400)
|
|
52
|
+
expect(w.emitted('dismiss')?.[0]).toEqual(['end-to-start'])
|
|
53
|
+
expect(w.emitted('update:modelValue')?.[0]).toEqual(['end-to-start'])
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('springs back from a short swipe', async () => {
|
|
57
|
+
const w = setup()
|
|
58
|
+
await slowDrag(w.element, 30)
|
|
59
|
+
await wait(400)
|
|
60
|
+
expect(w.emitted('dismiss')).toBeUndefined()
|
|
61
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
it('a quick flick dismisses even a short swipe', async () => {
|
|
65
|
+
const w = setup()
|
|
66
|
+
await drag(w.element, 30, 10)
|
|
67
|
+
await wait(400)
|
|
68
|
+
expect(w.emitted('dismiss')?.[0]).toEqual(['start-to-end'])
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('only swipes in the allowed directions', async () => {
|
|
72
|
+
const w = setup({ endToStart: false })
|
|
73
|
+
await drag(w.element, -120, 300)
|
|
74
|
+
await wait(400)
|
|
75
|
+
expect(w.emitted('dismiss')).toBeUndefined()
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('slides back when v-model is reset from inside @dismiss', async () => {
|
|
79
|
+
const state = ref<'settled' | 'start-to-end' | 'end-to-start'>('settled')
|
|
80
|
+
wrapper = mount(defineComponent({
|
|
81
|
+
setup: () => () => h(MSwipeToDismiss, {
|
|
82
|
+
modelValue: state.value,
|
|
83
|
+
'onUpdate:modelValue': (v: typeof state.value) => { state.value = v },
|
|
84
|
+
onDismiss: () => { state.value = 'settled' },
|
|
85
|
+
}, () => h('div', 'Row')),
|
|
86
|
+
}), { attachTo: document.body })
|
|
87
|
+
const root = wrapper.find('.touch-pan-y').element
|
|
88
|
+
Object.defineProperty(root, 'offsetWidth', { value: 300, configurable: true })
|
|
89
|
+
await drag(root, 30, 10)
|
|
90
|
+
await wait(800)
|
|
91
|
+
expect(state.value).toBe('settled')
|
|
92
|
+
expect((root.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('animates back when v-model is reset', async () => {
|
|
96
|
+
const w = setup()
|
|
97
|
+
await w.setProps({ modelValue: 'start-to-end' })
|
|
98
|
+
await wait(400)
|
|
99
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('translateX(300px)')
|
|
100
|
+
await w.setProps({ modelValue: 'settled' })
|
|
101
|
+
await wait(400)
|
|
102
|
+
expect((w.element.lastElementChild as HTMLElement).style.transform).toBe('')
|
|
103
|
+
})
|
|
104
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MTabs from '../components/MTabs.vue'
|
|
4
|
+
|
|
5
|
+
const tabs = [
|
|
6
|
+
{ value: 'flights', label: 'Flights', icon: 'flight' },
|
|
7
|
+
{ value: 'hotels', label: 'Hotels', icon: 'hotel' },
|
|
8
|
+
]
|
|
9
|
+
|
|
10
|
+
const firstTab = (props: Record<string, unknown>) =>
|
|
11
|
+
mount(MTabs, { props: { modelValue: 'flights', tabs, ...props } }).find('button').classes()
|
|
12
|
+
|
|
13
|
+
describe('MTabs', () => {
|
|
14
|
+
it('stacks primary icons above the label in a 64px tab by default', () => {
|
|
15
|
+
const c = firstTab({})
|
|
16
|
+
expect(c).toContain('flex-col')
|
|
17
|
+
expect(c).toContain('h-16')
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('puts the icon beside the label in a 48px tab with iconPosition="leading" (LeadingIconTab)', () => {
|
|
21
|
+
const c = firstTab({ iconPosition: 'leading' })
|
|
22
|
+
expect(c).toContain('flex-row')
|
|
23
|
+
expect(c).toContain('h-12')
|
|
24
|
+
expect(c).toContain('gap-2')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('keeps secondary icons beside the label by default and stacks them with iconPosition="top"', () => {
|
|
28
|
+
expect(firstTab({ variant: 'secondary' })).toContain('flex-row')
|
|
29
|
+
const c = firstTab({ variant: 'secondary', iconPosition: 'top' })
|
|
30
|
+
expect(c).toContain('flex-col')
|
|
31
|
+
expect(c).toContain('h-16')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('emits the picked tab', async () => {
|
|
35
|
+
const w = mount(MTabs, { props: { modelValue: 'flights', tabs } })
|
|
36
|
+
await w.findAll('button')[1]!.trigger('click')
|
|
37
|
+
expect(w.emitted('update:modelValue')).toEqual([['hotels']])
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { nextTick } from 'vue'
|
|
4
|
+
import MTimePickerModal from '../components/MTimePickerModal.vue'
|
|
5
|
+
import MTimeScroll from '../components/MTimeScroll.vue'
|
|
6
|
+
|
|
7
|
+
let wrapper: VueWrapper | undefined
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
wrapper?.unmount()
|
|
10
|
+
wrapper = undefined
|
|
11
|
+
document.body.innerHTML = ''
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
async function open(props: Record<string, unknown>) {
|
|
15
|
+
wrapper = mount(MTimePickerModal, { props: { modelValue: null, ...props }, attachTo: document.body })
|
|
16
|
+
await wrapper.setProps({ show: true })
|
|
17
|
+
await nextTick()
|
|
18
|
+
return wrapper
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const button = (text: string) => [...document.body.querySelectorAll('button')].find((b) => b.textContent?.trim() === text)!
|
|
22
|
+
|
|
23
|
+
describe('MTimePickerModal', () => {
|
|
24
|
+
it('shows the clock dial by default', async () => {
|
|
25
|
+
const w = await open({ modelValue: '09:30' })
|
|
26
|
+
expect(w.findComponent(MTimeScroll).exists()).toBe(false)
|
|
27
|
+
expect(document.body.textContent).toContain('09')
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('picks the time with scroll wheels in scroll mode and confirms it as 24-hour', async () => {
|
|
31
|
+
const w = await open({ modelValue: '21:07', mode: 'scroll' })
|
|
32
|
+
const scroll = w.findComponent(MTimeScroll)
|
|
33
|
+
expect(scroll.exists()).toBe(true)
|
|
34
|
+
// The minute wheel only shows multiples of minuteStep (5): it starts on 05
|
|
35
|
+
expect(scroll.props('modelValue')).toBe('21:05')
|
|
36
|
+
await scroll.vm.$emit('update:modelValue', '08:45')
|
|
37
|
+
button('OK').click()
|
|
38
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['08:45'])
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('switches between scroll and keyboard input', async () => {
|
|
42
|
+
const w = await open({ modelValue: '14:00', mode: 'scroll', use24h: true })
|
|
43
|
+
const toggle = document.body.querySelector<HTMLButtonElement>('[aria-label="Switch to text input mode"]')!
|
|
44
|
+
toggle.click()
|
|
45
|
+
await nextTick()
|
|
46
|
+
expect(w.findComponent(MTimeScroll).exists()).toBe(false)
|
|
47
|
+
expect(document.body.querySelectorAll('input')).toHaveLength(2)
|
|
48
|
+
document.body.querySelector<HTMLButtonElement>('[aria-label="Switch to scroll mode"]')!.click()
|
|
49
|
+
await nextTick()
|
|
50
|
+
expect(w.findComponent(MTimeScroll).props('modelValue')).toBe('14:00')
|
|
51
|
+
})
|
|
52
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { mount } from '@vue/test-utils'
|
|
3
|
+
import MTimeScroll from '../components/MTimeScroll.vue'
|
|
4
|
+
import MScrollField from '../components/MScrollField.vue'
|
|
5
|
+
|
|
6
|
+
describe('MTimeScroll', () => {
|
|
7
|
+
it('maps a 12-hour time onto the wheels (12 o\'clock is the last hour item)', () => {
|
|
8
|
+
const w = mount(MTimeScroll, { props: { modelValue: '00:30' } })
|
|
9
|
+
const [hours, minutes] = w.findAllComponents(MScrollField)
|
|
10
|
+
expect(hours!.props('count')).toBe(12)
|
|
11
|
+
expect(hours!.props('modelValue')).toBe(11)
|
|
12
|
+
expect(minutes!.props('modelValue')).toBe(30)
|
|
13
|
+
expect(w.find('[role="radio"][aria-checked="true"]').text()).toMatch(/AM/i)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('keeps AM/PM when the hour wheel turns', async () => {
|
|
17
|
+
const w = mount(MTimeScroll, { props: { modelValue: '15:00' } })
|
|
18
|
+
await w.findAllComponents(MScrollField)[0]!.vm.$emit('update:modelValue', 0)
|
|
19
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['13:00'])
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('switches period with the toggle', async () => {
|
|
23
|
+
const w = mount(MTimeScroll, { props: { modelValue: '09:15' } })
|
|
24
|
+
await w.findAll('[role="radio"]')[1]!.trigger('click')
|
|
25
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['21:15'])
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
it('uses a 24-hour wheel without the toggle', async () => {
|
|
29
|
+
const w = mount(MTimeScroll, { props: { modelValue: '18:40', use24h: true } })
|
|
30
|
+
const [hours] = w.findAllComponents(MScrollField)
|
|
31
|
+
expect(hours!.props('count')).toBe(24)
|
|
32
|
+
expect(hours!.props('modelValue')).toBe(18)
|
|
33
|
+
expect(w.find('[role="radiogroup"]').exists()).toBe(false)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('steps minutes by minuteStep', async () => {
|
|
37
|
+
const w = mount(MTimeScroll, { props: { modelValue: '10:07', minuteStep: 5 } })
|
|
38
|
+
const minutes = w.findAllComponents(MScrollField)[1]!
|
|
39
|
+
expect(minutes.props('count')).toBe(12)
|
|
40
|
+
expect(minutes.props('modelValue')).toBe(1)
|
|
41
|
+
await minutes.vm.$emit('update:modelValue', 3)
|
|
42
|
+
expect(w.emitted('update:modelValue')!.at(-1)).toEqual(['10:15'])
|
|
43
|
+
})
|
|
44
|
+
})
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { describe, it, expect, afterEach } from 'vitest'
|
|
2
|
+
import { mount, type VueWrapper } from '@vue/test-utils'
|
|
3
|
+
import { defineComponent, h, nextTick, ref } from 'vue'
|
|
4
|
+
import MTransition from '../components/MTransition.vue'
|
|
5
|
+
|
|
6
|
+
let wrapper: VueWrapper | undefined
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
wrapper?.unmount()
|
|
9
|
+
wrapper = undefined
|
|
10
|
+
document.body.innerHTML = ''
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
const wait = (ms = 600) => new Promise((r) => setTimeout(r, ms))
|
|
14
|
+
|
|
15
|
+
describe('MTransition', () => {
|
|
16
|
+
it('overlaps both views while animating, then removes the old one', async () => {
|
|
17
|
+
const page = ref('a')
|
|
18
|
+
wrapper = mount(defineComponent({
|
|
19
|
+
setup: () => () => h(MTransition, { type: 'fade-through' }, () => h('div', { key: page.value, class: 'page' }, page.value)),
|
|
20
|
+
}), { attachTo: document.body, global: { stubs: { transition: false } } })
|
|
21
|
+
page.value = 'b'
|
|
22
|
+
await nextTick()
|
|
23
|
+
expect(wrapper.findAll('.page').map((p) => p.text())).toEqual(['a', 'b'])
|
|
24
|
+
await wait(800)
|
|
25
|
+
expect(wrapper.findAll('.page').map((p) => p.text())).toEqual(['b'])
|
|
26
|
+
})
|
|
27
|
+
})
|