@m3ui-vue/m3ui-vue 1.1.3 → 1.2.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.
Files changed (236) hide show
  1. package/README.md +1 -1
  2. package/dist/API.md +579 -40
  3. package/dist/MMenuItem-DI351kIf.js +929 -0
  4. package/dist/MMenuItem-DI351kIf.js.map +1 -0
  5. package/dist/MSlider-BnEy5ieZ.js +1500 -0
  6. package/dist/MSlider-BnEy5ieZ.js.map +1 -0
  7. package/dist/MTextField-BBmkaIbO.js +633 -0
  8. package/dist/MTextField-BBmkaIbO.js.map +1 -0
  9. package/dist/api.json +1 -1
  10. package/dist/chart.js +83 -49
  11. package/dist/chart.js.map +1 -1
  12. package/dist/code-editor.js +1 -1
  13. package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
  14. package/dist/components/MButton.vue.d.ts +9 -1
  15. package/dist/components/MButtonGroup.vue.d.ts +40 -31
  16. package/dist/components/MCarousel.vue.d.ts +2 -0
  17. package/dist/components/MChart.vue.d.ts +6 -0
  18. package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
  19. package/dist/components/MContainerTransform.vue.d.ts +59 -0
  20. package/dist/components/MContextMenu.vue.d.ts +2 -2
  21. package/dist/components/MCopyButton.vue.d.ts +1 -1
  22. package/dist/components/MDialog.vue.d.ts +8 -5
  23. package/dist/components/MExportButton.vue.d.ts +1 -1
  24. package/dist/components/MFab.vue.d.ts +2 -2
  25. package/dist/components/MFabMenu.vue.d.ts +1 -1
  26. package/dist/components/MFlex.vue.d.ts +1 -1
  27. package/dist/components/MIconButton.vue.d.ts +15 -1
  28. package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
  29. package/dist/components/MListItem.vue.d.ts +5 -5
  30. package/dist/components/MMap.vue.d.ts +20 -2
  31. package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
  32. package/dist/components/MMapFilter.vue.d.ts +3 -0
  33. package/dist/components/MMapLayers.vue.d.ts +3 -0
  34. package/dist/components/MMenu.vue.d.ts +2 -2
  35. package/dist/components/MMenuItem.vue.d.ts +7 -3
  36. package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
  37. package/dist/components/MNavigationRail.vue.d.ts +1 -1
  38. package/dist/components/MOverlay.vue.d.ts +12 -1
  39. package/dist/components/MProgressBar.vue.d.ts +5 -3
  40. package/dist/components/MPullToRefresh.vue.d.ts +7 -2
  41. package/dist/components/MRichTextEditor.vue.d.ts +7 -1
  42. package/dist/components/MSearchField.vue.d.ts +58 -0
  43. package/dist/components/MSegmentedButton.vue.d.ts +31 -23
  44. package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
  45. package/dist/components/MSkeleton.vue.d.ts +6 -3
  46. package/dist/components/MSplitter.vue.d.ts +1 -1
  47. package/dist/components/MStack.vue.d.ts +1 -1
  48. package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
  49. package/dist/components/MSwitch.vue.d.ts +1 -1
  50. package/dist/components/MTextField.vue.d.ts +5 -1
  51. package/dist/components/MTimeline.vue.d.ts +85 -22
  52. package/dist/components/MToolbar.vue.d.ts +32 -5
  53. package/dist/components/MTooltip.vue.d.ts +1 -1
  54. package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
  55. package/dist/components/_MToolbarFab.vue.d.ts +16 -0
  56. package/dist/composables/_containerTransform.d.ts +48 -0
  57. package/dist/composables/_mapStyle.d.ts +13 -0
  58. package/dist/composables/_themeTransition.d.ts +2 -0
  59. package/dist/composables/_tooltipTrigger.d.ts +22 -0
  60. package/dist/composables/_useMenuNav.d.ts +28 -0
  61. package/dist/composables/useAutoGrow.d.ts +21 -0
  62. package/dist/composables/useColorPalette.d.ts +1 -1
  63. package/dist/composables/useContainerTransform.d.ts +30 -0
  64. package/dist/composables/useLocale.d.ts +6 -0
  65. package/dist/composables/useMap.d.ts +19 -3
  66. package/dist/composables/useMapFilter.d.ts +4 -1
  67. package/dist/composables/useMapLayers.d.ts +5 -2
  68. package/dist/composables/useScrollReveal.d.ts +44 -0
  69. package/dist/composables/useThemeTokens.d.ts +21 -0
  70. package/dist/composables/viewportHints.d.ts +27 -0
  71. package/dist/directives/vClickOutside.d.ts +25 -0
  72. package/dist/directives/vFocusRing.d.ts +22 -0
  73. package/dist/directives/vLongPress.d.ts +27 -0
  74. package/dist/directives/vReveal.d.ts +10 -0
  75. package/dist/directives/vScrollElevation.d.ts +31 -0
  76. package/dist/directives/vSkeleton.d.ts +19 -0
  77. package/dist/directives/vStateLayer.d.ts +20 -0
  78. package/dist/directives/vSwipe.d.ts +45 -0
  79. package/dist/directives/vTooltip.d.ts +23 -0
  80. package/dist/index.d.ts +31 -1
  81. package/dist/locales/index.js +35 -7
  82. package/dist/locales/index.js.map +1 -1
  83. package/dist/m3ui-vue.css +1 -1
  84. package/dist/m3ui.js +7692 -6273
  85. package/dist/m3ui.js.map +1 -1
  86. package/dist/map.d.ts +1 -1
  87. package/dist/map.js +823 -793
  88. package/dist/map.js.map +1 -1
  89. package/dist/motion-DZiXG09o.js +150 -0
  90. package/dist/motion-DZiXG09o.js.map +1 -0
  91. package/dist/plugin.d.ts +24 -0
  92. package/dist/rich-text-editor.js +20 -16
  93. package/dist/rich-text-editor.js.map +1 -1
  94. package/dist/styles/theme.css +63 -0
  95. package/dist/styles.css +1 -1
  96. package/dist/{useLocale-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -2
  97. package/dist/useLocale-JYxDDeXC.js.map +1 -0
  98. package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
  99. package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
  100. package/package.json +2 -1
  101. package/src/__tests__/MAnimatedNumber.test.ts +24 -2
  102. package/src/__tests__/MButton.test.ts +22 -0
  103. package/src/__tests__/MCarousel.test.ts +9 -0
  104. package/src/__tests__/MChart.test.ts +77 -5
  105. package/src/__tests__/MContainerTransform.test.ts +279 -0
  106. package/src/__tests__/MDialog.test.ts +27 -0
  107. package/src/__tests__/MIconButton.test.ts +33 -0
  108. package/src/__tests__/MListItemExpandable.test.ts +48 -0
  109. package/src/__tests__/MListItemShape.test.ts +9 -6
  110. package/src/__tests__/MListKeyboard.test.ts +90 -0
  111. package/src/__tests__/MMap.test.ts +53 -1
  112. package/src/__tests__/MMapLayers.test.ts +46 -2
  113. package/src/__tests__/MMapTools.test.ts +2 -1
  114. package/src/__tests__/MMenu.test.ts +104 -1
  115. package/src/__tests__/MMenuItem.test.ts +18 -0
  116. package/src/__tests__/MNavigationDrawer.test.ts +80 -0
  117. package/src/__tests__/MNavigationRail.test.ts +33 -0
  118. package/src/__tests__/MOverlay.test.ts +49 -0
  119. package/src/__tests__/MProgressBar.test.ts +41 -0
  120. package/src/__tests__/MPullToRefresh.test.ts +33 -0
  121. package/src/__tests__/MRichTextEditor.test.ts +22 -0
  122. package/src/__tests__/MSearchField.test.ts +71 -0
  123. package/src/__tests__/MSkeleton.test.ts +38 -0
  124. package/src/__tests__/MSlider.test.ts +161 -0
  125. package/src/__tests__/MTimeline.test.ts +238 -0
  126. package/src/__tests__/MToolbar.test.ts +157 -0
  127. package/src/__tests__/_fakeMaplibre.ts +3 -1
  128. package/src/__tests__/attrsFallthrough.test.ts +9 -0
  129. package/src/__tests__/escapeStack.test.ts +93 -0
  130. package/src/__tests__/hydration.test.ts +25 -0
  131. package/src/__tests__/ssr.test.ts +21 -2
  132. package/src/__tests__/useAutoGrow.test.ts +103 -0
  133. package/src/__tests__/useScrollReveal.test.ts +102 -0
  134. package/src/__tests__/useThemeTokens.test.ts +114 -0
  135. package/src/__tests__/vClickOutside.test.ts +82 -0
  136. package/src/__tests__/vFocusRing.test.ts +36 -0
  137. package/src/__tests__/vLongPress.test.ts +81 -0
  138. package/src/__tests__/vScrollElevation.test.ts +89 -0
  139. package/src/__tests__/vSkeleton.test.ts +48 -0
  140. package/src/__tests__/vStateLayer.test.ts +53 -0
  141. package/src/__tests__/vSwipe.test.ts +93 -0
  142. package/src/__tests__/vTooltip.test.ts +95 -0
  143. package/src/__tests__/viewportHints.test.ts +41 -0
  144. package/src/components/MAnimatedNumber.vue +32 -6
  145. package/src/components/MAutocomplete.vue +5 -0
  146. package/src/components/MBottomSheet.vue +4 -1
  147. package/src/components/MButton.vue +19 -3
  148. package/src/components/MButtonGroup.vue +22 -17
  149. package/src/components/MCarousel.vue +7 -1
  150. package/src/components/MChart.vue +74 -34
  151. package/src/components/MCircleProgressBar.vue +14 -9
  152. package/src/components/MCommandPalette.vue +3 -2
  153. package/src/components/MContainerTransform.vue +321 -0
  154. package/src/components/MContextMenu.vue +19 -60
  155. package/src/components/MDialog.vue +31 -6
  156. package/src/components/MDragDropList.vue +2 -0
  157. package/src/components/MFab.vue +10 -5
  158. package/src/components/MIconButton.vue +43 -2
  159. package/src/components/MKanban.vue +2 -0
  160. package/src/components/MLightbox.vue +7 -2
  161. package/src/components/MList.vue +26 -2
  162. package/src/components/MListItem.vue +138 -84
  163. package/src/components/MMap.vue +38 -5
  164. package/src/components/MMapBaseLayers.vue +7 -3
  165. package/src/components/MMapFilter.vue +7 -4
  166. package/src/components/MMapGeoJson.vue +1 -1
  167. package/src/components/MMapLayers.vue +6 -2
  168. package/src/components/MMapMeasure.vue +5 -2
  169. package/src/components/MMenu.vue +18 -59
  170. package/src/components/MMenuItem.vue +11 -2
  171. package/src/components/MMultiAutocomplete.vue +5 -0
  172. package/src/components/MNavigationDrawer.vue +96 -11
  173. package/src/components/MNavigationRail.vue +44 -25
  174. package/src/components/MOverlay.vue +32 -13
  175. package/src/components/MProgressBar.vue +25 -27
  176. package/src/components/MPullToRefresh.vue +20 -1
  177. package/src/components/MRichTextEditor.vue +19 -5
  178. package/src/components/MSearchBar.vue +5 -0
  179. package/src/components/MSearchField.vue +142 -0
  180. package/src/components/MSegmentedButton.vue +19 -17
  181. package/src/components/MSelect.vue +10 -1
  182. package/src/components/MSideSheet.vue +5 -2
  183. package/src/components/MSimpleCarousel.vue +10 -1
  184. package/src/components/MSkeleton.vue +30 -8
  185. package/src/components/MSlider.vue +161 -42
  186. package/src/components/MSpotlightSearch.vue +3 -2
  187. package/src/components/MTextField.vue +15 -2
  188. package/src/components/MTimeline.vue +370 -81
  189. package/src/components/MToolbar.vue +256 -15
  190. package/src/components/MTooltip.vue +20 -152
  191. package/src/components/_MDrawerItemList.vue +25 -6
  192. package/src/components/_MToolbarFab.vue +14 -0
  193. package/src/composables/_containerTransform.ts +179 -0
  194. package/src/composables/_mapStyle.ts +45 -0
  195. package/src/composables/_themeTransition.ts +2 -0
  196. package/src/composables/_tooltipTrigger.ts +184 -0
  197. package/src/composables/_useEscapeStack.ts +2 -0
  198. package/src/composables/_useMenuNav.ts +209 -0
  199. package/src/composables/useAutoGrow.ts +78 -0
  200. package/src/composables/useContainerTransform.ts +59 -0
  201. package/src/composables/useLocale.ts +10 -0
  202. package/src/composables/useMap.ts +43 -5
  203. package/src/composables/useMapFilter.ts +6 -5
  204. package/src/composables/useMapLayers.ts +7 -6
  205. package/src/composables/useScrollReveal.ts +151 -0
  206. package/src/composables/useThemeTokens.ts +116 -0
  207. package/src/composables/viewportHints.ts +80 -0
  208. package/src/directives/vClickOutside.ts +90 -0
  209. package/src/directives/vFocusRing.ts +60 -0
  210. package/src/directives/vLongPress.ts +134 -0
  211. package/src/directives/vReveal.ts +57 -0
  212. package/src/directives/vScrollElevation.ts +116 -0
  213. package/src/directives/vSkeleton.ts +87 -0
  214. package/src/directives/vStateLayer.ts +83 -0
  215. package/src/directives/vSwipe.ts +197 -0
  216. package/src/directives/vTooltip.ts +128 -0
  217. package/src/index.ts +31 -1
  218. package/src/locales/de.ts +4 -0
  219. package/src/locales/es.ts +4 -0
  220. package/src/locales/fr.ts +4 -0
  221. package/src/locales/ja.ts +4 -0
  222. package/src/locales/ko.ts +4 -0
  223. package/src/locales/pt.ts +4 -0
  224. package/src/locales/zh.ts +4 -0
  225. package/src/map.ts +1 -1
  226. package/src/plugin.ts +34 -0
  227. package/src/styles/theme.css +63 -0
  228. package/dist/MMenuItem-BckcR0nW.js +0 -809
  229. package/dist/MMenuItem-BckcR0nW.js.map +0 -1
  230. package/dist/MSlider-LyH_gy8D.js +0 -1411
  231. package/dist/MSlider-LyH_gy8D.js.map +0 -1
  232. package/dist/MTextField-FCPOTB0o.js +0 -672
  233. package/dist/MTextField-FCPOTB0o.js.map +0 -1
  234. package/dist/composables/_useThemeTokens.d.ts +0 -7
  235. package/dist/useLocale-SfQHnJfp.js.map +0 -1
  236. package/src/composables/_useThemeTokens.ts +0 -42
@@ -10,8 +10,10 @@ const props = withDefaults(
10
10
  value?: number;
11
11
  /** Indeterminate animation — also implied by omitting value */
12
12
  indeterminate?: boolean;
13
- /** Bar color */
14
- color?: "primary" | "secondary" | "tertiary" | "error";
13
+ /** Bar color: an M3 role or any CSS color (`#fff` over a photo, say) */
14
+ color?: "primary" | "secondary" | "tertiary" | "error" | (string & {});
15
+ /** Track color: an M3 role or any CSS color. Default the role's container, or the bar color at 24% for a CSS color */
16
+ trackColor?: string;
15
17
  /** Bar style */
16
18
  variant?: "linear" | "wavy";
17
19
  /** Label text above the bar */
@@ -25,15 +27,18 @@ const props = withDefaults(
25
27
  const isIndeterminate = computed(() => props.indeterminate || props.value === undefined);
26
28
  const clampedValue = computed(() => Math.min(100, Math.max(0, props.value ?? 0)));
27
29
 
28
- const colorMap: Record<
29
- "primary" | "secondary" | "tertiary" | "error",
30
- { bar: string; track: string; text: string }
31
- > = {
32
- primary: { bar: "bg-primary", track: "bg-primary-container", text: "text-primary" },
33
- secondary: { bar: "bg-secondary", track: "bg-secondary-container", text: "text-secondary" },
34
- tertiary: { bar: "bg-tertiary", track: "bg-tertiary-container", text: "text-tertiary" },
35
- error: { bar: "bg-error", track: "bg-error-container", text: "text-error" },
36
- };
30
+ const ROLES = ["primary", "secondary", "tertiary", "error"];
31
+ const roleOr = (c: string) => (ROLES.includes(c) || c.endsWith("-container") ? `var(--color-${c})` : c);
32
+ // Both colors go through custom properties on the root, read by the bar/track/wave below.
33
+ const colorVars = computed(() => {
34
+ const bar = roleOr(props.color);
35
+ const track = props.trackColor
36
+ ? roleOr(props.trackColor)
37
+ : ROLES.includes(props.color)
38
+ ? `var(--color-${props.color}-container)`
39
+ : `color-mix(in srgb, ${props.color} 24%, transparent)`;
40
+ return { "--m3-progress-bar": bar, "--m3-progress-track": track };
41
+ });
37
42
 
38
43
  // ── Wave geometry ─────────────────────────────────────────────────────────
39
44
  const PERIOD = 20;
@@ -199,14 +204,14 @@ watch(isIndeterminate, async (v) => {
199
204
  </script>
200
205
 
201
206
  <template>
202
- <div class="flex flex-col gap-1">
207
+ <div class="flex flex-col gap-1" :style="colorVars">
203
208
  <span v-if="label" class="text-label-small text-on-surface-variant">{{ label }}</span>
204
209
 
205
210
  <!-- ── Linear variant ────────────────────────────────────────────────── -->
206
211
  <div
207
212
  v-if="variant === 'linear'"
208
213
  class="relative w-full overflow-hidden rounded-full"
209
- :class="isIndeterminate ? colorMap[color].track : ''"
214
+ :class="isIndeterminate ? 'bg-(--m3-progress-track)' : ''"
210
215
  :style="{ height: `${effectiveThickness}px` }"
211
216
  role="progressbar"
212
217
  :aria-valuenow="isIndeterminate ? undefined : clampedValue"
@@ -217,20 +222,17 @@ watch(isIndeterminate, async (v) => {
217
222
  a fixed gap after the active bar, not flush against it. -->
218
223
  <template v-if="!isIndeterminate">
219
224
  <div
220
- class="absolute inset-y-0 left-0 rounded-full transition-[width] duration-300 ease-in-out"
221
- :class="colorMap[color].bar"
225
+ class="absolute inset-y-0 left-0 rounded-full transition-[width] duration-300 ease-in-out bg-(--m3-progress-bar)"
222
226
  :style="{ width: `${clampedValue}%` }"
223
227
  />
224
228
  <div
225
- class="absolute inset-y-0 right-0 rounded-full transition-[left] duration-300 ease-in-out"
226
- :class="colorMap[color].track"
229
+ class="absolute inset-y-0 right-0 rounded-full transition-[left] duration-300 ease-in-out bg-(--m3-progress-track)"
227
230
  :style="{ left: `calc(${clampedValue}% + 4px)` }"
228
231
  />
229
232
  </template>
230
233
  <div
231
234
  v-else
232
- class="absolute inset-y-0 w-2/5 rounded-full animate-[m3-progress-indeterminate_1.6s_ease-in-out_infinite]"
233
- :class="colorMap[color].bar"
235
+ class="absolute inset-y-0 w-2/5 rounded-full animate-[m3-progress-indeterminate_1.6s_ease-in-out_infinite] bg-(--m3-progress-bar)"
234
236
  />
235
237
  </div>
236
238
 
@@ -253,8 +255,7 @@ watch(isIndeterminate, async (v) => {
253
255
  style="clip-path: inset(0 100% 0 0)"
254
256
  >
255
257
  <svg
256
- class="absolute top-0 left-0 h-full"
257
- :class="colorMap[color].text"
258
+ class="absolute top-0 left-0 h-full text-(--m3-progress-bar)"
258
259
  :width="waveWidth"
259
260
  :height="waveViewH"
260
261
  :viewBox="`0 0 ${waveWidth} ${waveViewH}`"
@@ -272,15 +273,13 @@ watch(isIndeterminate, async (v) => {
272
273
  <!-- Inactive track — rAF owns left and height; no Vue-managed left -->
273
274
  <div
274
275
  ref="trackEl"
275
- class="absolute right-0"
276
- :class="colorMap[color].track"
276
+ class="absolute right-0 bg-(--m3-progress-track)"
277
277
  style="border-radius: 9999px; top: 50%; transform: translateY(-50%);"
278
278
  />
279
279
 
280
280
  <!-- Stop dot at far right -->
281
281
  <div
282
- class="absolute rounded-full"
283
- :class="colorMap[color].bar"
282
+ class="absolute rounded-full bg-(--m3-progress-bar)"
284
283
  :style="{
285
284
  right: '0',
286
285
  top: '50%',
@@ -294,8 +293,7 @@ watch(isIndeterminate, async (v) => {
294
293
  <!-- INDETERMINATE — keeps original CSS-animated wide strip -->
295
294
  <div v-else class="absolute inset-0 overflow-hidden rounded-full">
296
295
  <div
297
- class="absolute top-0 left-0 h-full animate-[m3-wave-flow_0.9s_linear_infinite]"
298
- :class="colorMap[color].text"
296
+ class="absolute top-0 left-0 h-full animate-[m3-wave-flow_0.9s_linear_infinite] text-(--m3-progress-bar)"
299
297
  :style="{ width: `${waveWidth}px` }"
300
298
  >
301
299
  <svg
@@ -8,7 +8,7 @@
8
8
  * @event refresh Emitted when the user drags past threshold and releases. Set refreshing to true in the
9
9
  * handler, then back to false once the fetch resolves.
10
10
  */
11
- import { ref, watch, onMounted, onBeforeUnmount } from "vue";
11
+ import { ref, watch, onMounted, onBeforeUnmount, onActivated } from "vue";
12
12
  import MLoadingIndicator from "./MLoadingIndicator.vue";
13
13
 
14
14
  const props = withDefaults(
@@ -254,9 +254,27 @@ onMounted(() => {
254
254
  el.addEventListener("touchmove", onTouchMove, { passive: false });
255
255
  el.addEventListener("touchend", onTouchEnd);
256
256
  el.addEventListener("scroll", updateTouchAction, { passive: true });
257
+ el.addEventListener("scroll", rememberScroll, { passive: true });
257
258
  updateTouchAction();
258
259
  el.addEventListener("touchcancel", onTouchEnd);
259
260
  });
261
+ // Inside a <KeepAlive>, the browser forgets a detached element's scroll position (and reads 0 once it's detached),
262
+ // so remember the last one from the scroll events and put it back when the view comes back.
263
+ let lastScrollTop = 0;
264
+ function rememberScroll() {
265
+ lastScrollTop = scrollEl.value?.scrollTop ?? 0;
266
+ }
267
+ onActivated(() => {
268
+ if (lastScrollTop && scrollEl.value) scrollEl.value.scrollTop = lastScrollTop;
269
+ });
270
+
271
+ defineExpose({
272
+ /** The element that scrolls the slot's content */
273
+ scrollEl,
274
+ /** Scrolls the content, like `Element.scrollTo()` (e.g. `{ top: 0, behavior: 'smooth' }`) */
275
+ scrollTo: (options: ScrollToOptions) => scrollEl.value?.scrollTo(options),
276
+ });
277
+
260
278
  onBeforeUnmount(() => {
261
279
  pulling = false;
262
280
  const el = scrollEl.value;
@@ -265,6 +283,7 @@ onBeforeUnmount(() => {
265
283
  el.removeEventListener("touchmove", onTouchMove);
266
284
  el.removeEventListener("touchend", onTouchEnd);
267
285
  el.removeEventListener("scroll", updateTouchAction);
286
+ el.removeEventListener("scroll", rememberScroll);
268
287
  el.removeEventListener("touchcancel", onTouchEnd);
269
288
  });
270
289
  </script>
@@ -52,15 +52,20 @@ const props = withDefaults(
52
52
  placeholder?: string
53
53
  /** Disables editing */
54
54
  disabled?: boolean
55
- /** Minimum editor height */
55
+ /** Minimum height of the text area (not used with `fill`) */
56
56
  minHeight?: string
57
+ /**
58
+ * Fills the height you give the editor (`class="h-full"`, `flex-1`…): the toolbar stays put and the text
59
+ * scrolls inside, instead of the editor growing with its content
60
+ */
61
+ fill?: boolean
57
62
  /**
58
63
  * Object with all toolbar/dialog label overrides for i18n (see `RichTextEditorLabels`) — defaults come from
59
64
  * useLocale()
60
65
  */
61
66
  labels?: RichTextEditorLabels
62
67
  }>(),
63
- { disabled: false, minHeight: '200px' },
68
+ { disabled: false, minHeight: '200px', fill: false },
64
69
  )
65
70
 
66
71
  const l = computed<Required<RichTextEditorLabels>>(() => ({
@@ -231,10 +236,13 @@ function confirmImage() {
231
236
  <template>
232
237
  <div
233
238
  class="overflow-hidden rounded-lg border transition-colors duration-150"
234
- :class="disabled ? 'border-outline-variant/50 opacity-60' : 'border-outline-variant focus-within:border-primary'"
239
+ :class="[
240
+ disabled ? 'border-outline-variant/50 opacity-60' : 'border-outline-variant focus-within:border-primary',
241
+ { 'flex flex-col': fill },
242
+ ]"
235
243
  >
236
244
  <!-- Toolbar -->
237
- <div v-if="ready" class="flex flex-wrap items-center gap-0.5 border-b border-outline-variant bg-surface-container px-2 py-1.5">
245
+ <div v-if="ready" class="flex shrink-0 flex-wrap items-center gap-0.5 border-b border-outline-variant bg-surface-container px-2 py-1.5">
238
246
  <!-- Heading menu -->
239
247
  <MMenu align="left">
240
248
  <template #trigger>
@@ -293,7 +301,8 @@ function confirmImage() {
293
301
  <div
294
302
  ref="editorContainer"
295
303
  class="rte-content bg-surface px-4 py-3 text-body-large text-on-surface"
296
- :style="{ minHeight: minHeight }"
304
+ :class="{ 'rte-fill flex min-h-0 flex-1 flex-col overflow-y-auto': fill }"
305
+ :style="fill ? undefined : { minHeight }"
297
306
  />
298
307
 
299
308
  <!-- Link dialog -->
@@ -322,6 +331,11 @@ function confirmImage() {
322
331
  min-height: inherit;
323
332
  }
324
333
 
334
+ /* Filling: the document takes the whole area, so a click anywhere below the text lands in it. */
335
+ .rte-fill :deep(.tiptap) {
336
+ flex: 1;
337
+ }
338
+
325
339
  .rte-content :deep(.tiptap p.is-editor-empty:first-child::before) {
326
340
  content: attr(data-placeholder);
327
341
  float: left;
@@ -20,6 +20,7 @@ import MSpinner from './MSpinner.vue'
20
20
  import { useLocale } from '../composables/useLocale'
21
21
  import { searchAppBarKey } from '../composables/_searchAppBar'
22
22
  import { useScrollLock } from '../composables/_useScrollLock'
23
+ import { useEscapeStack } from '../composables/_useEscapeStack'
23
24
 
24
25
  // Root is a fragment (bar div + a sibling Teleport for the expanded overlay panel), so Vue
25
26
  // can't auto-apply a consumer's class/attrs to either one — forward them onto the bar div below.
@@ -121,6 +122,8 @@ function onClear() {
121
122
 
122
123
  function onKeydown(e: KeyboardEvent) {
123
124
  if (e.key === 'Escape') {
125
+ // Collapsing uses the key: keep it from also closing a dialog around the bar
126
+ if (expanded.value) e.stopPropagation()
124
127
  close()
125
128
  inputEl.value?.blur()
126
129
  } else if (e.key === 'Enter') {
@@ -151,6 +154,8 @@ onUnmounted(() => {
151
154
  })
152
155
 
153
156
  useScrollLock(() => expanded.value && fullscreen.value)
157
+ // Expanded, it's a popup (or a modal view): Escape collapses it first, wherever the focus is
158
+ useEscapeStack(() => expanded.value, () => close())
154
159
  </script>
155
160
 
156
161
  <template>
@@ -0,0 +1,142 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * A pill-shaped search input that filters in place: a list, a table, a grid of products. Unlike MSearchBar, it never
4
+ * expands into a results view; it's just the field, in M3's search bar colors and shape.
5
+ *
6
+ * Your `class` and `style` go on the pill; every other attribute (`name`, `autocomplete`, `aria-*`, listeners like
7
+ * `@focus` or `@keydown`) goes on the `<input>`.
8
+ *
9
+ * @slot leading Replaces the search icon (an avatar, a back or menu button…). Spaced for a 40px icon button, as in
10
+ * M3's search bar: its icon lands 16px from the edge, like the default one, and the text at the same place
11
+ * @slot trailing Extra content after the clear button (a mic button, a filter menu…)
12
+ * @event update:modelValue The text, on every keystroke — powers v-model
13
+ * @event search Enter was pressed, with the text
14
+ * @event clear The clear button (or Escape) emptied the field
15
+ */
16
+ import { computed, ref, useAttrs } from 'vue'
17
+ import MIcon from './MIcon.vue'
18
+ import { useLocale } from '../composables/useLocale'
19
+
20
+ defineOptions({ inheritAttrs: false })
21
+
22
+ const props = withDefaults(
23
+ defineProps<{
24
+ /** The text (v-model) */
25
+ modelValue?: string
26
+ /** Placeholder. Defaults to the locale's `search` */
27
+ placeholder?: string
28
+ /** Accessible name when there's no visible label. Defaults to the placeholder */
29
+ label?: string
30
+ /** Leading icon, a Material Symbol. Set to '' for none */
31
+ icon?: string
32
+ /** Height: `sm` 40px (body-medium text), `md` 48px, `lg` 56px (M3's search bar) */
33
+ size?: 'sm' | 'md' | 'lg'
34
+ /** Shows a clear button while there's text */
35
+ clearable?: boolean
36
+ /**
37
+ * Escape empties the field (keeping the key from closing a dialog or menu around it); on an empty field it
38
+ * leaves it and lets the key through
39
+ */
40
+ clearOnEscape?: boolean
41
+ /** Disables the field */
42
+ disabled?: boolean
43
+ }>(),
44
+ { modelValue: '', icon: 'search', size: 'lg', clearable: true, clearOnEscape: true, disabled: false },
45
+ )
46
+
47
+ const emit = defineEmits<{ 'update:modelValue': [string]; search: [string]; clear: [] }>()
48
+
49
+ const locale = useLocale()
50
+ const attrs = useAttrs()
51
+ const rootAttrs = computed(() => ({ class: attrs.class, style: attrs.style }))
52
+ const inputAttrs = computed(() => {
53
+ const { class: _c, style: _s, ...rest } = attrs
54
+ return rest
55
+ })
56
+
57
+ const inputEl = ref<HTMLInputElement>()
58
+ const placeholderText = computed(() => props.placeholder ?? locale.search)
59
+ const iconSize = computed(() => (props.size === 'sm' ? 20 : props.size === 'md' ? 22 : 24))
60
+
61
+ function onInput(e: Event) {
62
+ emit('update:modelValue', (e.target as HTMLInputElement).value)
63
+ }
64
+ function clear() {
65
+ emit('update:modelValue', '')
66
+ emit('clear')
67
+ inputEl.value?.focus()
68
+ }
69
+ function onKeydown(e: KeyboardEvent) {
70
+ if (e.key === 'Enter') emit('search', props.modelValue)
71
+ else if (e.key === 'Escape' && props.clearOnEscape) {
72
+ if (props.modelValue) {
73
+ // Handled here: a dialog or overlay around the field keeps its Escape for the next press
74
+ e.stopPropagation()
75
+ e.preventDefault()
76
+ emit('update:modelValue', '')
77
+ emit('clear')
78
+ } else inputEl.value?.blur()
79
+ }
80
+ }
81
+
82
+ defineExpose({
83
+ /** The `<input>` element */
84
+ inputEl,
85
+ /** Focuses the input */
86
+ focus: (options?: FocusOptions) => inputEl.value?.focus(options),
87
+ /** Takes focus away from the input */
88
+ blur: () => inputEl.value?.blur(),
89
+ })
90
+ </script>
91
+
92
+ <template>
93
+ <label
94
+ class="m3-search-field flex min-w-0 items-center text-on-surface focus-within:ring-2 focus-within:ring-secondary"
95
+ :class="[`m3-search-field-${size}`, { 'm3-search-field-slotted': $slots.leading }, disabled ? 'cursor-not-allowed opacity-38' : 'cursor-text']"
96
+ v-bind="rootAttrs"
97
+ >
98
+ <!-- A slotted 40px button sits 8px in and 4px from the text: its icon then lines up with the default one -->
99
+ <span v-if="$slots.leading" class="-me-2 flex shrink-0 items-center"><slot name="leading" /></span>
100
+ <MIcon v-else-if="icon" :name="icon" :size="iconSize" class="shrink-0 text-on-surface-variant" />
101
+ <input
102
+ ref="inputEl"
103
+ :value="modelValue"
104
+ type="search"
105
+ :placeholder="placeholderText"
106
+ :aria-label="label ?? placeholderText"
107
+ :disabled="disabled"
108
+ enterkeyhint="search"
109
+ class="min-w-0 flex-1 bg-transparent text-on-surface outline-none placeholder:text-on-surface-variant disabled:cursor-not-allowed [&::-webkit-search-cancel-button]:hidden"
110
+ :class="size === 'sm' ? 'text-body-medium' : 'text-body-large'"
111
+ v-bind="inputAttrs"
112
+ @input="onInput"
113
+ @keydown="onKeydown"
114
+ />
115
+ <button
116
+ v-if="clearable && modelValue && !disabled"
117
+ type="button"
118
+ class="-mr-1 flex shrink-0 cursor-pointer rounded-full p-1 text-on-surface-variant hover:bg-on-surface/8"
119
+ :aria-label="locale.clearSearch"
120
+ @click="clear"
121
+ >
122
+ <MIcon name="close" :size="iconSize - 2" />
123
+ </button>
124
+ <slot name="trailing" />
125
+ </label>
126
+ </template>
127
+
128
+ <style>
129
+ /* Default color, shape, spacing and height in the base layer, so a consumer's bg-*, rounded-*, px-*, gap-* or h-* wins */
130
+ @layer base {
131
+ .m3-search-field {
132
+ gap: 12px;
133
+ padding-inline: 16px;
134
+ background-color: var(--color-surface-container-high);
135
+ border-radius: 9999px;
136
+ }
137
+ .m3-search-field-slotted { padding-inline-start: 8px; }
138
+ .m3-search-field-sm { height: 40px; }
139
+ .m3-search-field-md { height: 48px; }
140
+ .m3-search-field-lg { height: 56px; }
141
+ }
142
+ </style>
@@ -1,4 +1,13 @@
1
- <script setup lang="ts">
1
+ <script lang="ts">
2
+ export interface SegmentedOption<V extends string | number = string | number> {
3
+ value: V
4
+ label: string
5
+ icon?: string
6
+ disabled?: boolean
7
+ }
8
+ </script>
9
+
10
+ <script setup lang="ts" generic="V extends string | number, M extends V | V[] = V">
2
11
  /**
3
12
  * A row of joined segments for choosing between a small set of related options — single or multi select.
4
13
  *
@@ -6,18 +15,11 @@
6
15
  */
7
16
  import MIcon from './MIcon.vue'
8
17
 
9
- export interface SegmentedOption {
10
- value: string | number
11
- label: string
12
- icon?: string
13
- disabled?: boolean
14
- }
15
-
16
18
  withDefaults(defineProps<{
17
- /** Selected value(s) */
18
- modelValue: string | number | (string | number)[]
19
+ /** Selected value, or values with `multiSelect` (v-model); typed after the options' values */
20
+ modelValue: M
19
21
  /** The options to choose from; see `SegmentedOption`. */
20
- options: SegmentedOption[]
22
+ options: SegmentedOption<V>[]
21
23
  /** Allow multiple selections */
22
24
  multiSelect?: boolean
23
25
  /** Button density */
@@ -26,22 +28,22 @@ withDefaults(defineProps<{
26
28
  color?: 'primary' | 'secondary' | 'tertiary'
27
29
  }>(), { multiSelect: false, density: 'default', color: 'primary' })
28
30
 
29
- const emit = defineEmits<{ 'update:modelValue': [string | number | (string | number)[]] }>()
31
+ const emit = defineEmits<{ 'update:modelValue': [M] }>()
30
32
 
31
- function isSelected(value: string | number, modelValue: string | number | (string | number)[]) {
33
+ function isSelected(value: V, modelValue: M) {
32
34
  return Array.isArray(modelValue) ? modelValue.includes(value) : modelValue === value
33
35
  }
34
36
 
35
- function toggle(opt: SegmentedOption, modelValue: string | number | (string | number)[], multi: boolean) {
37
+ function toggle(opt: SegmentedOption<V>, modelValue: M, multi: boolean) {
36
38
  if (opt.disabled) return
37
39
  if (multi) {
38
- const arr = Array.isArray(modelValue) ? [...modelValue] : [modelValue]
40
+ const arr: V[] = Array.isArray(modelValue) ? [...modelValue] : [modelValue as V]
39
41
  const idx = arr.indexOf(opt.value)
40
42
  if (idx >= 0) arr.splice(idx, 1)
41
43
  else arr.push(opt.value)
42
- emit('update:modelValue', arr)
44
+ emit('update:modelValue', arr as M)
43
45
  } else {
44
- emit('update:modelValue', opt.value)
46
+ emit('update:modelValue', opt.value as M)
45
47
  }
46
48
  }
47
49
  </script>
@@ -10,6 +10,7 @@ import MIconButton from './MIconButton.vue'
10
10
  import { useFieldBg } from '../composables/useFieldBg'
11
11
  import { useLocale } from '../composables/useLocale'
12
12
  import { useScrollLock } from '../composables/_useScrollLock'
13
+ import { useEscapeStack } from '../composables/_useEscapeStack'
13
14
 
14
15
  export interface SelectOption {
15
16
  label: string
@@ -140,7 +141,13 @@ function onScroll(e: Event) {
140
141
  }
141
142
 
142
143
  function onKeydown(e: KeyboardEvent) {
143
- if (e.key === 'Escape') { open.value = false; modalOpen.value = false; return }
144
+ if (e.key === 'Escape') {
145
+ // Used to close the list: keep it from also closing a dialog around the select (the escape stack)
146
+ if (open.value || modalOpen.value) e.stopPropagation()
147
+ open.value = false
148
+ modalOpen.value = false
149
+ return
150
+ }
144
151
  if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); toggle(); return }
145
152
  if (!open.value && !modalOpen.value) return
146
153
  const opts = props.options.filter((o) => !o.disabled)
@@ -158,6 +165,8 @@ function onKeydown(e: KeyboardEvent) {
158
165
  }
159
166
 
160
167
  useScrollLock(modalOpen)
168
+ // The modal list is a modal surface: Escape closes it first, before a dialog it was opened from
169
+ useEscapeStack(modalOpen, () => (modalOpen.value = false))
161
170
 
162
171
  function closeModal() { modalOpen.value = false }
163
172
 
@@ -6,15 +6,16 @@
6
6
  * @slot header Replaces the default title text entirely — the close button stays
7
7
  * @slot default Sheet body content (scrollable)
8
8
  * @slot actions Footer action buttons, shown in a bordered strip below the content
9
- * @event update:modelValue Emitted when the sheet closes (scrim click, drag-to-dismiss from the left edge, or
9
+ * @event update:modelValue Emitted when the sheet closes (scrim click, drag-to-dismiss from the left edge, Escape, or
10
10
  * the close button) — powers v-model
11
11
  */
12
12
  import MIcon from './MIcon.vue'
13
13
  import { useSheetMotion } from '../composables/_useSheetMotion'
14
+ import { useEscapeStack } from '../composables/_useEscapeStack'
14
15
  import { useLocale } from '../composables/useLocale'
15
16
 
16
17
  const locale = useLocale()
17
- withDefaults(defineProps<{
18
+ const props = withDefaults(defineProps<{
18
19
  /** Open/closed state (v-model) */
19
20
  modelValue: boolean
20
21
  /** Sheet header title, ignored if the header slot is used */
@@ -25,6 +26,8 @@ withDefaults(defineProps<{
25
26
 
26
27
  const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
27
28
  const close = () => emit('update:modelValue', false)
29
+ // Modal: Escape closes it, through the library's stack (a dialog or menu over it takes it first)
30
+ useEscapeStack(() => props.modelValue, close)
28
31
 
29
32
  // Slide in/out and drag-to-dismiss, as springs (see _useSheetMotion).
30
33
  const motion = useSheetMotion('x', close)
@@ -58,6 +58,7 @@ const props = withDefaults(
58
58
 
59
59
  const emit = defineEmits<{ change: [index: number] }>()
60
60
 
61
+ const rootEl = ref<HTMLElement>()
61
62
  const trackEl = ref<HTMLElement>()
62
63
  const itemEls = ref<HTMLElement[]>([])
63
64
  const activeIndex = ref(0)
@@ -251,11 +252,19 @@ onBeforeUnmount(() => {
251
252
  if (rafId) cancelAnimationFrame(rafId)
252
253
  })
253
254
 
254
- defineExpose({ next, prev, scrollToItem, scrollToPage })
255
+ defineExpose({
256
+ next,
257
+ prev,
258
+ scrollToItem,
259
+ scrollToPage,
260
+ /** Moves keyboard focus to the carousel, so the arrow keys move it */
261
+ focus: (options?: FocusOptions) => rootEl.value?.focus(options),
262
+ })
255
263
  </script>
256
264
 
257
265
  <template>
258
266
  <div
267
+ ref="rootEl"
259
268
  class="group relative overflow-hidden"
260
269
  tabindex="0"
261
270
  @keydown="onKeydown"
@@ -2,7 +2,9 @@
2
2
  /**
3
3
  * A loading placeholder shape — text, circular, rectangular, or rounded — with pulse or wave animation.
4
4
  */
5
- withDefaults(defineProps<{
5
+ import { computed } from 'vue'
6
+
7
+ const props = withDefaults(defineProps<{
6
8
  /** Skeleton shape */
7
9
  variant?: 'text' | 'circular' | 'rectangular' | 'rounded'
8
10
  /** CSS width (defaults to 100%, or 40px for circular) */
@@ -13,11 +15,24 @@ withDefaults(defineProps<{
13
15
  lines?: number
14
16
  /** Animation style */
15
17
  animation?: 'pulse' | 'wave' | 'none'
18
+ /**
19
+ * Corner radius: an M3 shape step (`none`, `xs` 4px, `sm` 8px, `md` 12px, `lg` 16px, `xl` 28px, `full`) or any CSS
20
+ * length, to match the card or thumbnail it stands in for. Defaults to the variant's (a Tailwind `rounded-*` class
21
+ * works too)
22
+ */
23
+ radius?: 'none' | 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'full' | (string & {})
16
24
  }>(), {
17
25
  variant: 'text',
18
26
  animation: 'pulse',
19
27
  lines: 1,
20
28
  })
29
+
30
+ const STEPS: Record<string, string> = { none: '0', full: '9999px' }
31
+ const borderRadius = computed(() => {
32
+ const r = props.radius
33
+ if (!r) return undefined
34
+ return STEPS[r] ?? (/^(xs|sm|md|lg|xl)$/.test(r) ? `var(--radius-${r})` : r)
35
+ })
21
36
  </script>
22
37
 
23
38
  <template>
@@ -28,25 +43,32 @@ withDefaults(defineProps<{
28
43
  :key="i"
29
44
  class="h-3.5 rounded-full bg-on-surface/10"
30
45
  :class="animation === 'pulse' ? 'animate-pulse' : animation === 'wave' ? 'skeleton-wave' : ''"
31
- :style="{ width: i === lines ? '60%' : (width ?? '100%') }"
46
+ :style="{ width: i === lines ? '60%' : (width ?? '100%'), borderRadius }"
32
47
  />
33
48
  </div>
34
49
 
35
50
  <!-- Single element -->
36
51
  <div
37
52
  v-else
38
- class="bg-on-surface/10"
53
+ class="m3-skeleton bg-on-surface/10"
39
54
  :class="[
40
- variant === 'circular' ? 'rounded-full' : variant === 'rounded' ? 'rounded-lg' : variant === 'text' ? 'rounded-full' : 'rounded-sm',
55
+ `m3-skeleton-${variant}`,
41
56
  animation === 'pulse' ? 'animate-pulse' : animation === 'wave' ? 'skeleton-wave' : '',
42
57
  ]"
43
- :style="{
44
- width: width ?? (variant === 'circular' ? '40px' : '100%'),
45
- height: height ?? (variant === 'circular' ? '40px' : variant === 'text' ? '14px' : '100px'),
46
- }"
58
+ :style="{ width, height, borderRadius }"
47
59
  />
48
60
  </template>
49
61
 
62
+ <style>
63
+ /* Default size and corners in the base layer, so a consumer's w-40, aspect-video or rounded-xl wins */
64
+ @layer base {
65
+ .m3-skeleton { width: 100%; height: 100px; border-radius: var(--radius-sm); }
66
+ .m3-skeleton-rounded { border-radius: var(--radius-lg); }
67
+ .m3-skeleton-text { height: 14px; border-radius: 9999px; }
68
+ .m3-skeleton-circular { width: 40px; height: 40px; border-radius: 9999px; }
69
+ }
70
+ </style>
71
+
50
72
  <style scoped>
51
73
  @keyframes skeleton-wave-move {
52
74
  0% { transform: translateX(-100%); }