@m3ui-vue/m3ui-vue 0.7.1 → 0.8.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 (118) hide show
  1. package/README.md +14 -6
  2. package/dist/{MMenuItem-xQ1x6-DH.js → MMenuItem-CDWfeU4F.js} +331 -252
  3. package/dist/MMenuItem-CDWfeU4F.js.map +1 -0
  4. package/dist/code-editor.d.ts +1 -0
  5. package/dist/code-editor.js +22 -7
  6. package/dist/code-editor.js.map +1 -1
  7. package/dist/components/MButton.vue.d.ts +7 -0
  8. package/dist/components/MCalendar.vue.d.ts +0 -1
  9. package/dist/components/MCard.vue.d.ts +2 -0
  10. package/dist/components/MCarousel.vue.d.ts +12 -14
  11. package/dist/components/MChatBubble.vue.d.ts +0 -1
  12. package/dist/components/MCircleProgressBar.vue.d.ts +0 -1
  13. package/dist/components/MCodeEditor.vue.d.ts +1 -1
  14. package/dist/components/MConfirmDialog.vue.d.ts +3 -0
  15. package/dist/components/MDatePicker.vue.d.ts +1 -3
  16. package/dist/components/MDatePickerModal.vue.d.ts +0 -1
  17. package/dist/components/MDateRangePicker.vue.d.ts +1 -3
  18. package/dist/components/MDateRangePickerModal.vue.d.ts +0 -1
  19. package/dist/components/MDialog.vue.d.ts +23 -7
  20. package/dist/components/MFab.vue.d.ts +2 -2
  21. package/dist/components/MKanban.vue.d.ts +1 -0
  22. package/dist/components/MListItem.vue.d.ts +11 -6
  23. package/dist/components/MNavigationRail.vue.d.ts +17 -1
  24. package/dist/components/MScheduler.vue.d.ts +0 -1
  25. package/dist/components/MSelect.vue.d.ts +1 -0
  26. package/dist/components/MShape.vue.d.ts +51 -0
  27. package/dist/components/MShortNavigationBar.vue.d.ts +34 -0
  28. package/dist/components/MSimpleCarousel.vue.d.ts +45 -0
  29. package/dist/components/MSwitch.vue.d.ts +8 -0
  30. package/dist/components/MTabs.vue.d.ts +3 -0
  31. package/dist/components/MToggleButton.vue.d.ts +29 -0
  32. package/dist/components/MTree.vue.d.ts +0 -1
  33. package/dist/components/MTreeTable.vue.d.ts +1 -0
  34. package/dist/index.d.ts +9 -1
  35. package/dist/m3ui-vue.css +1 -1
  36. package/dist/m3ui.js +4387 -2525
  37. package/dist/m3ui.js.map +1 -1
  38. package/dist/rich-text-editor.js +1 -1
  39. package/dist/styles/palettes.css +659 -0
  40. package/dist/styles/theme.css +1 -0
  41. package/dist/styles.css +1 -1
  42. package/package.json +16 -1
  43. package/src/__tests__/MCarousel.test.ts +33 -0
  44. package/src/__tests__/MShape.test.ts +36 -0
  45. package/src/__tests__/MToggleButton.test.ts +27 -0
  46. package/src/__tests__/useColorPalette.test.ts +2 -2
  47. package/src/code-editor.ts +1 -0
  48. package/src/components/MAutocomplete.vue +40 -27
  49. package/src/components/MBadge.vue +1 -1
  50. package/src/components/MBottomSheet.vue +4 -4
  51. package/src/components/MButton.vue +51 -21
  52. package/src/components/MButtonGroup.vue +2 -2
  53. package/src/components/MCalendar.vue +9 -5
  54. package/src/components/MCard.vue +76 -11
  55. package/src/components/MCarousel.vue +123 -173
  56. package/src/components/MChatBubble.vue +0 -1
  57. package/src/components/MCheckbox.vue +58 -13
  58. package/src/components/MChip.vue +26 -6
  59. package/src/components/MCircleProgressBar.vue +7 -4
  60. package/src/components/MCodeEditor.vue +60 -9
  61. package/src/components/MColorPicker.vue +9 -8
  62. package/src/components/MColorPickerModal.vue +2 -2
  63. package/src/components/MCommandPalette.vue +1 -1
  64. package/src/components/MConfirmDialog.vue +4 -0
  65. package/src/components/MContextMenu.vue +27 -6
  66. package/src/components/MDatePicker.vue +23 -20
  67. package/src/components/MDatePickerModal.vue +14 -9
  68. package/src/components/MDateRangePicker.vue +24 -21
  69. package/src/components/MDateRangePickerModal.vue +12 -7
  70. package/src/components/MDialog.vue +103 -12
  71. package/src/components/MFab.vue +10 -7
  72. package/src/components/MFabMenu.vue +1 -1
  73. package/src/components/MIconButton.vue +41 -19
  74. package/src/components/MKanban.vue +5 -1
  75. package/src/components/MListItem.vue +35 -17
  76. package/src/components/MLoadingIndicator.vue +14 -7
  77. package/src/components/MMaskField.vue +14 -6
  78. package/src/components/MMenu.vue +32 -7
  79. package/src/components/MMenuItem.vue +2 -2
  80. package/src/components/MMultiAutocomplete.vue +46 -27
  81. package/src/components/MMultiSelect.vue +45 -23
  82. package/src/components/MNavigationBar.vue +5 -10
  83. package/src/components/MNavigationDrawer.vue +10 -9
  84. package/src/components/MNavigationRail.vue +335 -22
  85. package/src/components/MNumberField.vue +14 -6
  86. package/src/components/MOverlay.vue +1 -1
  87. package/src/components/MPinInput.vue +7 -4
  88. package/src/components/MProgressBar.vue +16 -10
  89. package/src/components/MRadio.vue +54 -12
  90. package/src/components/MScheduler.vue +10 -6
  91. package/src/components/MSearchBar.vue +8 -3
  92. package/src/components/MSegmentedButton.vue +14 -9
  93. package/src/components/MSelect.vue +49 -33
  94. package/src/components/MShape.vue +107 -0
  95. package/src/components/MShortNavigationBar.vue +113 -0
  96. package/src/components/MSideSheet.vue +1 -1
  97. package/src/components/MSimpleCarousel.vue +325 -0
  98. package/src/components/MSnackbar.vue +4 -4
  99. package/src/components/MSplitButton.vue +32 -17
  100. package/src/components/MSpotlightSearch.vue +1 -1
  101. package/src/components/MSwitch.vue +96 -18
  102. package/src/components/MTabs.vue +16 -12
  103. package/src/components/MTagInput.vue +33 -22
  104. package/src/components/MTextField.vue +14 -6
  105. package/src/components/MTimePicker.vue +9 -9
  106. package/src/components/MTimePickerModal.vue +16 -16
  107. package/src/components/MToggleButton.vue +188 -0
  108. package/src/components/MToolbar.vue +5 -3
  109. package/src/components/MTooltip.vue +4 -4
  110. package/src/components/MTopAppBar.vue +19 -7
  111. package/src/components/MTour.vue +1 -1
  112. package/src/components/MTree.vue +4 -2
  113. package/src/components/MTreeTable.vue +5 -1
  114. package/src/composables/useColorPalette.ts +10 -0
  115. package/src/index.ts +9 -1
  116. package/src/styles/palettes.css +659 -0
  117. package/src/styles/theme.css +1 -0
  118. package/dist/MMenuItem-xQ1x6-DH.js.map +0 -1
