@m3ui-vue/m3ui-vue 0.8.0 → 0.8.2

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 (67) hide show
  1. package/README.md +9 -1
  2. package/dist/{MMenuItem-vSLbJGqe.js → MMenuItem-BAWmUTT3.js} +367 -189
  3. package/dist/MMenuItem-BAWmUTT3.js.map +1 -0
  4. package/dist/code-editor.js +1 -1
  5. package/dist/code-editor.js.map +1 -1
  6. package/dist/components/MButton.vue.d.ts +7 -0
  7. package/dist/components/MCalendar.vue.d.ts +0 -1
  8. package/dist/components/MCarousel.vue.d.ts +12 -14
  9. package/dist/components/MContextMenu.vue.d.ts +25 -4
  10. package/dist/components/MDatePicker.vue.d.ts +1 -3
  11. package/dist/components/MDatePickerModal.vue.d.ts +0 -1
  12. package/dist/components/MDateRangePicker.vue.d.ts +1 -3
  13. package/dist/components/MDateRangePickerModal.vue.d.ts +0 -1
  14. package/dist/components/MKanban.vue.d.ts +1 -0
  15. package/dist/components/MMenu.vue.d.ts +20 -2
  16. package/dist/components/MMenuDivider.vue.d.ts +13 -1
  17. package/dist/components/MMenuItem.vue.d.ts +3 -0
  18. package/dist/components/MScheduler.vue.d.ts +0 -1
  19. package/dist/components/MShape.vue.d.ts +51 -0
  20. package/dist/components/MShortNavigationBar.vue.d.ts +34 -0
  21. package/dist/components/MSimpleCarousel.vue.d.ts +45 -0
  22. package/dist/components/MToggleButton.vue.d.ts +29 -0
  23. package/dist/components/MTree.vue.d.ts +0 -1
  24. package/dist/components/MTreeTable.vue.d.ts +1 -0
  25. package/dist/index.d.ts +8 -1
  26. package/dist/m3ui-vue.css +1 -1
  27. package/dist/m3ui.js +5599 -3973
  28. package/dist/m3ui.js.map +1 -1
  29. package/dist/rich-text-editor.js +8 -8
  30. package/dist/styles/palettes.css +22 -22
  31. package/dist/styles.css +1 -1
  32. package/package.json +4 -1
  33. package/src/__tests__/MCarousel.test.ts +33 -0
  34. package/src/__tests__/MShape.test.ts +36 -0
  35. package/src/__tests__/MToggleButton.test.ts +27 -0
  36. package/src/components/MAutocomplete.vue +5 -1
  37. package/src/components/MButton.vue +15 -2
  38. package/src/components/MCalendar.vue +9 -5
  39. package/src/components/MCarousel.vue +123 -173
  40. package/src/components/MCodeEditor.vue +6 -1
  41. package/src/components/MCommandPalette.vue +4 -0
  42. package/src/components/MContextMenu.vue +287 -13
  43. package/src/components/MDatePicker.vue +12 -9
  44. package/src/components/MDatePickerModal.vue +9 -4
  45. package/src/components/MDateRangePicker.vue +12 -9
  46. package/src/components/MDateRangePickerModal.vue +9 -4
  47. package/src/components/MKanban.vue +5 -1
  48. package/src/components/MMenu.vue +308 -20
  49. package/src/components/MMenuDivider.vue +16 -0
  50. package/src/components/MMenuItem.vue +60 -18
  51. package/src/components/MMultiAutocomplete.vue +5 -1
  52. package/src/components/MMultiSelect.vue +5 -1
  53. package/src/components/MScheduler.vue +10 -6
  54. package/src/components/MSearchBar.vue +5 -1
  55. package/src/components/MSelect.vue +5 -1
  56. package/src/components/MShape.vue +107 -0
  57. package/src/components/MShortNavigationBar.vue +113 -0
  58. package/src/components/MSimpleCarousel.vue +325 -0
  59. package/src/components/MSpotlightSearch.vue +6 -0
  60. package/src/components/MToggleButton.vue +188 -0
  61. package/src/components/MTopAppBar.vue +6 -2
  62. package/src/components/MTree.vue +4 -2
  63. package/src/components/MTreeTable.vue +5 -1
  64. package/src/composables/useColorPalette.ts +1 -1
  65. package/src/index.ts +8 -1
  66. package/src/styles/palettes.css +22 -22
  67. package/dist/MMenuItem-vSLbJGqe.js.map +0 -1
@@ -1,19 +1,259 @@
1
1
  <script setup lang="ts">
