@m3ui-vue/m3ui-vue 0.9.2 → 1.0.0
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 +26 -29
- package/dist/API.md +242 -22
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-Ck0oWDMk.js → MTextField-TZ7lfr09.js} +551 -216
- package/dist/MTextField-TZ7lfr09.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.md +547 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MAppBarWithSearch.vue.d.ts +70 -0
- package/dist/components/MBottomAppBar.vue.d.ts +37 -0
- package/dist/components/MBottomSheetScaffold.vue.d.ts +40 -0
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MChatBubble.vue.d.ts +1 -1
- package/dist/components/MChip.vue.d.ts +19 -2
- package/dist/components/MContainer.vue.d.ts +1 -1
- package/dist/components/MDataTable.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +15 -4
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MListItem.vue.d.ts +2 -2
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MNavigationRail.vue.d.ts +6 -0
- package/dist/components/MSearchBar.vue.d.ts +5 -3
- package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTimePickerModal.vue.d.ts +3 -0
- package/dist/components/MTimeScroll.vue.d.ts +22 -0
- package/dist/components/MToggleButton.vue.d.ts +2 -0
- package/dist/components/MTopAppBar.vue.d.ts +33 -2
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_searchAppBar.d.ts +6 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_useSpring.d.ts +5 -5
- package/dist/composables/motion.d.ts +101 -0
- package/dist/composables/useColorPalette.d.ts +10 -0
- package/dist/composables/useLocale.d.ts +9 -0
- package/dist/directives/vRipple.d.ts +16 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/locales/index.js +63 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7716 -6768
- package/dist/m3ui.js.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/palettes-contrast.css +7764 -0
- package/dist/styles/theme.css +59 -2
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CFW8cIzL.js → useLocale-CuvWRZ1h.js} +10 -1
- package/dist/useLocale-CuvWRZ1h.js.map +1 -0
- package/package.json +4 -2
- package/src/__tests__/MAppBarWithSearch.test.ts +96 -0
- package/src/__tests__/MBottomAppBar.test.ts +71 -0
- package/src/__tests__/MBottomSheetScaffold.test.ts +101 -0
- package/src/__tests__/MChip.test.ts +63 -0
- package/src/__tests__/MFab.test.ts +36 -0
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MNavigationRail.test.ts +77 -0
- package/src/__tests__/MScrollField.test.ts +28 -0
- package/src/__tests__/MTabs.test.ts +39 -0
- package/src/__tests__/MTimePickerModal.test.ts +52 -0
- package/src/__tests__/MTimeScroll.test.ts +44 -0
- package/src/__tests__/MTopAppBar.test.ts +99 -0
- package/src/__tests__/contrast.test.ts +64 -0
- package/src/__tests__/dynamicColor.test.ts +17 -0
- package/src/__tests__/motion.test.ts +37 -0
- package/src/__tests__/themeTransition.test.ts +119 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MAppBarWithSearch.vue +236 -0
- package/src/components/MBottomAppBar.vue +181 -0
- package/src/components/MBottomSheetScaffold.vue +296 -0
- package/src/components/MBreadcrumbs.vue +1 -1
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +4 -11
- package/src/components/MChip.vue +137 -5
- package/src/components/MFab.vue +81 -27
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MNavigationDrawer.vue +2 -2
- package/src/components/MNavigationRail.vue +135 -8
- package/src/components/MScrollField.vue +10 -2
- package/src/components/MSearchBar.vue +28 -12
- package/src/components/MSplitButton.vue +5 -12
- package/src/components/MTabs.vue +16 -5
- package/src/components/MTimePickerModal.vue +48 -8
- package/src/components/MTimeScroll.vue +161 -0
- package/src/components/MToggleButton.vue +5 -12
- package/src/components/MTopAppBar.vue +252 -28
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_searchAppBar.ts +9 -0
- package/src/composables/_themeColor.ts +11 -4
- package/src/composables/_themeTransition.ts +71 -0
- package/src/composables/_useSpring.ts +12 -20
- package/src/composables/motion.ts +73 -0
- package/src/composables/useColorPalette.ts +103 -20
- package/src/composables/useLocale.ts +18 -0
- package/src/composables/useTheme.ts +4 -12
- package/src/data/emoji-names/emoji-names-de.ts +1 -0
- package/src/data/emoji-names/emoji-names-en.ts +1 -0
- package/src/data/emoji-names/emoji-names-es.ts +1 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1 -0
- package/src/data/emojis.ts +1 -0
- package/src/directives/vRipple.ts +73 -0
- package/src/index.ts +13 -1
- package/src/locales/de.ts +9 -0
- package/src/locales/es.ts +9 -0
- package/src/locales/fr.ts +9 -0
- package/src/locales/ja.ts +9 -0
- package/src/locales/ko.ts +9 -0
- package/src/locales/pt.ts +9 -0
- package/src/locales/zh.ts +9 -0
- package/src/plugin.ts +11 -1
- package/src/styles/palettes-contrast.css +7764 -0
- package/src/styles/theme.css +59 -2
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-Ck0oWDMk.js.map +0 -1
- package/dist/useLocale-CFW8cIzL.js.map +0 -1
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* @slot fab A FAB (or MFabMenu) at the top of the rail, above the items.
|
|
7
7
|
* @event update:modelValue Emitted when an item is clicked — powers v-model
|
|
8
8
|
* @event update:expanded Emitted when the modal panel closes (modal mode only) — pair with :expanded for
|
|
9
|
-
* v-model:expanded
|
|
9
|
+
* v-model:expanded. With `hideOnCollapse`, swiping the panel away closes it too
|
|
10
10
|
*/
|
|
11
11
|
import { computed, ref, watch, onUnmounted } from 'vue'
|
|
12
12
|
import MIcon from './MIcon.vue'
|
|
@@ -49,7 +49,12 @@ const props = withDefaults(defineProps<{
|
|
|
49
49
|
// affects the app's layout grid — `ModalWideNavigationRail`'s whole point) and `expanded`
|
|
50
50
|
// instead opens a Teleported, scrim-backed panel that floats above the rest of the app.
|
|
51
51
|
modal?: boolean
|
|
52
|
-
|
|
52
|
+
/**
|
|
53
|
+
* With `modal`: no collapsed rail on screen; the expanded rail slides in from off-screen and can be swiped
|
|
54
|
+
* away (Compose's `hideOnCollapse`). Open it from your own menu button
|
|
55
|
+
*/
|
|
56
|
+
hideOnCollapse?: boolean
|
|
57
|
+
}>(), { alignment: 'top', expanded: false, modal: false, hideOnCollapse: false })
|
|
53
58
|
|
|
54
59
|
const emit = defineEmits<{
|
|
55
60
|
'update:modelValue': [string | number]
|
|
@@ -101,6 +106,9 @@ function onKeydown(e: KeyboardEvent) {
|
|
|
101
106
|
const PANEL_WIDTH = 220
|
|
102
107
|
const SPRING_DAMPING = 0.9
|
|
103
108
|
const SPRING_STIFFNESS = 1400
|
|
109
|
+
// The dismissible (hideOnCollapse) panel slides instead: ModalWideNavigationRailState's DefaultSpatial
|
|
110
|
+
const SLIDE_DAMPING = 0.9
|
|
111
|
+
const SLIDE_STIFFNESS = 700
|
|
104
112
|
|
|
105
113
|
// Guards against two overlapping spring loops fighting over the same element's
|
|
106
114
|
// `style.width` (e.g. a close fired before a still-running open settles) — each call gets
|
|
@@ -109,25 +117,38 @@ const SPRING_STIFFNESS = 1400
|
|
|
109
117
|
const springTokens = new WeakMap<HTMLElement, number>()
|
|
110
118
|
|
|
111
119
|
function springWidth(el: HTMLElement, from: number, to: number, done?: () => void) {
|
|
120
|
+
springValue(el, from, to, (v) => { el.style.width = `${v}px` }, SPRING_STIFFNESS, SPRING_DAMPING, 0, done)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function springValue(
|
|
124
|
+
el: HTMLElement,
|
|
125
|
+
from: number,
|
|
126
|
+
to: number,
|
|
127
|
+
apply: (v: number) => void,
|
|
128
|
+
stiffness: number,
|
|
129
|
+
damping: number,
|
|
130
|
+
initialVelocity: number,
|
|
131
|
+
done?: () => void,
|
|
132
|
+
) {
|
|
112
133
|
const token = (springTokens.get(el) ?? 0) + 1
|
|
113
134
|
springTokens.set(el, token)
|
|
114
135
|
let pos = from
|
|
115
|
-
let vel =
|
|
136
|
+
let vel = initialVelocity
|
|
116
137
|
let last = performance.now()
|
|
117
138
|
const start = last
|
|
118
|
-
|
|
139
|
+
apply(from)
|
|
119
140
|
function finish() {
|
|
120
|
-
|
|
141
|
+
apply(to)
|
|
121
142
|
done?.()
|
|
122
143
|
}
|
|
123
144
|
function tick(now: number) {
|
|
124
145
|
if (springTokens.get(el) !== token) return
|
|
125
146
|
const dt = Math.min((now - last) / 1000, 1 / 30)
|
|
126
147
|
last = now
|
|
127
|
-
const accel = -
|
|
148
|
+
const accel = -stiffness * (pos - to) - 2 * damping * Math.sqrt(stiffness) * vel
|
|
128
149
|
vel += accel * dt
|
|
129
150
|
pos += vel * dt
|
|
130
|
-
|
|
151
|
+
apply(pos)
|
|
131
152
|
// Settled normally, or a safety net in case rAF stalls/throttles badly enough that the
|
|
132
153
|
// spring can't converge in reasonable real time (e.g. a backgrounded tab) — either way
|
|
133
154
|
// the panel must never get stuck mid-animation forever.
|
|
@@ -140,7 +161,97 @@ function springWidth(el: HTMLElement, from: number, to: number, done?: () => voi
|
|
|
140
161
|
requestAnimationFrame(tick)
|
|
141
162
|
}
|
|
142
163
|
|
|
164
|
+
// ── Dismissible panel (hideOnCollapse): slide + swipe ─────────────────────────────────────────
|
|
165
|
+
// The panel's x runs from -width (off-screen) to 0, and the scrim's opacity follows it.
|
|
166
|
+
let panelX = 0
|
|
167
|
+
let releaseVelocity = 0
|
|
168
|
+
|
|
169
|
+
function setSlide(panel: HTMLElement, scrim: HTMLElement | null, x: number) {
|
|
170
|
+
panelX = x
|
|
171
|
+
panel.style.transform = `translateX(${x}px)`
|
|
172
|
+
if (scrim) scrim.style.opacity = String(Math.min(1, Math.max(0, 1 + x / (panel.offsetWidth || PANEL_WIDTH))))
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function slide(el: Element, to: number, done?: () => void) {
|
|
176
|
+
const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
|
|
177
|
+
const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
|
|
178
|
+
if (!panel) return done?.()
|
|
179
|
+
if (scrim) scrim.style.transition = 'none'
|
|
180
|
+
const v = releaseVelocity
|
|
181
|
+
releaseVelocity = 0
|
|
182
|
+
springValue(panel, panelX, to, (x) => setSlide(panel, scrim, x), SLIDE_STIFFNESS, SLIDE_DAMPING, v, done)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// AnchoredDraggableDefaults: settles at the nearer anchor (positionalThreshold 50%) unless released faster
|
|
186
|
+
// than 125dp/s, which goes the way of the fling
|
|
187
|
+
const FLING_VELOCITY = 125
|
|
188
|
+
let drag: { id: number; x: number; y: number; startX: number; active: boolean; samples: { t: number; x: number }[] } | null = null
|
|
189
|
+
let suppressClick = false
|
|
190
|
+
|
|
191
|
+
function onPanelPointerDown(e: PointerEvent) {
|
|
192
|
+
if (!props.hideOnCollapse || e.button !== 0) return
|
|
193
|
+
drag = { id: e.pointerId, x: e.clientX, y: e.clientY, startX: panelX, active: false, samples: [{ t: e.timeStamp, x: e.clientX }] }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function onPanelPointerMove(e: PointerEvent) {
|
|
197
|
+
if (!drag || e.pointerId !== drag.id) return
|
|
198
|
+
const dx = e.clientX - drag.x
|
|
199
|
+
const dy = e.clientY - drag.y
|
|
200
|
+
if (!drag.active) {
|
|
201
|
+
if (Math.abs(dy) > 8 && Math.abs(dy) > Math.abs(dx)) { drag = null; return }
|
|
202
|
+
if (Math.abs(dx) < 8) return
|
|
203
|
+
drag.active = true
|
|
204
|
+
;(e.currentTarget as HTMLElement).setPointerCapture?.(e.pointerId)
|
|
205
|
+
}
|
|
206
|
+
const panel = e.currentTarget as HTMLElement
|
|
207
|
+
springTokens.set(panel, (springTokens.get(panel) ?? 0) + 1) // stop a running slide
|
|
208
|
+
const scrim = panel.parentElement?.querySelector<HTMLElement>('.wnr-scrim') ?? null
|
|
209
|
+
if (scrim) scrim.style.transition = 'none'
|
|
210
|
+
setSlide(panel, scrim, Math.min(0, Math.max(-(panel.offsetWidth || PANEL_WIDTH), drag.startX + dx)))
|
|
211
|
+
drag.samples.push({ t: e.timeStamp, x: e.clientX })
|
|
212
|
+
drag.samples = drag.samples.filter((p) => e.timeStamp - p.t < 100)
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
function onPanelPointerUp(e: PointerEvent) {
|
|
216
|
+
if (!drag || e.pointerId !== drag.id) return
|
|
217
|
+
const wasActive = drag.active
|
|
218
|
+
const first = drag.samples[0]!
|
|
219
|
+
const lastSample = drag.samples[drag.samples.length - 1]!
|
|
220
|
+
const dt = (lastSample.t - first.t) / 1000
|
|
221
|
+
const velocity = dt > 0 ? (lastSample.x - first.x) / dt : 0
|
|
222
|
+
drag = null
|
|
223
|
+
if (!wasActive) return
|
|
224
|
+
suppressClick = true
|
|
225
|
+
setTimeout(() => { suppressClick = false })
|
|
226
|
+
const panel = e.currentTarget as HTMLElement
|
|
227
|
+
const width = panel.offsetWidth || PANEL_WIDTH
|
|
228
|
+
const dismiss = Math.abs(velocity) > FLING_VELOCITY ? velocity < 0 : panelX < -width / 2
|
|
229
|
+
releaseVelocity = velocity
|
|
230
|
+
if (dismiss) close()
|
|
231
|
+
else slide(panel.parentElement!, 0)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// Belt and braces once a swipe has started: the browser must not scroll or navigate with it
|
|
235
|
+
function onPanelTouchMove(e: TouchEvent) {
|
|
236
|
+
if (drag?.active && e.cancelable) e.preventDefault()
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
function onPanelClickCapture(e: MouseEvent) {
|
|
240
|
+
if (!suppressClick) return
|
|
241
|
+
e.preventDefault()
|
|
242
|
+
e.stopPropagation()
|
|
243
|
+
}
|
|
244
|
+
|
|
143
245
|
function onPanelEnter(el: Element, done: () => void) {
|
|
246
|
+
if (props.hideOnCollapse) {
|
|
247
|
+
// Standalone modal: the items are expanded from the start, the panel slides in from off-screen
|
|
248
|
+
panelExpanded.value = true
|
|
249
|
+
const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
|
|
250
|
+
const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
|
|
251
|
+
if (panel) setSlide(panel, scrim, -(panel.offsetWidth || PANEL_WIDTH))
|
|
252
|
+
slide(el, 0, done)
|
|
253
|
+
return
|
|
254
|
+
}
|
|
144
255
|
const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
|
|
145
256
|
const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
|
|
146
257
|
panelExpanded.value = false
|
|
@@ -157,6 +268,11 @@ function onPanelEnter(el: Element, done: () => void) {
|
|
|
157
268
|
else done()
|
|
158
269
|
}
|
|
159
270
|
function onPanelLeave(el: Element, done: () => void) {
|
|
271
|
+
if (props.hideOnCollapse) {
|
|
272
|
+
const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
|
|
273
|
+
slide(el, -(panel?.offsetWidth || PANEL_WIDTH), done)
|
|
274
|
+
return
|
|
275
|
+
}
|
|
160
276
|
const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
|
|
161
277
|
const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
|
|
162
278
|
panelExpanded.value = false
|
|
@@ -193,6 +309,7 @@ onUnmounted(() => {
|
|
|
193
309
|
that actually reacts to `expanded` when `modal` is set.
|
|
194
310
|
-->
|
|
195
311
|
<nav
|
|
312
|
+
v-if="!(modal && hideOnCollapse)"
|
|
196
313
|
v-bind="$attrs"
|
|
197
314
|
class="flex h-full flex-col border-r border-outline-variant bg-surface transition-[width] duration-200"
|
|
198
315
|
:class="railExpanded ? 'w-[220px]' : 'w-20'"
|
|
@@ -341,6 +458,13 @@ onUnmounted(() => {
|
|
|
341
458
|
|
|
342
459
|
<nav
|
|
343
460
|
class="wnr-panel fixed inset-y-0 left-0 z-10 flex flex-col overflow-hidden rounded-r-lg bg-surface-container shadow-elevation-2"
|
|
461
|
+
:class="hideOnCollapse ? 'w-[220px] touch-pan-y' : ''"
|
|
462
|
+
@pointerdown="onPanelPointerDown"
|
|
463
|
+
@pointermove="onPanelPointerMove"
|
|
464
|
+
@pointerup="onPanelPointerUp"
|
|
465
|
+
@pointercancel="onPanelPointerUp"
|
|
466
|
+
@touchmove="onPanelTouchMove"
|
|
467
|
+
@click.capture="onPanelClickCapture"
|
|
344
468
|
>
|
|
345
469
|
<div v-if="$slots.fab" class="flex shrink-0 flex-col items-start gap-2 px-3 pt-3 pb-2">
|
|
346
470
|
<div class="flex min-h-10 min-w-14 shrink-0 items-center justify-center">
|
|
@@ -348,9 +472,12 @@ onUnmounted(() => {
|
|
|
348
472
|
</div>
|
|
349
473
|
</div>
|
|
350
474
|
|
|
475
|
+
<!-- touch-action stops at the nearest scroll container, so this one needs pan-y of its own or a
|
|
476
|
+
finger landing on an item lets the browser take the horizontal swipe -->
|
|
351
477
|
<div
|
|
352
|
-
class="flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-3 py-3"
|
|
478
|
+
class="scrollbar-none flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-3 py-3"
|
|
353
479
|
:class="{
|
|
480
|
+
'touch-pan-y': hideOnCollapse,
|
|
354
481
|
'justify-start': alignment === 'top',
|
|
355
482
|
'justify-center': alignment === 'center',
|
|
356
483
|
'justify-end': alignment === 'bottom',
|
|
@@ -95,13 +95,18 @@ function write() {
|
|
|
95
95
|
let raf = 0
|
|
96
96
|
let last = 0
|
|
97
97
|
let dragging = false
|
|
98
|
+
// The value this wheel itself last emitted: v-model hands it back while the wheel is still moving
|
|
99
|
+
let lastEmitted: number | null = null
|
|
98
100
|
|
|
99
101
|
function setSelected() {
|
|
100
102
|
const page = Math.round(pos)
|
|
101
103
|
if (page === selectedPage.value) return
|
|
102
104
|
selectedPage.value = page
|
|
103
105
|
updatePages()
|
|
104
|
-
if (props.count > 0)
|
|
106
|
+
if (props.count > 0) {
|
|
107
|
+
lastEmitted = mod(page)
|
|
108
|
+
emit('update:modelValue', lastEmitted)
|
|
109
|
+
}
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
function frame(now: number) {
|
|
@@ -164,7 +169,10 @@ watch(selectedPage, (page, prev) => {
|
|
|
164
169
|
|
|
165
170
|
// Outside changes take the short way around the wheel
|
|
166
171
|
watch(() => props.modelValue, (v) => {
|
|
167
|
-
|
|
172
|
+
// Our own value coming back through v-model mid-fling isn't an outside change. Treating it as one
|
|
173
|
+
// retargeted the snap toward an item the wheel had already passed, and on a short wheel (4 items)
|
|
174
|
+
// the shortest-way-around math flipped the target back and forth forever.
|
|
175
|
+
if (props.count <= 0 || v === lastEmitted) return
|
|
168
176
|
const current = target ?? Math.round(pos)
|
|
169
177
|
let d = mod(v) - mod(current)
|
|
170
178
|
if (d > props.count / 2) d -= props.count
|
|
@@ -10,11 +10,12 @@
|
|
|
10
10
|
* @event search Emitted when Enter is pressed in the input, with the current query
|
|
11
11
|
* @event update:expanded Emitted when the expanded state changes — powers v-model:expanded
|
|
12
12
|
*/
|
|
13
|
-
import { computed, ref, watch, onMounted, onUnmounted, nextTick, useId } from 'vue'
|
|
13
|
+
import { computed, inject, ref, watch, onMounted, onUnmounted, nextTick, useId } from 'vue'
|
|
14
14
|
import MIcon from './MIcon.vue'
|
|
15
15
|
import MIconButton from './MIconButton.vue'
|
|
16
16
|
import MSpinner from './MSpinner.vue'
|
|
17
17
|
import { useLocale } from '../composables/useLocale'
|
|
18
|
+
import { searchAppBarKey } from '../composables/_searchAppBar'
|
|
18
19
|
|
|
19
20
|
// Root is a fragment (bar div + a sibling Teleport for the expanded overlay panel), so Vue
|
|
20
21
|
// can't auto-apply a consumer's class/attrs to either one — forward them onto the bar div below.
|
|
@@ -30,8 +31,10 @@ const props = withDefaults(
|
|
|
30
31
|
placeholder?: string
|
|
31
32
|
/** 'docked' grows into a rounded panel anchored below the bar (default).
|
|
32
33
|
* 'fullscreen' takes over the whole viewport, matching M3's mobile
|
|
33
|
-
* search pattern — the leading icon becomes a back button either way.
|
|
34
|
-
|
|
34
|
+
* search pattern — the leading icon becomes a back button either way.
|
|
35
|
+
* 'fullscreen-contained' (M3 Expressive's ExpandedFullScreenContainedSearchBar) also takes the whole
|
|
36
|
+
* viewport, on surface-container-low, but keeps the input in its pill shape, with no divider. */
|
|
37
|
+
variant?: 'docked' | 'fullscreen' | 'fullscreen-contained'
|
|
35
38
|
/** Icon shown in the collapsed bar */
|
|
36
39
|
leadingIcon?: string
|
|
37
40
|
/** Which side of the *collapsed* bar the leading icon sits on. The
|
|
@@ -68,6 +71,10 @@ const emit = defineEmits<{
|
|
|
68
71
|
|
|
69
72
|
const locale = useLocale()
|
|
70
73
|
const id = useId()
|
|
74
|
+
const fullscreen = computed(() => props.variant !== 'docked')
|
|
75
|
+
const contained = computed(() => props.variant === 'fullscreen-contained')
|
|
76
|
+
// Inside an MAppBarWithSearch the bar is flat and darkens when content scrolls under the app bar
|
|
77
|
+
const appBar = inject(searchAppBarKey, null)
|
|
71
78
|
|
|
72
79
|
const expanded = ref(props.expanded ?? false)
|
|
73
80
|
watch(
|
|
@@ -140,7 +147,7 @@ onUnmounted(() => {
|
|
|
140
147
|
})
|
|
141
148
|
|
|
142
149
|
watch(expanded, (v) => {
|
|
143
|
-
if (v &&
|
|
150
|
+
if (v && fullscreen.value) document.body.style.overflow = 'hidden'
|
|
144
151
|
else document.body.style.overflow = ''
|
|
145
152
|
})
|
|
146
153
|
onUnmounted(() => { document.body.style.overflow = '' })
|
|
@@ -150,8 +157,12 @@ onUnmounted(() => { document.body.style.overflow = '' })
|
|
|
150
157
|
<div ref="barEl" class="relative w-full" v-bind="$attrs">
|
|
151
158
|
<div
|
|
152
159
|
v-show="!expanded"
|
|
153
|
-
class="flex h-14 items-center gap-3 rounded-full
|
|
154
|
-
:class="
|
|
160
|
+
class="flex h-14 items-center gap-3 rounded-full px-4 transition-[box-shadow,background-color] duration-150 focus-within:outline focus-within:outline-2 focus-within:outline-secondary focus-within:-outline-offset-2"
|
|
161
|
+
:class="[
|
|
162
|
+
disabled ? 'pointer-events-none opacity-[0.38]' : '',
|
|
163
|
+
appBar?.scrolled.value ? 'bg-surface-container-highest' : 'bg-surface-container-high',
|
|
164
|
+
appBar ? '' : 'shadow-elevation-3',
|
|
165
|
+
]"
|
|
155
166
|
>
|
|
156
167
|
<span class="inline-flex shrink-0 items-center" :class="iconPosition === 'end' ? 'order-last' : ''">
|
|
157
168
|
<slot name="leading">
|
|
@@ -185,17 +196,22 @@ onUnmounted(() => { document.body.style.overflow = '' })
|
|
|
185
196
|
</div>
|
|
186
197
|
|
|
187
198
|
<Teleport to="body">
|
|
188
|
-
<Transition :name="
|
|
199
|
+
<Transition :name="fullscreen ? 'm3-searchbar-full' : 'm3-searchbar-docked'">
|
|
189
200
|
<div
|
|
190
201
|
v-if="expanded"
|
|
191
202
|
ref="panelEl"
|
|
192
|
-
class="fixed z-500 flex flex-col overflow-hidden
|
|
193
|
-
:class="
|
|
203
|
+
class="fixed z-500 flex flex-col overflow-hidden"
|
|
204
|
+
:class="[
|
|
205
|
+
fullscreen ? 'inset-0' : 'max-h-[70vh] rounded-[28px] shadow-elevation-3',
|
|
206
|
+
contained ? 'bg-surface-container-low' : 'bg-surface-container-high',
|
|
207
|
+
]"
|
|
194
208
|
:style="variant === 'docked' ? panelPos : undefined"
|
|
195
209
|
>
|
|
210
|
+
<!-- Contained: the input keeps the collapsed pill (collapsedContainedSearchBarColor), 8dp from the
|
|
211
|
+
sides, 4dp from the top and 8dp above the results (FullScreenSearchBarLayout's isContained) -->
|
|
196
212
|
<div
|
|
197
|
-
class="flex shrink-0 items-center gap-3
|
|
198
|
-
:class="variant === 'fullscreen' ? 'h-[72px]' : 'h-14'"
|
|
213
|
+
class="flex shrink-0 items-center gap-3"
|
|
214
|
+
:class="contained ? 'mx-2 mt-1 mb-2 h-14 rounded-full bg-surface-container-high px-1' : variant === 'fullscreen' ? 'h-[72px] px-4' : 'h-14 px-4'"
|
|
199
215
|
>
|
|
200
216
|
<MIconButton
|
|
201
217
|
icon="arrow_back"
|
|
@@ -227,7 +243,7 @@ onUnmounted(() => { document.body.style.overflow = '' })
|
|
|
227
243
|
<slot name="trailing" />
|
|
228
244
|
</div>
|
|
229
245
|
|
|
230
|
-
<div class="h-px shrink-0 bg-outline" />
|
|
246
|
+
<div v-if="!contained" class="h-px shrink-0 bg-outline" />
|
|
231
247
|
|
|
232
248
|
<div class="flex-1 overflow-y-auto">
|
|
233
249
|
<slot />
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
10
10
|
import MIcon from './MIcon.vue'
|
|
11
|
+
import { vRipple } from '../directives/vRipple'
|
|
11
12
|
|
|
12
13
|
export interface SplitButtonItem {
|
|
13
14
|
label: string
|
|
@@ -33,6 +34,8 @@ const props = withDefaults(defineProps<{
|
|
|
33
34
|
disabled?: boolean
|
|
34
35
|
/** Dropdown menu items; see `SplitButtonItem` */
|
|
35
36
|
items?: SplitButtonItem[]
|
|
37
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
38
|
+
rippleColor?: string
|
|
36
39
|
}>(), {
|
|
37
40
|
variant: 'tonal',
|
|
38
41
|
color: 'primary',
|
|
@@ -134,16 +137,6 @@ function toggleMenu() {
|
|
|
134
137
|
open.value = !open.value
|
|
135
138
|
}
|
|
136
139
|
|
|
137
|
-
function createRipple(event: PointerEvent) {
|
|
138
|
-
const button = event.currentTarget as HTMLElement
|
|
139
|
-
const rect = button.getBoundingClientRect()
|
|
140
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
141
|
-
const el = document.createElement('span')
|
|
142
|
-
el.className = 'm3-ripple'
|
|
143
|
-
el.style.cssText = `width:${d}px;height:${d}px;top:${event.clientY - rect.top - d / 2}px;left:${event.clientX - rect.left - d / 2}px`
|
|
144
|
-
button.appendChild(el)
|
|
145
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
146
|
-
}
|
|
147
140
|
|
|
148
141
|
function selectItem(item: SplitButtonItem) {
|
|
149
142
|
if (item.disabled) return
|
|
@@ -187,7 +180,7 @@ onUnmounted(() => {
|
|
|
187
180
|
]"
|
|
188
181
|
:style="{ borderRadius: `${sizeConfig.r}px ${sizeConfig.ri}px ${sizeConfig.ri}px ${sizeConfig.r}px` }"
|
|
189
182
|
:disabled="disabled"
|
|
190
|
-
|
|
183
|
+
v-ripple="rippleColor"
|
|
191
184
|
@click="emit('click', $event)"
|
|
192
185
|
>
|
|
193
186
|
<MIcon v-if="icon" :name="icon" :size="sizeConfig.icon" />
|
|
@@ -205,7 +198,7 @@ onUnmounted(() => {
|
|
|
205
198
|
]"
|
|
206
199
|
:style="{ borderRadius: open ? `${sizeConfig.r}px` : `${sizeConfig.ri}px ${sizeConfig.r}px ${sizeConfig.r}px ${sizeConfig.ri}px` }"
|
|
207
200
|
:disabled="disabled"
|
|
208
|
-
|
|
201
|
+
v-ripple="rippleColor"
|
|
209
202
|
@click="toggleMenu"
|
|
210
203
|
>
|
|
211
204
|
<MIcon
|
package/src/components/MTabs.vue
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @event update:modelValue Emitted with the value of the tab you picked.
|
|
7
7
|
*/
|
|
8
|
-
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
8
|
+
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
10
|
|
|
11
11
|
interface Tab {
|
|
@@ -27,8 +27,16 @@ const props = withDefaults(defineProps<{
|
|
|
27
27
|
variant?: 'primary' | 'secondary'
|
|
28
28
|
/** Fixed (default, M3 `TabRow`): tabs evenly share the available width, no scrolling — use for 2-5 tabs. Scrollable (M3 `ScrollableTabRow`): tabs keep their natural width and the row scrolls horizontally when they overflow — use for many tabs. */
|
|
29
29
|
scrollable?: boolean
|
|
30
|
+
/**
|
|
31
|
+
* Where a tab's icon goes: `top`, stacked above the label in a 64px tab (Compose's `Tab`), or `leading`,
|
|
32
|
+
* beside the label in a 48px tab (Compose's `LeadingIconTab`). Defaults to `top` for primary tabs and
|
|
33
|
+
* `leading` for secondary ones.
|
|
34
|
+
*/
|
|
35
|
+
iconPosition?: 'top' | 'leading'
|
|
30
36
|
}>(), { variant: 'primary', scrollable: false })
|
|
31
37
|
|
|
38
|
+
const leading = computed(() => (props.iconPosition ?? (props.variant === 'primary' ? 'top' : 'leading')) === 'leading')
|
|
39
|
+
|
|
32
40
|
const emit = defineEmits<{ 'update:modelValue': [string | number] }>()
|
|
33
41
|
|
|
34
42
|
const tabEls = ref<HTMLElement[]>([])
|
|
@@ -125,6 +133,7 @@ watch(() => props.modelValue, () => updateIndicator(true))
|
|
|
125
133
|
// modelValue-triggered animation. Re-running the same animated update is a
|
|
126
134
|
// no-op when the target hasn't actually moved, so this is safe either way.
|
|
127
135
|
watch(() => props.tabs, () => updateIndicator(true), { deep: true })
|
|
136
|
+
watch(leading, () => updateIndicator(true))
|
|
128
137
|
|
|
129
138
|
function select(tab: Tab) {
|
|
130
139
|
if (!tab.disabled) emit('update:modelValue', tab.value)
|
|
@@ -140,10 +149,11 @@ function select(tab: Tab) {
|
|
|
140
149
|
:key="tab.value"
|
|
141
150
|
:ref="(el) => { if (el) tabEls[tabs.indexOf(tab)] = el as HTMLElement }"
|
|
142
151
|
type="button"
|
|
143
|
-
class="relative flex
|
|
152
|
+
class="relative flex items-center justify-center pb-1.5 text-title-small transition-colors duration-150 focus-visible:outline-none"
|
|
144
153
|
:class="[
|
|
145
154
|
scrollable ? 'shrink-0' : 'flex-1 min-w-0',
|
|
146
|
-
|
|
155
|
+
// LeadingIconTab: 48dp row, 16dp side padding, 8dp from the icon to the label
|
|
156
|
+
leading ? 'h-12 flex-row gap-2 px-4' : ['flex-col gap-1 px-6', tab.icon ? 'h-16' : 'h-12'],
|
|
147
157
|
tab.value === modelValue
|
|
148
158
|
? 'text-primary'
|
|
149
159
|
: tab.disabled
|
|
@@ -171,9 +181,10 @@ function select(tab: Tab) {
|
|
|
171
181
|
:key="tab.value"
|
|
172
182
|
:ref="(el) => { if (el) tabEls[tabs.indexOf(tab)] = el as HTMLElement }"
|
|
173
183
|
type="button"
|
|
174
|
-
class="relative flex
|
|
184
|
+
class="relative flex items-center justify-center text-title-small transition-colors duration-150 focus-visible:outline-none"
|
|
175
185
|
:class="[
|
|
176
186
|
scrollable ? 'shrink-0' : 'flex-1 min-w-0',
|
|
187
|
+
leading ? 'h-12 flex-row gap-2 px-4' : ['flex-col gap-1 px-6', tab.icon ? 'h-16' : 'h-12'],
|
|
177
188
|
tab.value === modelValue
|
|
178
189
|
? 'text-on-surface'
|
|
179
190
|
: tab.disabled
|
|
@@ -184,7 +195,7 @@ function select(tab: Tab) {
|
|
|
184
195
|
@click="select(tab)"
|
|
185
196
|
>
|
|
186
197
|
<MIcon v-if="tab.icon" :name="tab.icon" :size="24" />
|
|
187
|
-
{{ tab.label }}
|
|
198
|
+
<span>{{ tab.label }}</span>
|
|
188
199
|
</button>
|
|
189
200
|
<div
|
|
190
201
|
class="absolute bottom-0 h-[3px] bg-primary"
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
* A modal, centered time picker with a clock dial
|
|
4
|
-
* format — the sibling of MTimePicker, a
|
|
3
|
+
* A modal, centered time picker with a clock dial (or, with `mode="scroll"`, M3 Expressive's scroll wheels from
|
|
4
|
+
* MTimeScroll) and a keyboard input mode. Supports AM/PM toggle and 24h format — the sibling of MTimePicker, a
|
|
5
|
+
* fully separate component rather than a shared internal.
|
|
5
6
|
*
|
|
6
7
|
* @event update:modelValue Emitted when a time is confirmed — powers v-model
|
|
7
8
|
* @event update:show Emitted when the dialog opens or closes — powers v-model:show
|
|
@@ -9,6 +10,7 @@
|
|
|
9
10
|
import { computed, ref, watch } from 'vue'
|
|
10
11
|
import MButton from './MButton.vue'
|
|
11
12
|
import MIconButton from './MIconButton.vue'
|
|
13
|
+
import MTimeScroll from './MTimeScroll.vue'
|
|
12
14
|
import { useLocale } from '../composables/useLocale'
|
|
13
15
|
|
|
14
16
|
const props = withDefaults(defineProps<{
|
|
@@ -22,11 +24,14 @@ const props = withDefaults(defineProps<{
|
|
|
22
24
|
minuteStep?: number
|
|
23
25
|
/** Dialog title */
|
|
24
26
|
title?: string
|
|
27
|
+
/** How the time is picked before switching to keyboard input: a clock `dial`, or `scroll` wheels (MTimeScroll) */
|
|
28
|
+
mode?: 'dial' | 'scroll'
|
|
25
29
|
}>(), {
|
|
26
30
|
modelValue: null,
|
|
27
31
|
show: false,
|
|
28
32
|
use24h: false,
|
|
29
33
|
minuteStep: 5,
|
|
34
|
+
mode: 'dial',
|
|
30
35
|
})
|
|
31
36
|
|
|
32
37
|
const locale = useLocale()
|
|
@@ -36,7 +41,7 @@ const emit = defineEmits<{
|
|
|
36
41
|
}>()
|
|
37
42
|
|
|
38
43
|
const step = ref<'hour' | 'minute'>('hour')
|
|
39
|
-
const inputMode = ref<'dial' | 'input'>('dial')
|
|
44
|
+
const inputMode = ref<'dial' | 'scroll' | 'input'>('dial')
|
|
40
45
|
const period = ref<'AM' | 'PM'>('AM')
|
|
41
46
|
const selectedHour = ref(12)
|
|
42
47
|
const selectedMinute = ref(0)
|
|
@@ -61,9 +66,10 @@ watch(() => props.show, (open) => {
|
|
|
61
66
|
period.value = h >= 12 ? 'PM' : 'AM'
|
|
62
67
|
selectedHour.value = h % 12 || 12
|
|
63
68
|
}
|
|
64
|
-
|
|
69
|
+
// The minute wheel only has multiples of minuteStep: start on the one it shows
|
|
70
|
+
selectedMinute.value = props.mode === 'scroll' ? Math.floor(m / props.minuteStep) * props.minuteStep : m
|
|
65
71
|
step.value = 'hour'
|
|
66
|
-
inputMode.value =
|
|
72
|
+
inputMode.value = props.mode
|
|
67
73
|
document.addEventListener('keydown', onKeydown)
|
|
68
74
|
document.body.style.overflow = 'hidden'
|
|
69
75
|
} else {
|
|
@@ -199,6 +205,35 @@ function selectHour(h: number) {
|
|
|
199
205
|
step.value = 'minute'
|
|
200
206
|
}
|
|
201
207
|
|
|
208
|
+
// ── Scroll mode ────────────────────────────────────────────────────
|
|
209
|
+
// MTimeScroll speaks 24-hour HH:MM; the dialog keeps a 1–12 hour plus period in 12-hour mode
|
|
210
|
+
const scrollTime = computed({
|
|
211
|
+
get() {
|
|
212
|
+
let h = selectedHour.value
|
|
213
|
+
if (!props.use24h) h = (h % 12) + (period.value === 'PM' ? 12 : 0)
|
|
214
|
+
return `${pad(h)}:${pad(selectedMinute.value)}`
|
|
215
|
+
},
|
|
216
|
+
set(t: string) {
|
|
217
|
+
const { h, m } = parseTime(t)
|
|
218
|
+
if (props.use24h) {
|
|
219
|
+
selectedHour.value = h
|
|
220
|
+
} else {
|
|
221
|
+
period.value = h >= 12 ? 'PM' : 'AM'
|
|
222
|
+
selectedHour.value = h % 12 || 12
|
|
223
|
+
}
|
|
224
|
+
selectedMinute.value = m
|
|
225
|
+
},
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const toggleIcon = computed(() =>
|
|
229
|
+
inputMode.value !== 'input' ? 'keyboard' : props.mode === 'scroll' ? 'swipe_vertical' : 'schedule',
|
|
230
|
+
)
|
|
231
|
+
const toggleLabel = computed(() =>
|
|
232
|
+
inputMode.value !== 'input'
|
|
233
|
+
? locale.timeToggleKeyboard
|
|
234
|
+
: props.mode === 'scroll' ? locale.timeToggleScroll : locale.timeToggleDial,
|
|
235
|
+
)
|
|
236
|
+
|
|
202
237
|
// ── Input mode ─────────────────────────────────────────────────────
|
|
203
238
|
const inputHour = ref('')
|
|
204
239
|
const inputMinute = ref('')
|
|
@@ -384,6 +419,11 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
384
419
|
</div>
|
|
385
420
|
</template>
|
|
386
421
|
|
|
422
|
+
<!-- ── Scroll mode ─────────────────────────────────── -->
|
|
423
|
+
<div v-else-if="inputMode === 'scroll'" class="flex justify-center pb-4">
|
|
424
|
+
<MTimeScroll v-model="scrollTime" :use24h="use24h" :minute-step="minuteStep" />
|
|
425
|
+
</div>
|
|
426
|
+
|
|
387
427
|
<!-- ── Input mode ──────────────────────────────────── -->
|
|
388
428
|
<div v-else class="mx-auto flex items-center justify-center gap-2 py-8">
|
|
389
429
|
<input
|
|
@@ -435,9 +475,9 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
435
475
|
<!-- Footer -->
|
|
436
476
|
<div class="mt-2 flex items-center justify-between">
|
|
437
477
|
<MIconButton
|
|
438
|
-
:icon="
|
|
439
|
-
:label="
|
|
440
|
-
@click="inputMode = inputMode === '
|
|
478
|
+
:icon="toggleIcon"
|
|
479
|
+
:label="toggleLabel"
|
|
480
|
+
@click="inputMode = inputMode === 'input' ? mode : 'input'"
|
|
441
481
|
/>
|
|
442
482
|
<div class="flex gap-2">
|
|
443
483
|
<MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
|