@m3ui-vue/m3ui-vue 0.8.6 → 0.8.7

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.
Files changed (61) hide show
  1. package/README.md +4 -0
  2. package/dist/{MMenuItem-BmPLAyv5.js → MMenuItem-DmrsQrK7.js} +2 -2
  3. package/dist/{MMenuItem-BmPLAyv5.js.map → MMenuItem-DmrsQrK7.js.map} +1 -1
  4. package/dist/chart.js +5 -1
  5. package/dist/chart.js.map +1 -1
  6. package/dist/code-editor.js +1 -1
  7. package/dist/components/MBottomSheet.vue.d.ts +3 -3
  8. package/dist/components/MListDetail.vue.d.ts +31 -0
  9. package/dist/components/MNavigationRail.vue.d.ts +6 -3
  10. package/dist/components/MNavigationSuite.vue.d.ts +46 -0
  11. package/dist/components/MShortNavigationBar.vue.d.ts +6 -1
  12. package/dist/components/MSideSheet.vue.d.ts +4 -4
  13. package/dist/components/MSupportingPane.vue.d.ts +34 -0
  14. package/dist/components/MTransferList.vue.d.ts +55 -34
  15. package/dist/components/MWindow.vue.d.ts +39 -1
  16. package/dist/components/_MTransferPane.vue.d.ts +10 -3
  17. package/dist/composables/_useItemLink.d.ts +30 -0
  18. package/dist/composables/_useSheetMotion.d.ts +7 -0
  19. package/dist/composables/useLocale.d.ts +3 -0
  20. package/dist/composables/useWindowSizeClass.d.ts +19 -0
  21. package/dist/index.d.ts +6 -0
  22. package/dist/locales/index.js +28 -7
  23. package/dist/locales/index.js.map +1 -1
  24. package/dist/m3ui-vue.css +1 -1
  25. package/dist/m3ui.js +2357 -1868
  26. package/dist/m3ui.js.map +1 -1
  27. package/dist/rich-text-editor.js +2 -2
  28. package/dist/styles.css +1 -1
  29. package/dist/{useLocale-4afAzuuP.js → useLocale-Bircp823.js} +5 -2
  30. package/dist/useLocale-Bircp823.js.map +1 -0
  31. package/package.json +1 -1
  32. package/src/__tests__/MChart.test.ts +28 -0
  33. package/src/__tests__/MShortNavigationBar.test.ts +25 -0
  34. package/src/__tests__/MTransferList.test.ts +73 -0
  35. package/src/__tests__/MWindow.test.ts +258 -0
  36. package/src/__tests__/adaptiveLayouts.test.ts +191 -0
  37. package/src/__tests__/sheets.test.ts +76 -0
  38. package/src/components/MBottomSheet.vue +11 -57
  39. package/src/components/MChart.vue +2 -1
  40. package/src/components/MListDetail.vue +103 -0
  41. package/src/components/MNavigationRail.vue +13 -8
  42. package/src/components/MNavigationSuite.vue +89 -0
  43. package/src/components/MShortNavigationBar.vue +37 -17
  44. package/src/components/MSideSheet.vue +11 -56
  45. package/src/components/MSupportingPane.vue +70 -0
  46. package/src/components/MTransferList.vue +43 -9
  47. package/src/components/MWindow.vue +507 -108
  48. package/src/components/_MTransferPane.vue +113 -35
  49. package/src/composables/_useItemLink.ts +19 -0
  50. package/src/composables/_useSheetMotion.ts +181 -0
  51. package/src/composables/useLocale.ts +7 -0
  52. package/src/composables/useWindowSizeClass.ts +93 -0
  53. package/src/index.ts +6 -0
  54. package/src/locales/de.ts +3 -0
  55. package/src/locales/es.ts +3 -0
  56. package/src/locales/fr.ts +3 -0
  57. package/src/locales/ja.ts +3 -0
  58. package/src/locales/ko.ts +3 -0
  59. package/src/locales/pt.ts +3 -0
  60. package/src/locales/zh.ts +3 -0
  61. package/dist/useLocale-4afAzuuP.js.map +0 -1