2
- import { computed, nextTick, onMounted, onUnmounted, provide, ref } from 'vue'
2
+ import { computed, Fragment, inject, nextTick, onMounted, onUnmounted, provide, ref, useSlots, watch, type VNode } from 'vue'
3
+ import MIcon from './MIcon.vue'
4
+ import MMenuDivider from './MMenuDivider.vue'
3
5
 
4
6
  const props = withDefaults(
5
7
  defineProps<{
6
8
  /** Which edge of the trigger the dropdown aligns to. */
7
9
  align?: 'left' | 'right'
10
+ /**
11
+ * How items with a `#children` slot behave.
12
+ * `'flyout'` opens a hover-positioned side panel (desktop).
13
+ * `'push'` replaces the panel's own content with the submenu and a
14
+ * back header — no positioning math, works with touch. Useful for mobile.
15
+ */
16
+ submenuMode?: 'flyout' | 'push'
17
+ /**
18
+ * `'standard'` is M3's baseline menu — square-ish 4dp corners
19
+ * (`MenuTokens.ContainerShape`/`CornerExtraSmall`).
20
+ * `'expressive'` is M3's rounder "vertical menu" styling — 16dp corners
21
+ * (`SegmentedMenuTokens.ContainerShape`/`CornerLarge`). Combine with
22
+ * `<MMenuDivider gap />` to split the panel into independently-rounded
23
+ * groups with a visible gap between them, instead of a plain line.
24
+ */
25
+ variant?: 'standard' | 'expressive'
8
26
  }>(),
9
- { align: 'right' },
27
+ { align: 'right', submenuMode: 'flyout', variant: 'standard' },
10
28
  )
11
29
 
