@m3ui-vue/m3ui-vue 1.1.2 → 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (128) hide show
  1. package/README.md +1 -1
  2. package/dist/API.md +202 -10
  3. package/dist/{MIcon-DLOkQduI.js → MIcon-Bxh9j135.js} +15 -8
  4. package/dist/MIcon-Bxh9j135.js.map +1 -0
  5. package/dist/{MMenuItem-DVxKEv1W.js → MMenuItem-BfjqwcYP.js} +85 -64
  6. package/dist/MMenuItem-BfjqwcYP.js.map +1 -0
  7. package/dist/MSlider-JflHJ70q.js +1525 -0
  8. package/dist/MSlider-JflHJ70q.js.map +1 -0
  9. package/dist/{MTextField-rML9jnXs.js → MTextField-NaIB6RbM.js} +68 -66
  10. package/dist/MTextField-NaIB6RbM.js.map +1 -0
  11. package/dist/api.json +1 -1
  12. package/dist/code-editor.js +2 -2
  13. package/dist/components/MAnimatedNumber.vue.d.ts +29 -0
  14. package/dist/components/MButton.vue.d.ts +2 -0
  15. package/dist/components/MContainerTransform.vue.d.ts +59 -0
  16. package/dist/components/MDialog.vue.d.ts +8 -5
  17. package/dist/components/MFlex.vue.d.ts +1 -1
  18. package/dist/components/MIcon.vue.d.ts +2 -0
  19. package/dist/components/MIconButton.vue.d.ts +2 -0
  20. package/dist/components/MListGroup.vue.d.ts +23 -0
  21. package/dist/components/MListItem.vue.d.ts +5 -5
  22. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  23. package/dist/components/MScheduler.vue.d.ts +2 -2
  24. package/dist/components/MScheme.vue.d.ts +60 -0
  25. package/dist/components/MSparkline.vue.d.ts +41 -0
  26. package/dist/components/MSplitter.vue.d.ts +1 -1
  27. package/dist/components/MStack.vue.d.ts +1 -1
  28. package/dist/components/MToolbar.vue.d.ts +32 -5
  29. package/dist/components/MWindow.vue.d.ts +2 -2
  30. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  31. package/dist/components/_MToolbarFab.vue.d.ts +16 -0
  32. package/dist/composables/_containerTransform.d.ts +48 -0
  33. package/dist/composables/_useSegmentRuns.d.ts +8 -0
  34. package/dist/composables/dynamicColor.d.ts +11 -0
  35. package/dist/composables/useColorPalette.d.ts +3 -1
  36. package/dist/composables/useConfetti.d.ts +32 -0
  37. package/dist/composables/useContainerTransform.d.ts +30 -0
  38. package/dist/composables/useLocale.d.ts +9 -0
  39. package/dist/index.d.ts +10 -1
  40. package/dist/locales/index.js +35 -0
  41. package/dist/locales/index.js.map +1 -1
  42. package/dist/m3ui-vue.css +1 -1
  43. package/dist/m3ui.js +16844 -15530
  44. package/dist/m3ui.js.map +1 -1
  45. package/dist/map.js +55 -55
  46. package/dist/{material-color-utilities-Cktu8DBU.js → material-color-utilities-C_iikgRm.js} +928 -603
  47. package/dist/material-color-utilities-C_iikgRm.js.map +1 -0
  48. package/dist/rich-text-editor.js +11 -11
  49. package/dist/styles.css +1 -1
  50. package/dist/terminal.js +1 -1
  51. package/dist/{useLocale-CqQrhWFl.js → useLocale-CXibICQA.js} +6 -1
  52. package/dist/useLocale-CXibICQA.js.map +1 -0
  53. package/package.json +2 -1
  54. package/src/__tests__/MAnimatedNumber.test.ts +128 -0
  55. package/src/__tests__/MContainerTransform.test.ts +279 -0
  56. package/src/__tests__/MDialog.test.ts +27 -0
  57. package/src/__tests__/MIcon.test.ts +19 -0
  58. package/src/__tests__/MListItemExpandable.test.ts +48 -0
  59. package/src/__tests__/MListItemShape.test.ts +42 -5
  60. package/src/__tests__/MListKeyboard.test.ts +90 -0
  61. package/src/__tests__/MMapTools.test.ts +2 -1
  62. package/src/__tests__/MNavigationRail.test.ts +33 -0
  63. package/src/__tests__/MScheme.test.ts +107 -0
  64. package/src/__tests__/MSlider.test.ts +161 -0
  65. package/src/__tests__/MSparkline.test.ts +96 -0
  66. package/src/__tests__/MToolbar.test.ts +157 -0
  67. package/src/__tests__/attrsFallthrough.test.ts +6 -0
  68. package/src/__tests__/hydration.test.ts +25 -0
  69. package/src/__tests__/iconButtonNames.test.ts +124 -0
  70. package/src/__tests__/ssr.test.ts +1 -0
  71. package/src/__tests__/useConfetti.test.ts +81 -0
  72. package/src/components/MAnimatedNumber.vue +327 -0
  73. package/src/components/MAutocomplete.vue +34 -4
  74. package/src/components/MBottomSheet.vue +1 -0
  75. package/src/components/MButton.vue +4 -2
  76. package/src/components/MContainerTransform.vue +321 -0
  77. package/src/components/MDataTable.vue +1 -1
  78. package/src/components/MDialog.vue +31 -6
  79. package/src/components/MFab.vue +10 -5
  80. package/src/components/MIcon.vue +11 -4
  81. package/src/components/MIconButton.vue +3 -1
  82. package/src/components/MList.vue +33 -31
  83. package/src/components/MListGroup.vue +66 -0
  84. package/src/components/MListItem.vue +138 -84
  85. package/src/components/MMaskField.vue +3 -0
  86. package/src/components/MMultiAutocomplete.vue +5 -1
  87. package/src/components/MMultiSelect.vue +19 -9
  88. package/src/components/MNavigationRail.vue +40 -10
  89. package/src/components/MScheme.vue +162 -0
  90. package/src/components/MSearchBar.vue +2 -0
  91. package/src/components/MSelect.vue +44 -10
  92. package/src/components/MSideSheet.vue +3 -0
  93. package/src/components/MSimpleCarousel.vue +6 -0
  94. package/src/components/MSlider.vue +161 -42
  95. package/src/components/MSparkline.vue +250 -0
  96. package/src/components/MSplitButton.vue +3 -0
  97. package/src/components/MSpotlightSearch.vue +1 -0
  98. package/src/components/MTable.vue +1 -0
  99. package/src/components/MTagInput.vue +4 -0
  100. package/src/components/MTextField.vue +3 -0
  101. package/src/components/MToolbar.vue +256 -15
  102. package/src/components/MTour.vue +1 -0
  103. package/src/components/MTreeTable.vue +1 -0
  104. package/src/components/_MToolbarFab.vue +14 -0
  105. package/src/components/_MTreeNode.vue +3 -0
  106. package/src/composables/_containerTransform.ts +179 -0
  107. package/src/composables/_useEscapeStack.ts +2 -0
  108. package/src/composables/_useSegmentRuns.ts +39 -0
  109. package/src/composables/dynamicColor.ts +66 -0
  110. package/src/composables/useColorPalette.ts +2 -2
  111. package/src/composables/useConfetti.ts +204 -0
  112. package/src/composables/useContainerTransform.ts +59 -0
  113. package/src/composables/useLocale.ts +14 -0
  114. package/src/index.ts +10 -1
  115. package/src/locales/de.ts +5 -0
  116. package/src/locales/es.ts +5 -0
  117. package/src/locales/fr.ts +5 -0
  118. package/src/locales/ja.ts +5 -0
  119. package/src/locales/ko.ts +5 -0
  120. package/src/locales/pt.ts +5 -0
  121. package/src/locales/zh.ts +5 -0
  122. package/dist/MIcon-DLOkQduI.js.map +0 -1
  123. package/dist/MMenuItem-DVxKEv1W.js.map +0 -1
  124. package/dist/MSlider-BXsBv0ox.js +0 -1402
  125. package/dist/MSlider-BXsBv0ox.js.map +0 -1
  126. package/dist/MTextField-rML9jnXs.js.map +0 -1
  127. package/dist/material-color-utilities-Cktu8DBU.js.map +0 -1
  128. package/dist/useLocale-CqQrhWFl.js.map +0 -1
