@m3ui-vue/m3ui-vue 0.9.1 → 0.9.3

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 (139) hide show
  1. package/README.md +43 -0
  2. package/dist/API.md +266 -60
  3. package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
  4. package/dist/MIcon-DLOkQduI.js.map +1 -0
  5. package/dist/{MTextField-pJU1vFaR.js → MTextField-DKtgPymd.js} +422 -206
  6. package/dist/MTextField-DKtgPymd.js.map +1 -0
  7. package/dist/THIRD_PARTY_LICENSES.md +547 -0
  8. package/dist/api.json +1 -1
  9. package/dist/code-editor.js +2 -2
  10. package/dist/components/MBox.vue.d.ts +3 -3
  11. package/dist/components/MButton.vue.d.ts +4 -2
  12. package/dist/components/MButtonGroup.vue.d.ts +2 -0
  13. package/dist/components/MColorPicker.vue.d.ts +13 -1
  14. package/dist/components/MColorPickerModal.vue.d.ts +14 -2
  15. package/dist/components/MDragHandle.vue.d.ts +12 -0
  16. package/dist/components/MEmojiSelector.vue.d.ts +1 -1
  17. package/dist/components/MFab.vue.d.ts +5 -3
  18. package/dist/components/MFabMenu.vue.d.ts +1 -1
  19. package/dist/components/MIcon.vue.d.ts +3 -0
  20. package/dist/components/MIconButton.vue.d.ts +15 -1
  21. package/dist/components/MListItem.vue.d.ts +5 -5
  22. package/dist/components/MMenuItem.vue.d.ts +17 -4
  23. package/dist/components/MOverlay.vue.d.ts +1 -1
  24. package/dist/components/MScrollField.vue.d.ts +40 -0
  25. package/dist/components/MScrollable.vue.d.ts +9 -0
  26. package/dist/components/MSplitButton.vue.d.ts +2 -0
  27. package/dist/components/MSplitter.vue.d.ts +2 -2
  28. package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
  29. package/dist/components/MTabs.vue.d.ts +6 -0
  30. package/dist/components/MTimePickerModal.vue.d.ts +3 -0
  31. package/dist/components/MTimeScroll.vue.d.ts +22 -0
  32. package/dist/components/MToggleButton.vue.d.ts +2 -0
  33. package/dist/components/MTransition.vue.d.ts +34 -0
  34. package/dist/components/MTree.vue.d.ts +2 -2
  35. package/dist/components/MWindow.vue.d.ts +1 -1
  36. package/dist/components/_MColorPanel.vue.d.ts +18 -0
  37. package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
  38. package/dist/composables/_colorUtils.d.ts +34 -0
  39. package/dist/composables/_themeColor.d.ts +1 -0
  40. package/dist/composables/_useSpring.d.ts +17 -0
  41. package/dist/composables/dynamicColor.d.ts +18 -0
  42. package/dist/composables/useColorPalette.d.ts +27 -0
  43. package/dist/composables/useLocale.d.ts +16 -0
  44. package/dist/directives/vRipple.d.ts +16 -0
  45. package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
  46. package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
  47. package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
  48. package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
  49. package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
  50. package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
  51. package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
  52. package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
  53. package/dist/index.d.ts +12 -1
  54. package/dist/locales/index.js +112 -0
  55. package/dist/locales/index.js.map +1 -1
  56. package/dist/m3ui-vue.css +1 -1
  57. package/dist/m3ui.js +7443 -6150
  58. package/dist/m3ui.js.map +1 -1
  59. package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
  60. package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
  61. package/dist/plugin.d.ts +18 -0
  62. package/dist/rich-text-editor.js +22 -22
  63. package/dist/styles/palettes.css +546 -0
  64. package/dist/styles/theme.css +90 -0
  65. package/dist/styles.css +1 -1
  66. package/dist/terminal.js +1 -1
  67. package/dist/{useLocale-Drihe5G2.js → useLocale-Cn9MVIdw.js} +17 -1
  68. package/dist/useLocale-Cn9MVIdw.js.map +1 -0
  69. package/package.json +3 -2
  70. package/src/__tests__/MButtonGroup.test.ts +51 -0
  71. package/src/__tests__/MColorPicker.test.ts +141 -0
  72. package/src/__tests__/MDragHandle.test.ts +57 -0
  73. package/src/__tests__/MIconButton.test.ts +60 -0
  74. package/src/__tests__/MListItemShape.test.ts +76 -0
  75. package/src/__tests__/MMenuItem.test.ts +84 -0
  76. package/src/__tests__/MScrollField.test.ts +69 -0
  77. package/src/__tests__/MScrollable.test.ts +42 -0
  78. package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
  79. package/src/__tests__/MTabs.test.ts +39 -0
  80. package/src/__tests__/MTimePickerModal.test.ts +52 -0
  81. package/src/__tests__/MTimeScroll.test.ts +44 -0
  82. package/src/__tests__/MTransition.test.ts +27 -0
  83. package/src/__tests__/dynamicColor.test.ts +191 -0
  84. package/src/__tests__/vRipple.test.ts +92 -0
  85. package/src/components/MBox.vue +4 -2
  86. package/src/components/MButton.vue +4 -13
  87. package/src/components/MButtonGroup.vue +118 -44
  88. package/src/components/MColorPicker.vue +114 -210
  89. package/src/components/MColorPickerModal.vue +50 -251
  90. package/src/components/MDragHandle.vue +54 -0
  91. package/src/components/MFab.vue +8 -15
  92. package/src/components/MIcon.vue +4 -2
  93. package/src/components/MIconButton.vue +96 -24
  94. package/src/components/MList.vue +33 -3
  95. package/src/components/MListItem.vue +75 -5
  96. package/src/components/MMenuItem.vue +115 -13
  97. package/src/components/MScrollField.vue +310 -0
  98. package/src/components/MScrollable.vue +160 -5
  99. package/src/components/MSplitButton.vue +5 -12
  100. package/src/components/MSplitter.vue +33 -10
  101. package/src/components/MSwipeToDismiss.vue +247 -0
  102. package/src/components/MTabs.vue +16 -5
  103. package/src/components/MTimePickerModal.vue +48 -8
  104. package/src/components/MTimeScroll.vue +161 -0
  105. package/src/components/MToggleButton.vue +5 -12
  106. package/src/components/MTransition.vue +149 -0
  107. package/src/components/_MColorPanel.vue +478 -0
  108. package/src/composables/_carouselStrategy.ts +3 -0
  109. package/src/composables/_colorUtils.ts +107 -0
  110. package/src/composables/_themeColor.ts +33 -0
  111. package/src/composables/_useSpring.ts +91 -0
  112. package/src/composables/dynamicColor.ts +85 -0
  113. package/src/composables/useColorPalette.ts +171 -25
  114. package/src/composables/useFieldBg.ts +6 -0
  115. package/src/composables/useLocale.ts +34 -0
  116. package/src/data/emoji-names/emoji-names-de.ts +1 -0
  117. package/src/data/emoji-names/emoji-names-en.ts +1 -0
  118. package/src/data/emoji-names/emoji-names-es.ts +1 -0
  119. package/src/data/emoji-names/emoji-names-fr.ts +1 -0
  120. package/src/data/emoji-names/emoji-names-ja.ts +1 -0
  121. package/src/data/emoji-names/emoji-names-ko.ts +1 -0
  122. package/src/data/emoji-names/emoji-names-pt.ts +1 -0
  123. package/src/data/emoji-names/emoji-names-zh.ts +1 -0
  124. package/src/data/emojis.ts +1 -0
  125. package/src/directives/vRipple.ts +73 -0
  126. package/src/index.ts +14 -1
  127. package/src/locales/de.ts +16 -0
  128. package/src/locales/es.ts +16 -0
  129. package/src/locales/fr.ts +16 -0
  130. package/src/locales/ja.ts +16 -0
  131. package/src/locales/ko.ts +16 -0
  132. package/src/locales/pt.ts +16 -0
  133. package/src/locales/zh.ts +16 -0
  134. package/src/plugin.ts +30 -7
  135. package/src/styles/palettes.css +546 -0
  136. package/src/styles/theme.css +90 -0
  137. package/dist/MIcon-CaEooCmZ.js.map +0 -1
  138. package/dist/MTextField-pJU1vFaR.js.map +0 -1
  139. package/dist/useLocale-Drihe5G2.js.map +0 -1