30
+ const slots = useSlots()
31
+
32
+ function flattenVNodes(vnodes: VNode[]): VNode[] {
33
+ const out: VNode[] = []
34
+ for (const vnode of vnodes) {
35
+ if (vnode.type === Fragment && Array.isArray(vnode.children)) {
36
+ out.push(...flattenVNodes(vnode.children as VNode[]))
37
+ } else {
38
+ out.push(vnode)
39
+ }
40
+ }
41
+ return out
42
+ }
43
+
44
+ function isGapDivider(vnode: VNode): boolean {
45
+ if (vnode.type !== MMenuDivider) return false
46
+ const gap = (vnode.props as { gap?: unknown } | null)?.gap
47
+ return gap === '' || gap === true || gap === 'true'
48
+ }
49
+
50
+ // Splits the default slot's content into groups at each `<MMenuDivider gap />`
51
+ // — only used by the 'expressive' variant to render independently-rounded
52
+ // group boxes. A plain `<MMenuDivider />` (no `gap`) stays a normal in-line
53
+ // divider inside a single group, same as 'standard'.
54
+ const groups = computed(() => {
55
+ if (props.variant !== 'expressive') return null
56
+ const raw = flattenVNodes((slots.default?.({ close }) ?? []) as VNode[])
57
+ const result: VNode[][] = [[]]
58
+ for (const vnode of raw) {
59
+ if (isGapDivider(vnode)) result.push([])
60
+ else result[result.length - 1]!.push(vnode)
61
+ }
62
+ return result.filter(g => g.length > 0)
63
+ })
64
+ const isGrouped = computed(() => !!groups.value && groups.value.length > 1)
65
+
66
+ type NavEntry = { icon?: string, header?: () => any, content?: () => any }
67
+ const navStack = ref<NavEntry[]>([])
68
+ const currentNav = computed(() => navStack.value[navStack.value.length - 1])
69
+ const navDirection = ref<'forward' | 'backward'>('forward')
70
+
71
+ // Driven by the Web Animations API rather than Vue's CSS-class transition
72
+ // hooks — with dynamic (direction-dependent) enter/leave classes on a
73
+ // Transition with no `mode`, Vue's from->active->to class swap unreliably
74
+ // never completed (elements got stuck straddling from/active with the
75
+ // animation never actually running), so this drives it directly instead.
76
+ const slideDuration = 220
77
+ function navSlideEnter(el: Element, done: () => void) {
78
+ const dir = navDirection.value === 'forward' ? 1 : -1
79
+ const anim = (el as HTMLElement).animate(
80
+ [
81
+ { transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
82
+ { transform: 'translateX(0%)', opacity: 1 },
83
+ ],
84
+ { duration: slideDuration, easing: 'cubic-bezier(0.05,0.7,0.1,1)' },
85
+ )
86
+ anim.onfinish = done
87
+ }
88
+ function navSlideLeave(el: Element, done: () => void) {
89
+ const dir = navDirection.value === 'forward' ? -1 : 1
90
+ const htmlEl = el as HTMLElement
91
+ htmlEl.style.position = 'absolute'
92
+ htmlEl.style.insetInline = '0'
93
+ htmlEl.style.top = '0'
94
+ const anim = htmlEl.animate(
95
+ [
96
+ { transform: 'translateX(0%)', opacity: 1 },
97
+ { transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
98
+ ],
99
+ { duration: slideDuration, easing: 'cubic-bezier(0.3,0,0.8,0.15)' },
100
+ )
101
+ anim.onfinish = done
102
+ }
103
+
104
+ // The real DropdownMenuContent in Menu.kt animates scale (0.8 -> 1) and alpha
105
+ // (0 -> 1) with actual springs (MotionSchemeKeyTokens.FastSpatial/FastEffects
106
+ // on the Standard scheme, StandardMotionTokens: scale dampingRatio 0.9/
107
+ // stiffness 1400, alpha dampingRatio 1.0/stiffness 3800) — not a duration+
108
+ // easing tween, which is why a cubic-bezier stand-in read as an abrupt cut on
109
+ // close (a bezier can't carry a spring's momentum). But running the *close*
110
+ // as its own independent spring toward the opposite target isn't right
111
+ // either: alpha (stiffness 3800) settles much faster than scale (stiffness
112
+ // 1400), so on close the panel fades to invisible well before it finishes
113
+ // shrinking — you never actually see the shrink. On open this isn't a
114
+ // problem (it becomes visible early, *then* you watch it keep growing), but
115
+ // close needs to be the literal time-reverse of open, not a forward
116
+ // simulation toward reversed targets, so the shrink stays visible the whole
117
+ // time and only the fade races ahead right at the very end (mirroring how
118
+ // the fade led at the very start of open). Simulated once (open direction
119
+ // only) and played back forwards for enter, backwards for leave.
120
+ //
121
+ // A damped spring approaches its target exponentially, so it keeps "settling"
122
+ // long after the motion is visually done — with a tight (0.001) tolerance on
123
+ // both position *and* velocity, roughly the last third of the recorded
124
+ // trajectory is values within a fraction of a percent of the target, visually
125
+ // indistinguishable from it. Reversed for close, that flat tail lands at the
126
+ // *start* instead, so nothing visibly happens for the first ~80ms before the
127
+ // close animation actually appears to begin. Trimmed on position alone with a
128
+ // much looser tolerance instead, since that's what's actually visible.
129
+ let cachedTrajectory: { scale: number, alpha: number }[] | null = null
130
+ const trajectoryStep = 1 / 240
131
+ function openTrajectory() {
132
+ if (cachedTrajectory) return cachedTrajectory
133
+ const samples: { scale: number, alpha: number }[] = []
134
+ let scale = 0.8
135
+ let scaleVel = 0
136
+ let alpha = 0
137
+ let alphaVel = 0
138
+ const scaleDamping = 0.9
139
+ const scaleStiffness = 1400
140
+ const alphaDamping = 1.0
141
+ const alphaStiffness = 3800
142
+ for (let t = 0; t < 1; t += trajectoryStep) {
143
+ samples.push({ scale, alpha })
144
+ scaleVel += (-scaleStiffness * (scale - 1) - 2 * scaleDamping * Math.sqrt(scaleStiffness) * scaleVel) * trajectoryStep
145
+ scale += scaleVel * trajectoryStep
146
+ alphaVel += (-alphaStiffness * (alpha - 1) - 2 * alphaDamping * Math.sqrt(alphaStiffness) * alphaVel) * trajectoryStep
147
+ alpha += alphaVel * trajectoryStep
148
+ const visuallySettled = Math.abs(scale - 1) < 0.003 && Math.abs(alpha - 1) < 0.003
149
+ if (visuallySettled) break
150
+ }
151
+ samples.push({ scale: 1, alpha: 1 })
152
+ cachedTrajectory = samples
153
+ return samples
154
+ }
155
+
156
+ // Vue interrupts and reverses this mid-flight when the menu is toggled
157
+ // quickly (close while still opening, or vice versa) — it calls the other
158
+ // hook on the same still-mounted element without waiting for `done()`. Both
159
+ // `currentIdx` (how far along the trajectory we are, so a reversal continues
160
+ // smoothly from wherever it currently is instead of snapping back to a fixed
161
+ // start) and `cancelActive` (so the previous rAF loop actually stops instead
162
+ // of running alongside the new one, fighting over the same style every
163
+ // frame) have to live outside this function to survive that interruption.
164
+ let currentIdx = 0
165
+ let cancelActive: (() => void) | null = null
166
+
167
+ function playTrajectory(el: Element, done: () => void, opening: boolean) {
168
+ cancelActive?.()
169
+ const htmlEl = el as HTMLElement
170
+ const samples = openTrajectory()
171
+ const last = samples.length - 1
172
+ const direction = opening ? 1 : -1
173
+ const target = opening ? last : 0
174
+ let lastTime = 0
175
+ let rafId = 0
176
+ let cancelled = false
177
+
178
+ function apply(idx: number) {
179
+ const sample = samples[Math.round(Math.max(0, Math.min(last, idx)))]!
180
+ htmlEl.style.transform = `scale(${sample.scale})`
181
+ htmlEl.style.opacity = String(Math.min(1, Math.max(0, sample.alpha)))
182
+ }
183
+
184
+ function step(now: number) {
185
+ if (cancelled) return
186
+ const dtSteps = lastTime ? (now - lastTime) / 1000 / trajectoryStep : 1
187
+ lastTime = now
188
+ currentIdx = Math.max(0, Math.min(last, currentIdx + direction * dtSteps))
189
+ apply(currentIdx)
190
+ if ((opening && currentIdx >= target) || (!opening && currentIdx <= target)) {
191
+ cancelActive = null
192
+ done()
193
+ return
194
+ }
195
+ rafId = requestAnimationFrame(step)
196
+ }
197
+
198
+ cancelActive = () => { cancelled = true; cancelAnimationFrame(rafId) }
199
+ apply(currentIdx)
200
+ rafId = requestAnimationFrame(step)
201
+ }
202
+ function panelEnter(el: Element, done: () => void) {
203
+ playTrajectory(el, done, true)
204
+ }
205
+ function panelLeave(el: Element, done: () => void) {
206
+ playTrajectory(el, done, false)
207
+ }
208
+
209
+ function pushNav(entry: NavEntry) {
210
+ navDirection.value = 'forward'
211
+ navStack.value.push(entry)
212
+ nextTick(() => focusFirstItem())
213
+ }
214
+
215
+ function popNav() {
216
+ navDirection.value = 'backward'
217
+ navStack.value.pop()
218
+ nextTick(() => focusFirstItem())
219
+ }
220
+
12
221
  const open = ref(false)
13
222
  const triggerEl = ref<HTMLElement | null>(null)
14
223
  const dropdownEl = ref<HTMLElement | null>(null)
15
224
  const dropStyle = ref<Record<string, string>>({})
16
225
 
226
+ // A menu can be nested inside another MMenu/MContextMenu's slot (e.g. a
227
+ // "Language" picker menu inside a "More options" overflow menu) — since both
228
+ // Teleport straight to <body>, the outer one's panel DOM never contains the
229
+ // inner one's, so the outer's outside-click check would otherwise see a click
230
+ // inside the nested menu as "outside" and close (unmount) itself on
231
+ // mousedown, before the inner button's own click can fire. Sharing one
232
+ // registry of open panel elements across the whole logical (not DOM) menu
233
+ // tree via provide/inject fixes that for arbitrary nesting depth.
234
+ const panelRegistry = inject<Set<HTMLElement>>('m-menu-panel-registry', new Set())
235
+ provide('m-menu-panel-registry', panelRegistry)
236
+
237
+ watch(dropdownEl, (el, oldEl) => {
238
+ if (oldEl) panelRegistry.delete(oldEl)
239
+ if (el) panelRegistry.add(el)
240
+ })
241
+
242
+ onUnmounted(() => {
243
+ if (dropdownEl.value) panelRegistry.delete(dropdownEl.value)
244
+ })
245
+
246
+ // Separate from panelRegistry above: that one is shared all the way down the
247
+ // nesting chain so a click inside a descendant menu never closes an ancestor.
248
+ // This one is scoped to just this menu's *direct* children (e.g. "Language"
249
+ // and "Color palette", both nested inside the same "More options" menu) —
250
+ // without it, opening one no longer closes the other (since panelRegistry now
251
+ // treats a click on either as "inside" the shared ancestor), so two sibling
252
+ // pickers could stay open at once. Only one child of the same parent open at
253
+ // a time, like an accordion; doesn't affect unrelated top-level menus.
254
+ const siblingGroup = inject<{ current: (() => void) | null } | null>('m-menu-sibling-group', null)
255
+ provide('m-menu-sibling-group', { current: null })
256
+
17
257
  function computePos() {
18
258
  if (!triggerEl.value) return
19
259
  const rect = triggerEl.value.getBoundingClientRect()
@@ -61,22 +301,35 @@ function moveFocus(dir: 1 | -1) {
61
301
  }
62
302
 
63
303
  function toggle() {
64
- if (!open.value) computePos()
304
+ if (!open.value) {
305
+ if (siblingGroup && siblingGroup.current && siblingGroup.current !== close) {
306
+ siblingGroup.current()
307
+ }
308
+ if (siblingGroup) siblingGroup.current = close
309
+ computePos()
310
+ navStack.value = []
311
+ } else if (siblingGroup?.current === close) {
312
+ siblingGroup.current = null
313
+ }
65
314
  open.value = !open.value
66
315
  if (open.value) focusFirstItem()
67
316
  }
68
317
 
69
318
  function close() {
319
+ if (siblingGroup?.current === close) siblingGroup.current = null
70
320
  open.value = false
71
321
  }
72
322
 
73
323
  provide('m-menu-close', close)
324
+ provide('m-menu-nav', { mode: props.submenuMode, push: pushNav })
74
325
  defineExpose({ close, open })
75
326
 
76
327
  function onOutsideClick(e: MouseEvent) {
77
328
  const t = e.target as Node
78
329
  if (triggerEl.value?.contains(t)) return
79
- if (dropdownEl.value?.contains(t)) return
330
+ for (const panel of panelRegistry) {
331
+ if (panel.contains(t)) return
332
+ }
80
333
  if ((t as Element).closest?.('.m3-submenu')) return
81
334
  close()
82
335
  }
@@ -84,14 +337,15 @@ function onOutsideClick(e: MouseEvent) {
84
337
  function onScroll(e: Event) {
85
338
  if (!open.value) return
86
339
  if (dropdownEl.value?.contains(e.target as Node)) return
87
- if (!triggerEl.value) return
88
- const rect = triggerEl.value.getBoundingClientRect()
89
- if (rect.bottom < 0 || rect.top > window.innerHeight) { close(); return }
90
- computePos()
340
+ close()
91
341
  }
92
342
 
93
343
  function onKeydown(e: KeyboardEvent) {
94
- if (e.key === 'Escape') { close(); return }
344
+ if (e.key === 'Escape') {
345
+ if (navStack.value.length) popNav()
346
+ else close()
347
+ return
348
+ }
95
349
  if (!open.value) return
96
350
  if (e.key === 'ArrowDown') { e.preventDefault(); moveFocus(1) }
97
351
  else if (e.key === 'ArrowUp') { e.preventDefault(); moveFocus(-1) }
@@ -107,6 +361,7 @@ onUnmounted(() => {
107
361
  document.removeEventListener('mousedown', onOutsideClick)
108
362
  document.removeEventListener('keydown', onKeydown)
109
363
  window.removeEventListener('scroll', onScroll, true)
364
+ cancelActive?.()
110
365
  })
111
366
 
112
367
  const origin = computed(() =>
@@ -120,22 +375,55 @@ const origin = computed(() =>
120
375
  </div>
121
376
 
122
377
  <Teleport to="body">
123
- <Transition
124
- enter-active-class="transition-[opacity,transform] duration-100 ease-out"
125
- enter-from-class="opacity-0 scale-95"
126
- enter-to-class="opacity-100 scale-100"
127
- leave-active-class="transition-[opacity,transform] duration-75 ease-in"
128
- leave-from-class="opacity-100 scale-100"
129
- leave-to-class="opacity-0 scale-95"
130
- >
378
+ <Transition :css="false" @enter="panelEnter" @leave="panelLeave">
131
379
  <div
132
380
  v-if="open"
133
381
  ref="dropdownEl"
134
- class="fixed z-500 min-w-48 overflow-hidden rounded-xs bg-surface-container shadow-elevation-2"
382
+ class="fixed z-500 min-w-48"
383
+ :class="[
384
+ variant === 'expressive' ? 'rounded-lg' : 'rounded-xs',
385
+ isGrouped ? '' : 'shadow-elevation-2',
386
+ ]"
135
387
  :style="{ ...dropStyle, transformOrigin: origin }"
136
388
  >
137
- <div class="overflow-y-auto py-1" :style="{ maxHeight: dropStyle.maxHeight }">
138
- <slot :close="close" />
389
+ <!-- overflow-hidden (for the rounded-corner clip and to clip the push
390
+ submenu's slide) lives on this inner wrapper, never together with
391
+ shadow-elevation-2 on the same box — overflow-hidden clips an
392
+ element's own box-shadow too, so the two have to be on separate
393
+ elements or the shadow gets cut off -->
394
+ <div
395
+ class="overflow-hidden"
396
+ :class="[
397
+ variant === 'expressive' ? 'rounded-lg' : 'rounded-xs',
398
+ isGrouped ? '' : 'bg-surface-container',
399
+ ]"
400
+ >
401
+ <div class="relative overflow-y-auto py-1" :style="{ maxHeight: dropStyle.maxHeight }">
402
+ <Transition :css="false" @enter="navSlideEnter" @leave="navSlideLeave">
403
+ <div v-if="currentNav" :key="navStack.length">
404
+ <button
405
+ type="button"
406
+ class="flex w-full items-center gap-3 border-b border-outline-variant px-4 py-2.5 text-left text-body-large text-on-surface outline-none transition-colors hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
407
+ @click="popNav"
408
+ >
409
+ <MIcon name="chevron_left" :size="20" class="shrink-0 text-on-surface-variant" />
410
+ <MIcon v-if="currentNav.icon" :name="currentNav.icon" :size="20" class="shrink-0 text-on-surface-variant" />
411
+ <span class="flex-1 truncate"><component :is="() => currentNav?.header?.()" /></span>
412
+ </button>
413
+ <component :is="() => currentNav?.content?.()" />
414
+ </div>
415
+ <div v-else key="root">
416
+ <div v-if="isGrouped" class="flex flex-col gap-1 px-1.5">
417
+ <div v-for="(group, i) in groups" :key="i" class="rounded-lg shadow-elevation-2">
418
+ <div class="overflow-hidden rounded-lg bg-surface-container">
419
+ <component :is="() => group" />
420
+ </div>
421
+ </div>
422
+ </div>
423
+ <slot v-else :close="close" />
424
+ </div>
425
+ </Transition>
426
+ </div>
139
427
  </div>
140
428
  </div>
141
429
  </Transition>
@@ -1,3 +1,19 @@
1
+ <script setup lang="ts">
2
+ withDefaults(
3
+ defineProps<{
4
+ /**
5
+ * Marks this as a group boundary for `MMenu`/`MContextMenu`'s
6
+ * `variant="expressive"` — instead of rendering this divider in place,
7
+ * the parent menu splits its panel into two independently-rounded group
8
+ * boxes with a small gap between them. Has no effect outside an
9
+ * `expressive` menu, where it renders as a normal divider line.
10
+ */
11
+ gap?: boolean
12
+ }>(),
13
+ { gap: false },
14
+ )
15
+ </script>
16
+
1
17
  <template>
2
18
  <hr class="my-1 border-outline-variant" />
3
19
  </template>
@@ -8,9 +8,12 @@ const props = withDefaults(defineProps<{
8
8
  to?: string | Record<string, any>
9
9
  disabled?: boolean
10
10
  danger?: boolean
11
+ /** Keep the menu open after this item is clicked (e.g. checkable/toggle items). */
12
+ keepOpen?: boolean
11
13
  }>(), {
12
14
  disabled: false,
13
15
  danger: false,
16
+ keepOpen: false,
14
17
  })
15
18
 
16
19
  const emit = defineEmits<{ click: [] }>()
@@ -19,19 +22,16 @@ const slots = useSlots()
19
22
  const tag = computed(() => props.to ? 'RouterLink' : 'button')
20
23
  const hasChildren = computed(() => !!slots.children)
21
24
  const menuClose = inject<(() => void) | null>('m-menu-close', null)
25
+ const nav = inject<{
26
+ mode: 'flyout' | 'push'
27
+ push: (entry: { icon?: string, header?: () => any, content?: () => any }) => void
28
+ } | null>('m-menu-nav', null)
22
29
 
23
- function handleClick() {
24
- if (props.disabled || hasChildren.value) return
25
- emit('click')
26
- menuClose?.()
27
- }
28
- const showSub = ref(false)
29
30
  const itemEl = ref<HTMLElement>()
31
+ const showSub = ref(false)
30
32
  const subStyle = ref<Record<string, string>>({})
31
33
 
32
- function onMouseEnter() {
33
- if (!hasChildren.value || props.disabled) return
34
- showSub.value = true
34
+ function positionSub() {
35
35
  if (!itemEl.value) return
36
36
  const rect = itemEl.value.getBoundingClientRect()
37
37
  const right = rect.right + 200 > window.innerWidth
@@ -45,13 +45,49 @@ function onMouseEnter() {
45
45
  }
46
46
  }
47
47
 
48
- function onMouseLeave(e: MouseEvent) {
48
+ function toggleSub() {
49
+ if (showSub.value) {
50
+ showSub.value = false
51
+ return
52
+ }
53
+ positionSub()
54
+ showSub.value = true
55
+ }
56
+
57
+ function handleClick() {
58
+ if (props.disabled) return
59
+
60
+ if (hasChildren.value) {
61
+ if (nav?.mode === 'push') {
62
+ nav.push({ icon: props.icon, header: slots.default, content: slots.children })
63
+ } else {
64
+ toggleSub()
65
+ }
66
+ return
67
+ }
68
+
69
+ emit('click')
70
+ if (!props.keepOpen) menuClose?.()
71
+ }
72
+
73
+ // Desktop hover convenience for the flyout variant — ignored on touch/pen so a
74
+ // tap doesn't fire a spurious pointerleave (relatedTarget is null on touch)
75
+ // and close the submenu before its click event can land.
76
+ function onPointerEnter(e: PointerEvent) {
77
+ if (e.pointerType !== 'mouse' || !hasChildren.value || props.disabled) return
78
+ positionSub()
79
+ showSub.value = true
80
+ }
81
+
82
+ function onPointerLeave(e: PointerEvent) {
83
+ if (e.pointerType !== 'mouse') return
49
84
  const related = e.relatedTarget as Element | null
50
85
  if (related?.closest('.m3-submenu')) return
51
86
  showSub.value = false
52
87
  }
53
88
 
54
- function onSubLeave(e: MouseEvent) {
89
+ function onSubPointerLeave(e: PointerEvent) {
90
+ if (e.pointerType !== 'mouse') return
55
91
  const related = e.relatedTarget as Element | null
56
92
  if (related?.closest('.m3-submenu') || itemEl.value?.contains(related as Node)) return
57
93
  showSub.value = false
@@ -61,8 +97,8 @@ function onSubLeave(e: MouseEvent) {
61
97
  <template>
62
98
  <div
63
99
  ref="itemEl"
64
- @mouseenter="onMouseEnter"
65
- @mouseleave="onMouseLeave"
100
+ @pointerenter="onPointerEnter"
101
+ @pointerleave="onPointerLeave"
66
102
  >
67
103
  <component
68
104
  :is="tag"
@@ -75,6 +111,8 @@ function onSubLeave(e: MouseEvent) {
75
111
  !disabled && !danger ? 'text-on-surface hover:bg-on-surface/8' : '',
76
112
  ]"
77
113
  :disabled="disabled || undefined"
114
+ :aria-haspopup="hasChildren ? 'menu' : undefined"
115
+ :aria-expanded="hasChildren ? showSub : undefined"
78
116
  @click="handleClick"
79
117
  >
80
118
  <MIcon v-if="icon" :name="icon" :size="20" class="shrink-0" :class="danger ? 'text-error' : 'text-on-surface-variant'" />
@@ -83,8 +121,8 @@ function onSubLeave(e: MouseEvent) {
83
121
  <MIcon v-if="hasChildren" name="chevron_right" :size="18" class="shrink-0 text-on-surface-variant" />
84
122
  </component>
85
123
 
86
- <!-- Submenu -->
87
- <Teleport v-if="hasChildren" to="body">
124
+ <!-- Submenu (flyout variant only — "push" mode is rendered by the root MMenu/MContextMenu panel) -->
125
+ <Teleport v-if="hasChildren && nav?.mode !== 'push'" to="body">
88
126
  <Transition
89
127
  enter-active-class="transition-opacity duration-100"
90
128
  enter-from-class="opacity-0"
@@ -93,11 +131,15 @@ function onSubLeave(e: MouseEvent) {
93
131
  >
94
132
  <div
95
133
  v-if="showSub"
96
- class="m3-submenu min-w-44 overflow-hidden rounded-xs bg-surface-container py-1 shadow-elevation-2"
134
+ class="m3-submenu min-w-44 rounded-xs shadow-elevation-2"
97
135
  :style="subStyle"
98
- @mouseleave="onSubLeave"
136
+ @pointerleave="onSubPointerLeave"
99
137
  >
100
- <slot name="children" />
138
+ <!-- overflow-hidden lives here, separate from shadow-elevation-2 above —
139
+ overflow-hidden clips an element's own box-shadow too -->
140
+ <div class="overflow-hidden rounded-xs bg-surface-container py-1">
141
+ <slot name="children" />
142
+ </div>
101
143
  </div>
102
144
  </Transition>
103
145
  </Teleport>
@@ -8,6 +8,10 @@ import { useLocale } from '../composables/useLocale'
8
8
  import { useDebounce } from '../composables/useDebounce'
9
9
  import type { MultiSelectOption } from './MMultiSelect.vue'
10
10
 
11
+ // Root is a fragment (field div + a sibling Teleport for the dropdown panel), so Vue can't
12
+ // auto-apply a consumer's class/attrs to either one — forward them onto the field div below.
13
+ defineOptions({ inheritAttrs: false })
14
+
11
15
  const props = withDefaults(
12
16
  defineProps<{
13
17
  modelValue: unknown[]
@@ -344,7 +348,7 @@ const labelClasses = computed(() => {
344
348
  </script>
345
349
 
346
350
  <template>
347
- <div class="flex flex-col gap-1">
351
+ <div class="flex flex-col gap-1" v-bind="$attrs">
348
352
  <div
349
353
  ref="fieldEl"
350
354
  class="relative"
@@ -14,6 +14,10 @@ export interface MultiSelectOption {
14
14
  disabled?: boolean
15
15
  }
16
16
 
17
+ // Root is a fragment (field div + a sibling Teleport for the dropdown panel), so Vue can't
18
+ // auto-apply a consumer's class/attrs to either one — forward them onto the field div below.
19
+ defineOptions({ inheritAttrs: false })
20
+
17
21
  const props = withDefaults(
18
22
  defineProps<{
19
23
  modelValue: unknown[]
@@ -252,7 +256,7 @@ const labelClasses = computed(() => {
252
256
  </script>
253
257
 
254
258
  <template>
255
- <div class="flex flex-col gap-1">
259
+ <div class="flex flex-col gap-1" v-bind="$attrs">
256
260
  <div
257
261
  ref="fieldEl"
258
262
  class="relative"
@@ -31,10 +31,14 @@ const props = withDefaults(
31
31
  view: 'week',
32
32
  startHour: 7,
33
33
  endHour: 22,
34
- locale: 'es-ES',
35
34
  },
36
35
  )
37
36
 
37
+ // Falls back to the app's own configured locale (via createM3UI/useLocale) rather than a
38
+ // fixed default, matching the pattern MRelativeTime already uses — previously this defaulted
39
+ // to a hardcoded 'es-ES' regardless of what locale the app actually provided.
40
+ const resolvedLocale = computed(() => props.locale ?? locale.lang)
41
+
38
42
  const emit = defineEmits<{
39
43
  eventClick: [SchedulerEvent]
40
44
  slotClick: [{ date: string; hour: number }]
@@ -78,17 +82,17 @@ function fmt(d: Date) {
78
82
  return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`
79
83
  }
80
84
 
81
- const dayFormat = new Intl.DateTimeFormat(props.locale, { weekday: 'short' })
82
- const dateFormat = new Intl.DateTimeFormat(props.locale, { day: 'numeric' })
85
+ const dayFormat = computed(() => new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'short' }))
86
+ const dateFormat = computed(() => new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric' }))
83
87
 
84
88
  const headerLabel = computed(() => {
85
89
  if (currentView.value === 'day') {
86
- return new Intl.DateTimeFormat(props.locale, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' })
90
+ return new Intl.DateTimeFormat(resolvedLocale.value, { weekday: 'long', day: 'numeric', month: 'long', year: 'numeric' })
87
91
  .format(currentDate.value)
88
92
  }
89
93
  const start = weekDays.value[0]!
90
94
  const end = weekDays.value[6]!
91
- const f = new Intl.DateTimeFormat(props.locale, { day: 'numeric', month: 'short' })
95
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { day: 'numeric', month: 'short' })
92
96
  return `${f.format(start)} – ${f.format(end)}, ${end.getFullYear()}`
93
97
  })
94
98
 
@@ -125,7 +129,7 @@ function eventDuration(ev: SchedulerEvent) {
125
129
  }
126
130
 
127
131
  function timeLabel(ev: SchedulerEvent) {
128
- const f = new Intl.DateTimeFormat(props.locale, { hour: '2-digit', minute: '2-digit' })
132
+ const f = new Intl.DateTimeFormat(resolvedLocale.value, { hour: '2-digit', minute: '2-digit' })
129
133
  return `${f.format(new Date(ev.start))} – ${f.format(new Date(ev.end))}`
130
134
  }
131
135
 
@@ -5,6 +5,10 @@ import MIconButton from './MIconButton.vue'
5
5
  import MSpinner from './MSpinner.vue'
6
6
  import { useLocale } from '../composables/useLocale'
7
7
 
8
+ // Root is a fragment (bar div + a sibling Teleport for the expanded overlay panel), so Vue
9
+ // can't auto-apply a consumer's class/attrs to either one — forward them onto the bar div below.
10
+ defineOptions({ inheritAttrs: false })
11
+
8
12
  const props = withDefaults(
9
13
  defineProps<{
10
14
  modelValue?: string
@@ -126,7 +130,7 @@ onUnmounted(() => { document.body.style.overflow = '' })
126
130
  </script>
127
131
 
128
132
  <template>
129
- <div ref="barEl" class="relative w-full">
133
+ <div ref="barEl" class="relative w-full" v-bind="$attrs">
130
134
  <div
131
135
  v-show="!expanded"
132
136
  class="flex h-14 items-center gap-3 rounded-full bg-surface-container-high px-4 shadow-elevation-3 transition-shadow duration-150 focus-within:outline focus-within:outline-2 focus-within:outline-secondary focus-within:-outline-offset-2"