@@ -0,0 +1,325 @@
1
+ <script setup lang="ts">
2
+ import { ref, computed, onMounted, onBeforeUnmount, watch, nextTick } from 'vue'
3
+ import MIcon from './MIcon.vue'
4
+
5
+ export interface SimpleCarouselItem {
6
+ src: string
7
+ alt?: string
8
+ label?: string
9
+ supportingText?: string
10
+ ratio?: number
11
+ }
12
+
13
+ const props = withDefaults(
14
+ defineProps<{
15
+ items: SimpleCarouselItem[]
16
+ layout?: 'hero' | 'multi-browse' | 'uncontained'
17
+ height?: string
18
+ showArrows?: boolean
19
+ showIndicators?: boolean
20
+ autoplay?: boolean
21
+ interval?: number
22
+ gap?: number
23
+ visibleItems?: number
24
+ animated?: boolean
25
+ }>(),
26
+ {
27
+ layout: 'hero',
28
+ height: '320px',
29
+ showArrows: true,
30
+ showIndicators: true,
31
+ autoplay: false,
32
+ interval: 5000,
33
+ gap: 8,
34
+ visibleItems: 3,
35
+ animated: false,
36
+ },
37
+ )
38
+
39
+ const emit = defineEmits<{ change: [index: number] }>()
40
+
41
+ const trackEl = ref<HTMLElement>()
42
+ const itemEls = ref<HTMLElement[]>([])
43
+ const activeIndex = ref(0)
44
+ const scrollPos = ref(0)
45
+ const isPageBased = computed(() => props.layout === 'multi-browse' || props.layout === 'uncontained')
46
+
47
+ const totalPages = computed(() => {
48
+ if (!isPageBased.value) return props.items.length
49
+ if (!trackEl.value) return 1
50
+ const track = trackEl.value
51
+ return Math.max(1, Math.ceil(track.scrollWidth / track.clientWidth))
52
+ })
53
+
54
+ const activePage = computed(() => {
55
+ if (!isPageBased.value) return activeIndex.value
56
+ if (!trackEl.value) return 0
57
+ const track = trackEl.value
58
+ if (track.scrollWidth <= track.clientWidth) return 0
59
+ const _ = scrollPos.value
60
+ return Math.round(track.scrollLeft / track.clientWidth)
61
+ })
62
+ const itemTransforms = ref<string[]>([])
63
+ const imageTransforms = ref<string[]>([])
64
+ let autoTimer: ReturnType<typeof setInterval> | null = null
65
+ let rafId = 0
66
+ let scrollTimeout: ReturnType<typeof setTimeout> | null = null
67
+
68
+ function setItemRef(el: any, i: number) {
69
+ if (el) itemEls.value[i] = el as HTMLElement
70
+ }
71
+
72
+ // ── Scroll handling (only transforms, never layout) ────────────
73
+ function onScroll() {
74
+ if (rafId) return
75
+ rafId = requestAnimationFrame(() => {
76
+ rafId = 0
77
+ updateTransforms()
78
+ })
79
+
80
+ if (scrollTimeout) clearTimeout(scrollTimeout)
81
+ }
82
+
83
+ function updateTransforms() {
84
+ if (!trackEl.value) return
85
+ const track = trackEl.value
86
+ scrollPos.value = track.scrollLeft
87
+ const trackRect = track.getBoundingClientRect()
88
+ const trackW = trackRect.width
89
+ const centerX = trackRect.left + trackW / 2
90
+ const transforms: string[] = []
91
+ const imgTransforms: string[] = []
92
+ let closest = 0
93
+ let closestDist = Infinity
94
+
95
+ const refX = props.layout === 'multi-browse' ? trackRect.left : centerX
96
+
97
+ for (let i = 0; i < itemEls.value.length; i++) {
98
+ const el = itemEls.value[i]
99
+ if (!el) { transforms.push(''); imgTransforms.push(''); continue }
100
+ const rect = el.getBoundingClientRect()
101
+ const itemCenterX = rect.left + rect.width / 2
102
+ const dist = props.layout === 'multi-browse'
103
+ ? Math.abs(rect.left - refX)
104
+ : Math.abs(itemCenterX - centerX)
105
+ const norm = Math.min(dist / (trackW * 0.5), 1)
106
+
107
+ if (props.layout === 'hero') {
108
+ imgTransforms.push(`translateX(${(itemCenterX - centerX) * -0.08}px) scale(1.1)`)
109
+ transforms.push('')
110
+ } else if (props.layout === 'uncontained' && props.animated) {
111
+ const s = 1 - norm * 0.12
112
+ transforms.push(`scale(${s})`)
113
+ imgTransforms.push('')
114
+ } else {
115
+ transforms.push('')
116
+ imgTransforms.push('')
117
+ }
118
+
119
+ if (dist < closestDist) {
120
+ closestDist = dist
121
+ closest = i
122
+ }
123
+ }
124
+
125
+ itemTransforms.value = transforms
126
+ imageTransforms.value = imgTransforms
127
+
128
+ if (closest !== activeIndex.value) {
129
+ activeIndex.value = closest
130
+ emit('change', closest)
131
+ }
132
+ }
133
+
134
+ // ── Fixed item widths (never change during scroll) ─────────────
135
+ function itemWidth(i: number) {
136
+ switch (props.layout) {
137
+ case 'hero':
138
+ return `calc(100% - 48px)`
139
+ case 'multi-browse':
140
+ return `calc(${100 / props.visibleItems}% - ${props.gap * (props.visibleItems - 1) / props.visibleItems}px)`
141
+ case 'uncontained':
142
+ return `${(props.items[i]?.ratio ?? 1) * 260}px`
143
+ default:
144
+ return '80%'
145
+ }
146
+ }
147
+
148
+ function itemStyle(i: number) {
149
+ const style: Record<string, string> = {
150
+ flexShrink: '0',
151
+ width: itemWidth(i),
152
+ }
153
+ const t = itemTransforms.value[i]
154
+ if (t) {
155
+ style.transform = t
156
+ style.transition = 'transform 120ms ease-out'
157
+ }
158
+ return style
159
+ }
160
+
161
+ function imgStyle(i: number) {
162
+ const t = imageTransforms.value[i]
163
+ if (!t) return {}
164
+ return { transform: t }
165
+ }
166
+
167
+ // ── Navigation ─────────────────────────────────────────────────
168
+ function scrollToItem(index: number) {
169
+ const el = itemEls.value[index]
170
+ if (!el || !trackEl.value) return
171
+ const track = trackEl.value
172
+ const scrollLeft = el.offsetLeft - (track.clientWidth - el.offsetWidth) / 2
173
+ track.scrollTo({ left: scrollLeft, behavior: 'smooth' })
174
+ }
175
+
176
+ function scrollToPage(page: number) {
177
+ if (!trackEl.value) return
178
+ const track = trackEl.value
179
+ track.scrollTo({ left: page * track.clientWidth, behavior: 'smooth' })
180
+ }
181
+
182
+ function next() {
183
+ if (isPageBased.value) {
184
+ if (!trackEl.value) return
185
+ trackEl.value.scrollBy({ left: trackEl.value.clientWidth, behavior: 'smooth' })
186
+ } else {
187
+ const i = activeIndex.value < props.items.length - 1 ? activeIndex.value + 1 : 0
188
+ scrollToItem(i)
189
+ }
190
+ }
191
+
192
+ function prev() {
193
+ if (isPageBased.value) {
194
+ if (!trackEl.value) return
195
+ trackEl.value.scrollBy({ left: -trackEl.value.clientWidth, behavior: 'smooth' })
196
+ } else {
197
+ const i = activeIndex.value > 0 ? activeIndex.value - 1 : props.items.length - 1
198
+ scrollToItem(i)
199
+ }
200
+ }
201
+
202
+ function startAutoplay() {
203
+ stopAutoplay()
204
+ if (props.autoplay && props.items.length > 1) {
205
+ autoTimer = setInterval(next, props.interval)
206
+ }
207
+ }
208
+
209
+ function stopAutoplay() {
210
+ if (autoTimer) { clearInterval(autoTimer); autoTimer = null }
211
+ }
212
+
213
+ function onKeydown(e: KeyboardEvent) {
214
+ if (e.key === 'ArrowRight') next()
215
+ else if (e.key === 'ArrowLeft') prev()
216
+ }
217
+
218
+ const trackPadding = computed(() => {
219
+ if (props.layout === 'hero') return '0 24px'
220
+ if (props.layout === 'uncontained') return '0 24px'
221
+ return '0'
222
+ })
223
+
224
+ watch(() => props.autoplay, startAutoplay)
225
+ onMounted(() => {
226
+ startAutoplay()
227
+ nextTick(() => updateTransforms())
228
+ })
229
+ onBeforeUnmount(() => {
230
+ stopAutoplay()
231
+ if (rafId) cancelAnimationFrame(rafId)
232
+ })
233
+
234
+ defineExpose({ next, prev, scrollToItem, scrollToPage })
235
+ </script>
236
+
237
+ <template>
238
+ <div
239
+ class="group relative overflow-hidden"
240
+ tabindex="0"
241
+ @keydown="onKeydown"
242
+ @mouseenter="stopAutoplay"
243
+ @mouseleave="startAutoplay"
244
+ >
245
+ <div
246
+ ref="trackEl"
247
+ class="carousel-track flex overflow-x-auto"
248
+ :class="layout === 'multi-browse' ? 'snap-start' : 'snap-center'"
249
+ :style="{ height, gap: `${gap}px`, padding: trackPadding }"
250
+ @scroll.passive="onScroll"
251
+ >
252
+ <div
253
+ v-for="(item, i) in items"
254
+ :key="i"
255
+ :ref="(el) => setItemRef(el, i)"
256
+ class="relative overflow-hidden rounded-2xl"
257
+ :style="itemStyle(i)"
258
+ >
259
+ <img
260
+ :src="item.src"
261
+ :alt="item.alt ?? item.label ?? ''"
262
+ class="pointer-events-none h-full w-full object-cover"
263
+ :style="imgStyle(i)"
264
+ />
265
+
266
+ <div
267
+ v-if="item.label || item.supportingText"
268
+ class="absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/70 via-black/30 to-transparent px-5 pb-4 pt-12"
269
+ >
270
+ <p v-if="item.label" class="text-title-medium font-medium text-white">{{ item.label }}</p>
271
+ <p v-if="item.supportingText" class="mt-0.5 text-body-small text-white/80">{{ item.supportingText }}</p>
272
+ </div>
273
+ </div>
274
+ </div>
275
+
276
+ <template v-if="showArrows && items.length > 1">
277
+ <button
278
+ type="button"
279
+ class="absolute left-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-surface/80 text-on-surface shadow-elevation-1 opacity-0 backdrop-blur-sm transition-all duration-200 hover:bg-surface hover:shadow-elevation-2 group-hover:opacity-100"
280
+ @click="prev"
281
+ >
282
+ <MIcon name="chevron_left" :size="24" />
283
+ </button>
284
+ <button
285
+ type="button"
286
+ class="absolute right-3 top-1/2 z-10 flex h-10 w-10 -translate-y-1/2 cursor-pointer items-center justify-center rounded-full bg-surface/80 text-on-surface shadow-elevation-1 opacity-0 backdrop-blur-sm transition-all duration-200 hover:bg-surface hover:shadow-elevation-2 group-hover:opacity-100"
287
+ @click="next"
288
+ >
289
+ <MIcon name="chevron_right" :size="24" />
290
+ </button>
291
+ </template>
292
+
293
+ </div>
294
+
295
+ <div
296
+ v-if="showIndicators && totalPages > 1"
297
+ class="flex justify-center gap-1.5 pt-3"
298
+ >
299
+ <button
300
+ v-for="p in totalPages"
301
+ :key="p"
302
+ type="button"
303
+ class="h-2 cursor-pointer rounded-full transition-all duration-300"
304
+ :class="(p - 1) === activePage ? 'w-5 bg-on-surface' : 'w-2 bg-on-surface/30 hover:bg-on-surface/50'"
305
+ @click="isPageBased ? scrollToPage(p - 1) : scrollToItem(p - 1)"
306
+ />
307
+ </div>
308
+ </template>
309
+
310
+ <style scoped>
311
+ .carousel-track {
312
+ scroll-snap-type: x mandatory;
313
+ -webkit-overflow-scrolling: touch;
314
+ scrollbar-width: none;
315
+ }
316
+ .carousel-track::-webkit-scrollbar {
317
+ display: none;
318
+ }
319
+ .snap-center > * {
320
+ scroll-snap-align: center;
321
+ }
322
+ .snap-start > * {
323
+ scroll-snap-align: start;
324
+ }
325
+ </style>
@@ -103,15 +103,15 @@ const getVariantStyle = (variant: string): VariantStyle =>
103
103
  </Transition>