@@ -0,0 +1,191 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import { widthSizeClass, heightSizeClass } from '../composables/useWindowSizeClass'
5
+ import MNavigationSuite from '../components/MNavigationSuite.vue'
6
+ import MListDetail from '../components/MListDetail.vue'
7
+ import MSupportingPane from '../components/MSupportingPane.vue'
8
+
9
+ // happy-dom has no layout: every element reports the size below, and resizing fires the
10
+ // mocked ResizeObserver callbacks the way the browser would.
11
+ let size = { w: 1000, h: 800 }
12
+ const observers = new Set<() => void>()
13
+ class FakeResizeObserver {
14
+ constructor(private cb: () => void) {}
15
+ observe() { observers.add(this.cb) }
16
+ disconnect() { observers.delete(this.cb) }
17
+ }
18
+ async function resize(w: number, h = 800) {
19
+ size = { w, h }
20
+ observers.forEach((cb) => cb())
21
+ await nextTick()
22
+ }
23
+
24
+ beforeEach(() => {
25
+ size = { w: 1000, h: 800 }
26
+ vi.stubGlobal('ResizeObserver', FakeResizeObserver)
27
+ vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockImplementation(() => size.w)
28
+ vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockImplementation(() => size.h)
29
+ })
30
+ afterEach(() => {
31
+ vi.unstubAllGlobals()
32
+ vi.restoreAllMocks()
33
+ observers.clear()
34
+ })
35
+
36
+ describe('window size classes', () => {
37
+ it('uses the androidx WindowSizeClass breakpoints', () => {
38
+ expect([599, 600, 839, 840, 1199, 1200, 1599, 1600].map(widthSizeClass)).toEqual([
39
+ 'compact', 'medium', 'medium', 'expanded', 'expanded', 'large', 'large', 'extra-large',
40
+ ])
41
+ expect([479, 480, 899, 900].map(heightSizeClass)).toEqual(['compact', 'medium', 'medium', 'expanded'])
42
+ })
43
+ })
44
+
45
+ const navItems = [
46
+ { value: 'home', label: 'Home', icon: 'home' },
47
+ { value: 'search', label: 'Search', icon: 'search' },
48
+ ]
49
+
50
+ describe('MNavigationSuite', () => {
51
+ const setup = (props = {}) =>
52
+ mount(MNavigationSuite, {
53
+ props: { modelValue: 'home', items: navItems, ...props },
54
+ slots: { default: `<template #default="{ layout }"><p class="content">{{ layout }}</p></template>` },
55
+ attachTo: document.body,
56
+ })
57
+
58
+ it('picks bar, landscape bar or rail from its own size, keeping the content element', async () => {
59
+ const w = setup()
60
+ await nextTick()
61
+ expect(w.find('.content').text()).toBe('rail')
62
+ expect(w.findComponent({ name: 'MNavigationRail' }).exists()).toBe(true)
63
+ const content = w.find('.content').element
64
+
65
+ await resize(400)
66
+ expect(w.find('.content').text()).toBe('bar')
67
+ expect(w.findComponent({ name: 'MNavigationRail' }).exists()).toBe(false)
68
+ expect(w.findComponent({ name: 'MShortNavigationBar' }).props()).toMatchObject({ arrangement: 'equal', iconPosition: 'top' })
69
+
70
+ await resize(800, 400)
71
+ expect(w.find('.content').text()).toBe('bar-medium')
72
+ expect(w.findComponent({ name: 'MShortNavigationBar' }).props()).toMatchObject({ arrangement: 'centered', iconPosition: 'start' })
73
+ expect(w.find('.content').element).toBe(content)
74
+ w.unmount()
75
+ })
76
+
77
+ it('layout forces a navigation and selection goes through v-model', async () => {
78
+ const w = setup({ layout: 'rail-expanded' })
79
+ await resize(400)
80
+ expect(w.findComponent({ name: 'MNavigationRail' }).props('expanded')).toBe(true)
81
+ w.findComponent({ name: 'MNavigationRail' }).vm.$emit('update:modelValue', 'search')
82
+ expect(w.emitted('update:modelValue')![0]).toEqual(['search'])
83
+ w.unmount()
84
+ })
85
+ })
86
+
87
+ describe('MListDetail', () => {
88
+ const setup = (props = {}) =>
89
+ mount(MListDetail, {
90
+ props: { ...props },
91
+ slots: {
92
+ list: `<template #list="{ twoPane }"><p class="list">{{ twoPane }}</p></template>`,
93
+ detail: `<template #detail="{ back }"><button class="back" @click="back">back</button></template>`,
94
+ },
95
+ attachTo: document.body,
96
+ })
97
+ const panes = (w: ReturnType<typeof setup>) => w.element.children as HTMLCollectionOf<HTMLElement>
98
+
99
+ it('shows both panes from 840px, with the list at 360px (412px from 1200px)', async () => {
100
+ const w = setup()
101
+ await nextTick()
102
+ expect(w.find('.list').text()).toBe('true')
103
+ expect(panes(w)[0]!.style.width).toBe('360px')
104
+ expect(panes(w)[1]!.hasAttribute('inert')).toBe(false)
105
+ await resize(1300)
106
+ expect(panes(w)[0]!.style.width).toBe('412px')
107
+ w.unmount()
108
+ })
109
+
110
+ it('one pane: shows the list or the detail, and back() returns to the list', async () => {
111
+ const w = setup()
112
+ await resize(700)
113
+ expect(w.find('.list').text()).toBe('false')
114
+ expect(panes(w)[1]!.hasAttribute('inert')).toBe(true)
115
+ expect(panes(w)[0]!.hasAttribute('inert')).toBe(false)
116
+
117
+ await w.setProps({ showDetail: true })
118
+ expect(panes(w)[0]!.hasAttribute('inert')).toBe(true)
119
+ expect(panes(w)[1]!.hasAttribute('inert')).toBe(false)
120
+ await w.find('.back').trigger('click')
121
+ expect(w.emitted('update:showDetail')![0]).toEqual([false])
122
+ w.unmount()
123
+ })
124
+ })
125
+
126
+ describe('MSupportingPane', () => {
127
+ const setup = (props = {}) =>
128
+ mount(MSupportingPane, {
129
+ props: { ...props },
130
+ slots: { main: '<p class="main">main</p>', supporting: '<p class="sup">sup</p>' },
131
+ attachTo: document.body,
132
+ })
133
+
134
+ it('puts the supporting pane beside, then below the main one', async () => {
135
+ const w = setup()
136
+ await nextTick()
137
+ expect(w.classes()).not.toContain('flex-col')
138
+ expect((w.element.children[1] as HTMLElement).style.width).toBe('360px')
139
+ await resize(500)
140
+ expect(w.classes()).toContain('flex-col')
141
+ expect(w.find('.sup').exists()).toBe(true)
142
+ w.unmount()
143
+ })
144
+
145
+ it("singlePane='sheet' moves it into a bottom sheet and closes it once it fits again", async () => {
146
+ const w = setup({ singlePane: 'sheet', open: true, 'onUpdate:open': (v: boolean) => w.setProps({ open: v }) })
147
+ await resize(500)
148
+ const sheet = w.findComponent({ name: 'MBottomSheet' })
149
+ expect(sheet.exists()).toBe(true)
150
+ expect(sheet.props('modelValue')).toBe(true)
151
+ await resize(1000)
152
+ expect(w.emitted('update:open')![0]).toEqual([false])
153
+ expect(w.findComponent({ name: 'MBottomSheet' }).exists()).toBe(false)
154
+ expect(w.find('.sup').exists()).toBe(true)
155
+ w.unmount()
156
+ })
157
+ })
158
+
159
+ describe('navigation items with `to`', () => {
160
+ const linkItems = [
161
+ { value: 'home', label: 'Home', icon: 'home', to: '/home' },
162
+ { value: 'search', label: 'Search', icon: 'search' },
163
+ { value: 'off', label: 'Off', icon: 'block', to: '/off', disabled: true },
164
+ ]
165
+
166
+ it('render as plain links without vue-router, buttons otherwise, and still update v-model', async () => {
167
+ for (const [layout, name] of [['rail', 'MNavigationRail'], ['bar', 'MShortNavigationBar']] as const) {
168
+ const w = mount(MNavigationSuite, { props: { modelValue: 'search', items: linkItems, layout } })
169
+ const nav = w.findComponent({ name })
170
+ const els = nav.findAll('nav a, nav button').filter((e) => e.text().match(/Home|Search|Off/))
171
+ expect(els.map((e) => e.element.tagName)).toEqual(['A', 'BUTTON', 'BUTTON'])
172
+ expect(els[0]!.attributes('href')).toBe('/home')
173
+ await els[0]!.trigger('click')
174
+ expect(w.emitted('update:modelValue')![0]).toEqual(['home'])
175
+ w.unmount()
176
+ }
177
+ })
178
+
179
+ it('render as RouterLink when vue-router is installed', () => {
180
+ const RouterLink = { name: 'RouterLink', props: ['to'], template: '<a class="rl" :href="String(to)"><slot /></a>' }
181
+ const w = mount(MNavigationSuite, {
182
+ props: { modelValue: 'home', items: linkItems, layout: 'rail' },
183
+ global: { components: { RouterLink } },
184
+ })
185
+ const links = w.findAllComponents({ name: 'RouterLink' })
186
+ expect(links).toHaveLength(1)
187
+ expect(links[0]!.props('to')).toBe('/home')
188
+ w.unmount()
189
+ })
190
+ })
191
+
@@ -0,0 +1,76 @@
1
+ import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
2
+ import { mount } from '@vue/test-utils'
3
+ import { nextTick } from 'vue'
4
+ import MBottomSheet from '../components/MBottomSheet.vue'
5
+ import MSideSheet from '../components/MSideSheet.vue'
6
+
7
+ // happy-dom has no layout: the panel is 400px tall / 320px wide. Fake timers drive rAF.
8
+ beforeEach(() => {
9
+ vi.useFakeTimers({ toFake: ['requestAnimationFrame', 'cancelAnimationFrame', 'performance', 'setTimeout', 'Date'] })
10
+ vi.spyOn(HTMLElement.prototype, 'offsetHeight', 'get').mockReturnValue(400)
11
+ vi.spyOn(HTMLElement.prototype, 'offsetWidth', 'get').mockReturnValue(320)
12
+ })
13
+ afterEach(() => {
14
+ vi.useRealTimers()
15
+ vi.restoreAllMocks()
16
+ document.body.innerHTML = ''
17
+ })
18
+
19
+ const panel = () => document.querySelector<HTMLElement>('[data-sheet-panel]')
20
+ const scrim = () => document.querySelector<HTMLElement>('[data-sheet-scrim]')
21
+
22
+ describe.each([
23
+ ['MBottomSheet', MBottomSheet, 'translateY', 400],
24
+ ['MSideSheet', MSideSheet, 'translateX', 320],
25
+ ] as const)('%s motion', (_, Comp, fn, size) => {
26
+ it('slides in from fully off-screen with the scrim fading in, then out on close', async () => {
27
+ const w = mount(Comp as any, { props: { modelValue: false }, attachTo: document.body, global: { stubs: { transition: false } } })
28
+ await w.setProps({ modelValue: true })
29
+ await nextTick()
30
+ expect(panel()!.style.transform).toBe(`${fn}(${size}px)`)
31
+ expect(scrim()!.style.opacity).toBe('0')
32
+
33
+ vi.advanceTimersByTime(80)
34
+ const mid = parseFloat(panel()!.style.transform.match(/\(([-\d.]+)px/)![1]!)
35
+ expect(mid).toBeGreaterThan(0)
36
+ expect(mid).toBeLessThan(size)
37
+
38
+ vi.advanceTimersByTime(1500)
39
+ expect(panel()!.style.transform).toBe(`${fn}(0px)`)
40
+ expect(scrim()!.style.opacity).toBe('1')
41
+
42
+ await w.setProps({ modelValue: false })
43
+ vi.advanceTimersByTime(1500)
44
+ await nextTick()
45
+ expect(panel()).toBeNull()
46
+ w.unmount()
47
+ })
48
+
49
+ it('a short drag springs back; a long one dismisses', async () => {
50
+ const w = mount(Comp as any, { props: { modelValue: true }, attachTo: document.body, global: { stubs: { transition: false } } })
51
+ await nextTick()
52
+ vi.advanceTimersByTime(1500)
53
+ const handle = (fn === 'translateY'
54
+ ? panel()!.querySelector('.cursor-grab')
55
+ : panel()!.querySelector('.cursor-ew-resize')) as HTMLElement
56
+ handle.setPointerCapture = () => {}
57
+ const at = (v: number) => (fn === 'translateY' ? { clientY: v, clientX: 0 } : { clientX: v, clientY: 0 })
58
+
59
+ handle.dispatchEvent(new PointerEvent('pointerdown', { ...at(0), pointerId: 1 }))
60
+ vi.advanceTimersByTime(16)
61
+ handle.dispatchEvent(new PointerEvent('pointermove', { ...at(40), pointerId: 1 }))
62
+ expect(panel()!.style.transform).toBe(`${fn}(40px)`)
63
+ vi.advanceTimersByTime(200)
64
+ handle.dispatchEvent(new PointerEvent('pointerup', { pointerId: 1 }))
65
+ vi.advanceTimersByTime(1500)
66
+ expect(panel()!.style.transform).toBe(`${fn}(0px)`)
67
+ expect(w.emitted('update:modelValue')).toBeUndefined()
68
+
69
+ handle.dispatchEvent(new PointerEvent('pointerdown', { ...at(0), pointerId: 1 }))
70
+ vi.advanceTimersByTime(16)
71
+ handle.dispatchEvent(new PointerEvent('pointermove', { ...at(150), pointerId: 1 }))
72
+ handle.dispatchEvent(new PointerEvent('pointerup', { pointerId: 1 }))
73
+ expect(w.emitted('update:modelValue')![0]).toEqual([false])
74
+ w.unmount()
75
+ })
76
+ })
@@ -1,6 +1,6 @@
1
1
  <script setup lang="ts">
2
- import { computed, ref } from 'vue'
3
2
  import MIcon from './MIcon.vue'
3
+ import { useSheetMotion } from '../composables/_useSheetMotion'
4
4
 
5
5
  withDefaults(defineProps<{
6
6
  modelValue: boolean
@@ -11,52 +11,30 @@ withDefaults(defineProps<{
11
11
  const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
12
12
  const close = () => emit('update:modelValue', false)
13
13
 
14
- // Drag-to-dismiss state
15
- const dragY = ref(0)
16
- const dragging = ref(false)
17
- let startY = 0
18
-
19
- function onHandlePointerDown(e: PointerEvent) {
20
- dragging.value = true
21
- startY = e.clientY
22
- dragY.value = 0
23
- ;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
24
- }
25
- function onHandlePointerMove(e: PointerEvent) {
26
- if (!dragging.value) return
27
- dragY.value = Math.max(0, e.clientY - startY)
28
- }
29
- function onHandlePointerUp() {
30
- if (dragY.value > 100) close()
31
- dragging.value = false
32
- dragY.value = 0
33
- }
34
-
35
- const sheetStyle = computed(() => ({
36
- transform: `translateY(${dragY.value}px)`,
37
- transition: dragging.value ? 'none' : undefined,
38
- }))
14
+ // Slide in/out and drag-to-dismiss, as springs (see _useSheetMotion).
15
+ const motion = useSheetMotion('y', close)
39
16
  </script>
40
17
 
41
18
  <template>
42
19
  <Teleport to="body">
43
- <Transition name="bs" :duration="{ enter: 320, leave: 280 }">
20
+ <Transition :css="false" @enter="motion.onEnter" @leave="motion.onLeave">
44
21
  <div v-if="modelValue" class="fixed inset-0 z-200 flex flex-col justify-end">
45
22
  <!-- Scrim -->
46
- <div class="bs-scrim absolute inset-0 bg-scrim/32" @click="close" />
23
+ <div data-sheet-scrim class="absolute inset-0 bg-scrim/32" @click="close" />
47
24
 
48
25
  <!-- Panel -->
49
26
  <div
50
- class="bs-panel relative mx-auto flex w-full max-w-[640px] flex-col rounded-t-[28px] bg-surface-container-low shadow-elevation-1"
27
+ data-sheet-panel
28
+ class="relative mx-auto flex w-full max-w-[640px] flex-col rounded-t-[28px] bg-surface-container-low shadow-elevation-1"
51
29
  :class="fullHeight ? 'max-h-[92vh]' : 'max-h-[60vh]'"
52
- :style="sheetStyle"
53
30
  >
54
31
  <!-- Drag handle -->
55
32
  <div
56
33
  class="flex h-12 shrink-0 cursor-grab touch-none select-none items-center justify-center active:cursor-grabbing"
57
- @pointerdown="onHandlePointerDown"
58
- @pointermove="onHandlePointerMove"
59
- @pointerup="onHandlePointerUp"
34
+ @pointerdown="motion.onDragStart"
35
+ @pointermove="motion.onDragMove"
36
+ @pointerup="motion.onDragEnd"
37
+ @pointercancel="motion.onDragEnd"
60
38
  >
61
39
  <div class="h-1 w-8 rounded-full bg-on-surface-variant" />
62
40
  </div>
@@ -87,27 +65,3 @@ const sheetStyle = computed(() => ({
87
65
  </Transition>
88
66
  </Teleport>
89
67
  </template>
90
-
91
- <style scoped>
92
- .bs-scrim {
93
- transition: opacity 300ms ease;
94
- }
95
- .bs-enter-from .bs-scrim,
96
- .bs-leave-to .bs-scrim {
97
- opacity: 0;
98
- }
99
-
100
- .bs-panel {
101
- transition:
102
- transform 320ms cubic-bezier(0.2, 0, 0, 1),
103
- opacity 240ms ease;
104
- }
105
- .bs-enter-from .bs-panel {
106
- transform: translateY(40%);
107
- opacity: 0;
108
- }
109
- .bs-leave-to .bs-panel {
110
- transform: translateY(100%) !important;
111
- opacity: 0;
112
- }
113
- </style>
@@ -40,7 +40,8 @@ onMounted(async () => {
40
40
  m3Colors.value = getM3Colors()
41
41
 
42
42
  themeObserver = new MutationObserver(() => { m3Colors.value = getM3Colors() })
43
- themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style'] })
43
+ // `class` flips light/dark, `data-palette` switches the palette (useColorPalette / createM3UI).
44
+ themeObserver.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'style', 'data-palette'] })
44
45
  // Canvas text drawn before a web font finishes loading keeps the fallback, so redraw once it has
45
46
  document.fonts?.ready.then(() => { m3Colors.value = getM3Colors() })
46
47
 
@@ -0,0 +1,103 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref } from 'vue'
3
+ import { useWindowSizeClass } from '../composables/useWindowSizeClass'
4
+
5
+ /*
6
+ * M3 list-detail canonical layout, after androidx ListDetailPaneScaffold +
7
+ * calculatePaneScaffoldDirective: from the expanded width class (840px) up, list and detail
8
+ * sit side by side with a 24dp spacer and the list at its preferred width (360dp, 412dp from
9
+ * large); below that only one pane shows, the detail when it's the current destination
10
+ * (`showDetail`), the list otherwise. Measured on the component itself, not the window.
11
+ */
12
+ const props = withDefaults(defineProps<{
13
+ /** Whether the detail is the current destination. One-pane layouts show it instead of the list. */
14
+ showDetail?: boolean
15
+ /** List pane width in the two-pane layout. Defaults to M3's 360px (412px from the large width class). */
16
+ listWidth?: string
17
+ }>(), { showDetail: false })
18
+
19
+ const emit = defineEmits<{ 'update:showDetail': [boolean] }>()
20
+
21
+ defineSlots<{
22
+ list?: (props: { twoPane: boolean }) => unknown
23
+ /** `back()` returns to the list (sets `showDetail` to false). */
24
+ detail?: (props: { twoPane: boolean; back: () => void }) => unknown
25
+ }>()
26
+
27
+ const root = ref<HTMLElement>()
28
+ const { widthClass } = useWindowSizeClass(root)
29
+ const twoPane = computed(() => widthClass.value !== 'compact' && widthClass.value !== 'medium')
30
+ const width = computed(() =>
31
+ props.listWidth ?? (widthClass.value === 'large' || widthClass.value === 'extra-large' ? '412px' : '360px'),
32
+ )
33
+ const back = () => emit('update:showDetail', false)
34
+
35
+ // One pane: both stay mounted (the list keeps its scroll position and the detail its state),
36
+ // the hidden one is moved aside, made invisible and `inert`.
37
+ const listHidden = computed(() => !twoPane.value && props.showDetail)
38
+ const detailHidden = computed(() => !twoPane.value && !props.showDetail)
39
+ </script>
40
+
41
+ <template>
42
+ <div ref="root" class="relative flex overflow-hidden" :class="twoPane ? 'gap-6' : ''">
43
+ <!-- No default size: give it a height so each pane scrolls on its own. -->
44
+ <div
45
+ class="min-h-0 overflow-auto"
46
+ :class="twoPane ? 'shrink-0' : ['m3-ld-pane absolute inset-0', listHidden && 'm3-ld-list-hidden']"
47
+ :style="twoPane ? { width } : undefined"
48
+ :inert="listHidden || undefined"
49
+ :aria-hidden="listHidden || undefined"
50
+ >
51
+ <slot name="list" :two-pane="twoPane" />
52
+ </div>
53
+ <div
54
+ class="min-h-0 min-w-0 flex-1 overflow-auto"
55
+ :class="twoPane ? '' : ['m3-ld-pane absolute inset-0', detailHidden && 'm3-ld-detail-hidden']"
56
+ :inert="detailHidden || undefined"
57
+ :aria-hidden="detailHidden || undefined"
58
+ >
59
+ <slot name="detail" :two-pane="twoPane" :back="back" />
60
+ </div>
61
+ </div>
62
+ </template>
63
+
64
+ <style scoped>
65
+ /* Visibility flips at the end of a hide (and at the start of a show) so the pane fades out first. */
66
+ .m3-ld-pane {
67
+ transition:
68
+ transform 0.4s cubic-bezier(0.2, 0, 0, 1),
69
+ opacity 0.2s linear,
70
+ visibility 0s;
71
+ }
72
+ .m3-ld-list-hidden {
73
+ transform: translateX(-12%);
74
+ opacity: 0;
75
+ visibility: hidden;
76
+ transition:
77
+ transform 0.4s cubic-bezier(0.2, 0, 0, 1),
78
+ opacity 0.2s linear,
79
+ visibility 0s 0.4s;
80
+ }
81
+ .m3-ld-detail-hidden {
82
+ transform: translateX(100%);
83
+ opacity: 0;
84
+ visibility: hidden;
85
+ transition:
86
+ transform 0.4s cubic-bezier(0.2, 0, 0, 1),
87
+ opacity 0.2s linear 0.2s,
88
+ visibility 0s 0.4s;
89
+ }
90
+ :global([dir='rtl']) .m3-ld-list-hidden {
91
+ transform: translateX(12%);
92
+ }
93
+ :global([dir='rtl']) .m3-ld-detail-hidden {
94
+ transform: translateX(-100%);
95
+ }
96
+ @media (prefers-reduced-motion: reduce) {
97
+ .m3-ld-pane,
98
+ .m3-ld-list-hidden,
99
+ .m3-ld-detail-hidden {
100
+ transition: visibility 0s;
101
+ }
102
+ }
103
+ </style>
@@ -2,6 +2,7 @@
2
2
  import { computed, ref, watch, onUnmounted } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
4
  import MBadge from './MBadge.vue'
5
+ import { useItemLink, type ItemLink } from '../composables/_useItemLink'
5
6
 
6
7
  export interface NavRailItem {
7
8
  value: string | number
@@ -10,6 +11,8 @@ export interface NavRailItem {
10
11
  badge?: number
11
12
  badgeDot?: boolean
12
13
  disabled?: boolean
14
+ /** Makes the item a link: a vue-router location (rendered as RouterLink), or a URL without vue-router. */
15
+ to?: ItemLink
13
16
  }
14
17
 
15
18
  const props = withDefaults(defineProps<{
@@ -47,6 +50,8 @@ const railExpanded = computed(() => !props.modal && props.expanded)
47
50
  * collapsed -> expanded change to animate, running alongside (not instead of) the panel's
48
51
  * own width spring.
49
52
  */
53
+ const itemLink = useItemLink()
54
+
50
55
  const panelExpanded = ref(false)
51
56
 
52
57
  function close() {
@@ -193,13 +198,13 @@ onUnmounted(() => {
193
198
  'justify-end': alignment === 'bottom',
194
199
  }"
195
200
  >
196
- <button
201
+ <component
202
+ :is="itemLink(item).tag"
197
203
  v-for="item in items"
198
204
  :key="item.value"
199
- type="button"
205
+ v-bind="itemLink(item).attrs"
200
206
  class="group relative block h-16 w-full cursor-pointer focus-visible:outline-none"
201
207
  :class="item.disabled ? 'cursor-not-allowed opacity-[0.38]' : ''"
202
- :disabled="item.disabled"
203
208
  @click="!item.disabled && $emit('update:modelValue', item.value)"
204
209
  >
205
210
  <!--
@@ -289,7 +294,7 @@ onUnmounted(() => {
289
294
  >
290
295
  {{ item.label }}
291
296
  </span>
292
- </button>
297
+ </component>
293
298
  </div>
294
299
  </nav>
295
300
 
@@ -334,13 +339,13 @@ onUnmounted(() => {
334
339
  can't just bind to `expanded` directly. Keep any pill/label fix in sync
335
340
  between the two copies.
336
341
  -->
337
- <button
342
+ <component
343
+ :is="itemLink(item).tag"
338
344
  v-for="item in items"
339
345
  :key="item.value"
340
- type="button"
346
+ v-bind="itemLink(item).attrs"
341
347
  class="group relative block h-16 w-full shrink-0 cursor-pointer focus-visible:outline-none"
342
348
  :class="item.disabled ? 'cursor-not-allowed opacity-[0.38]' : ''"
343
- :disabled="item.disabled"
344
349
  @click="selectModal(item)"
345
350
  >
346
351
  <span
@@ -383,7 +388,7 @@ onUnmounted(() => {
383
388
  >
384
389
  {{ item.label }}
385
390
  </span>
386
- </button>
391
+ </component>
387
392
  </div>
388
393
  </nav>
389
394
  </div>
@@ -0,0 +1,89 @@
1
+ <script setup lang="ts">
2
+ import { computed, ref } from 'vue'
3
+ import MNavigationRail from './MNavigationRail.vue'
4
+ import MShortNavigationBar from './MShortNavigationBar.vue'
5
+ import { useWindowSizeClass } from '../composables/useWindowSizeClass'
6
+ import type { ItemLink } from '../composables/_useItemLink'
7
+
8
+ export interface NavigationSuiteItem {
9
+ value: string | number
10
+ label: string
11
+ icon: string
12
+ badge?: number
13
+ badgeDot?: boolean
14
+ disabled?: boolean
15
+ /** Makes the item a link: a vue-router location (rendered as RouterLink), or a URL without vue-router. */
16
+ to?: ItemLink
17
+ }
18
+
19
+ /** The navigation component in use: a short bar (icons over labels, or beside them), or a rail. */
20
+ export type NavigationSuiteLayout = 'bar' | 'bar-medium' | 'rail' | 'rail-expanded' | 'none'
21
+
22
+ const props = withDefaults(defineProps<{
23
+ modelValue: string | number
24
+ items: NavigationSuiteItem[]
25
+ /**
26
+ * 'auto' picks by the component's own size, as M3's NavigationSuiteScaffold does
27
+ * (`navigationSuiteType`): compact width → short bar; compact height (a phone in landscape)
28
+ * → short bar with icons beside labels; anything else → collapsed rail. Set it to force one.
29
+ */
30
+ layout?: 'auto' | NavigationSuiteLayout
31
+ }>(), { layout: 'auto' })
32
+
33
+ defineEmits<{ 'update:modelValue': [string | number] }>()
34
+
35
+ defineSlots<{
36
+ /** The app's content. Scrolls on its own, next to or above the navigation. */
37
+ default?: (props: { layout: NavigationSuiteLayout }) => unknown
38
+ /** Primary action (e.g. a FAB): the rail's header, or floating above the bar at the bottom end. */
39
+ fab?: () => unknown
40
+ }>()
41
+
42
+ const root = ref<HTMLElement>()
43
+ const { widthClass, heightClass } = useWindowSizeClass(root)
44
+
45
+ const resolved = computed<NavigationSuiteLayout>(() => {
46
+ if (props.layout !== 'auto') return props.layout
47
+ if (widthClass.value === 'compact') return 'bar'
48
+ if (heightClass.value === 'compact') return 'bar-medium'
49
+ return 'rail'
50
+ })
51
+ const isRail = computed(() => resolved.value === 'rail' || resolved.value === 'rail-expanded')
52
+ const isBar = computed(() => resolved.value === 'bar' || resolved.value === 'bar-medium')
53
+ </script>
54
+
55
+ <template>
56
+ <div ref="root" class="flex overflow-hidden bg-surface" :class="isBar ? 'flex-col' : 'flex-row'">
57
+ <!-- No default size: give it the app's height (e.g. h-dvh) so the bar sits at the bottom. -->
58
+ <MNavigationRail
59
+ v-if="isRail"
60
+ :model-value="modelValue"
61
+ :items="items"
62
+ :expanded="resolved === 'rail-expanded'"
63
+ class="shrink-0"
64
+ @update:model-value="$emit('update:modelValue', $event)"
65
+ >
66
+ <template v-if="$slots.fab" #fab><slot name="fab" /></template>
67
+ </MNavigationRail>
68
+
69
+ <!-- Same element in every layout, so the content keeps its state when the navigation swaps. -->
70
+ <div class="relative flex min-h-0 min-w-0 flex-1 flex-col">
71
+ <div class="min-h-0 flex-1 overflow-auto">
72
+ <slot :layout="resolved" />
73
+ </div>
74
+ <div v-if="!isRail && $slots.fab" class="absolute right-4 bottom-4">
75
+ <slot name="fab" />
76
+ </div>
77
+ </div>
78
+
79
+ <MShortNavigationBar
80
+ v-if="isBar"
81
+ :model-value="modelValue"
82
+ :items="items"
83
+ :arrangement="resolved === 'bar-medium' ? 'centered' : 'equal'"
84
+ :icon-position="resolved === 'bar-medium' ? 'start' : 'top'"
85
+ class="shrink-0"
86
+ @update:model-value="$emit('update:modelValue', $event)"
87
+ />
88
+ </div>
89
+ </template>