@m3ui-vue/m3ui-vue 0.7.1 → 0.8.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 (90) hide show
  1. package/README.md +5 -5
  2. package/dist/{MMenuItem-xQ1x6-DH.js → MMenuItem-vSLbJGqe.js} +299 -232
  3. package/dist/MMenuItem-vSLbJGqe.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/MCard.vue.d.ts +2 -0
  8. package/dist/components/MChatBubble.vue.d.ts +0 -1
  9. package/dist/components/MCircleProgressBar.vue.d.ts +0 -1
  10. package/dist/components/MCodeEditor.vue.d.ts +1 -1
  11. package/dist/components/MConfirmDialog.vue.d.ts +3 -0
  12. package/dist/components/MDialog.vue.d.ts +23 -7
  13. package/dist/components/MFab.vue.d.ts +2 -2
  14. package/dist/components/MListItem.vue.d.ts +11 -6
  15. package/dist/components/MNavigationRail.vue.d.ts +17 -1
  16. package/dist/components/MSelect.vue.d.ts +1 -0
  17. package/dist/components/MSwitch.vue.d.ts +8 -0
  18. package/dist/components/MTabs.vue.d.ts +3 -0
  19. package/dist/index.d.ts +1 -0
  20. package/dist/m3ui-vue.css +1 -1
  21. package/dist/m3ui.js +1798 -1432
  22. package/dist/m3ui.js.map +1 -1
  23. package/dist/rich-text-editor.js +1 -1
  24. package/dist/styles/palettes.css +659 -0
  25. package/dist/styles/theme.css +1 -0
  26. package/dist/styles.css +1 -1
  27. package/package.json +13 -1
  28. package/src/__tests__/useColorPalette.test.ts +2 -2
  29. package/src/code-editor.ts +1 -0
  30. package/src/components/MAutocomplete.vue +35 -26
  31. package/src/components/MBadge.vue +1 -1
  32. package/src/components/MBottomSheet.vue +4 -4
  33. package/src/components/MButton.vue +36 -19
  34. package/src/components/MButtonGroup.vue +2 -2
  35. package/src/components/MCard.vue +76 -11
  36. package/src/components/MChatBubble.vue +0 -1
  37. package/src/components/MCheckbox.vue +58 -13
  38. package/src/components/MChip.vue +26 -6
  39. package/src/components/MCircleProgressBar.vue +7 -4
  40. package/src/components/MCodeEditor.vue +54 -8
  41. package/src/components/MColorPicker.vue +9 -8
  42. package/src/components/MColorPickerModal.vue +2 -2
  43. package/src/components/MCommandPalette.vue +1 -1
  44. package/src/components/MConfirmDialog.vue +4 -0
  45. package/src/components/MContextMenu.vue +23 -2
  46. package/src/components/MDatePicker.vue +11 -11
  47. package/src/components/MDatePickerModal.vue +5 -5
  48. package/src/components/MDateRangePicker.vue +12 -12
  49. package/src/components/MDateRangePickerModal.vue +3 -3
  50. package/src/components/MDialog.vue +103 -12
  51. package/src/components/MFab.vue +10 -7
  52. package/src/components/MFabMenu.vue +1 -1
  53. package/src/components/MIconButton.vue +41 -19
  54. package/src/components/MListItem.vue +35 -17
  55. package/src/components/MLoadingIndicator.vue +14 -7
  56. package/src/components/MMaskField.vue +14 -6
  57. package/src/components/MMenu.vue +28 -3
  58. package/src/components/MMenuItem.vue +2 -2
  59. package/src/components/MMultiAutocomplete.vue +41 -26
  60. package/src/components/MMultiSelect.vue +40 -22
  61. package/src/components/MNavigationBar.vue +5 -10
  62. package/src/components/MNavigationDrawer.vue +10 -9
  63. package/src/components/MNavigationRail.vue +335 -22
  64. package/src/components/MNumberField.vue +14 -6
  65. package/src/components/MOverlay.vue +1 -1
  66. package/src/components/MPinInput.vue +7 -4
  67. package/src/components/MProgressBar.vue +16 -10
  68. package/src/components/MRadio.vue +54 -12
  69. package/src/components/MSearchBar.vue +3 -2
  70. package/src/components/MSegmentedButton.vue +14 -9
  71. package/src/components/MSelect.vue +44 -32
  72. package/src/components/MSideSheet.vue +1 -1
  73. package/src/components/MSnackbar.vue +4 -4
  74. package/src/components/MSplitButton.vue +32 -17
  75. package/src/components/MSpotlightSearch.vue +1 -1
  76. package/src/components/MSwitch.vue +96 -18
  77. package/src/components/MTabs.vue +16 -12
  78. package/src/components/MTagInput.vue +33 -22
  79. package/src/components/MTextField.vue +14 -6
  80. package/src/components/MTimePicker.vue +9 -9
  81. package/src/components/MTimePickerModal.vue +16 -16
  82. package/src/components/MToolbar.vue +5 -3
  83. package/src/components/MTooltip.vue +4 -4
  84. package/src/components/MTopAppBar.vue +14 -6
  85. package/src/components/MTour.vue +1 -1
  86. package/src/composables/useColorPalette.ts +10 -0
  87. package/src/index.ts +1 -0
  88. package/src/styles/palettes.css +659 -0
  89. package/src/styles/theme.css +1 -0
  90. package/dist/MMenuItem-xQ1x6-DH.js.map +0 -1