104
104
 
105
105
  <div
106
- class="toast-inner pointer-events-auto relative flex items-center gap-3 overflow-hidden rounded-2xl px-4 py-4 shadow-elevation-2"
106
+ class="toast-inner pointer-events-auto relative flex min-h-12 items-center gap-3 overflow-hidden rounded px-4 py-4 shadow-elevation-3"
107
107
  :class="t.color ? 'text-white ring-1 ring-inset ring-white/10' : getVariantStyle(t.variant).container"
108
108
  :style="t.color ? { backgroundColor: t.color } : undefined"
109
109
  >
110
- <MSpinner v-if="t.loading" :size="20" class="shrink-0" />
110
+ <MSpinner v-if="t.loading" :size="24" class="shrink-0" />
111
111
  <MIcon
112
112
  v-else-if="t.icon !== null"
113
113
  :name="t.icon ?? getVariantStyle(t.variant).iconName"
114
- :size="20"
114
+ :size="24"
115
115
  class="shrink-0"
116
116
  :class="t.color ? '' : getVariantStyle(t.variant).icon"
117
117
  />
@@ -122,7 +122,7 @@ const getVariantStyle = (variant: string): VariantStyle =>
122
122
  <button
123
123
  v-if="t.action"
124
124
  type="button"
125
- class="cursor-pointer rounded px-2 py-1 text-label-medium font-semibold transition-colors"
125
+ class="cursor-pointer rounded px-2 py-1 text-label-large font-semibold transition-colors"
126
126
  :class="t.color ? 'text-white/90 hover:bg-white/15' : getVariantStyle(t.variant).action"
