@m3ui-vue/m3ui-vue 0.9.3 → 1.0.1

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 (97) hide show
  1. package/README.md +24 -29
  2. package/dist/API.md +179 -19
  3. package/dist/{MTextField-DKtgPymd.js → MTextField-BPbFeI9M.js} +305 -177
  4. package/dist/MTextField-BPbFeI9M.js.map +1 -0
  5. package/dist/api.json +1 -1
  6. package/dist/code-editor.js +1 -1
  7. package/dist/components/MAppBarWithSearch.vue.d.ts +70 -0
  8. package/dist/components/MBottomAppBar.vue.d.ts +37 -0
  9. package/dist/components/MBottomSheetScaffold.vue.d.ts +40 -0
  10. package/dist/components/MChatBubble.vue.d.ts +1 -1
  11. package/dist/components/MChip.vue.d.ts +19 -2
  12. package/dist/components/MContainer.vue.d.ts +1 -1
  13. package/dist/components/MDataTable.vue.d.ts +1 -1
  14. package/dist/components/MDialog.vue.d.ts +1 -1
  15. package/dist/components/MFab.vue.d.ts +13 -4
  16. package/dist/components/MListItem.vue.d.ts +2 -2
  17. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  18. package/dist/components/MNavigationDrawer.vue.d.ts +9 -6
  19. package/dist/components/MNavigationRail.vue.d.ts +6 -0
  20. package/dist/components/MSearchBar.vue.d.ts +5 -3
  21. package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
  22. package/dist/components/MTable.vue.d.ts +1 -1
  23. package/dist/components/MTopAppBar.vue.d.ts +33 -2
  24. package/dist/components/MTransition.vue.d.ts +0 -9
  25. package/dist/composables/_searchAppBar.d.ts +6 -0
  26. package/dist/composables/_springAnimation.d.ts +17 -0
  27. package/dist/composables/_themeTransition.d.ts +2 -0
  28. package/dist/composables/_useSpring.d.ts +3 -5
  29. package/dist/composables/motion.d.ts +101 -0
  30. package/dist/composables/useColorPalette.d.ts +10 -0
  31. package/dist/composables/useLocale.d.ts +3 -0
  32. package/dist/index.d.ts +8 -1
  33. package/dist/locales/index.js +21 -0
  34. package/dist/locales/index.js.map +1 -1
  35. package/dist/m3ui-vue.css +1 -1
  36. package/dist/m3ui.js +7345 -6317
  37. package/dist/m3ui.js.map +1 -1
  38. package/dist/plugin.d.ts +7 -0
  39. package/dist/rich-text-editor.js +2 -2
  40. package/dist/styles/palettes-contrast.css +7764 -0
  41. package/dist/styles/theme.css +46 -2
  42. package/dist/styles.css +1 -1
  43. package/dist/{useLocale-Cn9MVIdw.js → useLocale-CuvWRZ1h.js} +4 -1
  44. package/dist/useLocale-CuvWRZ1h.js.map +1 -0
  45. package/package.json +3 -1
  46. package/src/__tests__/MAppBarWithSearch.test.ts +108 -0
  47. package/src/__tests__/MBottomAppBar.test.ts +71 -0
  48. package/src/__tests__/MBottomSheetScaffold.test.ts +122 -0
  49. package/src/__tests__/MChip.test.ts +63 -0
  50. package/src/__tests__/MFab.test.ts +36 -0
  51. package/src/__tests__/MNavigationDrawer.test.ts +185 -0
  52. package/src/__tests__/MNavigationRail.test.ts +93 -0
  53. package/src/__tests__/MPullToRefresh.test.ts +18 -1
  54. package/src/__tests__/MTopAppBar.test.ts +99 -0
  55. package/src/__tests__/MTransition.test.ts +12 -0
  56. package/src/__tests__/contrast.test.ts +64 -0
  57. package/src/__tests__/dynamicColor.test.ts +17 -0
  58. package/src/__tests__/motion.test.ts +37 -0
  59. package/src/__tests__/sheets.test.ts +19 -15
  60. package/src/__tests__/themeTransition.test.ts +119 -0
  61. package/src/components/MAppBarWithSearch.vue +236 -0
  62. package/src/components/MBottomAppBar.vue +181 -0
  63. package/src/components/MBottomSheetScaffold.vue +317 -0
  64. package/src/components/MBreadcrumbs.vue +1 -1
  65. package/src/components/MChip.vue +137 -5
  66. package/src/components/MContextMenu.vue +34 -33
  67. package/src/components/MFab.vue +73 -12
  68. package/src/components/MMenu.vue +34 -33
  69. package/src/components/MNavigationDrawer.vue +298 -38
  70. package/src/components/MNavigationRail.vue +189 -8
  71. package/src/components/MPullToRefresh.vue +18 -0
  72. package/src/components/MSearchBar.vue +29 -12
  73. package/src/components/MTopAppBar.vue +252 -28
  74. package/src/components/MTransition.vue +36 -41
  75. package/src/composables/_searchAppBar.ts +9 -0
  76. package/src/composables/_springAnimation.ts +74 -0
  77. package/src/composables/_themeColor.ts +11 -4
  78. package/src/composables/_themeTransition.ts +71 -0
  79. package/src/composables/_useSheetMotion.ts +101 -88
  80. package/src/composables/_useSpring.ts +11 -21
  81. package/src/composables/motion.ts +73 -0
  82. package/src/composables/useColorPalette.ts +103 -20
  83. package/src/composables/useLocale.ts +6 -0
  84. package/src/composables/useTheme.ts +4 -12
  85. package/src/index.ts +8 -1
  86. package/src/locales/de.ts +3 -0
  87. package/src/locales/es.ts +3 -0
  88. package/src/locales/fr.ts +3 -0
  89. package/src/locales/ja.ts +3 -0
  90. package/src/locales/ko.ts +3 -0
  91. package/src/locales/pt.ts +3 -0
  92. package/src/locales/zh.ts +3 -0
  93. package/src/plugin.ts +9 -1
  94. package/src/styles/palettes-contrast.css +7764 -0
  95. package/src/styles/theme.css +46 -2
  96. package/dist/MTextField-DKtgPymd.js.map +0 -1
  97. package/dist/useLocale-Cn9MVIdw.js.map +0 -1