@@ -129,7 +129,7 @@ onUnmounted(() => { document.body.style.overflow = '' })
129
129
  <div ref="barEl" class="relative w-full">
130
130
  <div
131
131
  v-show="!expanded"
132
- class="flex h-14 items-center gap-3 rounded-full bg-surface-container-high px-4 shadow-elevation-1 transition-shadow duration-150"
132
+ class="flex h-14 items-center gap-3 rounded-full bg-surface-container-high px-4 shadow-elevation-3 transition-shadow duration-150 focus-within:outline focus-within:outline-2 focus-within:outline-secondary focus-within:-outline-offset-2"
133
133
  :class="disabled ? 'pointer-events-none opacity-[0.38]' : ''"
134
134
  >
135
135
  <span class="inline-flex shrink-0 items-center" :class="iconPosition === 'end' ? 'order-last' : ''">
@@ -180,6 +180,7 @@ onUnmounted(() => { document.body.style.overflow = '' })
180
180
  icon="arrow_back"
181
181
  :label="locale.close"
182
182
  variant="standard"
183
+ style="color: var(--color-on-surface)"
183
184
  @click="close"
184
185
  />
185
186
  <input
@@ -205,7 +206,7 @@ onUnmounted(() => { document.body.style.overflow = '' })
205
206
  <slot name="trailing" />
206
207
  </div>
207
208
 
208
- <div class="h-px shrink-0 bg-outline-variant" />
209
+ <div class="h-px shrink-0 bg-outline" />
209
210
 
210
211
  <div class="flex-1 overflow-y-auto">
211
212
  <slot />