127
127
  @click="
128
128
  () => {
@@ -61,17 +61,40 @@ const containerClasses = computed(() => {
61
61
  return 'inline-flex items-center gap-0.5'
62
62
  })
63
63
 
64
+ // Dimensions matched to SplitButton{XSmall,Small,Medium,Large,XLarge}Tokens.kt: ContainerHeight,
65
+ // TrailingIconSize, LeadingButton*Space (symmetric padding here vs the real tokens' slightly
66
+ // asymmetric leading/trailing split — simplification, not worth separate left/right padding
67
+ // classes), and resting InnerCorner*CornerSize (`ri`). `r` is always height/2 to keep the outer
68
+ // shape a true pill (ContainerShape = CornerFull) regardless of tier.
64
69
  const sizeConfig = computed(() => {
65
70
  const map = {
66
- xs: { h: 'h-8', w: 'w-8', px: 'px-3', text: 'text-label-medium', icon: 16, arrow: 16, r: 16, ri: 4 },
67
- sm: { h: 'h-10', w: 'w-10', px: 'px-4', text: 'text-label-large', icon: 18, arrow: 18, r: 20, ri: 6 },
68
- md: { h: 'h-14', w: 'w-14', px: 'px-5', text: 'text-title-medium', icon: 20, arrow: 20, r: 28, ri: 6 },
69
- lg: { h: 'h-16', w: 'w-16', px: 'px-6', text: 'text-title-large', icon: 22, arrow: 22, r: 32, ri: 7 },
70
- xl: { h: 'h-20', w: 'w-20', px: 'px-7', text: 'text-headline-small', icon: 24, arrow: 24, r: 40, ri: 8 },
71
+ xs: { h: 'h-8', w: 'w-8', px: 'px-3', text: 'text-label-medium', icon: 20, arrow: 22, r: 16, ri: 4 },
72
+ sm: { h: 'h-10', w: 'w-10', px: 'px-4', text: 'text-label-large', icon: 20, arrow: 22, r: 20, ri: 4 },
73
+ md: { h: 'h-14', w: 'w-14', px: 'px-6', text: 'text-title-medium', icon: 24, arrow: 26, r: 28, ri: 4 },
74
+ lg: { h: 'h-24', w: 'w-24', px: 'px-12', text: 'text-title-large', icon: 32, arrow: 38, r: 48, ri: 8 },
75
+ xl: { h: 'h-[136px]', w: 'w-[136px]', px: 'px-16', text: 'text-headline-small', icon: 40, arrow: 50, r: 68, ri: 12 },
71
76
  }
72
77
  return map[props.size] ?? map.sm
73
78
  })
74
79
 
80
+ // M3 disabled tokens: content at 38% on-surface opacity, container at 10% (same split already
81
+ // established for MButton) — replaces a blanket 38% opacity that was applied to the whole button.
82
+ const buttonStateClasses = computed(() => {
83
+ if (props.disabled) {
84
+ return [
85
+ 'text-on-surface/38',
86
+ props.variant === 'outlined' ? 'border border-outline-variant/10' : 'bg-on-surface/10',
87
+ ]
88
+ }
89
+ return [
90
+ colorStyles.value.bg,
91
+ colorStyles.value.text,
92
+ colorStyles.value.hover,
93
+ props.variant === 'outlined' ? 'border border-outline' : '',
94
+ props.variant === 'elevated' ? 'shadow-elevation-1' : '',
95
+ ]
96
+ })
97
+
75
98
  function computeMenuPos() {
76
99
  if (!containerEl.value) return
77
100
  const rect = containerEl.value.getBoundingClientRect()
@@ -143,12 +166,8 @@ onUnmounted(() => {
143
166
  class="relative flex cursor-pointer items-center gap-2 overflow-hidden font-medium transition-colors"
144
167
  :class="[
145
168
  sizeConfig.h, sizeConfig.px, sizeConfig.text,
146
- colorStyles.bg,
147
- colorStyles.text,
148
- colorStyles.hover,
149
- variant === 'outlined' ? 'border border-outline' : '',
150
- variant === 'elevated' ? 'shadow-elevation-1' : '',
151
- disabled ? 'pointer-events-none opacity-[0.38]' : '',
169
+ buttonStateClasses,
170
+ disabled ? 'pointer-events-none' : '',
152
171
  ]"
153
172
  :style="{ borderRadius: `${sizeConfig.r}px ${sizeConfig.ri}px ${sizeConfig.ri}px ${sizeConfig.r}px` }"
154
173
  :disabled="disabled"
@@ -165,12 +184,8 @@ onUnmounted(() => {
165
184
  class="toggle-btn relative flex cursor-pointer items-center justify-center overflow-hidden"
166
185
  :class="[
167
186
  sizeConfig.h, sizeConfig.w,
168
- colorStyles.bg,
169
- colorStyles.text,
170
- colorStyles.hover,
171
- variant === 'outlined' ? 'border border-outline' : '',
172
- variant === 'elevated' ? 'shadow-elevation-1' : '',
173
- disabled ? 'pointer-events-none opacity-[0.38]' : '',
187
+ buttonStateClasses,
188
+ disabled ? 'pointer-events-none' : '',
174
189
  ]"
175
190
  :style="{ borderRadius: open ? `${sizeConfig.r}px` : `${sizeConfig.ri}px ${sizeConfig.r}px ${sizeConfig.r}px ${sizeConfig.ri}px` }"
176
191
  :disabled="disabled"
@@ -141,7 +141,7 @@ onBeforeUnmount(() => {
141
141
  <Transition name="m3-spot">
142
142
  <div
143
143
  v-if="modelValue"
144
- class="fixed inset-0 z-50 flex items-start justify-center bg-scrim/50 pt-[12vh]"
144
+ class="fixed inset-0 z-50 flex items-start justify-center bg-scrim/32 pt-[12vh]"
145
145
  @click.self="close"
146
146
  >
147
147
  <div class="spot-box flex w-full max-w-xl flex-col overflow-hidden rounded-2xl bg-surface-container-high shadow-elevation-3">
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed } from 'vue'
2
+ import { computed, ref } from 'vue'
3
3
  import MIcon from './MIcon.vue'
4
4
 
5
5
  const props = withDefaults(
@@ -8,8 +8,15 @@ const props = withDefaults(
8
8
  disabled?: boolean
9
9
  label?: string
10
10
  color?: 'primary' | 'secondary' | 'tertiary' | 'error'
11
+ /**
12
+ * M3 officially has two Switch variants: with a check icon inside the thumb (the
13
+ * `thumbContent` slot filled), and without (Compose's actual default — `thumbContent`
14
+ * defaults to `null`). Defaults to `true` here to keep this component's existing look;
15
+ * pass `false` for the plain/no-icon variant.
16
+ */
17
+ icon?: boolean
11
18
  }>(),
12
- { disabled: false, color: 'primary' },
19
+ { disabled: false, color: 'primary', icon: true },
13
20
  )
14
21
 
15
22
  const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
@@ -21,37 +28,95 @@ const trackClasses: Record<string, string> = {
21
28
  tertiary: 'border-tertiary bg-tertiary',
22
29
  error: 'border-error bg-error',
23
30
  }
31
+ // Selected handle: resting = on-{color} (OnPrimary etc.), hover/focus/press = {color}-container
32
+ // (SwitchTokens.Selected{Hover,Focus,Pressed}HandleColor = PrimaryContainer, NOT OnPrimary —
33
+ // the handle itself recolors on interaction, distinct from the track staying put).
24
34
  const thumbClasses: Record<string, string> = {
25
- primary: 'bg-on-primary',
26
- secondary: 'bg-on-secondary',
27
- tertiary: 'bg-on-tertiary',
28
- error: 'bg-on-error',
35
+ primary: 'bg-on-primary group-hover:bg-primary-container group-active:bg-primary-container peer-focus-visible:bg-primary-container',
36
+ secondary: 'bg-on-secondary group-hover:bg-secondary-container group-active:bg-secondary-container peer-focus-visible:bg-secondary-container',
37
+ tertiary: 'bg-on-tertiary group-hover:bg-tertiary-container group-active:bg-tertiary-container peer-focus-visible:bg-tertiary-container',
38
+ error: 'bg-on-error group-hover:bg-error-container group-active:bg-error-container peer-focus-visible:bg-error-container',
29
39
  }
40
+ // Unselected handle: resting = outline, hover/focus/press = on-surface-variant — a fixed
41
+ // color regardless of the `color` prop, since the unselected state never carries it.
42
+ const unselectedThumbClasses =
43
+ 'bg-outline group-hover:bg-on-surface-variant group-active:bg-on-surface-variant peer-focus-visible:bg-on-surface-variant'
44
+
45
+ // Icon-on-handle color is a DIFFERENT role from the handle's own fill (SelectedIconColor =
46
+ // OnPrimaryContainer, not OnPrimary) — it needs to read against whatever the handle is
47
+ // currently showing (on-primary at rest, primary-container on hover/press), and
48
+ // on-primary-container works against both.
30
49
  const iconClasses: Record<string, string> = {
31
- primary: 'text-primary',
32
- secondary: 'text-secondary',
33
- tertiary: 'text-tertiary',
34
- error: 'text-error',
50
+ primary: 'text-on-primary-container',
51
+ secondary: 'text-on-secondary-container',
52
+ tertiary: 'text-on-tertiary-container',
53
+ error: 'text-on-error-container',
54
+ }
55
+
56
+ // State layer + focus ring tint, same idea as the handle color map above but for the
57
+ // larger 40px circle that trails the thumb (see stateLayerStyle below) rather than the
58
+ // handle itself — reuses the selected color's own base tone (bg-primary etc.), not the
59
+ // container variant, matching StateLayerShape's plain-color state-layer convention used
60
+ // for MCheckbox/MChip/MRadio elsewhere in this library.
61
+ const stateLayerBg: Record<string, string> = {
62
+ primary: 'bg-primary',
63
+ secondary: 'bg-secondary',
64
+ tertiary: 'bg-tertiary',
65
+ error: 'bg-error',
66
+ }
67
+
68
+ // Real handle grows from 24dp (selected) / 16dp (unselected) to a shared 28dp while
69
+ // pressed (SwitchTokens.Pressed{Handle}Width/Height) — via `scale()` on the same fixed-size
70
+ // box the 16dp unselected state already uses `scale(0.667)` for, not by changing width/
71
+ // height directly (which would fight the JS-computed inline `transform` below on
72
+ // specificity, the same class-vs-inline-style trap already hit once this session).
73
+ // Needs real pointerdown/up tracking (not a CSS `active:` utility) because that transform
74
+ // is computed in JS, not a plain class, so CSS pseudo-classes can't reach into it.
75
+ const isPressed = ref(false)
76
+ function onPointerDown() {
77
+ if (!props.disabled) isPressed.value = true
78
+ }
79
+ function onPointerEnd() {
80
+ isPressed.value = false
35
81
  }
36
82
 
83
+ const thumbScale = computed(() => {
84
+ if (isPressed.value) return 28 / 24
85
+ return props.modelValue ? 1 : 16 / 24
86
+ })
87
+
37
88
  // All thumb transforms live here so each direction can use its own easing curve.
38
- // translateY(-50%) vertically centres the 24px thumb in the 32px track.
89
+ // translateY(-50%) vertically centres the thumb in the 32px track.
39
90
  // ON → spring cubic-bezier: overshoots ~2px then settles → satisfying "click"
40
91
  // OFF → M3 standard decelerate: clean snap back, no undershoot
41
92
  const thumbStyle = computed(() => ({
42
- transform: props.modelValue
43
- ? 'translateY(-50%) translateX(18px) scale(1)'
44
- : 'translateY(-50%) translateX(0px) scale(0.667)',
93
+ transform: `translateY(-50%) translateX(${props.modelValue ? 18 : 0}px) scale(${thumbScale.value})`,
45
94
  transition: props.modelValue
46
95
  ? 'transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1), background-color 280ms ease'
47
96
  : 'transform 240ms cubic-bezier(0.2, 0, 0, 1), background-color 240ms ease',
48
97
  }))
98
+
99
+ // StateLayerSize/StateLayerShape = 40dp circle, CornerFull — positioned to trail the
100
+ // thumb's own translateX so it's centered on the thumb at both ends of the track, not a
101
+ // static overlay covering the whole switch the way MCheckbox/MRadio's does (those don't
102
+ // have a moving part). Base offset -4px accounts for the 40px circle being 8px taller/wider
103
+ // than the 32px track and 24px thumb it's centered on.
104
+ const stateLayerStyle = computed(() => ({
105
+ transform: `translateX(${props.modelValue ? 18 : 0}px)`,
106
+ transition: props.modelValue
107
+ ? 'transform 320ms cubic-bezier(0.34, 1.56, 0.64, 1)'
108
+ : 'transform 240ms cubic-bezier(0.2, 0, 0, 1)',
109
+ }))
49
110
  </script>
50
111
 
51
112
  <template>
52
113
  <label
53
- class="inline-flex items-center gap-3 select-none"
114
+ class="group inline-flex items-center gap-3 select-none"
54
115
  :class="disabled ? 'cursor-not-allowed opacity-[0.38]' : 'cursor-pointer'"
116
+ @pointerdown="onPointerDown"
117
+ @pointerup="onPointerEnd"
118
+ @pointerleave="onPointerEnd"
119
+ @pointercancel="onPointerEnd"
55
120
  >
56
121
  <span class="relative -my-2 inline-flex h-12 shrink-0 items-center">
57
122
  <span
@@ -60,16 +125,29 @@ const thumbStyle = computed(() => ({
60
125
  >
61
126
  <input
62
127
  type="checkbox"
63
- class="sr-only"
128
+ class="peer sr-only"
64
129
  :checked="modelValue"
65
130
  :disabled="disabled"
66
131
  @change="emit('update:modelValue', !modelValue)"
67
132
  />
68
133
 
134
+ <!-- Hover/press/focus state layer + focus ring, both tracking the thumb's position (see stateLayerStyle doc above) -->
135
+ <span
136
+ v-if="!disabled"
137
+ class="pointer-events-none absolute top-1/2 -left-1 h-10 w-10 -translate-y-1/2 rounded-full opacity-0 transition-opacity duration-150 group-hover:opacity-[0.08] group-active:opacity-[0.12] peer-focus-visible:opacity-[0.08]"
138
+ :class="modelValue ? stateLayerBg[color] : 'bg-on-surface-variant'"
139
+ :style="stateLayerStyle"
140
+ />
141
+ <span
142
+ v-if="!disabled"
143
+ class="pointer-events-none absolute top-1/2 -left-1 h-10 w-10 -translate-y-1/2 rounded-full ring-0 ring-secondary transition-[box-shadow] duration-150 peer-focus-visible:ring-2"
144
+ :style="stateLayerStyle"
145
+ />
146
+
69
147
  <!-- Thumb: position + size animated via inline style (allows per-direction easing) -->
70
148
  <span
71
149
  class="absolute left-1 top-1/2 flex h-6 w-6 items-center justify-center rounded-full will-change-transform"
72
- :class="modelValue ? [thumbClasses[color], 'shadow-sm'] : 'bg-outline'"
150
+ :class="modelValue ? [thumbClasses[color], 'shadow-sm'] : unselectedThumbClasses"
73
151
  :style="thumbStyle"
74
152
  >
75
153
  <Transition
@@ -80,7 +158,7 @@ const thumbStyle = computed(() => ({
80
158
  leave-from-class="opacity-100"
81
159
  leave-to-class="opacity-0"
82
160
  >
83
- <MIcon v-if="modelValue" name="check" :size="14" :class="iconClasses[color]" />
161
+ <MIcon v-if="modelValue && icon" name="check" :size="14" :class="iconClasses[color]" />
84
162
  </Transition>
85
163
  </span>
86
164
  </span>