@@ -6,12 +6,13 @@
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'
13
13
  import MBadge from './MBadge.vue'
14
14
  import { useItemLink, type ItemLink } from '../composables/_useItemLink'
15
+ import { sampleSpring, sampleAt, playSamples, prefersReducedMotion } from '../composables/_springAnimation'
15
16
 
16
17
  export interface NavRailItem {
17
18
  value: string | number
@@ -49,7 +50,12 @@ const props = withDefaults(defineProps<{
49
50
  // affects the app's layout grid — `ModalWideNavigationRail`'s whole point) and `expanded`
50
51
  // instead opens a Teleported, scrim-backed panel that floats above the rest of the app.
51
52
  modal?: boolean
52
- }>(), { alignment: 'top', expanded: false, modal: false })
53
+ /**
54
+ * With `modal`: no collapsed rail on screen; the expanded rail slides in from off-screen and can be swiped
55
+ * away (Compose's `hideOnCollapse`). Open it from your own menu button
56
+ */
57
+ hideOnCollapse?: boolean
58
+ }>(), { alignment: 'top', expanded: false, modal: false, hideOnCollapse: false })
53
59
 
54
60
  const emit = defineEmits<{
55
61
  'update:modelValue': [string | number]
@@ -101,6 +107,9 @@ function onKeydown(e: KeyboardEvent) {
101
107
  const PANEL_WIDTH = 220
102
108
  const SPRING_DAMPING = 0.9
103
109
  const SPRING_STIFFNESS = 1400
110
+ // The dismissible (hideOnCollapse) panel slides instead: ModalWideNavigationRailState's DefaultSpatial
111
+ const SLIDE_DAMPING = 0.9
112
+ const SLIDE_STIFFNESS = 700
104
113
 
105
114
  // Guards against two overlapping spring loops fighting over the same element's
106
115
  // `style.width` (e.g. a close fired before a still-running open settles) — each call gets
@@ -109,25 +118,38 @@ const SPRING_STIFFNESS = 1400
109
118
  const springTokens = new WeakMap<HTMLElement, number>()
110
119
 
111
120
  function springWidth(el: HTMLElement, from: number, to: number, done?: () => void) {
121
+ springValue(el, from, to, (v) => { el.style.width = `${v}px` }, SPRING_STIFFNESS, SPRING_DAMPING, 0, done)
122
+ }
123
+
124
+ function springValue(
125
+ el: HTMLElement,
126
+ from: number,
127
+ to: number,
128
+ apply: (v: number) => void,
129
+ stiffness: number,
130
+ damping: number,
131
+ initialVelocity: number,
132
+ done?: () => void,
133
+ ) {
112
134
  const token = (springTokens.get(el) ?? 0) + 1
113
135
  springTokens.set(el, token)
114
136
  let pos = from
115
- let vel = 0
137
+ let vel = initialVelocity
116
138
  let last = performance.now()
117
139
  const start = last
118
- el.style.width = `${from}px`
140
+ apply(from)
119
141
  function finish() {
120
- el.style.width = `${to}px`
142
+ apply(to)
121
143
  done?.()
122
144
  }
123
145
  function tick(now: number) {
124
146
  if (springTokens.get(el) !== token) return
125
147
  const dt = Math.min((now - last) / 1000, 1 / 30)
126
148
  last = now
127
- const accel = -SPRING_STIFFNESS * (pos - to) - 2 * SPRING_DAMPING * Math.sqrt(SPRING_STIFFNESS) * vel
149
+ const accel = -stiffness * (pos - to) - 2 * damping * Math.sqrt(stiffness) * vel
128
150
  vel += accel * dt
129
151
  pos += vel * dt
130
- el.style.width = `${pos}px`
152
+ apply(pos)
131
153
  // Settled normally, or a safety net in case rAF stalls/throttles badly enough that the
132
154
  // spring can't converge in reasonable real time (e.g. a backgrounded tab) — either way
133
155
  // the panel must never get stuck mid-animation forever.
@@ -140,7 +162,149 @@ function springWidth(el: HTMLElement, from: number, to: number, done?: () => voi
140
162
  requestAnimationFrame(tick)
141
163
  }
142
164
 
165
+ // ── Dismissible panel (hideOnCollapse): slide + swipe ─────────────────────────────────────────
166
+ // The panel's x runs from -1 (off-screen, a fraction of its width) to 0, and the scrim's opacity follows it.
167
+ // Slides play as Web Animations (see _springAnimation.ts), on the compositor, so the open isn't janked by the
168
+ // panel mounting at the same moment; only the drag writes the transform directly.
169
+ let panelX = 0
170
+ let releaseVelocity = 0
171
+ let slideAnim: Animation | null = null
172
+ let slideScrimAnim: Animation | null = null
173
+ let slideSamples: number[] = []
174
+ let slidePanel: HTMLElement | null = null
175
+ let slideScrim: HTMLElement | null = null
176
+ let slideDone: (() => void) | null = null
177
+
178
+ function setSlide(panel: HTMLElement, scrim: HTMLElement | null, x: number) {
179
+ panelX = x
180
+ panel.style.transform = `translateX(${x * 100}%)`
181
+ if (scrim) scrim.style.opacity = String(Math.min(1, Math.max(0, 1 + x)))
182
+ }
183
+
184
+ // Freezes the panel where the running slide has it
185
+ function stopSlide() {
186
+ if (!slideAnim) return
187
+ if (slidePanel) setSlide(slidePanel, slideScrim, sampleAt(slideSamples, slideAnim.currentTime))
188
+ slideAnim.cancel()
189
+ slideScrimAnim?.cancel()
190
+ slideAnim = slideScrimAnim = null
191
+ }
192
+
193
+ function finishSlide() {
194
+ const cb = slideDone
195
+ slideDone = null
196
+ cb?.()
197
+ }
198
+
199
+ // Without `done`, a pending Transition callback (an enter interrupted by a swipe) is kept for this slide
200
+ function slide(el: Element, to: number, done?: () => void) {
201
+ const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
202
+ const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
203
+ if (done) {
204
+ finishSlide()
205
+ slideDone = done
206
+ }
207
+ if (!panel) return finishSlide()
208
+ if (scrim) scrim.style.transition = 'none'
209
+ stopSlide()
210
+ const from = panelX
211
+ const v = releaseVelocity
212
+ releaseVelocity = 0
213
+ // The end state goes inline underneath, so nothing jumps when the animation ends
214
+ setSlide(panel, scrim, to)
215
+ if (prefersReducedMotion() || from === to) return finishSlide()
216
+ slideSamples = sampleSpring(from, to, v, { dampingRatio: SLIDE_DAMPING, stiffness: SLIDE_STIFFNESS }, 0.001)
217
+ const a = playSamples(panel, slideSamples, (x) => ({ transform: `translateX(${x * 100}%)` }))
218
+ if (!a) return finishSlide()
219
+ slideScrimAnim = playSamples(scrim, slideSamples, (x) => ({ opacity: String(Math.min(1, Math.max(0, 1 + x))) }))
220
+ slideAnim = a
221
+ slidePanel = panel
222
+ slideScrim = scrim
223
+ a.onfinish = () => {
224
+ if (slideAnim !== a) return
225
+ slideAnim = slideScrimAnim = null
226
+ finishSlide()
227
+ }
228
+ }
229
+
230
+ // AnchoredDraggableDefaults: settles at the nearer anchor (positionalThreshold 50%) unless released faster
231
+ // than 125dp/s, which goes the way of the fling
232
+ const FLING_VELOCITY = 125
233
+ let drag: { id: number; x: number; y: number; startX: number; width: number; active: boolean; samples: { t: number; x: number }[] } | null = null
234
+ let suppressClick = false
235
+
236
+ function onPanelPointerDown(e: PointerEvent) {
237
+ if (!props.hideOnCollapse || e.button !== 0) return
238
+ drag = { id: e.pointerId, x: e.clientX, y: e.clientY, startX: 0, width: 1, active: false, samples: [{ t: e.timeStamp, x: e.clientX }] }
239
+ }
240
+
241
+ function onPanelPointerMove(e: PointerEvent) {
242
+ if (!drag || e.pointerId !== drag.id) return
243
+ const dx = e.clientX - drag.x
244
+ const dy = e.clientY - drag.y
245
+ if (!drag.active) {
246
+ if (Math.abs(dy) > 8 && Math.abs(dy) > Math.abs(dx)) { drag = null; return }
247
+ if (Math.abs(dx) < 8) return
248
+ drag.active = true
249
+ ;(e.currentTarget as HTMLElement).setPointerCapture?.(e.pointerId)
250
+ // Stop a running slide; the finger owns the panel from where it is
251
+ stopSlide()
252
+ drag.startX = panelX
253
+ drag.width = (e.currentTarget as HTMLElement).offsetWidth || PANEL_WIDTH
254
+ }
255
+ const panel = e.currentTarget as HTMLElement
256
+ const scrim = panel.parentElement?.querySelector<HTMLElement>('.wnr-scrim') ?? null
257
+ if (scrim) scrim.style.transition = 'none'
258
+ setSlide(panel, scrim, Math.min(0, Math.max(-1, drag.startX + dx / drag.width)))
259
+ drag.samples.push({ t: e.timeStamp, x: e.clientX })
260
+ drag.samples = drag.samples.filter((p) => e.timeStamp - p.t < 100)
261
+ }
262
+
263
+ function onPanelPointerUp(e: PointerEvent) {
264
+ if (!drag || e.pointerId !== drag.id) return
265
+ const wasActive = drag.active
266
+ const first = drag.samples[0]!
267
+ const lastSample = drag.samples[drag.samples.length - 1]!
268
+ const dt = (lastSample.t - first.t) / 1000
269
+ const velocity = dt > 0 ? (lastSample.x - first.x) / dt : 0
270
+ const width = drag.width
271
+ drag = null
272
+ if (!wasActive) return
273
+ suppressClick = true
274
+ setTimeout(() => { suppressClick = false })
275
+ const panel = e.currentTarget as HTMLElement
276
+ const dismiss = Math.abs(velocity) > FLING_VELOCITY ? velocity < 0 : panelX < -0.5
277
+ releaseVelocity = velocity / width
278
+ if (dismiss) close()
279
+ else slide(panel.parentElement!, 0)
280
+ }
281
+
282
+ // Belt and braces once a swipe has started: the browser must not scroll or navigate with it
283
+ function onPanelTouchMove(e: TouchEvent) {
284
+ if (drag?.active && e.cancelable) e.preventDefault()
285
+ }
286
+
287
+ function onPanelClickCapture(e: MouseEvent) {
288
+ if (!suppressClick) return
289
+ e.preventDefault()
290
+ e.stopPropagation()
291
+ }
292
+
143
293
  function onPanelEnter(el: Element, done: () => void) {
294
+ if (props.hideOnCollapse) {
295
+ // Standalone modal: the items are expanded from the start, the panel slides in from off-screen
296
+ panelExpanded.value = true
297
+ // Reopened mid-close: the old panel goes now
298
+ finishSlide()
299
+ slideAnim?.cancel()
300
+ slideScrimAnim?.cancel()
301
+ slideAnim = slideScrimAnim = null
302
+ const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
303
+ const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
304
+ if (panel) setSlide(panel, scrim, -1)
305
+ slide(el, 0, done)
306
+ return
307
+ }
144
308
  const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
145
309
  const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
146
310
  panelExpanded.value = false
@@ -157,6 +321,10 @@ function onPanelEnter(el: Element, done: () => void) {
157
321
  else done()
158
322
  }
159
323
  function onPanelLeave(el: Element, done: () => void) {
324
+ if (props.hideOnCollapse) {
325
+ slide(el, -1, done)
326
+ return
327
+ }
160
328
  const panel = (el as HTMLElement).querySelector<HTMLElement>('.wnr-panel')
161
329
  const scrim = (el as HTMLElement).querySelector<HTMLElement>('.wnr-scrim')
162
330
  panelExpanded.value = false
@@ -179,6 +347,8 @@ watch(
179
347
  )
180
348
 
181
349
  onUnmounted(() => {
350
+ slideAnim?.cancel()
351
+ slideScrimAnim?.cancel()
182
352
  document.removeEventListener('keydown', onKeydown)
183
353
  if (props.modal && props.expanded) document.body.style.overflow = ''
184
354
  })
@@ -193,6 +363,7 @@ onUnmounted(() => {
193
363
  that actually reacts to `expanded` when `modal` is set.
194
364
  -->
195
365
  <nav
366
+ v-if="!(modal && hideOnCollapse)"
196
367
  v-bind="$attrs"
197
368
  class="flex h-full flex-col border-r border-outline-variant bg-surface transition-[width] duration-200"
198
369
  :class="railExpanded ? 'w-[220px]' : 'w-20'"
@@ -341,6 +512,13 @@ onUnmounted(() => {
341
512
 
342
513
  <nav
343
514
  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"
515
+ :class="hideOnCollapse ? 'w-[220px] touch-pan-y' : ''"
516
+ @pointerdown="onPanelPointerDown"
517
+ @pointermove="onPanelPointerMove"
518
+ @pointerup="onPanelPointerUp"
519
+ @pointercancel="onPanelPointerUp"
520
+ @touchmove="onPanelTouchMove"
521
+ @click.capture="onPanelClickCapture"
344
522
  >
345
523
  <div v-if="$slots.fab" class="flex shrink-0 flex-col items-start gap-2 px-3 pt-3 pb-2">
346
524
  <div class="flex min-h-10 min-w-14 shrink-0 items-center justify-center">
@@ -348,9 +526,12 @@ onUnmounted(() => {
348
526
  </div>
349
527
  </div>
350
528
 
529
+ <!-- touch-action stops at the nearest scroll container, so this one needs pan-y of its own or a
530
+ finger landing on an item lets the browser take the horizontal swipe -->
351
531
  <div
352
- class="flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-3 py-3"
532
+ class="scrollbar-none flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto px-3 py-3"
353
533
  :class="{
534
+ 'touch-pan-y': hideOnCollapse,
354
535
  'justify-start': alignment === 'top',
355
536
  'justify-center': alignment === 'center',
356
537
  'justify-end': alignment === 'bottom',
@@ -89,6 +89,18 @@ function canStart() {
89
89
  return !props.disabled && !props.refreshing && !committed && !!scrollEl.value && scrollEl.value.scrollTop <= 0;
90
90
  }
91
91
 
92
+ // While a pull can start, the scroller only allows the finger moving up (pan-down): a touch-action that lets the
93
+ // browser pan along the pull makes Chrome deliver it at 60Hz on a 120Hz phone, as a possible scroll waiting on
94
+ // our touchmove listener (see CLAUDE.md). Scrolled, refreshing or disabled, it pans both ways. Browsers without
95
+ // directional pan values (Safari) keep pan-y.
96
+ function updateTouchAction() {
97
+ const el = scrollEl.value;
98
+ if (!el) return;
99
+ const directional = typeof CSS !== "undefined" && !!CSS.supports?.("touch-action", "pan-down");
100
+ const action = canStart() && directional ? "pan-down" : "pan-y";
101
+ if (el.style.touchAction !== action) el.style.touchAction = action;
102
+ }
103
+
92
104
  function beginPull(y: number) {
93
105
  startY = y;
94
106
  pulling = true;
@@ -125,6 +137,7 @@ function finishPull() {
125
137
  hideIndicator(true);
126
138
  }
127
139
  pullDistance = 0;
140
+ updateTouchAction();
128
141
  }
129
142
 
130
143
  // Mouse/pen: pointer events. Touch is handled separately below — a touch's
@@ -220,8 +233,10 @@ watch(
220
233
  committed = false;
221
234
  hideIndicator(true);
222
235
  }
236
+ updateTouchAction();
223
237
  },
224
238
  );
239
+ watch(() => props.disabled, updateTouchAction);
225
240
 
226
241
  // The indicator's transform/opacity are owned entirely by the functions
227
242
  // above, written directly to the DOM — never bound reactively in the
@@ -238,6 +253,8 @@ onMounted(() => {
238
253
  // Must be non-passive: preventDefault() here is what stops the native scroll.
239
254
  el.addEventListener("touchmove", onTouchMove, { passive: false });
240
255
  el.addEventListener("touchend", onTouchEnd);
256
+ el.addEventListener("scroll", updateTouchAction, { passive: true });
257
+ updateTouchAction();
241
258
  el.addEventListener("touchcancel", onTouchEnd);
242
259
  });
243
260
  onBeforeUnmount(() => {
@@ -247,6 +264,7 @@ onBeforeUnmount(() => {
247
264
  el.removeEventListener("touchstart", onTouchStart);
248
265
  el.removeEventListener("touchmove", onTouchMove);
249
266
  el.removeEventListener("touchend", onTouchEnd);
267
+ el.removeEventListener("scroll", updateTouchAction);
250
268
  el.removeEventListener("touchcancel", onTouchEnd);
251
269
  });
252
270
  </script>
@@ -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
- variant?: 'docked' | 'fullscreen'
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 && props.variant === 'fullscreen') document.body.style.overflow = 'hidden'
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 = '' })
@@ -148,10 +155,15 @@ onUnmounted(() => { document.body.style.overflow = '' })
148
155
 
149
156
  <template>
150
157
  <div ref="barEl" class="relative w-full" v-bind="$attrs">
158
+ <!-- Flat, told apart by its color: Compose's SearchBarDefaults.ShadowElevation is Level0 for every variant
159
+ (SearchBarTokens.ContainerElevation's Level3 isn't used by any of them) -->
151
160
  <div
152
161
  v-show="!expanded"
153
- class="flex h-14 items-center gap-3 rounded-full bg-surface-container-high px-4 shadow-elevation-3 transition-shadow duration-150 focus-within:outline focus-within:outline-2 focus-within:outline-secondary focus-within:-outline-offset-2"
154
- :class="disabled ? 'pointer-events-none opacity-[0.38]' : ''"
162
+ class="flex h-14 items-center gap-3 rounded-full px-4 transition-[background-color] duration-150 focus-within:outline focus-within:outline-2 focus-within:outline-secondary focus-within:-outline-offset-2"
163
+ :class="[
164
+ disabled ? 'pointer-events-none opacity-[0.38]' : '',
165
+ appBar?.scrolled.value ? 'bg-surface-container-highest' : 'bg-surface-container-high',
166
+ ]"
155
167
  >
156
168
  <span class="inline-flex shrink-0 items-center" :class="iconPosition === 'end' ? 'order-last' : ''">
157
169
  <slot name="leading">
@@ -185,17 +197,22 @@ onUnmounted(() => { document.body.style.overflow = '' })
185
197
  </div>
186
198
 
187
199
  <Teleport to="body">
188
- <Transition :name="variant === 'fullscreen' ? 'm3-searchbar-full' : 'm3-searchbar-docked'">
200
+ <Transition :name="fullscreen ? 'm3-searchbar-full' : 'm3-searchbar-docked'">
189
201
  <div
190
202
  v-if="expanded"
191
203
  ref="panelEl"
192
- class="fixed z-500 flex flex-col overflow-hidden bg-surface-container-high"
193
- :class="variant === 'fullscreen' ? 'inset-0' : 'max-h-[70vh] rounded-[28px] shadow-elevation-3'"
204
+ class="fixed z-500 flex flex-col overflow-hidden"
205
+ :class="[
206
+ fullscreen ? 'inset-0' : 'max-h-[70vh] rounded-[28px]',
207
+ contained ? 'bg-surface-container-low' : 'bg-surface-container-high',
208
+ ]"
194
209
  :style="variant === 'docked' ? panelPos : undefined"
195
210
  >
211
+ <!-- Contained: the input keeps the collapsed pill (collapsedContainedSearchBarColor), 8dp from the
212
+ sides, 4dp from the top and 8dp above the results (FullScreenSearchBarLayout's isContained) -->
196
213
  <div
197
- class="flex shrink-0 items-center gap-3 px-4"
198
- :class="variant === 'fullscreen' ? 'h-[72px]' : 'h-14'"
214
+ class="flex shrink-0 items-center gap-3"
215
+ :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
216
  >
200
217
  <MIconButton
201
218
  icon="arrow_back"
@@ -227,7 +244,7 @@ onUnmounted(() => { document.body.style.overflow = '' })
227
244
  <slot name="trailing" />
228
245
  </div>
229
246
 
230
- <div class="h-px shrink-0 bg-outline" />
247
+ <div v-if="!contained" class="h-px shrink-0 bg-outline" />
231
248
 
232
249
  <div class="flex-1 overflow-y-auto">
233
250
  <slot />