@@ -0,0 +1,321 @@
1
+ <script setup lang="ts" generic="T = unknown">
2
+ /**
3
+ * Material's container transform: an element (a card, a list item, an image, a FAB…) grows into an expanded view
4
+ * and shrinks back into it, morphing its bounds and shape while its content fades into the new one. The expanded
5
+ * view opens over the page, full screen, as a centered panel, or wherever your classes put it (`custom`), with a
6
+ * scrim (optional), Escape and scroll lock; focus goes to it and back to the element on close. A port of Android's
7
+ * MaterialContainerTransform, played on the compositor. For elements that live apart from the expanded view (a grid
8
+ * of cards, one detail), pass a `useContainerTransform()` controller instead of the default slot.
9
+ *
10
+ * @slot default The element that opens it, with `{ open, isOpen }`: call `open()` from its click
11
+ * @slot expanded The expanded view, with `{ close, item }` (`item` is what the controller's `open` was given)
12
+ * @event update:open The expanded view opened or closed (v-model:open)
13
+ */
14
+ import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
15
+ import { useContainerTransform, type ContainerTransformController } from '../composables/useContainerTransform'
16
+ import {
17
+ CLOSE_MS, OPEN_MS, SCRIM_OPACITY, boxOf, containerFrames, playContainerFrames, radiusOf, type Box,
18
+ } from '../composables/_containerTransform'
19
+ import { prefersReducedMotion } from '../composables/_springAnimation'
20
+ import { useScrollLock } from '../composables/_useScrollLock'
21
+ import { useEscapeStack } from '../composables/_useEscapeStack'
22
+
23
+ defineOptions({ inheritAttrs: false })
24
+
25
+ const props = withDefaults(defineProps<{
26
+ /** A `useContainerTransform()` controller, to open it from elements elsewhere (`controller.open($event, item)`) */
27
+ controller?: ContainerTransformController<T>
28
+ /**
29
+ * Where the expanded view opens: over the whole screen, as a centered panel (wider screens), or `custom`: the
30
+ * classes you give the component place and size it (`bottom-4 right-4 w-80 h-96`, `inset-y-0 right-0 w-96`…),
31
+ * anywhere over the page
32
+ */
33
+ mode?: 'fullscreen' | 'dialog' | 'custom'
34
+ /** The centered panel's maximum width (`dialog` mode) */
35
+ maxWidth?: string
36
+ /** Accessible name of the expanded view */
37
+ label?: string
38
+ /**
39
+ * Dims the page behind it, which makes it modal (scroll lock, `aria-modal`). Without one the page stays usable:
40
+ * a click outside closes it instead (unless `persistent`)
41
+ */
42
+ scrim?: boolean
43
+ /** A click on the scrim, or outside without one, doesn't close it */
44
+ persistent?: boolean
45
+ /**
46
+ * Android's back (button or gesture) closes it, like an expanded view in an app, where the browser has the
47
+ * CloseWatcher API (Chrome, Edge); the history and the router are left alone. Default `true`
48
+ */
49
+ closeOnBack?: boolean
50
+ }>(), { mode: 'fullscreen', maxWidth: '560px', scrim: true, persistent: false, closeOnBack: true })
51
+
52
+ /** Whether the expanded view is open; opening it from here grows it from the default slot's element */
53
+ const openModel = defineModel<boolean>('open', { default: false })
54
+
55
+ const own = useContainerTransform<T>()
56
+ const ctl = computed(() => props.controller ?? own)
57
+
58
+ const anchor = ref<HTMLElement>()
59
+ const scrimEl = ref<HTMLElement>()
60
+ const clip = ref<HTMLElement>()
61
+ const shadowEl = ref<HTMLElement>()
62
+ const panel = ref<HTMLElement>()
63
+ const mounted = ref(false)
64
+
65
+ const anchorElement = () => (anchor.value?.firstElementChild as HTMLElement | null) ?? null
66
+ const openFromSlot = () => ctl.value.open(anchorElement())
67
+
68
+ let anims: Animation[] = []
69
+ let ghost: HTMLElement | null = null
70
+ let hidden: HTMLElement | null = null
71
+ let returnFocus = false
72
+
73
+ // The element it opens from, cloned into the transition (it stays hidden in the page meanwhile). The clone keeps
74
+ // what it inherited there: text styles and the custom properties (an MScheme's colors, for one)
75
+ function makeGhost(src: HTMLElement, box: Box) {
76
+ const g = src.cloneNode(true) as HTMLElement
77
+ g.removeAttribute('id')
78
+ g.querySelectorAll('[id]').forEach((el) => el.removeAttribute('id'))
79
+ g.setAttribute('aria-hidden', 'true')
80
+ g.inert = true
81
+ const cs = getComputedStyle(src)
82
+ for (let i = 0; i < cs.length; i++) {
83
+ const name = cs[i]!
84
+ if (name.startsWith('--')) g.style.setProperty(name, cs.getPropertyValue(name))
85
+ }
86
+ for (const p of ['color', 'font-family', 'font-size', 'font-weight', 'line-height', 'letter-spacing', 'direction', 'text-align']) {
87
+ g.style.setProperty(p, cs.getPropertyValue(p))
88
+ }
89
+ Object.assign(g.style, {
90
+ position: 'absolute', left: `${box.left}px`, top: `${box.top}px`, width: `${box.width}px`, height: `${box.height}px`,
91
+ margin: '0', boxSizing: 'border-box', transformOrigin: '0 0', pointerEvents: 'none', visibility: 'visible',
92
+ })
93
+ clip.value!.insertBefore(g, panel.value!)
94
+ return g
95
+ }
96
+
97
+ function clearRun() {
98
+ for (const a of anims) a.cancel()
99
+ anims = []
100
+ ghost?.remove()
101
+ ghost = null
102
+ if (shadowEl.value) shadowEl.value.style.filter = ''
103
+ }
104
+
105
+ // The clip would cut the panel's own shadow off until the end, so while it morphs a drop shadow on the layer
106
+ // around it (which follows the clipped shape) stands in for it: elevation 3's two layers, as drop-shadow can't spread
107
+ function shadeTransition() {
108
+ if (!shadowEl.value || !panel.value || getComputedStyle(panel.value).boxShadow === 'none') return
109
+ shadowEl.value.style.filter = 'drop-shadow(0 1px 3px rgb(0 0 0 / 0.3)) drop-shadow(0 4px 8px rgb(0 0 0 / 0.15))'
110
+ }
111
+
112
+ function hideSource(src: HTMLElement | null) {
113
+ if (hidden && hidden !== src) hidden.style.visibility = ''
114
+ hidden = src
115
+ if (src) src.style.visibility = 'hidden'
116
+ }
117
+
118
+ function opened() {
119
+ clearRun()
120
+ }
121
+
122
+ function closed() {
123
+ clearRun()
124
+ mounted.value = false
125
+ const src = hidden
126
+ hideSource(null)
127
+ if (returnFocus) src?.focus?.({ preventScroll: true })
128
+ returnFocus = false
129
+ }
130
+
131
+ // A box with no size (an element that isn't rendered) can't be scaled from: open or close without the transform
132
+ const sized = (b: Box) => b.width > 0 && b.height > 0
133
+
134
+ // When the running animations end (whichever way they were last turned), settle in the state asked for now. Every
135
+ // waiter on a run calls this; the first one clears the run, so the others find it replaced and do nothing. (Each
136
+ // waiter used to settle in its own direction: closing mid-opening, the opening's waiter could win, jump open and
137
+ // leave the controller closed with the view still on screen.)
138
+ function whenDone(run: Animation[]) {
139
+ Promise.all(run.map((a) => a.finished)).then(() => {
140
+ if (anims !== run) return
141
+ if (ctl.value.isOpen.value) opened()
142
+ else closed()
143
+ }, () => {})
144
+ }
145
+
146
+ // Plays the running animations the other way. They hold their last frame meanwhile, so an opening turned into a
147
+ // closing doesn't show the open view for a frame between its end and the layer going away
148
+ function turnAround() {
149
+ for (const a of anims) {
150
+ a.effect?.updateTiming({ fill: 'both' })
151
+ a.reverse()
152
+ }
153
+ }
154
+
155
+ // Plays a run, settling when it ends (see whenDone)
156
+ function play(entering: boolean, start: Box, end: Box, startRadius: number, endRadius: number, done: () => void) {
157
+ const frames = containerFrames(start, end, startRadius, endRadius, entering, entering ? OPEN_MS : CLOSE_MS)
158
+ shadeTransition()
159
+ // The views' resting boxes: the clone sits on the element's, the panel on its own
160
+ anims = playContainerFrames(
161
+ frames,
162
+ { clip: clip.value!, start: entering ? ghost : panel.value!, end: entering ? panel.value! : ghost!, scrim: scrimEl.value },
163
+ window.innerWidth,
164
+ window.innerHeight,
165
+ entering ? undefined : 'forwards',
166
+ )
167
+ if (!anims.length) return done()
168
+ whenDone(anims)
169
+ }
170
+
171
+ async function show() {
172
+ // Closing: turn around and grow back
173
+ if (anims.length && mounted.value) {
174
+ turnAround()
175
+ return
176
+ }
177
+ const src = ctl.value.source.value
178
+ mounted.value = true
179
+ await nextTick()
180
+ if (!panel.value || !ctl.value.isOpen.value) return
181
+ returnFocus = true
182
+ panel.value.focus({ preventScroll: true })
183
+ if (!src || !src.isConnected || prefersReducedMotion()) return hideSource(src)
184
+ const start = boxOf(src)
185
+ const end = boxOf(panel.value)
186
+ if (!sized(start) || !sized(end)) return hideSource(src)
187
+ ghost = makeGhost(src, start)
188
+ hideSource(src)
189
+ play(true, start, end, radiusOf(src), radiusOf(panel.value), opened)
190
+ }
191
+
192
+ function hide() {
193
+ if (!mounted.value) return
194
+ // Opening: turn around and shrink back
195
+ if (anims.length) {
196
+ turnAround()
197
+ return
198
+ }
199
+ const src = hidden
200
+ if (!panel.value || !src || !src.isConnected || prefersReducedMotion()) return closed()
201
+ returnFocus = !!panel.value.contains(document.activeElement) || document.activeElement === document.body
202
+ const start = boxOf(panel.value)
203
+ const end = boxOf(src)
204
+ if (!sized(start) || !sized(end)) return closed()
205
+ ghost = makeGhost(src, end)
206
+ play(false, start, end, radiusOf(panel.value), radiusOf(src), closed)
207
+ }
208
+
209
+ // Android's back closes it through a CloseWatcher (the platform's own close request, which also gets Escape where
210
+ // nothing handled it), so the history isn't touched: pushing an entry made a router navigate on every close
211
+ interface CloseWatcherLike { onclose: (() => void) | null; destroy: () => void }
212
+ let closeWatcher: CloseWatcherLike | null = null
213
+ function watchClose() {
214
+ if (!props.closeOnBack || closeWatcher || typeof window === 'undefined') return
215
+ const Watcher = (window as unknown as { CloseWatcher?: new () => CloseWatcherLike }).CloseWatcher
216
+ if (!Watcher) return
217
+ const w = new Watcher()
218
+ w.onclose = () => {
219
+ closeWatcher = null
220
+ ctl.value.close()
221
+ }
222
+ closeWatcher = w
223
+ }
224
+ function unwatchClose() {
225
+ closeWatcher?.destroy()
226
+ closeWatcher = null
227
+ }
228
+
229
+ watch(() => ctl.value.isOpen.value, (open) => {
230
+ if (openModel.value !== open) openModel.value = open
231
+ if (open) {
232
+ watchClose()
233
+ show()
234
+ } else {
235
+ unwatchClose()
236
+ hide()
237
+ }
238
+ })
239
+ watch(openModel, (open) => {
240
+ if (open === ctl.value.isOpen.value) return
241
+ if (open) ctl.value.open(ctl.value.source.value ?? anchorElement())
242
+ else ctl.value.close()
243
+ }, { immediate: true })
244
+
245
+ useScrollLock(() => mounted.value && props.scrim)
246
+ useEscapeStack(() => mounted.value && ctl.value.isOpen.value, () => ctl.value.close())
247
+
248
+ // Without a scrim the page stays usable: a press outside the expanded view (and the element it came from) closes it
249
+ function onOutside(e: PointerEvent) {
250
+ const target = e.target as Node | null
251
+ if (!target || panel.value?.contains(target) || hidden?.contains(target)) return
252
+ ctl.value.close()
253
+ }
254
+ watch(() => mounted.value && ctl.value.isOpen.value && !props.scrim && !props.persistent, (on) => {
255
+ if (typeof document === 'undefined') return
256
+ if (on) document.addEventListener('pointerdown', onOutside, true)
257
+ else document.removeEventListener('pointerdown', onOutside, true)
258
+ })
259
+
260
+ onBeforeUnmount(() => {
261
+ clearRun()
262
+ hideSource(null)
263
+ unwatchClose()
264
+ if (typeof document !== 'undefined') document.removeEventListener('pointerdown', onOutside, true)
265
+ })
266
+
267
+ const close = () => ctl.value.close()
268
+ const panelStyle = computed(() => (props.mode === 'dialog' ? { width: `min(${props.maxWidth}, calc(100% - 48px))` } : undefined))
269
+ </script>
270
+
271
+ <template>
272
+ <span v-if="$slots.default" ref="anchor" class="contents">
273
+ <slot :open="openFromSlot" :is-open="ctl.isOpen.value" />
274
+ </span>
275
+ <Teleport to="body">
276
+ <div v-if="mounted" class="fixed inset-0 z-50" :class="!scrim && 'pointer-events-none'">
277
+ <div
278
+ v-if="scrim"
279
+ ref="scrimEl"
280
+ class="absolute inset-0 bg-black"
281
+ :style="{ opacity: SCRIM_OPACITY }"
282
+ @click="mode !== 'fullscreen' && !persistent && close()"
283
+ />
284
+ <!-- The container: its clip morphs between the two boxes during a transition; the views move inside it. The
285
+ layer around it draws the panel's shadow meanwhile -->
286
+ <div ref="shadowEl" class="pointer-events-none absolute inset-0">
287
+ <div ref="clip" class="pointer-events-none absolute inset-0">
288
+ <div
289
+ ref="panel"
290
+ v-bind="$attrs"
291
+ role="dialog"
292
+ :aria-modal="scrim ? 'true' : undefined"
293
+ :aria-label="label"
294
+ tabindex="-1"
295
+ class="m3-ct-panel pointer-events-auto absolute overflow-y-auto outline-none"
296
+ :class="mode === 'dialog' ? 'm3-ct-dialog inset-0 m-auto h-fit max-h-[calc(100%-48px)]' : mode === 'fullscreen' ? 'inset-0' : ''"
297
+ :style="panelStyle"
298
+ style="transform-origin: 0 0"
299
+ >
300
+ <slot name="expanded" :close="close" :item="ctl.item.value" />
301
+ </div>
302
+ </div>
303
+ </div>
304
+ </div>
305
+ </Teleport>
306
+ </template>
307
+
308
+ <style>
309
+ /* The expanded surface's look, in the base layer so the consumer's classes on the component win (see MShape) */
310
+ @layer base {
311
+ .m3-ct-panel {
312
+ background-color: var(--color-surface);
313
+ color: var(--color-on-surface);
314
+ }
315
+ .m3-ct-dialog {
316
+ background-color: var(--color-surface-container-high);
317
+ border-radius: 28px;
318
+ box-shadow: var(--shadow-elevation-3);
319
+ }
320
+ }
321
+ </style>
@@ -411,7 +411,7 @@ function colStyle(col: DataTableColumn) {
411
411
  <div v-if="searchable" class="flex min-w-48 flex-1 items-center gap-2 rounded-full border border-outline-variant bg-surface-container px-3 py-1.5 transition-[border-color,box-shadow] duration-150 focus-within:border-primary focus-within:ring-1 focus-within:ring-primary/30">
412
412
  <MIcon name="search" :size="16" class="shrink-0 text-on-surface-variant" />
413
413
  <input v-model="search" type="text" :placeholder="searchPlaceholder ?? locale.search" class="w-full bg-transparent text-body-medium text-on-surface outline-none placeholder:text-on-surface-variant" />
414
- <button v-if="search" class="text-on-surface-variant transition-colors hover:text-on-surface" @click="search = ''">
414
+ <button type="button" :aria-label="locale.clearSearch" v-if="search" class="text-on-surface-variant transition-colors hover:text-on-surface" @click="search = ''">
415
415
  <MIcon name="close" :size="14" />
416
416
  </button>
417
417
  </div>
@@ -51,7 +51,8 @@ const props = withDefaults(
51
51
  /**
52
52
  * Just the dialog's box (surface, shape, elevation), scrim, Escape, scroll lock and animation, with the default
53
53
  * slot filling it: no title row, padding, close button or actions. For dialogs that draw everything themselves
54
- * (the date and time pickers). `title` then only names it for assistive technology
54
+ * (the date and time pickers). With `fullscreen`, the slot fills the screen and draws its own top bar. `title`
55
+ * then only names it for assistive technology
55
56
  */
56
57
  bare?: boolean
57
58
  }>(),
@@ -66,6 +67,9 @@ const props = withDefaults(
66
67
  },
67
68
  )
