@m3ui-vue/m3ui-vue 0.9.2 → 1.0.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 (139) hide show
  1. package/README.md +26 -29
  2. package/dist/API.md +242 -22
  3. package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
  4. package/dist/MIcon-DLOkQduI.js.map +1 -0
  5. package/dist/{MTextField-Ck0oWDMk.js → MTextField-TZ7lfr09.js} +551 -216
  6. package/dist/MTextField-TZ7lfr09.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/MAppBarWithSearch.vue.d.ts +70 -0
  11. package/dist/components/MBottomAppBar.vue.d.ts +37 -0
  12. package/dist/components/MBottomSheetScaffold.vue.d.ts +40 -0
  13. package/dist/components/MButton.vue.d.ts +4 -2
  14. package/dist/components/MButtonGroup.vue.d.ts +2 -0
  15. package/dist/components/MChatBubble.vue.d.ts +1 -1
  16. package/dist/components/MChip.vue.d.ts +19 -2
  17. package/dist/components/MContainer.vue.d.ts +1 -1
  18. package/dist/components/MDataTable.vue.d.ts +1 -1
  19. package/dist/components/MDialog.vue.d.ts +1 -1
  20. package/dist/components/MFab.vue.d.ts +15 -4
  21. package/dist/components/MIcon.vue.d.ts +3 -0
  22. package/dist/components/MIconButton.vue.d.ts +15 -1
  23. package/dist/components/MListItem.vue.d.ts +2 -2
  24. package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
  25. package/dist/components/MMenuItem.vue.d.ts +17 -4
  26. package/dist/components/MNavigationRail.vue.d.ts +6 -0
  27. package/dist/components/MSearchBar.vue.d.ts +5 -3
  28. package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
  29. package/dist/components/MSplitButton.vue.d.ts +2 -0
  30. package/dist/components/MTable.vue.d.ts +1 -1
  31. package/dist/components/MTabs.vue.d.ts +6 -0
  32. package/dist/components/MTimePickerModal.vue.d.ts +3 -0
  33. package/dist/components/MTimeScroll.vue.d.ts +22 -0
  34. package/dist/components/MToggleButton.vue.d.ts +2 -0
  35. package/dist/components/MTopAppBar.vue.d.ts +33 -2
  36. package/dist/components/MTree.vue.d.ts +2 -2
  37. package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
  38. package/dist/composables/_searchAppBar.d.ts +6 -0
  39. package/dist/composables/_themeTransition.d.ts +2 -0
  40. package/dist/composables/_useSpring.d.ts +5 -5
  41. package/dist/composables/motion.d.ts +101 -0
  42. package/dist/composables/useColorPalette.d.ts +10 -0
  43. package/dist/composables/useLocale.d.ts +9 -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 +11 -1
  54. package/dist/locales/index.js +63 -0
  55. package/dist/locales/index.js.map +1 -1
  56. package/dist/m3ui-vue.css +1 -1
  57. package/dist/m3ui.js +7716 -6768
  58. package/dist/m3ui.js.map +1 -1
  59. package/dist/plugin.d.ts +7 -0
  60. package/dist/rich-text-editor.js +22 -22
  61. package/dist/styles/palettes-contrast.css +7764 -0
  62. package/dist/styles/theme.css +59 -2
  63. package/dist/styles.css +1 -1
  64. package/dist/terminal.js +1 -1
  65. package/dist/{useLocale-CFW8cIzL.js → useLocale-CuvWRZ1h.js} +10 -1
  66. package/dist/useLocale-CuvWRZ1h.js.map +1 -0
  67. package/package.json +4 -2
  68. package/src/__tests__/MAppBarWithSearch.test.ts +96 -0
  69. package/src/__tests__/MBottomAppBar.test.ts +71 -0
  70. package/src/__tests__/MBottomSheetScaffold.test.ts +101 -0
  71. package/src/__tests__/MChip.test.ts +63 -0
  72. package/src/__tests__/MFab.test.ts +36 -0
  73. package/src/__tests__/MIconButton.test.ts +60 -0
  74. package/src/__tests__/MMenuItem.test.ts +84 -0
  75. package/src/__tests__/MNavigationRail.test.ts +77 -0
  76. package/src/__tests__/MScrollField.test.ts +28 -0
  77. package/src/__tests__/MTabs.test.ts +39 -0
  78. package/src/__tests__/MTimePickerModal.test.ts +52 -0
  79. package/src/__tests__/MTimeScroll.test.ts +44 -0
  80. package/src/__tests__/MTopAppBar.test.ts +99 -0
  81. package/src/__tests__/contrast.test.ts +64 -0
  82. package/src/__tests__/dynamicColor.test.ts +17 -0
  83. package/src/__tests__/motion.test.ts +37 -0
  84. package/src/__tests__/themeTransition.test.ts +119 -0
  85. package/src/__tests__/vRipple.test.ts +92 -0
  86. package/src/components/MAppBarWithSearch.vue +236 -0
  87. package/src/components/MBottomAppBar.vue +181 -0
  88. package/src/components/MBottomSheetScaffold.vue +296 -0
  89. package/src/components/MBreadcrumbs.vue +1 -1
  90. package/src/components/MButton.vue +4 -13
  91. package/src/components/MButtonGroup.vue +4 -11
  92. package/src/components/MChip.vue +137 -5
  93. package/src/components/MFab.vue +81 -27
  94. package/src/components/MIcon.vue +4 -2
  95. package/src/components/MIconButton.vue +96 -24
  96. package/src/components/MMenuItem.vue +115 -13
  97. package/src/components/MNavigationDrawer.vue +2 -2
  98. package/src/components/MNavigationRail.vue +135 -8
  99. package/src/components/MScrollField.vue +10 -2
  100. package/src/components/MSearchBar.vue +28 -12
  101. package/src/components/MSplitButton.vue +5 -12
  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/MTopAppBar.vue +252 -28
  107. package/src/composables/_carouselStrategy.ts +3 -0
  108. package/src/composables/_searchAppBar.ts +9 -0
  109. package/src/composables/_themeColor.ts +11 -4
  110. package/src/composables/_themeTransition.ts +71 -0
  111. package/src/composables/_useSpring.ts +12 -20
  112. package/src/composables/motion.ts +73 -0
  113. package/src/composables/useColorPalette.ts +103 -20
  114. package/src/composables/useLocale.ts +18 -0
  115. package/src/composables/useTheme.ts +4 -12
  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 +13 -1
  127. package/src/locales/de.ts +9 -0
  128. package/src/locales/es.ts +9 -0
  129. package/src/locales/fr.ts +9 -0
  130. package/src/locales/ja.ts +9 -0
  131. package/src/locales/ko.ts +9 -0
  132. package/src/locales/pt.ts +9 -0
  133. package/src/locales/zh.ts +9 -0
  134. package/src/plugin.ts +11 -1
  135. package/src/styles/palettes-contrast.css +7764 -0
  136. package/src/styles/theme.css +59 -2
  137. package/dist/MIcon-CaEooCmZ.js.map +0 -1
  138. package/dist/MTextField-Ck0oWDMk.js.map +0 -1
  139. package/dist/useLocale-CFW8cIzL.js.map +0 -1
