@m3ui-vue/m3ui-vue 1.1.3 → 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.
- package/README.md +1 -1
- package/dist/API.md +70 -8
- package/dist/{MMenuItem-BckcR0nW.js → MMenuItem-BfjqwcYP.js} +84 -63
- package/dist/MMenuItem-BfjqwcYP.js.map +1 -0
- package/dist/MSlider-JflHJ70q.js +1525 -0
- package/dist/MSlider-JflHJ70q.js.map +1 -0
- package/dist/{MTextField-FCPOTB0o.js → MTextField-NaIB6RbM.js} +5 -4
- package/dist/MTextField-NaIB6RbM.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
- package/dist/components/MButton.vue.d.ts +2 -0
- package/dist/components/MContainerTransform.vue.d.ts +59 -0
- package/dist/components/MDialog.vue.d.ts +8 -5
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +2 -0
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MToolbar.vue.d.ts +32 -5
- package/dist/components/_MToolbarFab.vue.d.ts +16 -0
- package/dist/composables/_containerTransform.d.ts +48 -0
- package/dist/composables/useContainerTransform.d.ts +30 -0
- package/dist/composables/useLocale.d.ts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/locales/index.js +14 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4217 -3713
- package/dist/m3ui.js.map +1 -1
- package/dist/map.js +38 -38
- package/dist/rich-text-editor.js +10 -10
- package/dist/styles.css +1 -1
- package/dist/{useLocale-SfQHnJfp.js → useLocale-CXibICQA.js} +3 -1
- package/dist/useLocale-CXibICQA.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/MAnimatedNumber.test.ts +24 -2
- package/src/__tests__/MContainerTransform.test.ts +279 -0
- package/src/__tests__/MDialog.test.ts +27 -0
- package/src/__tests__/MListItemExpandable.test.ts +48 -0
- package/src/__tests__/MListItemShape.test.ts +9 -6
- package/src/__tests__/MListKeyboard.test.ts +90 -0
- package/src/__tests__/MMapTools.test.ts +2 -1
- package/src/__tests__/MNavigationRail.test.ts +33 -0
- package/src/__tests__/MSlider.test.ts +161 -0
- package/src/__tests__/MToolbar.test.ts +157 -0
- package/src/__tests__/attrsFallthrough.test.ts +6 -0
- package/src/__tests__/hydration.test.ts +25 -0
- package/src/components/MAnimatedNumber.vue +32 -6
- package/src/components/MButton.vue +4 -2
- package/src/components/MContainerTransform.vue +321 -0
- package/src/components/MDialog.vue +31 -6
- package/src/components/MFab.vue +10 -5
- package/src/components/MIconButton.vue +3 -1
- package/src/components/MList.vue +26 -2
- package/src/components/MListItem.vue +138 -84
- package/src/components/MNavigationRail.vue +40 -10
- package/src/components/MSlider.vue +161 -42
- package/src/components/MToolbar.vue +256 -15
- package/src/components/_MToolbarFab.vue +14 -0
- package/src/composables/_containerTransform.ts +179 -0
- package/src/composables/_useEscapeStack.ts +2 -0
- package/src/composables/useContainerTransform.ts +59 -0
- package/src/composables/useLocale.ts +5 -0
- package/src/index.ts +3 -0
- package/src/locales/de.ts +2 -0
- package/src/locales/es.ts +2 -0
- package/src/locales/fr.ts +2 -0
- package/src/locales/ja.ts +2 -0
- package/src/locales/ko.ts +2 -0
- package/src/locales/pt.ts +2 -0
- package/src/locales/zh.ts +2 -0
- package/dist/MMenuItem-BckcR0nW.js.map +0 -1
- package/dist/MSlider-LyH_gy8D.js +0 -1411
- package/dist/MSlider-LyH_gy8D.js.map +0 -1
- package/dist/MTextField-FCPOTB0o.js.map +0 -1
- package/dist/useLocale-SfQHnJfp.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>
|
|
@@ -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). `
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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>
|
package/src/components/MFab.vue
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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"
|
|
@@ -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>
|
package/src/components/MList.vue
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
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, provide, ref } from 'vue'
|
|
10
|
+
import { computed, nextTick, onMounted, onUpdated, provide, ref } from 'vue'
|
|
11
11
|
import { useSegmentRuns } from '../composables/_useSegmentRuns'
|
|
12
12
|
|
|
13
13
|
const props = withDefaults(
|
|
@@ -51,6 +51,30 @@ provide('m-list', {
|
|
|
51
51
|
select: (value: string | number) => emit('update:selected', value),
|
|
52
52
|
})
|
|
53
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
|
+
|
|
54
78
|
const classes = computed(() => [
|
|
55
79
|
'flex flex-col',
|
|
56
80
|
// ListTokens.SegmentedGap = 2dp
|
|
@@ -60,7 +84,7 @@ const classes = computed(() => [
|
|
|
60
84
|
</script>
|
|
61
85
|
|
|
62
86
|
<template>
|
|
63
|
-
<ul ref="listEl" role="list" :class="classes">
|
|
87
|
+
<ul ref="listEl" :role="selectable ? 'listbox' : 'list'" :class="classes" @keydown="onKeydown">
|
|
64
88
|
<slot />
|
|
65
89
|
</ul>
|
|
66
90
|
</template>
|