@@ -0,0 +1,247 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * Content that can be swiped left or right to dismiss it, uncovering a background behind it (a port of
4
+ * Compose's `SwipeToDismissBox`), typically a list item with "archive" and "delete" behind. Once swiped away it
5
+ * stays there until you reset it (`v-model` back to `'settled'`, or `reset()`), so you decide what happens:
6
+ * remove the item, or undo.
7
+ *
8
+ * @slot default The content that moves
9
+ * @slot background What the swipe uncovers. Receives `{ direction, target, progress }`: the side being
10
+ * swiped (`'start-to-end'`, `'end-to-start'` or `'settled'`), the state it would settle in if released now,
11
+ * and how far it has moved (0 to 1)
12
+ * @event update:modelValue Emitted when it settles in a new state — powers v-model
13
+ * @event dismiss Emitted with the direction when the content is swiped away
14
+ */
15
+ import { computed, getCurrentInstance, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
16
+ import { fastOutSlowIn } from '../composables/_useSpring'
17
+
18
+ export type SwipeToDismissValue = 'settled' | 'start-to-end' | 'end-to-start'
19
+
20
+ const props = withDefaults(defineProps<{
21
+ /** State (v-model): `'settled'`, or dismissed towards `'start-to-end'` / `'end-to-start'`. Set it to animate there. */
22
+ modelValue?: SwipeToDismissValue
23
+ /** Allow dismissing by swiping in the reading direction (right in LTR) */
24
+ startToEnd?: boolean
25
+ /** Allow dismissing by swiping against the reading direction (left in LTR) */
26
+ endToStart?: boolean
27
+ /** Turns the swipe gesture off (setting v-model still works) */
28
+ disabled?: boolean
29
+ /** How far, in px, the content has to move before releasing dismisses it (SwipeToDismissBoxDefaults: 56dp) */
30
+ threshold?: number
31
+ }>(), {
32
+ modelValue: 'settled',
33
+ startToEnd: true,
34
+ endToStart: true,
35
+ disabled: false,
36
+ threshold: 56,
37
+ })
38
+
39
+ const emit = defineEmits<{
40
+ 'update:modelValue': [SwipeToDismissValue]
41
+ dismiss: [Exclude<SwipeToDismissValue, 'settled'>]
42
+ }>()
43
+
44
+ const vnodeProps = getCurrentInstance()?.vnode.props ?? {}
45
+ const controlled = 'onUpdate:modelValue' in vnodeProps
46
+ const rootEl = ref<HTMLElement>()
47
+ const contentEl = ref<HTMLElement>()
48
+ // Offset in px along the reading direction (positive = towards the end)
49
+ const offset = ref(0)
50
+ const width = ref(0)
51
+ const settled = ref<SwipeToDismissValue>(props.modelValue)
52
+ let rtl = false
53
+
54
+ const anchorOf = (v: SwipeToDismissValue) => (v === 'start-to-end' ? width.value : v === 'end-to-start' ? -width.value : 0)
55
+
56
+ const direction = computed<SwipeToDismissValue>(() =>
57
+ offset.value > 0 ? 'start-to-end' : offset.value < 0 ? 'end-to-start' : 'settled')
58
+ // targetValue without a fling: the closest anchor once past the threshold from where the drag started
59
+ const target = computed<SwipeToDismissValue>(() => {
60
+ if (settled.value !== 'settled') return settled.value
61
+ if (offset.value >= props.threshold && props.startToEnd) return 'start-to-end'
62
+ if (offset.value <= -props.threshold && props.endToStart) return 'end-to-start'
63
+ return 'settled'
64
+ })
65
+ const progress = computed(() => (width.value ? Math.min(1, Math.abs(offset.value) / width.value) : 0))
66
+
67
+ function write() {
68
+ if (contentEl.value) contentEl.value.style.transform = offset.value ? `translateX(${rtl ? -offset.value : offset.value}px)` : ''
69
+ }
70
+ watch(offset, write)
71
+
72
+ // ── Settling: AnchoredDraggableDefaults.SnapAnimationSpec is tween() (300ms, FastOutSlowIn) ─────
73
+ let raf = 0
74
+ function animateTo(value: SwipeToDismissValue) {
75
+ cancelAnimationFrame(raf)
76
+ width.value = rootEl.value?.offsetWidth ?? width.value
77
+ const from = offset.value
78
+ const to = anchorOf(value)
79
+ const start = performance.now()
80
+ const step = (now: number) => {
81
+ const t = Math.min(1, (now - start) / 300)
82
+ offset.value = from + (to - from) * fastOutSlowIn(t)
83
+ if (t < 1) raf = requestAnimationFrame(step)
84
+ else settle(value)
85
+ }
86
+ if (from === to) settle(value)
87
+ else raf = requestAnimationFrame(step)
88
+ }
89
+
90
+ function settle(value: SwipeToDismissValue) {
91
+ raf = 0
92
+ offset.value = anchorOf(value)
93
+ if (settled.value === value) return
94
+ settled.value = value
95
+ emit('update:modelValue', value)
96
+ if (value !== 'settled') emit('dismiss', value)
97
+ // With v-model, a parent that sets it straight back (inside @dismiss, say) leaves the prop unchanged, so
98
+ // the watcher below never fires: compare once the parent has updated
99
+ if (controlled) nextTick(() => { if (props.modelValue !== settled.value) animateTo(props.modelValue) })
100
+ }
101
+
102
+ watch(() => props.modelValue, (v) => { if (v !== settled.value) animateTo(v) })
103
+
104
+ // ── Gesture ─────────────────────────────────────────────────────────────────────────────────────
105
+ // Touch keeps vertical scrolling (touch-action: pan-y); a drag only starts once the pointer has moved
106
+ // sideways more than it has vertically.
107
+ const SLOP = 8
108
+ // AnchoredDraggableMinFlingVelocity
109
+ const FLING_VELOCITY = 125
110
+ let pointerId: number | null = null
111
+ let startX = 0
112
+ let startY = 0
113
+ let startOffset = 0
114
+ let dragging = false
115
+ let samples: { t: number; x: number }[] = []
116
+ let suppressClick = false
117
+
118
+ function onPointerDown(e: PointerEvent) {
119
+ // Gestures are off while dismissed, as in SwipeToDismissBox
120
+ if (props.disabled || settled.value !== 'settled' || e.button !== 0) return
121
+ pointerId = e.pointerId
122
+ startX = e.clientX
123
+ startY = e.clientY
124
+ startOffset = offset.value
125
+ dragging = false
126
+ window.addEventListener('pointermove', onPointerMove)
127
+ window.addEventListener('pointerup', onPointerUp)
128
+ window.addEventListener('pointercancel', onPointerUp)
129
+ }
130
+
131
+ function along(e: PointerEvent) {
132
+ return rtl ? startX - e.clientX : e.clientX - startX
133
+ }
134
+
135
+ function onPointerMove(e: PointerEvent) {
136
+ if (e.pointerId !== pointerId) return
137
+ const dx = e.clientX - startX
138
+ const dy = e.clientY - startY
139
+ if (!dragging) {
140
+ if (Math.abs(dy) > SLOP && Math.abs(dy) > Math.abs(dx)) return release()
141
+ if (Math.abs(dx) <= SLOP) return
142
+ dragging = true
143
+ cancelAnimationFrame(raf)
144
+ raf = 0
145
+ width.value = rootEl.value?.offsetWidth ?? 0
146
+ document.body.style.userSelect = 'none'
147
+ }
148
+ const min = props.endToStart ? -width.value : 0
149
+ const max = props.startToEnd ? width.value : 0
150
+ offset.value = Math.min(max, Math.max(min, startOffset + along(e)))
151
+ samples.push({ t: e.timeStamp, x: rtl ? -e.clientX : e.clientX })
152
+ samples = samples.filter((s) => e.timeStamp - s.t < 100)
153
+ }
154
+
155
+ function onPointerUp(e: PointerEvent) {
156
+ if (e.pointerId !== pointerId) return
157
+ if (!dragging) return release()
158
+ const velocity = releaseVelocity(e.timeStamp)
159
+ suppressClick = true
160
+ release()
161
+ animateTo(computeTarget(velocity))
162
+ }
163
+
164
+ // Like Compose's VelocityTracker: the last 100ms of movement, and no velocity at all if the pointer had
165
+ // stopped (AssumePointerMoveStoppedMilliseconds = 40) before it was released
166
+ function releaseVelocity(upTime: number) {
167
+ const recent = samples.filter((s) => upTime - s.t < 100)
168
+ const first = recent[0]
169
+ const last = recent[recent.length - 1]
170
+ if (!first || !last || upTime - last.t > 40) return 0
171
+ const dt = (last.t - first.t) / 1000
172
+ return dt > 0 ? (last.x - first.x) / dt : 0
173
+ }
174
+
175
+ // AnchoredDraggable's computeTarget(): at rest the closest anchor; a fast fling goes to the next anchor in
176
+ // its direction; otherwise the next anchor once past the positional threshold from the previous one.
177
+ function computeTarget(velocity: number): SwipeToDismissValue {
178
+ const anchors: [SwipeToDismissValue, number][] = [['settled', 0]]
179
+ if (props.startToEnd) anchors.push(['start-to-end', width.value])
180
+ if (props.endToStart) anchors.push(['end-to-start', -width.value])
181
+ anchors.sort((a, b) => a[1] - b[1])
182
+ const x = offset.value
183
+ if (velocity === 0) {
184
+ return anchors.reduce((best, a) => (Math.abs(a[1] - x) < Math.abs(best[1] - x) ? a : best))[0]
185
+ }
186
+ const forward = velocity > 0
187
+ const below = [...anchors].reverse().find((a) => a[1] <= x) ?? anchors[0]!
188
+ const above = anchors.find((a) => a[1] >= x) ?? anchors[anchors.length - 1]!
189
+ if (Math.abs(velocity) >= FLING_VELOCITY) return (forward ? above : below)[0]
190
+ const from = forward ? below : above
191
+ return Math.abs(x - from[1]) >= props.threshold ? (forward ? above : below)[0] : from[0]
192
+ }
193
+
194
+ function release() {
195
+ pointerId = null
196
+ dragging = false
197
+ samples = []
198
+ document.body.style.userSelect = ''
199
+ window.removeEventListener('pointermove', onPointerMove)
200
+ window.removeEventListener('pointerup', onPointerUp)
201
+ window.removeEventListener('pointercancel', onPointerUp)
202
+ }
203
+
204
+ // A drag that ends over a button inside the content shouldn't also click it
205
+ function onClickCapture(e: MouseEvent) {
206
+ if (!suppressClick) return
207
+ suppressClick = false
208
+ e.stopPropagation()
209
+ e.preventDefault()
210
+ }
211
+
212
+ let resizeObserver: ResizeObserver | undefined
213
+ onMounted(() => {
214
+ rtl = rootEl.value ? getComputedStyle(rootEl.value).direction === 'rtl' : false
215
+ width.value = rootEl.value?.offsetWidth ?? 0
216
+ offset.value = anchorOf(settled.value)
217
+ write()
218
+ resizeObserver = new ResizeObserver(() => {
219
+ width.value = rootEl.value?.offsetWidth ?? 0
220
+ if (!dragging && !raf) offset.value = anchorOf(settled.value)
221
+ })
222
+ if (rootEl.value) resizeObserver.observe(rootEl.value)
223
+ })
224
+ onUnmounted(() => {
225
+ cancelAnimationFrame(raf)
226
+ release()
227
+ resizeObserver?.disconnect()
228
+ })
229
+
230
+ defineExpose({
231
+ /** Animates back to `'settled'` */
232
+ reset: () => animateTo('settled'),
233
+ /** Animates away in the given direction */
234
+ dismiss: (dir: Exclude<SwipeToDismissValue, 'settled'>) => animateTo(dir),
235
+ })
236
+ </script>
237
+
238
+ <template>
239
+ <div ref="rootEl" class="relative touch-pan-y overflow-hidden" @pointerdown="onPointerDown" @click.capture="onClickCapture">
240
+ <div class="absolute inset-0 flex">
241
+ <slot name="background" :direction="direction" :target="target" :progress="progress" />
242
+ </div>
243
+ <div ref="contentEl" class="relative">
244
+ <slot />
245
+ </div>
246
+ </div>
247
+ </template>
@@ -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 flex-col items-center justify-center gap-1 px-6 text-title-small transition-colors duration-150 focus-visible:outline-none"
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
- tab.icon ? 'h-16 pb-1.5' : 'h-12 pb-1.5',
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 h-12 items-center justify-center gap-2 px-6 text-title-small transition-colors duration-150 focus-visible:outline-none"
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 and a keyboard input mode. Supports AM/PM toggle and 24h
4
- * format — the sibling of MTimePicker, a fully separate component rather than a shared internal.
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
- selectedMinute.value = m
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 = 'dial'
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="inputMode === 'dial' ? 'keyboard' : 'schedule'"
439
- :label="inputMode === 'dial' ? 'Switch to keyboard' : 'Switch to dial'"
440
- @click="inputMode = inputMode === 'dial' ? 'input' : 'dial'"
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>
@@ -0,0 +1,161 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * M3 Expressive's time scroll picker (a port of Compose's `TimeScroll`): an hour wheel and a minute wheel
4
+ * side by side, plus an AM/PM toggle in 12-hour mode. It updates as the wheels turn; put it in a dialog or a
5
+ * form for the confirm step.
6
+ *
7
+ * @event update:modelValue Emitted with the time as HH:MM (24-hour) whenever a wheel or AM/PM changes
8
+ */
9
+ import { computed, ref, watch } from 'vue'
10
+ import MScrollField from './MScrollField.vue'
11
+ import { useLocale } from '../composables/useLocale'
12
+ import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
13
+
14
+ const props = withDefaults(defineProps<{
15
+ /** Selected time in HH:MM, 24-hour (v-model); null shows 12:00 AM (00:00 in 24-hour mode) */
16
+ modelValue: string | null
17
+ /** 24-hour wheel (00–23) instead of 1–12 with AM/PM */
18
+ use24h?: boolean
19
+ /** Minute increment step; the minute wheel shows only multiples of it */
20
+ minuteStep?: number
21
+ /** Disables the wheels and the AM/PM toggle */
22
+ disabled?: boolean
23
+ }>(), {
24
+ modelValue: null,
25
+ use24h: false,
26
+ minuteStep: 1,
27
+ disabled: false,
28
+ })
29
+
30
+ const emit = defineEmits<{ 'update:modelValue': [string] }>()
31
+ const locale = useLocale()
32
+
33
+ function parse(t: string | null) {
34
+ const [h, m] = (t ?? '').split(':').map(Number)
35
+ return { h: Number.isFinite(h) ? Math.min(23, Math.max(0, h!)) : 0, m: Number.isFinite(m) ? Math.min(59, Math.max(0, m!)) : 0 }
36
+ }
37
+
38
+ const step = computed(() => Math.min(30, Math.max(1, Math.floor(props.minuteStep))))
39
+ const hour = ref(0)
40
+ const minute = ref(0)
41
+
42
+ function sync() {
43
+ const { h, m } = parse(props.modelValue)
44
+ hour.value = h
45
+ minute.value = Math.floor(m / step.value) * step.value
46
+ }
47
+ sync()
48
+ watch(() => [props.modelValue, step.value], sync)
49
+
50
+ const isPm = computed(() => hour.value >= 12)
51
+
52
+ // TimeScrollImpl's mapping: in 12-hour mode index 0..11 shows 1..12, and 12 o'clock is the last item
53
+ const hourCount = computed(() => (props.use24h ? 24 : 12))
54
+ const hourIndex = computed(() => (props.use24h ? hour.value : (hour.value % 12 || 12) - 1))
55
+ const minuteIndex = computed(() => Math.round(minute.value / step.value))
56
+
57
+ function commit(h: number, m: number) {
58
+ hour.value = h
59
+ minute.value = m
60
+ const value = `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`
61
+ if (value !== props.modelValue) emit('update:modelValue', value)
62
+ }
63
+
64
+ function onHour(index: number) {
65
+ const h = props.use24h ? index : ((index + 1) % 12) + (isPm.value ? 12 : 0)
66
+ commit(h, minute.value)
67
+ }
68
+ function onMinute(index: number) {
69
+ commit(hour.value, index * step.value)
70
+ }
71
+ function setPm(pm: boolean) {
72
+ if (props.disabled || pm === isPm.value) return
73
+ commit(hour.value + (pm ? 12 : -12), minute.value)
74
+ }
75
+
76
+ const pad = (n: number) => String(n).padStart(2, '0')
77
+ const formatHour = (i: number) => pad(props.use24h ? i : i + 1)
78
+ const formatMinute = (i: number) => pad(i * step.value)
79
+
80
+ // AM/PM in the app language, from Intl (no locale keys: every language already has them there)
81
+ const periods = computed(() => {
82
+ const label = (h: number) => {
83
+ try {
84
+ return new Intl.DateTimeFormat(locale.lang, { hour: 'numeric', hour12: true })
85
+ .formatToParts(new Date(2000, 0, 1, h))
86
+ .find((p) => p.type === 'dayPeriod')?.value ?? (h < 12 ? 'AM' : 'PM')
87
+ } catch {
88
+ return h < 12 ? 'AM' : 'PM'
89
+ }
90
+ }
91
+ return [label(9), label(21)] as const
92
+ })
93
+
94
+ // The period toggle is two ToggleButtons (TimePicker.kt's ToggleItem): a circle that becomes a 12dp
95
+ // rounded square when checked or pressed, on the ToggleButton's FastSpatial spring.
96
+ const periodEls: (HTMLElement | null)[] = [null, null]
97
+ const pressedPeriod = ref(-1)
98
+ const SIZE = 56
99
+ useSpring(
100
+ () => [0, 1].map((i) => (pressedPeriod.value === i || (i === 1) === isPm.value ? 12 : SIZE / 2)),
101
+ (v) => periodEls.forEach((el, i) => { if (el) el.style.borderRadius = `${v[i]}px` }),
102
+ FAST_SPATIAL,
103
+ )
104
+ </script>
105
+
106
+ <template>
107
+ <div class="inline-flex items-start select-none" :aria-disabled="disabled || undefined">
108
+ <MScrollField
109
+ :model-value="hourIndex"
110
+ :count="hourCount"
111
+ :height="120"
112
+ :format="formatHour"
113
+ :label="locale.timeHourSelection"
114
+ :disabled="disabled"
115
+ class="w-[100px]"
116
+ @update:model-value="onHour"
117
+ />
118
+ <span
119
+ aria-hidden="true"
120
+ class="flex h-[120px] w-4 items-center justify-center pb-2 text-display-large text-on-surface"
121
+ :class="disabled ? 'opacity-38' : ''"
122
+ >:</span>
123
+ <MScrollField
124
+ :model-value="minuteIndex"
125
+ :count="Math.ceil(60 / step)"
126
+ :height="120"
127
+ :format="formatMinute"
128
+ :label="locale.timeMinuteSelection"
129
+ :disabled="disabled"
130
+ class="w-[100px]"
131
+ @update:model-value="onMinute"
132
+ />
133
+ <div
134
+ v-if="!use24h"
135
+ role="radiogroup"
136
+ :aria-label="locale.timePeriodToggle"
137
+ class="ml-2 flex h-[120px] w-14 flex-col gap-2"
138
+ >
139
+ <button
140
+ v-for="(text, i) in periods"
141
+ :key="i"
142
+ :ref="(el) => { periodEls[i] = el as HTMLElement | null }"
143
+ type="button"
144
+ role="radio"
145
+ :aria-checked="(i === 1) === isPm"
146
+ :disabled="disabled"
147
+ class="relative flex h-14 w-14 cursor-pointer items-center justify-center overflow-hidden text-title-medium transition-colors duration-150 disabled:cursor-default disabled:opacity-38 before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:content-[''] enabled:hover:before:opacity-[0.08] enabled:active:before:opacity-[0.12]"
148
+ :class="(i === 1) === isPm
149
+ ? 'bg-primary-container font-bold text-on-primary-container'
150
+ : 'bg-surface-container-lowest text-on-surface-variant'"
151
+ @pointerdown="pressedPeriod = i"
152
+ @pointerup="pressedPeriod = -1"
153
+ @pointerleave="pressedPeriod = -1"
154
+ @pointercancel="pressedPeriod = -1"
155
+ @click="setPm(i === 1)"
156
+ >
157
+ {{ text }}
158
+ </button>
159
+ </div>
160
+ </div>
161
+ </template>
@@ -9,6 +9,7 @@
9
9
  */
10
10
  import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
11
11
  import MIcon from './MIcon.vue'
12
+ import { vRipple } from '../directives/vRipple'
12
13
 
13
14
  const props = withDefaults(
14
15
  defineProps<{
@@ -22,6 +23,8 @@ const props = withDefaults(
22
23
  icon?: string
23
24
  /** Same 5-tier expressive sizing as MButton */
24
25
  size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
26
+ /** Any CSS color for the press ripple; defaults to the button's content color */
27
+ rippleColor?: string
25
28
  }>(),
26
29
  {
27
30
  variant: 'filled',
@@ -106,23 +109,12 @@ const disabledContainerClasses = computed(() => {
106
109
  const rootEl = ref<HTMLElement | null>(null)
107
110
  const pressed = ref(false)
108
111
 
109
- function onPointerDown(e: PointerEvent) {
112
+ function onPointerDown() {
110
113
  if (props.disabled) return
111
114
  pressed.value = true
112
- createRipple(e)
113
115
  }
114
116
  function onPointerUp() { pressed.value = false }
115
117
 
116
- function createRipple(event: PointerEvent) {
117
- const button = event.currentTarget as HTMLElement
118
- const rect = button.getBoundingClientRect()
119
- const d = Math.max(rect.width, rect.height) * 2
120
- const el = document.createElement('span')
121
- el.className = 'm3-ripple'
122
- 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`
123
- button.appendChild(el)
124
- el.addEventListener('animationend', () => el.remove(), { once: true })
125
- }
126
118
 
127
119
  function toggle() {
128
120
  if (props.disabled) return
@@ -188,6 +180,7 @@ onUnmounted(() => cancelAnimationFrame(rafId))
188
180
  :aria-pressed="checked"
189
181
  :disabled="disabled"
190
182
  :class="[base, sizeClasses, containerClasses, disabledContainerClasses]"
183
+ v-ripple="{ disabled, color: rippleColor }"
191
184
  @pointerdown="onPointerDown"
192
185
  @pointerup="onPointerUp"
193
186
  @pointerleave="onPointerUp"