@@ -7,8 +7,10 @@
7
7
  * `close()` closes it.
8
8
  * @event click Emitted when the FAB itself is clicked (not a speed-dial item)
9
9
  */
10
- import { computed, onMounted, onUnmounted, ref, useSlots } from 'vue'
10
+ import { computed, inject, onMounted, onUnmounted, ref, useSlots } from 'vue'
11
11
  import MIcon from './MIcon.vue'
12
+ import { vRipple } from '../directives/vRipple'
13
+ import { FAST_EFFECTS, FAST_SPATIAL, useSpring } from '../composables/_useSpring'
12
14
 
13
15
  export interface SpeedDialItem {
14
16
  icon: string
@@ -25,9 +27,17 @@ const props = withDefaults(
25
27
  icon: string
26
28
  /** Extended FAB label text */
27
29
  label?: string
28
- /** Color scheme */
30
+ /**
31
+ * Extended FAB only: false collapses it to a plain FAB (the label fades out and the width shrinks to a
32
+ * square), e.g. while the content scrolls. Compose's `expanded`
33
+ */
34
+ expanded?: boolean
35
+ /** Color scheme; defaults to primary, or secondary inside an MBottomAppBar */
29
36
  color?: 'primary' | 'secondary' | 'tertiary' | 'surface'
30
- /** FAB size */
37
+ /**
38
+ * FAB size. With a `label`, small/medium/large are M3 Expressive's extended FABs (56/80/96px, title-medium,
39
+ * title-large and headline-small labels); regular is the baseline extended FAB
40
+ */
31
41
  size?: 'small' | 'regular' | 'medium' | 'large'
32
42
  /** Disables interaction */
33
43
  disabled?: boolean
@@ -58,10 +68,13 @@ const props = withDefaults(
58
68
  * the content's own leave animation has time to play instead of just
59
69
  * vanishing. 'none' skips any panel-level transition entirely. */
60
70
  contentTransition?: 'scale' | 'fade' | 'none'
71
+ /** Any CSS color for the press ripple; defaults to the FAB's content color */
72
+ rippleColor?: string
61
73
  }>(),
62
74
  {
63
- color: 'primary',
75
+ color: undefined,
64
76
  size: 'regular',
77
+ expanded: true,
65
78
  disabled: false,
66
79
  direction: 'up',
67
80
  persistent: false,
@@ -84,6 +97,10 @@ const hasItems = computed(() => !!props.items?.length)
84
97
  const hasContent = computed(() => !!slots.content)
85
98
  const isExpandable = computed(() => hasItems.value || hasContent.value)
86
99
 
100
+ // Inside an MBottomAppBar: secondary and flat (bottomAppBarFabColor, bottomAppBarFabElevation)
101
+ const inBottomAppBar = inject('m-bottom-app-bar', false)
102
+ const color = computed(() => props.color ?? (inBottomAppBar ? 'secondary' : 'primary'))
103
+
87
104
  const colorMap: Record<string, string> = {
88
105
  primary: 'bg-primary-container text-on-primary-container',
89
106
  secondary: 'bg-secondary-container text-on-secondary-container',
@@ -91,20 +108,30 @@ const colorMap: Record<string, string> = {
91
108
  surface: 'bg-surface-container-high text-primary',
92
109
  }
93
110
 
111
+ // Extended FABs (androidx FloatingActionButton.kt). Baseline (`regular`): 16dp start, 12dp icon-to-label,
112
+ // 20dp end, 80dp minimum width, labelLarge. Small/Medium/Large (ExtendedFab*Tokens): leading = trailing space,
113
+ // minimum width = height, MediumExtendedFabIconPadding/LargeExtendedFabIconPadding (12/16dp, the tokens'
114
+ // IconLabelSpace is marked incorrect there).
115
+ const EXTENDED = {
116
+ regular: { px: 56, icon: 24, gap: 12, box: 'h-14 min-w-20 rounded-2xl pl-4 pr-5', text: 'text-label-large font-medium' },
117
+ small: { px: 56, icon: 24, gap: 8, box: 'h-14 min-w-14 rounded-2xl px-4', text: 'text-title-medium font-medium' },
118
+ medium: { px: 80, icon: 28, gap: 12, box: 'h-20 min-w-20 rounded-lg-increased px-[26px]', text: 'text-title-large' },
119
+ large: { px: 96, icon: 32, gap: 16, box: 'h-24 min-w-24 rounded-xl px-7', text: 'text-headline-small' },
120
+ } as const
121
+ const extended = computed(() => (props.label ? EXTENDED[props.size] : null))
122
+
94
123
  const fabSizeClasses = computed(() => {
95
- // Extended FAB (androidx FloatingActionButton.kt): 16dp start padding, 12dp
96
- // icon-to-label gap, 20dp end padding, 80dp minimum width.
97
- if (props.label) return 'h-14 min-w-20 rounded-2xl pl-4 pr-5 gap-3'
124
+ if (extended.value) return extended.value.box
98
125
  switch (props.size) {
99
126
  case 'small': return 'h-10 w-10 rounded-md'
100
- case 'medium': return 'h-20 w-20 rounded-[20px]'
127
+ case 'medium': return 'h-20 w-20 rounded-lg-increased'
101
128
  case 'large': return 'h-24 w-24 rounded-[28px]'
102
129
  default: return 'h-14 w-14 rounded-2xl'
103
130
  }
104
131
  })
105
132
 
106
133
  const fabIconSize = computed(() => {
107
- if (props.label) return 24
134
+ if (extended.value) return extended.value.icon
108
135
  switch (props.size) {
109
136
  case 'small': return 24
110
137
  case 'medium': return 28
@@ -114,7 +141,7 @@ const fabIconSize = computed(() => {
114
141
  })
115
142
 
116
143
  const fabPx = computed(() => {
117
- if (props.label) return 56
144
+ if (extended.value) return extended.value.px
118
145
  switch (props.size) {
119
146
  case 'small': return 40
120
147
  case 'medium': return 80
@@ -123,6 +150,34 @@ const fabPx = computed(() => {
123
150
  }
124
151
  })
125
152
 
153
+ // Collapsing an extended FAB: the width lerps from the square (the minimum width) to the full width on
154
+ // FastSpatial, the label fades on FastEffects, and it leaves the layout once fully collapsed.
155
+ const fabButton = ref<HTMLElement | { $el: HTMLElement }>()
156
+ const labelEl = ref<HTMLElement>()
157
+ const buttonEl = () => (fabButton.value instanceof HTMLElement ? fabButton.value : fabButton.value?.$el)
158
+
159
+ useSpring(
160
+ () => (extended.value ? [props.expanded ? 1 : 0] : []),
161
+ ([p]) => {
162
+ const el = buttonEl()
163
+ if (!el || p === undefined || !extended.value) return
164
+ if (labelEl.value) labelEl.value.style.display = p <= 0 && !props.expanded ? 'none' : ''
165
+ el.style.width = ''
166
+ el.style.minWidth = ''
167
+ if (p >= 1 && props.expanded) return
168
+ const full = el.offsetWidth
169
+ const min = extended.value.px
170
+ el.style.minWidth = '0'
171
+ el.style.width = `${min + (full - min) * Math.max(0, p)}px`
172
+ },
173
+ FAST_SPATIAL,
174
+ )
175
+ useSpring(
176
+ () => (extended.value ? [props.expanded ? 1 : 0] : []),
177
+ ([alpha]) => { if (labelEl.value && alpha !== undefined) labelEl.value.style.opacity = String(Math.min(1, Math.max(0, alpha))) },
178
+ FAST_EFFECTS,
179
+ )
180
+
126
181
  const ITEM_PX = 40
127
182
  const ITEM_GAP = 8
128
183
 
@@ -197,16 +252,6 @@ function onScroll() {
197
252
  open.value = false
198
253
  }
199
254
 
200
- function createRipple(event: PointerEvent | MouseEvent, target?: HTMLElement) {
201
- const button = (target ?? event.currentTarget) as HTMLElement
202
- const rect = button.getBoundingClientRect()
203
- const d = Math.max(rect.width, rect.height) * 2
204
- const el = document.createElement('span')
205
- el.className = 'm3-ripple'
206
- 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`
207
- button.appendChild(el)
208
- el.addEventListener('animationend', () => el.remove(), { once: true })
209
- }
210
255
 
211
256
  const contentStyle = ref<Record<string, string>>({})
212
257
 
@@ -260,8 +305,7 @@ function handleFabClick(e: PointerEvent) {
260
305
  }
261
306
  }
262
307
 
263
- function handleItemClick(e: PointerEvent, item: SpeedDialItem, buttonEl: HTMLElement) {
264
- createRipple(e, buttonEl)
308
+ function handleItemClick(item: SpeedDialItem) {
265
309
  if (!props.persistent) open.value = false
266
310
  item.onClick?.()
267
311
  }
@@ -297,12 +341,14 @@ onUnmounted(() => {
297
341
  <div ref="fabEl" v-bind="$attrs" class="relative inline-flex items-center justify-center">
298
342
  <component
299
343
  :is="fabTag"
344
+ ref="fabButton"
300
345
  :to="to || undefined"
301
346
  :type="to ? undefined : 'button'"
302
- class="relative inline-flex cursor-pointer items-center justify-center overflow-hidden shadow-elevation-3 transition-shadow duration-150 hover:shadow-elevation-4 active:shadow-elevation-3 disabled:cursor-not-allowed disabled:opacity-[0.38] before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
303
- :class="[colorMap[color], fabSizeClasses]"
347
+ class="relative inline-flex cursor-pointer items-center overflow-hidden transition-shadow duration-150 disabled:cursor-not-allowed disabled:opacity-[0.38] before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
348
+ :class="[colorMap[color], fabSizeClasses, extended ? 'justify-start' : 'justify-center', inBottomAppBar ? '' : 'shadow-elevation-3 hover:shadow-elevation-4 active:shadow-elevation-3']"
304
349
  :disabled="disabled"
305
- @pointerdown="createRipple"
350
+ :aria-label="label && !expanded ? label : undefined"
351
+ v-ripple="{ disabled, color: rippleColor }"
306
352
  @click="handleFabClick"
307
353
  >
308
354
  <MIcon
@@ -311,7 +357,14 @@ onUnmounted(() => {
311
357
  class="transition-transform duration-300 ease-[cubic-bezier(0.34,1.56,0.64,1)]"
312
358
  :class="isExpandable && open ? 'rotate-45' : ''"
313
359
  />
314
- <span v-if="label" class="text-label-large font-medium">{{ label }}</span>
360
+ <!-- The icon-to-label space belongs to the label, so it goes when the label does -->
361
+ <span
362
+ v-if="extended"
363
+ ref="labelEl"
364
+ class="shrink-0 whitespace-nowrap"
365
+ :class="extended.text"
366
+ :style="{ paddingLeft: `${extended.gap}px` }"
367
+ >{{ label }}</span>
315
368
  </component>
316
369
  </div>
317
370
 
@@ -338,7 +391,8 @@ onUnmounted(() => {
338
391
  class="relative flex cursor-pointer items-center justify-center overflow-hidden rounded-lg shadow-elevation-3 transition-shadow duration-150 hover:shadow-elevation-4 active:shadow-elevation-3 before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
339
392
  :class="colorMap[color]"
340
393
  :style="{ width: `${ITEM_PX}px`, height: `${ITEM_PX}px` }"
341
- @pointerdown="(e: PointerEvent) => handleItemClick(e, item, e.currentTarget as HTMLElement)"
394
+ v-ripple="rippleColor"
395
+ @pointerdown="handleItemClick(item)"
342
396
  >
343
397
  <MIcon :name="item.icon" :size="20" />
344
398
  </component>
@@ -8,11 +8,13 @@ withDefaults(defineProps<{
8
8
  name: string
9
9
  /** Icon size in px */
10
10
  size?: number
11
- }>(), { size: 24 })
11
+ /** Filled glyph (the Material Symbols FILL axis), as M3 draws a selected icon */
12
+ filled?: boolean
13
+ }>(), { size: 24, filled: false })
12
14
  </script>
13
15
 
14
16
  <template>
15
- <span class="material-symbols-outlined leading-none" :style="{ fontSize: `${size}px` }">{{
17
+ <span class="material-symbols-outlined leading-none" :style="{ fontSize: `${size}px`, fontVariationSettings: filled ? `'FILL' 1` : undefined }">{{
16
18
  name
17
19
  }}</span>
18
20
  </template>
@@ -1,9 +1,14 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
- * A button that shows only an icon — four visual styles, the same 5-tier expressive sizing as MButton.
3
+ * A button that shows only an icon — four visual styles, the same 5-tier expressive sizing as MButton. Give it
4
+ * `checked` (v-model:checked) and it becomes M3's icon toggle button.
5
+ *
6
+ * @event update:checked Emitted on click when `checked` is set — powers v-model:checked
4
7
  */
5
- import { computed } from 'vue'
8
+ import { computed, ref } from 'vue'
6
9
  import MIcon from './MIcon.vue'
10
+ import { vRipple } from '../directives/vRipple'
11
+ import { DEFAULT_EFFECTS, useSpring } from '../composables/_useSpring'
7
12
 
8
13
  const props = withDefaults(
9
14
  defineProps<{
@@ -24,16 +29,29 @@ const props = withDefaults(
24
29
  disabled?: boolean
25
30
  /** Vue Router destination — renders as RouterLink instead of button */
26
31
  to?: string | Record<string, any>
32
+ /** Any CSS color for the press ripple; defaults to the button's content color */
33
+ rippleColor?: string
34
+ /**
35
+ * Makes it a toggle button (v-model:checked): selected colors, a filled icon, and a shape that morphs when
36
+ * pressed and when checked. Leave it unset for a plain icon button
37
+ */
38
+ checked?: boolean
39
+ /** Icon shown while checked, when it differs from `icon` (e.g. 'pause' for 'play_arrow') */
40
+ checkedIcon?: string
27
41
  }>(),
28
42
  {
29
43
  variant: 'standard',
30
44
  shape: 'rounded',
31
45
  size: 'sm',
32
46
  disabled: false,
47
+ checked: undefined,
33
48
  },
34
49
  )
35
50
 
36
- const tag = computed(() => props.to ? 'RouterLink' : 'button')
51
+ const emit = defineEmits<{ 'update:checked': [boolean] }>()
52
+
53
+ const isToggle = computed(() => props.checked !== undefined)
54
+ const tag = computed(() => props.to && !isToggle.value ? 'RouterLink' : 'button')
37
55
 
38
56
  // Container height/width (icon buttons are always square by default — real
39
57
  // `IconButtonDefaults.<tier>ContainerSize()` also has Narrow/Wide width options not
@@ -41,19 +59,58 @@ const tag = computed(() => props.to ? 'RouterLink' : 'button')
41
59
  // per M3's 5-tier `{XSmall,Small,Medium,Large,XLarge}IconButtonTokens.kt`. `squareRadius`
42
60
  // matches each tier's own `ContainerShapeSquare` (12px xs/sm, 16px md, 28px lg/xl) — same
43
61
  // pattern as MButton's size tiers.
62
+ // Toggle radii (px) from the same token files: `square` is ContainerShapeSquare, `pressed`
63
+ // PressedContainerShape, `checkedRound` SelectedContainerShapeRound (a round button squares off when
64
+ // checked); SelectedContainerShapeSquare is CornerFull (a square one turns round), i.e. px / 2.
44
65
  const sizeMap = {
45
- xs: { px: 32, icon: 20, squareRadius: 'rounded-md' },
46
- sm: { px: 40, icon: 24, squareRadius: 'rounded-md' },
47
- md: { px: 56, icon: 24, squareRadius: 'rounded-lg' },
48
- lg: { px: 96, icon: 32, squareRadius: 'rounded-xl' },
49
- xl: { px: 136, icon: 40, squareRadius: 'rounded-xl' },
66
+ xs: { px: 32, icon: 20, squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 },
67
+ sm: { px: 40, icon: 24, squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 },
68
+ md: { px: 56, icon: 24, squareRadius: 'rounded-lg', square: 16, pressed: 12, checkedRound: 16 },
69
+ lg: { px: 96, icon: 32, squareRadius: 'rounded-xl', square: 28, pressed: 16, checkedRound: 28 },
70
+ xl: { px: 136, icon: 40, squareRadius: 'rounded-xl', square: 28, pressed: 16, checkedRound: 28 },
50
71
  }
51
72
 
52
73
  const resolved = computed(() => {
53
- if (typeof props.size === 'number') return { px: props.size, icon: Math.round(props.size * 0.55), squareRadius: 'rounded-md' }
74
+ if (typeof props.size === 'number') {
75
+ return { px: props.size, icon: Math.round(props.size * 0.55), squareRadius: 'rounded-md', square: 12, pressed: 8, checkedRound: 12 }
76
+ }
54
77
  return sizeMap[props.size] ?? sizeMap.sm
55
78
  })
56
79
 
80
+ // Icon toggle shape morph (IconButton.kt's shapeByInteraction: pressed, else checked, else the resting
81
+ // shape), on the DefaultEffects spring the source picks so it doesn't bounce. Plain icon buttons keep
82
+ // a static shape, like Compose's non-`shapes` overloads.
83
+ const rootEl = ref<unknown>(null)
84
+ const pressed = ref(false)
85
+
86
+ function targetRadius() {
87
+ const r = resolved.value
88
+ const full = r.px / 2
89
+ if (pressed.value) return r.pressed
90
+ if (props.checked) return props.shape === 'squared' ? full : r.checkedRound
91
+ return props.shape === 'squared' ? r.square : full
92
+ }
93
+
94
+ useSpring(
95
+ () => (isToggle.value ? [targetRadius()] : []),
96
+ (v) => {
97
+ // A RouterLink root (plain button with `to`) is a component instance, not an element
98
+ if (rootEl.value instanceof HTMLElement) rootEl.value.style.borderRadius = v.length ? `${v[0]}px` : ''
99
+ },
100
+ DEFAULT_EFFECTS,
101
+ )
102
+
103
+ function onPointerDown() {
104
+ if (isToggle.value && !props.disabled) pressed.value = true
105
+ }
106
+ function onPointerUp() {
107
+ pressed.value = false
108
+ }
109
+
110
+ function onClick() {
111
+ if (isToggle.value && !props.disabled) emit('update:checked', !props.checked)
112
+ }
113
+
57
114
  /*
58
115
  * State layer via a `before:` overlay (same technique MButton uses) rather than a direct
59
116
  * `hover:bg-*`/`active:bg-*` utility: a solid `bg-primary`/`bg-secondary-container`
@@ -76,6 +133,7 @@ const base =
76
133
  // `disabled:text-on-surface/38` in `base` above, exactly like the real `outlinedIconButtonBorder`
77
134
  // (which literally reuses `LocalContentColor` at the same disabled opacity as the icon).
78
135
  const disabledContainerClasses = computed(() => {
136
+ if (props.variant === 'outlined' && props.checked) return 'disabled:bg-on-surface/10'
79
137
  switch (props.variant) {
80
138
  case 'filled':
81
139
  case 'tonal':
@@ -87,19 +145,26 @@ const disabledContainerClasses = computed(() => {
87
145
 
88
146
  const shapeClass = computed(() => props.shape === 'squared' ? resolved.value.squareRadius : 'rounded-full')
89
147
 
90
- function createRipple(event: PointerEvent) {
91
- if (props.disabled) return
92
- const button = event.currentTarget as HTMLElement
93
- const rect = button.getBoundingClientRect()
94
- const d = Math.max(rect.width, rect.height) * 2
95
- const el = document.createElement('span')
96
- el.className = 'm3-ripple'
97
- 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`
98
- button.appendChild(el)
99
- el.addEventListener('animationend', () => el.remove(), { once: true })
100
- }
148
+
149
+ // Toggle colors: the Selected*/Unselected* tokens of each variant's *IconButtonTokens. Unchecked
150
+ // filled/tonal differ from the plain button's colors, so the checked state stands out.
151
+ const toggleClasses = computed(() => {
152
+ const on = props.checked
153
+ switch (props.variant) {
154
+ case 'filled':
155
+ return on ? 'bg-primary text-on-primary' : 'bg-surface-container text-on-surface-variant'
156
+ case 'tonal':
157
+ return on ? 'bg-secondary text-on-secondary' : 'bg-secondary-container text-on-secondary-container'
158
+ case 'outlined':
159
+ // outlinedIconToggleButtonBorder: no border once checked
160
+ return on ? 'bg-inverse-surface text-inverse-on-surface' : 'border border-current text-on-surface-variant'
161
+ default:
162
+ return on ? 'text-primary' : 'text-on-surface-variant'
163
+ }
164
+ })
101
165
 
102
166
  const variantClasses = computed(() => {
167
+ if (isToggle.value) return toggleClasses.value
103
168
  switch (props.variant) {
104
169
  case 'filled':
105
170
  // Real IconButton.kt has no elevation tokens at all for any variant — flat, unlike Button
@@ -119,14 +184,21 @@ const variantClasses = computed(() => {
119
184
  <template>
120
185
  <component
121
186
  :is="tag"
122
- :to="to || undefined"
123
- :type="to ? undefined : 'button'"
187
+ ref="rootEl"
188
+ :to="tag === 'RouterLink' ? to : undefined"
189
+ :type="tag === 'RouterLink' ? undefined : 'button'"
124
190
  :aria-label="label || undefined"
191
+ :aria-pressed="isToggle ? checked : undefined"
125
192
  :disabled="disabled"
126
193
  :class="[base, shapeClass, variantClasses, disabledContainerClasses]"
127
194
  :style="{ width: `${resolved.px}px`, height: `${resolved.px}px` }"
128
- @pointerdown="createRipple"
195
+ v-ripple="{ disabled, color: rippleColor }"
196
+ @pointerdown="onPointerDown"
197
+ @pointerup="onPointerUp"
198
+ @pointerleave="onPointerUp"
199
+ @pointercancel="onPointerUp"
200
+ @click="onClick"
129
201
  >
130
- <MIcon :name="icon" :size="resolved.icon" />
202
+ <MIcon :name="checked && checkedIcon ? checkedIcon : icon" :size="resolved.icon" :filled="!!checked" />
131
203
  </component>
132
204
  </template>
@@ -1,7 +1,9 @@
1
1
  <script setup lang="ts">
2
2
  /**
3
3
  * An item of an MMenu or MContextMenu: icon, label and a shortcut hint. Put more items in its `#children` slot
4
- * to make it open a submenu.
4
+ * to make it open a submenu. With `selected` it's one choice of several (Compose's SelectableDropdownMenuItem),
5
+ * with `checked` an on/off setting (CheckableDropdownMenuItem): tertiary-container and rounder while on, with a
6
+ * check that slides in.
5
7
  *
6
8
  * @slot default Item label text.
7
9
  * @slot children Nested submenu items. In the parent MMenu's default 'flyout' mode, clicking or hovering (mouse
@@ -9,9 +11,11 @@
9
11
  * instead swaps the whole menu panel to the submenu with a back header; hover does nothing.
10
12
  * @event click Emitted when a leaf item (no #children) is clicked. Not emitted for disabled items or for items
11
13
  * with #children, since clicking those just opens/toggles the submenu instead.
14
+ * @event update:checked Emitted on click when `checked` is set, with the new value — powers v-model:checked
12
15
  */
13
- import { computed, inject, ref, useSlots } from 'vue'
16
+ import { computed, inject, nextTick, onMounted, onUnmounted, ref, useSlots, watch } from 'vue'
14
17
  import MIcon from './MIcon.vue'
18
+ import { FAST_EFFECTS, FAST_SPATIAL, useSpring } from '../composables/_useSpring'
15
19
 
16
20
  const props = withDefaults(defineProps<{
17
21
  /** Material Symbol icon name */
@@ -24,15 +28,84 @@ const props = withDefaults(defineProps<{
24
28
  disabled?: boolean
25
29
  /** Danger/destructive styling (error color) */
26
30
  danger?: boolean
27
- /** Keep the menu open after this item is clicked (e.g. checkable/toggle items). */
31
+ /** Keep the menu open after this item is clicked. Defaults to true for `checked` items, false otherwise */
28
32
  keepOpen?: boolean
33
+ /** Makes it one choice of several (radio-like): selected look while true. Leave unset for a plain item */
34
+ selected?: boolean
35
+ /** Makes it an on/off setting (v-model:checked, checkbox-like): checked look while true. Leave unset for a plain item */
36
+ checked?: boolean
37
+ /**
38
+ * Icon shown while selected or checked. Defaults to a check that slides in when the item has no `icon`;
39
+ * with an `icon`, that icon stays and turns filled
40
+ */
41
+ selectedIcon?: string
29
42
  }>(), {
30
43
  disabled: false,
31
44
  danger: false,
32
- keepOpen: false,
45
+ keepOpen: undefined,
46
+ selected: undefined,
47
+ checked: undefined,
33
48
  })
34
49
 
35
- const emit = defineEmits<{ click: [] }>()
50
+ const emit = defineEmits<{ click: [], 'update:checked': [boolean] }>()
51
+
52
+ const checkable = computed(() => props.checked !== undefined)
53
+ const selectable = computed(() => checkable.value || props.selected !== undefined)
54
+ const on = computed(() => !!(props.checked ?? props.selected))
55
+ // Without an `icon`, the selected icon (a check by default) only shows while on and slides the label aside
56
+ const slidingIcon = computed(() => selectable.value && !props.icon)
57
+ const onIcon = computed(() => props.selectedIcon ?? (props.icon ? undefined : 'check'))
58
+
59
+ // Where this item sits in a run of consecutive selectable/checkable siblings, MenuDefaults.itemShape(index,
60
+ // count): the first rounds its top corners, the last its bottom ones, a lone one stays square-ish
61
+ const position = ref<'single' | 'first' | 'middle' | 'last'>('single')
62
+ function measurePosition() {
63
+ const el = itemEl.value
64
+ if (!el || !selectable.value) return
65
+ const choice = (n: Element | null) => !!n?.hasAttribute('data-m3-menu-choice')
66
+ const prev = choice(el.previousElementSibling)
67
+ const next = choice(el.nextElementSibling)
68
+ position.value = prev && next ? 'middle' : prev ? 'last' : next ? 'first' : 'single'
69
+ }
70
+
71
+ // Item shapes (SegmentedMenuTokens, MenuDefaults' leading/middle/trailing/standalone item shapes): ItemShape
72
+ // 4dp, CornerMedium 12dp on the group's outer corners, ItemSelectedShape 12dp all round; corners morph on
73
+ // FastSpatial. The sliding icon expands on FastSpatial and fades on FastEffects (AnimatedVisibility's
74
+ // expandHorizontally + fadeIn).
75
+ const ICON_SPACE = 32 // 20dp icon + 12dp to the label
76
+ function radii(): number[] {
77
+ if (on.value) return [12, 12, 12, 12]
78
+ const top = position.value === 'first' ? 12 : 4
79
+ const bottom = position.value === 'last' ? 12 : 4
80
+ return [top, top, bottom, bottom]
81
+ }
82
+ const { snap } = useSpring(
83
+ () => (selectable.value ? [...radii(), slidingIcon.value && on.value ? ICON_SPACE : 0] : []),
84
+ ([tl, tr, br, bl, width]) => {
85
+ const el = controlEl.value instanceof HTMLElement ? controlEl.value : controlEl.value?.$el
86
+ if (el && bl !== undefined) el.style.borderRadius = `${tl}px ${tr}px ${br}px ${bl}px`
87
+ if (iconSlotEl.value && width !== undefined) iconSlotEl.value.style.width = `${width}px`
88
+ },
89
+ FAST_SPATIAL,
90
+ )
91
+ // A position change comes from the layout (items added, removed, the menu opening): jump, don't morph
92
+ watch(position, () => snap())
93
+
94
+ let siblingsObserver: MutationObserver | null = null
95
+ onMounted(() => {
96
+ measurePosition()
97
+ const parent = itemEl.value?.parentElement
98
+ if (!parent) return
99
+ siblingsObserver = new MutationObserver(measurePosition)
100
+ siblingsObserver.observe(parent, { childList: true })
101
+ })
102
+ onUnmounted(() => siblingsObserver?.disconnect())
103
+ watch(selectable, () => nextTick(measurePosition))
104
+ useSpring(
105
+ () => (slidingIcon.value ? [on.value ? 1 : 0] : []),
106
+ ([opacity]) => { if (iconSlotEl.value && opacity !== undefined) iconSlotEl.value.style.opacity = String(opacity) },
107
+ FAST_EFFECTS,
108
+ )
36
109
 
37
110
  const slots = useSlots()
38
111
  const tag = computed(() => props.to ? 'RouterLink' : 'button')
@@ -44,6 +117,9 @@ const nav = inject<{
44
117
  } | null>('m-menu-nav', null)
45
118
 
46
119
  const itemEl = ref<HTMLElement>()
120
+ // The button, or a RouterLink instance when `to` is set
121
+ const controlEl = ref<HTMLElement | { $el: HTMLElement }>()
122
+ const iconSlotEl = ref<HTMLElement>()
47
123
  const showSub = ref(false)
48
124
  const subStyle = ref<Record<string, string>>({})
49
125
 
@@ -82,8 +158,9 @@ function handleClick() {
82
158
  return
83
159
  }
84
160
 
161
+ if (checkable.value) emit('update:checked', !props.checked)
85
162
  emit('click')
86
- if (!props.keepOpen) menuClose?.()
163
+ if (!(props.keepOpen ?? checkable.value)) menuClose?.()
87
164
  }
88
165
 
89
166
  // Desktop hover convenience for the flyout variant — ignored on touch/pen so a
@@ -113,25 +190,50 @@ function onSubPointerLeave(e: PointerEvent) {
113
190
  <template>
114
191
  <div
115
192
  ref="itemEl"
193
+ :data-m3-menu-choice="selectable || undefined"
116
194
  @pointerenter="onPointerEnter"
117
195
  @pointerleave="onPointerLeave"
118
196
  >
197
+ <!-- Selectable/checkable items sit 4dp in from the edges (DropdownMenuSelectableItemPadding) with 12dp
198
+ inside, so their label lines up with plain items; the state layer is a pseudo-element so it can
199
+ tint the selected container too -->
119
200
  <component
120
201
  :is="tag"
202
+ ref="controlEl"
121
203
  :to="to || undefined"
122
204
  :type="to ? undefined : 'button'"
123
- class="flex w-full items-center gap-3 px-4 py-2.5 text-left text-body-large transition-colors outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
124
- :class="[
125
- disabled ? 'cursor-not-allowed opacity-[0.38] text-on-surface' : 'cursor-pointer',
126
- !disabled && danger ? 'text-error hover:bg-error/8' : '',
127
- !disabled && !danger ? 'text-on-surface hover:bg-on-surface/8' : '',
128
- ]"
205
+ :role="selectable ? (checkable ? 'menuitemcheckbox' : 'menuitemradio') : undefined"
206
+ :aria-checked="selectable ? on : undefined"
207
+ class="flex items-center gap-3 py-2.5 text-left text-body-large transition-colors outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
208
+ :class="selectable
209
+ ? [
210
+ 'relative mx-1 w-[calc(100%-0.5rem)] px-3 duration-150 before:pointer-events-none before:absolute before:inset-0 before:rounded-[inherit] before:bg-current before:opacity-0 before:transition-opacity',
211
+ on ? 'bg-tertiary-container text-on-tertiary-container' : 'text-on-surface',
212
+ disabled ? 'cursor-not-allowed opacity-[0.38]' : 'cursor-pointer hover:before:opacity-[0.08] active:before:opacity-[0.12]',
213
+ ]
214
+ : [
215
+ 'w-full px-4',
216
+ disabled ? 'cursor-not-allowed opacity-[0.38] text-on-surface' : 'cursor-pointer',
217
+ !disabled && danger ? 'text-error hover:bg-error/8' : '',
218
+ !disabled && !danger ? 'text-on-surface hover:bg-on-surface/8' : '',
219
+ ]"
129
220
  :disabled="disabled || undefined"
130
221
  :aria-haspopup="hasChildren ? 'menu' : undefined"
131
222
  :aria-expanded="hasChildren ? showSub : undefined"
132
223
  @click="handleClick"
133
224
  >
134
- <MIcon v-if="icon" :name="icon" :size="20" class="shrink-0" :class="danger ? 'text-error' : 'text-on-surface-variant'" />
225
+ <!-- -mr-3 cancels the flex gap, so the label sits flush while the slot is closed -->
226
+ <span v-if="slidingIcon" ref="iconSlotEl" class="-mr-3 flex shrink-0 overflow-hidden" style="width: 0; opacity: 0">
227
+ <MIcon :name="onIcon!" :size="20" class="shrink-0" />
228
+ </span>
229
+ <MIcon
230
+ v-else-if="icon"
231
+ :name="on && onIcon ? onIcon : icon"
232
+ :filled="on && !onIcon"
233
+ :size="20"
234
+ class="shrink-0"
235
+ :class="selectable ? (on ? '' : 'text-on-surface-variant') : danger ? 'text-error' : 'text-on-surface-variant'"
236
+ />
135
237
  <span class="flex-1"><slot /></span>
136
238
  <span v-if="shortcut && !hasChildren" class="ml-4 shrink-0 text-label-small text-on-surface-variant opacity-60">{{ shortcut }}</span>
137
239
  <MIcon v-if="hasChildren" name="chevron_right" :size="18" class="shrink-0 text-on-surface-variant" />
@@ -192,7 +192,7 @@ watch(
192
192
  </h2>
193
193
  </div>
194
194
 
195
- <div class="flex min-h-0 flex-1 flex-col overflow-y-auto px-3 py-2">
195
+ <div class="scrollbar-none flex min-h-0 flex-1 flex-col overflow-y-auto px-3 py-2">
196
196
  <template v-for="(section, si) in sections" :key="si">
197
197
  <div v-if="si > 0" class="my-1 border-t border-outline-variant" />
198
198
 
@@ -329,7 +329,7 @@ watch(
329
329
  </div>
330
330
 
331
331
  <div
332
- class="flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto overflow-x-hidden px-3 py-2"
332
+ class="scrollbar-none flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto overflow-x-hidden px-3 py-2"
333
333
  >
334
334
  <template v-for="(section, si) in sections" :key="si">
335
335
  <div v-if="si > 0" class="my-1 border-t border-outline-variant" />