68
69
 
70
+ // The root is a Teleport, which can't take the consumer's class/style/attrs: they go on the dialog's surface
71
+ defineOptions({ inheritAttrs: false })
72
+
69
73
  const locale = useLocale()
70
74
 
71
75
  // maxWidth/maxHeight take either a Tailwind class or a CSS value: a bare length or a CSS function
@@ -145,7 +149,8 @@ onUnmounted(() => {
145
149
  @click.self="close"
146
150
  >
147
151
  <div
148
- class="dialog-box flex min-w-[280px] w-full flex-col rounded-xl bg-surface-container-high shadow-elevation-3"
152
+ v-bind="$attrs"
153
+ class="dialog-box m3-dialog-surface flex min-w-[280px] w-full flex-col"
149
154
  :class="sizeClasses"
150
155
  :style="sizeStyle"
151
156
  role="dialog"
@@ -226,12 +231,18 @@ onUnmounted(() => {
226
231
  <Transition v-else name="m3-dialog-fs" appear>
227
232
  <div
228
233
  v-if="modelValue"
229
- class="dialog-fs fixed inset-0 z-50 flex flex-col bg-surface"
234
+ v-bind="$attrs"
235
+ class="dialog-fs m3-dialog-fs-surface fixed inset-0 z-50 flex flex-col"
230
236
  role="dialog"
231
237
  aria-modal="true"
232
- :aria-labelledby="$slots.title || title ? titleId : undefined"
238
+ :aria-labelledby="!bare && ($slots.title || title) ? titleId : undefined"
239
+ :aria-label="bare ? title : undefined"
233
240
  >
234
- <div class="flex h-14 shrink-0 items-center gap-2 px-2">
241
+ <!-- Bare: the content is the whole screen, top bar included, in whatever colors it draws -->
242
+ <div v-if="bare" class="min-h-0 flex-1 overflow-y-auto">
243
+ <slot />
244
+ </div>
245
+ <div v-else class="flex h-14 shrink-0 items-center gap-2 px-2">
235
246
  <MIconButton v-if="!persistent" icon="close" :label="closeLabel ?? locale.close" @click="close" />
236
247
  <h2 :id="titleId" class="flex-1 text-title-large font-medium text-on-surface">
237
248
  <slot name="title">{{ title }}</slot>
@@ -240,7 +251,7 @@ onUnmounted(() => {
240
251
  <slot name="actions" />
241
252
  </div>
242
253
  </div>
243
- <div class="flex-1 overflow-y-auto px-6 py-4 text-body-medium text-on-surface-variant">
254
+ <div v-if="!bare" class="flex-1 overflow-y-auto px-6 py-4 text-body-medium text-on-surface-variant">
244
255
  <slot />
245
256
  </div>
246
257
  </div>
@@ -279,3 +290,17 @@ onUnmounted(() => {
279
290
  opacity: 0;
280
291
  }
281
292
  </style>
293
+
294
+ <style>
295
+ /* The surfaces' look, in the base layer so the consumer's classes on MDialog win (see MShape) */
296
+ @layer base {
297
+ .m3-dialog-surface {
298
+ background-color: var(--color-surface-container-high);
299
+ border-radius: var(--radius-xl);
300
+ box-shadow: var(--shadow-elevation-3);
301
+ }
302
+ .m3-dialog-fs-surface {
303
+ background-color: var(--color-surface);
304
+ }
305
+ }
306
+ </style>
@@ -99,7 +99,10 @@ const isExpandable = computed(() => hasItems.value || hasContent.value)
99
99
 
100
100
  // Inside an MBottomAppBar: secondary and flat (bottomAppBarFabColor, bottomAppBarFabElevation)
101
101
  const inBottomAppBar = inject('m-bottom-app-bar', false)
102
- const color = computed(() => props.color ?? (inBottomAppBar ? 'secondary' : 'primary'))
102
+ // In MToolbar's #fab slot: the toolbar sizes it (56 → 80px as it collapses), with the floating toolbar FAB's color
103
+ // and elevation (FloatingToolbarDefaults.StandardFloatingActionButton / VibrantFloatingActionButton)
104
+ const inToolbar = inject<{ color: 'primary' | 'tertiary' } | null>('m-toolbar-fab', null)
105
+ const color = computed(() => props.color ?? inToolbar?.color ?? (inBottomAppBar ? 'secondary' : 'primary'))
103
106
 
104
107
  const colorMap: Record<string, string> = {
105
108
  primary: 'bg-primary-container text-on-primary-container',
@@ -119,10 +122,12 @@ const EXTENDED = {
119
122
  medium: { px: 80, icon: 28, lead: 26, gap: 'pl-3', box: 'h-20 min-w-20 rounded-lg-increased px-[26px]', text: 'text-title-large' },
120
123
  large: { px: 96, icon: 32, lead: 28, gap: 'pl-4', box: 'h-24 min-w-24 rounded-xl px-7', text: 'text-headline-small' },
121
124
  } as const
122
- const extended = computed(() => (props.label ? EXTENDED[props.size] : null))
125
+ // In a toolbar the FAB is always the square one: its label only names it
126
+ const extended = computed(() => (props.label && !inToolbar ? EXTENDED[props.size] : null))
123
127
 
124
128
  const fabSizeClasses = computed(() => {
125
129
  if (extended.value) return extended.value.box
130
+ if (inToolbar) return 'h-full w-full rounded-2xl'
126
131
  switch (props.size) {
127
132
  case 'small': return 'h-10 w-10 rounded-md'
128
133
  case 'medium': return 'h-20 w-20 rounded-lg-increased'
@@ -359,16 +364,16 @@ onUnmounted(() => {
359
364
  </script>
360
365
 
361
366
  <template>
362
- <div ref="fabEl" v-bind="$attrs" class="relative inline-flex items-center justify-center">
367
+ <div ref="fabEl" v-bind="$attrs" class="relative inline-flex items-center justify-center" :class="inToolbar && !extended && 'h-full w-full'">
363
368
  <component
364
369
  :is="fabTag"
365
370
  ref="fabButton"
366
371
  :to="to || undefined"
367
372
  :type="to ? undefined : 'button'"
368
373
  class="relative inline-flex cursor-pointer items-center overflow-hidden transition-shadow duration-150 disabled:cursor-not-allowed disabled:opacity-[0.38] before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
369
- :class="[colorMap[color], fabSizeClasses, extended ? 'justify-start' : 'justify-center', inBottomAppBar ? '' : 'shadow-elevation-3 hover:shadow-elevation-4 active:shadow-elevation-3']"
374
+ :class="[colorMap[color], fabSizeClasses, extended ? 'justify-start' : 'justify-center', inBottomAppBar ? '' : inToolbar ? 'shadow-elevation-2 hover:shadow-elevation-3 active:shadow-elevation-2' : 'shadow-elevation-3 hover:shadow-elevation-4 active:shadow-elevation-3']"
370
375
  :disabled="disabled"
371
- :aria-label="label && !expanded ? label : undefined"
376
+ :aria-label="label && (!extended || !expanded) ? label : undefined"
372
377
  :style="initialButtonStyle"
373
378
  v-ripple="{ disabled, color: rippleColor }"
374
379
  @click="handleFabClick"
@@ -1,7 +1,8 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
3
  * Renders a Material Symbols Outlined glyph by name. Color follows the surrounding text color (set it with a
4
- * Tailwind text-* class).
4
+ * Tailwind text-* class). Decorative by default: hidden from assistive technology, which would otherwise read the
5
+ * glyph's ligature text (its name, e.g. "arrow_drop_down"). Give it a `label` when the icon says something on its own.
5
6
  */
6
7
  withDefaults(defineProps<{
7
8
  /** Material Symbol name (e.g. "settings", "favorite") */
@@ -10,11 +11,17 @@ withDefaults(defineProps<{
10
11
  size?: number
11
12
  /** Filled glyph (the Material Symbols FILL axis), as M3 draws a selected icon */
12
13
  filled?: boolean
14
+ /** What the icon means, when nothing next to it says so: makes it an image with this name instead of decoration */
15
+ label?: string
13
16
  }>(), { size: 24, filled: false })
14
17
  </script>
15
18
 
16
19
  <template>
17
- <span class="material-symbols-outlined leading-none" :style="{ fontSize: `${size}px`, fontVariationSettings: filled ? `'FILL' 1` : undefined }">{{
18
- name
19
- }}</span>
20
+ <span
21
+ class="material-symbols-outlined leading-none"
22
+ :role="label ? 'img' : undefined"
23
+ :aria-label="label"
24
+ :aria-hidden="label ? undefined : 'true'"
25
+ :style="{ fontSize: `${size}px`, fontVariationSettings: filled ? `'FILL' 1` : undefined }"
26
+ >{{ name }}</span>
20
27
  </template>
@@ -38,6 +38,8 @@ const props = withDefaults(
38
38
  checked?: boolean
39
39
  /** Icon shown while checked, when it differs from `icon` (e.g. 'pause' for 'play_arrow') */
40
40
  checkedIcon?: string
41
+ /** Draw the icon filled (Material Symbols' FILL axis) without making it a toggle, e.g. media controls */
42
+ iconFilled?: boolean
41
43
  }>(),
42
44
  {
43
45
  variant: 'standard',
@@ -199,6 +201,6 @@ const variantClasses = computed(() => {
199
201
  @pointercancel="onPointerUp"
200
202
  @click="onClick"
201
203
  >
202
- <MIcon :name="checked && checkedIcon ? checkedIcon : icon" :size="resolved.icon" :filled="!!checked" />
204
+ <MIcon :name="checked && checkedIcon ? checkedIcon : icon" :size="resolved.icon" :filled="!!checked || iconFilled" />
203
205
  </component>
204
206
  </template>
@@ -2,12 +2,13 @@
2
2
  /**
3
3
  * A vertical list container (MList) with rich, flexible rows (MListItem) and optional section headers
4
4
  * (MListSubheader) — one-line to three-line items, leading/trailing elements, selection, navigation, segmented,
5
- * and expandable variants.
5
+ * and expandable variants. MListGroup splits a list into groups (separate rounded runs in a segmented list).
6
6
  *
7
- * @slot default MListItem / MListSubheader children
7
+ * @slot default MListItem / MListSubheader / MListGroup children
8
8
  * @event update:selected Fires when a selectable item is clicked (via v-model:selected)
9
9
  */
10
- import { computed, onMounted, onUnmounted, provide, ref, shallowRef } from 'vue'
10
+ import { computed, nextTick, onMounted, onUpdated, provide, ref } from 'vue'
11
+ import { useSegmentRuns } from '../composables/_useSegmentRuns'
11
12
 
12
13
  const props = withDefaults(
13
14
  defineProps<{
@@ -33,36 +34,13 @@ const emit = defineEmits<{
33
34
  'update:selected': [value: string | number | null]
34
35
  }>()
35
36
 
36
- // Segmented items need to know whether they open or close their run of items (SegmentedListItem's
37
- // segmentedShapes(index, count)). A subheader or any other non-item child starts a new run.
37
+ // Segmented items need to know whether they open or close their run of items. A subheader, an MListGroup
38
+ // or any other non-item child starts a new run.
38
39
  const listEl = ref<HTMLElement>()
39
- const positions = shallowRef(new Map<Element, 'single' | 'first' | 'middle' | 'last'>())
40
- function measure() {
41
- const map = new Map<Element, 'single' | 'first' | 'middle' | 'last'>()
42
- let run: Element[] = []
43
- const flush = () => {
44
- run.forEach((el, i) => map.set(el, run.length === 1 ? 'single' : i === 0 ? 'first' : i === run.length - 1 ? 'last' : 'middle'))
45
- run = []
46
- }
47
- for (const child of listEl.value?.children ?? []) {
48
- if (child.getAttribute('role') === 'listitem') run.push(child)
49
- else flush()
50
- }
51
- flush()
52
- positions.value = map
53
- }
54
- let observer: MutationObserver | undefined
55
- onMounted(() => {
56
- measure()
57
- if (listEl.value) {
58
- observer = new MutationObserver(measure)
59
- observer.observe(listEl.value, { childList: true })
60
- }
61
- })
62
- onUnmounted(() => observer?.disconnect())
40
+ const segmentPosition = useSegmentRuns(listEl)
63
41
 
64
42
  provide('m-list', {
65
- segmentPosition: (el: Element | null | undefined) => (el ? positions.value.get(el) : undefined),
43
+ segmentPosition,
66
44
  dense: computed(() => props.dense),
67
45
  nav: computed(() => props.nav),
68
46
  segmented: computed(() => props.segmented),
@@ -73,6 +51,30 @@ provide('m-list', {
73
51
  select: (value: string | number) => emit('update:selected', value),
74
52
  })
75
53
 
54
+ // A selectable list is a listbox: its items are options, one Tab stop (the selected one, else the first), the
55
+ // arrows, Home and End move between them, Enter/Space select (MListItem)
56
+ const options = () => [...(listEl.value?.querySelectorAll<HTMLElement>('[role="option"]') ?? [])]
57
+ .filter((o) => o.getAttribute('aria-disabled') !== 'true')
58
+ function onKeydown(e: KeyboardEvent) {
59
+ if (!props.selectable) return
60
+ const all = options()
61
+ const i = all.indexOf(document.activeElement as HTMLElement)
62
+ if (i < 0) return
63
+ const next = e.key === 'ArrowDown' ? all[i + 1] : e.key === 'ArrowUp' ? all[i - 1] : e.key === 'Home' ? all[0] : e.key === 'End' ? all[all.length - 1] : undefined
64
+ if (!next) return
65
+ e.preventDefault()
66
+ next.focus()
67
+ }
68
+ // With nothing selected (or a selection not in the list), the first option takes the Tab stop. Bound tabindexes
69
+ // only patch when they change, so this one stays until the selection moves it.
70
+ function keepTabStop() {
71
+ if (!props.selectable) return
72
+ const all = options()
73
+ if (all.length && !all.some((o) => o.tabIndex === 0)) all[0]!.tabIndex = 0
74
+ }
75
+ onMounted(keepTabStop)
76
+ onUpdated(() => nextTick(keepTabStop))
77
+
76
78
  const classes = computed(() => [
77
79
  'flex flex-col',
78
80
  // ListTokens.SegmentedGap = 2dp
@@ -82,7 +84,7 @@ const classes = computed(() => [
82
84
  </script>
83
85
 
84
86
  <template>
85
- <ul ref="listEl" role="list" :class="classes">
87
+ <ul ref="listEl" :role="selectable ? 'listbox' : 'list'" :class="classes" @keydown="onKeydown">
86
88
  <slot />
87
89
  </ul>
88
90
  </template>
@@ -0,0 +1,66 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A group of items inside an MList, optionally titled. In a segmented list each group is a rounded run of its
4
+ * own (its first and last items take the large outer corners), set apart from the items and groups around it,
5
+ * like the grouped cards of a settings screen. Elsewhere it only groups and titles its items. Assistive
6
+ * technology announces it as a nested list named by its title.
7
+ *
8
+ * @slot default MListItem children
9
+ * @slot title Custom title content, replacing the title prop
10
+ */
11
+ import { computed, inject, provide, ref, useId, type ComputedRef } from 'vue'
12
+ import { useSegmentRuns } from '../composables/_useSegmentRuns'
13
+
14
+ withDefaults(
15
+ defineProps<{
16
+ /** Heading above the group, styled like MListSubheader */
17
+ title?: string
18
+ /** Align the title with items that have a leading icon (adds left padding) */
19
+ inset?: boolean
20
+ }>(),
21
+ { inset: false },
22
+ )
23
+
24
+ // Same context as MList's, with the group's own runs: its items are measured against each other, not the list
25
+ const parent = inject<({ segmented: ComputedRef<boolean>; nav: ComputedRef<boolean> } & Record<string, unknown>) | null>('m-list', null)
26
+ const groupEl = ref<HTMLElement>()
27
+ const segmentPosition = useSegmentRuns(groupEl)
28
+ if (parent) provide('m-list', { ...parent, segmentPosition })
29
+
30
+ const segmented = computed(() => parent?.segmented.value ?? false)
31
+ const nav = computed(() => parent?.nav.value ?? false)
32
+ const titleId = `m3-list-group-${useId()}`
33
+ </script>
34
+
35
+ <template>
36
+ <li role="none" class="m3-list-group flex flex-col" :class="segmented && 'm3-list-group-segmented'">
37
+ <div
38
+ v-if="title || $slots.title"
39
+ :id="titleId"
40
+ class="px-4 pb-2 text-label-medium font-medium text-on-surface-variant"
41
+ :class="[segmented ? 'pt-2' : 'pt-4', inset && 'pl-16']"
42
+ >
43
+ <slot name="title">{{ title }}</slot>
44
+ </div>
45
+ <ul
46
+ ref="groupEl"
47
+ role="list"
48
+ :aria-labelledby="title || $slots.title ? titleId : undefined"
49
+ class="flex flex-col"
50
+ :class="(segmented || nav) && 'gap-0.5'"
51
+ >
52
+ <slot />
53
+ </ul>
54
+ </li>
55
+ </template>
56
+
57
+ <style>
58
+ /* Segmented: 10px plus the list's 2dp gap sets a group apart from what comes before and after it.
59
+ In the components layer so a consumer's margin utility still wins. */
60
+ @layer components {
61
+ .m3-list-group-segmented:not(:first-child),
62
+ .m3-list-group-segmented + li[role='listitem'] {
63
+ margin-top: 10px;
64
+ }
65
+ }
66
+ </style>