@@ -48,15 +48,20 @@ function toggle(opt: SegmentedOption, modelValue: string | number | (string | nu
48
48
  class="relative inline-flex items-center justify-center gap-2 text-label-large font-medium transition-[background-color,color] duration-150 outline-none before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 enabled:hover:before:opacity-[0.08] enabled:active:before:opacity-[0.12]"
49
49
  :class="[
50
50
  density === 'compact' ? 'h-8 px-3' : density === 'comfortable' ? 'h-10 px-4' : 'h-10 px-6',
51
- i > 0 ? 'border-l border-outline' : '',
52
- opt.disabled ? 'cursor-not-allowed opacity-[0.38]' : 'cursor-pointer',
53
- isSelected(opt.value, modelValue)
54
- ? color === 'secondary'
55
- ? 'bg-secondary-container text-on-secondary-container'
56
- : color === 'tertiary'
57
- ? 'bg-tertiary-container text-on-tertiary-container'
58
- : 'bg-secondary-container text-on-secondary-container'
59
- : 'text-on-surface',
51
+ i > 0 ? (opt.disabled ? 'border-l border-outline/12' : 'border-l border-outline') : '',
52
+ opt.disabled ? 'cursor-not-allowed' : 'cursor-pointer',
53
+ isSelected(opt.value, modelValue) && (
54
+ color === 'secondary' ? 'bg-secondary-container'
55
+ : color === 'tertiary' ? 'bg-tertiary-container'
56
+ : 'bg-primary-container'
57
+ ),
58
+ opt.disabled
59
+ ? 'text-on-surface/38'
60
+ : isSelected(opt.value, modelValue)
61
+ ? color === 'secondary' ? 'text-on-secondary-container'
62
+ : color === 'tertiary' ? 'text-on-tertiary-container'
63
+ : 'text-on-primary-container'
64
+ : 'text-on-surface',
60
65
  ]"
61
66
  :disabled="opt.disabled"
62
67
  :aria-pressed="isSelected(opt.value, modelValue)"
@@ -27,6 +27,7 @@ const props = withDefaults(
27
27
  leadingIcon?: string
28
28
  clearable?: boolean
29
29
  fieldBg?: string
30
+ noResultsText?: string
30
31
  }>(),
31
32
  {
32
33
  modelValue: undefined,
@@ -59,6 +60,7 @@ const hasValue = computed(() => props.modelValue != null && props.modelValue !==
59
60
  const selectedLabel = computed(
60
61
  () => props.options.find((o) => eq(o.value, props.modelValue))?.label ?? '',
61
62
  )
63
+ const resolvedNoResultsText = computed(() => props.noResultsText ?? locale.noResults)
62
64
 
63
65
  function computeDropPos() {
64
66
  if (!fieldEl.value) return
@@ -142,27 +144,29 @@ onUnmounted(() => {
142
144
  const triggerClasses = computed(() => {
143
145
  const pl = props.leadingIcon ? 'pl-12' : 'pl-4'
144
146
  const base = [
145
- 'flex w-full cursor-pointer items-center pr-10 text-body-large transition-[border-color,border-width] duration-150',
147
+ 'flex w-full items-center pr-10 text-body-large transition-[border-color,border-width] duration-150',
148
+ props.disabled ? 'cursor-not-allowed' : 'cursor-pointer',
146
149
  pl,
147
150
  ]
148
151
 
149
152
  if (props.variant === 'outlined') {
150
- return [
151
- ...base,
152
- 'h-14 rounded-sm border bg-transparent',
153
- open.value
153
+ const border = props.disabled
154
+ ? 'border-on-surface/12'
155
+ : open.value
154
156
  ? (props.error ? 'border-2 border-error' : 'border-2 border-primary')
155
- : (props.error ? 'border-error' : 'border-outline hover:border-on-surface'),
156
- ].join(' ')
157
+ : (props.error ? 'border-error' : 'border-outline hover:border-on-surface')
158
+ return [...base, 'h-14 rounded-xs border bg-transparent', border].join(' ')
157
159
  }
158
160
 
159
- return [
160
- ...base,
161
- 'h-14 rounded-t-sm bg-surface-container-highest border-b pt-6 pb-2',
162
- open.value
161
+ const border = props.disabled
162
+ ? 'border-on-surface/38'
163
+ : open.value
163
164
  ? (props.error ? 'border-b-2 border-error' : 'border-b-2 border-primary')
164
- : (props.error ? 'border-error' : 'border-on-surface-variant hover:border-on-surface'),
165
- ].join(' ')
165
+ : (props.error ? 'border-error' : 'border-on-surface-variant hover:border-on-surface')
166
+ const bg = props.disabled
167
+ ? 'bg-[color-mix(in_srgb,var(--color-on-surface)_4%,var(--color-surface-container-highest))]'
168
+ : 'bg-surface-container-highest'
169
+ return [...base, 'h-14 rounded-t-xs border-b pt-6 pb-2', bg, border].join(' ')
166
170
  })
167
171
 
168
172
  const isFloated = computed(() => hasValue.value || open.value)
@@ -184,9 +188,11 @@ const labelClasses = computed(() => {
184
188
  'pointer-events-none absolute right-10 truncate transition-all duration-200',
185
189
  left,
186
190
  isFloated.value ? floated : unFloated,
187
- open.value
188
- ? (props.error ? 'text-error' : 'text-primary')
189
- : (props.error ? 'text-error' : 'text-on-surface-variant'),
191
+ props.disabled
192
+ ? 'text-on-surface/38'
193
+ : open.value
194
+ ? (props.error ? 'text-error' : 'text-primary')
195
+ : (props.error ? 'text-error' : 'text-on-surface-variant'),
190
196
  ].join(' ')
191
197
  })
192
198
  </script>
@@ -202,10 +208,13 @@ const labelClasses = computed(() => {
202
208
  <!-- Leading icon -->
203
209
  <div
204
210
  v-if="leadingIcon"
205
- class="pointer-events-none absolute left-3.5 text-on-surface-variant"
206
- :class="variant === 'filled' ? 'top-5' : 'top-4.5'"
211
+ class="pointer-events-none absolute left-3.5"
212
+ :class="[
213
+ variant === 'filled' ? 'top-4.5' : 'top-4',
214
+ disabled ? 'text-on-surface/38' : 'text-on-surface-variant',
215
+ ]"
207
216
  >
208
- <MIcon :name="leadingIcon" :size="20" />
217
+ <MIcon :name="leadingIcon" :size="24" />
209
218
  </div>
210
219
 
211
220
  <!-- Custom trigger -->
@@ -215,11 +224,11 @@ const labelClasses = computed(() => {
215
224
  role="combobox"
216
225
  :aria-expanded="open"
217
226
  :aria-disabled="disabled"
218
- :class="[triggerClasses, disabled ? 'pointer-events-none opacity-[0.38]' : '']"
227
+ :class="[triggerClasses, disabled ? 'pointer-events-none' : '']"
219
228
  @click="toggle"
220
229
  @keydown="onKeydown"
221
230
  >
222
- <span v-if="hasValue" class="text-on-surface">{{ selectedLabel }}</span>
231
+ <span v-if="hasValue" :class="disabled ? 'text-on-surface/38' : 'text-on-surface'">{{ selectedLabel }}</span>
223
232
  </div>
224
233
 
225
234
  <!-- Floating label -->
@@ -242,8 +251,11 @@ const labelClasses = computed(() => {
242
251
  <MIcon
243
252
  name="arrow_drop_down"
244
253
  :size="24"
245
- class="text-on-surface-variant transition-transform duration-200"
246
- :class="open || modalOpen ? 'rotate-180' : ''"
254
+ class="transition-transform duration-200"
255
+ :class="[
256
+ open || modalOpen ? 'rotate-180' : '',
257
+ disabled ? 'text-on-surface/38' : 'text-on-surface-variant',
258
+ ]"
247
259
  />
248
260
  </div>
249
261
  </div>
@@ -265,7 +277,7 @@ const labelClasses = computed(() => {
265
277
  <div
266
278
  v-if="open && mode === 'docked'"
267
279
  ref="dropdownEl"
268
- class="fixed z-500 max-h-60 overflow-auto rounded-sm bg-surface-container py-1 shadow-elevation-2"
280
+ class="fixed z-500 max-h-60 overflow-auto rounded-xs bg-surface-container py-1 shadow-elevation-2"
269
281
  :style="dropPos"
270
282
  >
271
283
  <div
@@ -276,7 +288,7 @@ const labelClasses = computed(() => {
276
288
  opt.disabled
277
289
  ? 'cursor-not-allowed opacity-38 text-on-surface'
278
290
  : 'text-on-surface hover:bg-on-surface/8',
279
- eq(opt.value, modelValue) ? 'bg-primary/8 text-primary font-medium' : '',
291
+ eq(opt.value, modelValue) ? 'bg-secondary-container text-on-secondary-container font-medium' : '',
280
292
  ]"
281
293
  @click="select(opt)"
282
294
  >
@@ -284,7 +296,7 @@ const labelClasses = computed(() => {
284
296
  v-if="eq(opt.value, modelValue)"
285
297
  name="check"
286
298
  :size="18"
287
- class="shrink-0 text-primary"
299
+ class="shrink-0 text-on-secondary-container"
288
300
  />
289
301
  <span v-else class="w-[18px] shrink-0" />
290
302
  {{ opt.label }}
@@ -293,7 +305,7 @@ const labelClasses = computed(() => {
293
305
  v-if="!options.length"
294
306
  class="px-4 py-3 text-center text-body-small text-on-surface-variant"
295
307
  >
296
- Sin opciones
308
+ {{ resolvedNoResultsText }}
297
309
  </p>
298
310
  </div>
299
311
  </Transition>
@@ -302,7 +314,7 @@ const labelClasses = computed(() => {
302
314
  <Transition name="m3-select-modal">
303
315
  <div
304
316
  v-if="modalOpen && mode === 'modal'"
305
- class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/40 p-4"
317
+ class="fixed inset-0 z-50 flex items-center justify-center bg-scrim/32 p-4"
306
318
  @click.self="closeModal"
307
319
  >
308
320
  <div class="select-modal-box flex max-h-[80vh] w-full max-w-sm flex-col overflow-hidden rounded-[28px] bg-surface-container-high shadow-elevation-3">
@@ -324,16 +336,16 @@ const labelClasses = computed(() => {
324
336
  opt.disabled
325
337
  ? 'cursor-not-allowed opacity-38 text-on-surface'
326
338
  : 'text-on-surface hover:bg-on-surface/8',
327
- eq(opt.value, modelValue) ? 'bg-primary/8' : '',
339
+ eq(opt.value, modelValue) ? 'bg-secondary-container' : '',
328
340
  ]"
329
341
  @click="select(opt)"
330
342
  >
331
343
  <MIcon
332
344
  :name="eq(opt.value, modelValue) ? 'radio_button_checked' : 'radio_button_unchecked'"
333
345
  :size="20"
334
- :class="eq(opt.value, modelValue) ? 'text-primary' : 'text-on-surface-variant'"
346
+ :class="eq(opt.value, modelValue) ? 'text-on-secondary-container' : 'text-on-surface-variant'"
335
347
  />
336
- <span :class="eq(opt.value, modelValue) ? 'text-primary font-medium' : ''">
348
+ <span :class="eq(opt.value, modelValue) ? 'text-on-secondary-container font-medium' : ''">
337
349
  {{ opt.label }}
338
350
  </span>
339
351
  </div>
@@ -341,7 +353,7 @@ const labelClasses = computed(() => {
341
353
  v-if="!options.length"
342
354
  class="px-6 py-4 text-center text-body-medium text-on-surface-variant"
343
355
  >
344
- Sin opciones
356
+ {{ resolvedNoResultsText }}
345
357
  </p>
346
358
  </div>
347
359
  </div>
@@ -42,7 +42,7 @@ const panelStyle = computed(() => ({
42
42
  <Transition name="ss" :duration="{ enter: 320, leave: 280 }">
43
43
  <div v-if="modelValue" class="fixed inset-0 z-200 flex justify-end">
44
44
  <!-- Scrim -->
45
- <div class="ss-scrim absolute inset-0 bg-scrim/40" @click="close" />
45
+ <div class="ss-scrim absolute inset-0 bg-scrim/32" @click="close" />
46
46
 
47
47
  <!-- Panel -->
48
48
  <aside
@@ -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>
@@ -13,7 +13,9 @@ const props = withDefaults(defineProps<{
13
13
  modelValue: string | number
14
14
  tabs: Tab[]
15
15
  variant?: 'primary' | 'secondary'
16
- }>(), { variant: 'primary' })
16
+ /** 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. */
17
+ scrollable?: boolean
18
+ }>(), { variant: 'primary', scrollable: false })
17
19
 
18
20
  const emit = defineEmits<{ 'update:modelValue': [string | number] }>()
19
21
 
@@ -120,15 +122,16 @@ function select(tab: Tab) {
120
122
  <template>
121
123
  <!-- ── Primary: sliding short indicator with stretch ──────────────── -->
122
124
  <div v-if="variant === 'primary'" class="border-b border-outline-variant">
123
- <div class="relative flex overflow-x-auto" style="scrollbar-width: none">
125
+ <div class="relative flex" :class="scrollable ? 'overflow-x-auto' : 'overflow-x-hidden'" style="scrollbar-width: none">
124
126
  <button
125
127
  v-for="tab in tabs"
126
128
  :key="tab.value"
127
129
  :ref="(el) => { if (el) tabEls[tabs.indexOf(tab)] = el as HTMLElement }"
128
130
  type="button"
129
- class="relative flex shrink-0 flex-col items-center justify-center gap-1 px-6 text-label-large transition-colors duration-150 focus-visible:outline-none"
131
+ class="relative flex flex-col items-center justify-center gap-1 px-6 text-title-small transition-colors duration-150 focus-visible:outline-none"
130
132
  :class="[
131
- tab.icon ? 'h-14 pb-1.5' : 'h-12 pb-1.5',
133
+ scrollable ? 'shrink-0' : 'flex-1 min-w-0',
134
+ tab.icon ? 'h-16 pb-1.5' : 'h-12 pb-1.5',
132
135
  tab.value === modelValue
133
136
  ? 'text-primary'
134
137
  : tab.disabled
@@ -138,7 +141,7 @@ function select(tab: Tab) {
138
141
  :disabled="tab.disabled"
139
142
  @click="select(tab)"
140
143
  >
141
- <MIcon v-if="tab.icon" :name="tab.icon" :size="20" />
144
+ <MIcon v-if="tab.icon" :name="tab.icon" :size="24" />
142
145
  <span>{{ tab.label }}</span>
143
146
  </button>
144
147
  <div
@@ -150,28 +153,29 @@ function select(tab: Tab) {
150
153
 
151
154
  <!-- ── Secondary: full-width underline indicator ─────────────────── -->
152
155
  <div v-else class="border-b border-outline-variant">
153
- <div class="relative flex overflow-x-auto" style="scrollbar-width: none">
156
+ <div class="relative flex" :class="scrollable ? 'overflow-x-auto' : 'overflow-x-hidden'" style="scrollbar-width: none">
154
157
  <button
155
158
  v-for="tab in tabs"
156
159
  :key="tab.value"
157
160
  :ref="(el) => { if (el) tabEls[tabs.indexOf(tab)] = el as HTMLElement }"
158
161
  type="button"
159
- class="relative flex h-12 shrink-0 items-center justify-center gap-2 px-6 text-label-large transition-colors duration-150 focus-visible:outline-none"
160
- :class="
162
+ class="relative flex h-12 items-center justify-center gap-2 px-6 text-title-small transition-colors duration-150 focus-visible:outline-none"
163
+ :class="[
164
+ scrollable ? 'shrink-0' : 'flex-1 min-w-0',
161
165
  tab.value === modelValue
162
166
  ? 'text-on-surface'
163
167
  : tab.disabled
164
168
  ? 'cursor-not-allowed text-on-surface/38'
165
- : 'cursor-pointer text-on-surface-variant hover:text-on-surface'
166
- "
169
+ : 'cursor-pointer text-on-surface-variant hover:text-on-surface',
170
+ ]"
167
171
  :disabled="tab.disabled"
168
172
  @click="select(tab)"
169
173
  >
170
- <MIcon v-if="tab.icon" :name="tab.icon" :size="18" />
174
+ <MIcon v-if="tab.icon" :name="tab.icon" :size="24" />
171
175
  {{ tab.label }}
172
176
  </button>
173
177
  <div
174
- class="absolute bottom-0 h-[2px] bg-primary"
178
+ class="absolute bottom-0 h-[3px] bg-primary"
175
179
  :style="{ left: `${indicatorLeft}px`, width: `${indicatorWidth}px` }"
176
180
  />
177
181
  </div>