@m3ui-vue/m3ui-vue 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -0
- package/dist/API.md +266 -60
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-pJU1vFaR.js → MTextField-DKtgPymd.js} +422 -206
- package/dist/MTextField-DKtgPymd.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.md +547 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MBox.vue.d.ts +3 -3
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MColorPicker.vue.d.ts +13 -1
- package/dist/components/MColorPickerModal.vue.d.ts +14 -2
- package/dist/components/MDragHandle.vue.d.ts +12 -0
- package/dist/components/MEmojiSelector.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +5 -3
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MOverlay.vue.d.ts +1 -1
- package/dist/components/MScrollField.vue.d.ts +40 -0
- package/dist/components/MScrollable.vue.d.ts +9 -0
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MSplitter.vue.d.ts +2 -2
- package/dist/components/MSwipeToDismiss.vue.d.ts +49 -0
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTimePickerModal.vue.d.ts +3 -0
- package/dist/components/MTimeScroll.vue.d.ts +22 -0
- package/dist/components/MToggleButton.vue.d.ts +2 -0
- package/dist/components/MTransition.vue.d.ts +34 -0
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/MWindow.vue.d.ts +1 -1
- package/dist/components/_MColorPanel.vue.d.ts +18 -0
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_colorUtils.d.ts +34 -0
- package/dist/composables/_themeColor.d.ts +1 -0
- package/dist/composables/_useSpring.d.ts +17 -0
- package/dist/composables/dynamicColor.d.ts +18 -0
- package/dist/composables/useColorPalette.d.ts +27 -0
- package/dist/composables/useLocale.d.ts +16 -0
- package/dist/directives/vRipple.d.ts +16 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/locales/index.js +112 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7443 -6150
- package/dist/m3ui.js.map +1 -1
- package/dist/material-color-utilities-Cktu8DBU.js +3160 -0
- package/dist/material-color-utilities-Cktu8DBU.js.map +1 -0
- package/dist/plugin.d.ts +18 -0
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/palettes.css +546 -0
- package/dist/styles/theme.css +90 -0
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-Drihe5G2.js → useLocale-Cn9MVIdw.js} +17 -1
- package/dist/useLocale-Cn9MVIdw.js.map +1 -0
- package/package.json +3 -2
- package/src/__tests__/MButtonGroup.test.ts +51 -0
- package/src/__tests__/MColorPicker.test.ts +141 -0
- package/src/__tests__/MDragHandle.test.ts +57 -0
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MListItemShape.test.ts +76 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MScrollField.test.ts +69 -0
- package/src/__tests__/MScrollable.test.ts +42 -0
- package/src/__tests__/MSwipeToDismiss.test.ts +104 -0
- package/src/__tests__/MTabs.test.ts +39 -0
- package/src/__tests__/MTimePickerModal.test.ts +52 -0
- package/src/__tests__/MTimeScroll.test.ts +44 -0
- package/src/__tests__/MTransition.test.ts +27 -0
- package/src/__tests__/dynamicColor.test.ts +191 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MBox.vue +4 -2
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +118 -44
- package/src/components/MColorPicker.vue +114 -210
- package/src/components/MColorPickerModal.vue +50 -251
- package/src/components/MDragHandle.vue +54 -0
- package/src/components/MFab.vue +8 -15
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MList.vue +33 -3
- package/src/components/MListItem.vue +75 -5
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MScrollField.vue +310 -0
- package/src/components/MScrollable.vue +160 -5
- package/src/components/MSplitButton.vue +5 -12
- package/src/components/MSplitter.vue +33 -10
- package/src/components/MSwipeToDismiss.vue +247 -0
- package/src/components/MTabs.vue +16 -5
- package/src/components/MTimePickerModal.vue +48 -8
- package/src/components/MTimeScroll.vue +161 -0
- package/src/components/MToggleButton.vue +5 -12
- package/src/components/MTransition.vue +149 -0
- package/src/components/_MColorPanel.vue +478 -0
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_colorUtils.ts +107 -0
- package/src/composables/_themeColor.ts +33 -0
- package/src/composables/_useSpring.ts +91 -0
- package/src/composables/dynamicColor.ts +85 -0
- package/src/composables/useColorPalette.ts +171 -25
- package/src/composables/useFieldBg.ts +6 -0
- package/src/composables/useLocale.ts +34 -0
- package/src/data/emoji-names/emoji-names-de.ts +1 -0
- package/src/data/emoji-names/emoji-names-en.ts +1 -0
- package/src/data/emoji-names/emoji-names-es.ts +1 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1 -0
- package/src/data/emojis.ts +1 -0
- package/src/directives/vRipple.ts +73 -0
- package/src/index.ts +14 -1
- package/src/locales/de.ts +16 -0
- package/src/locales/es.ts +16 -0
- package/src/locales/fr.ts +16 -0
- package/src/locales/ja.ts +16 -0
- package/src/locales/ko.ts +16 -0
- package/src/locales/pt.ts +16 -0
- package/src/locales/zh.ts +16 -0
- package/src/plugin.ts +30 -7
- package/src/styles/palettes.css +546 -0
- package/src/styles/theme.css +90 -0
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-pJU1vFaR.js.map +0 -1
- package/dist/useLocale-Drihe5G2.js.map +0 -1
package/src/components/MList.vue
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @slot default MListItem / MListSubheader children
|
|
8
8
|
* @event update:selected Fires when a selectable item is clicked (via v-model:selected)
|
|
9
9
|
*/
|
|
10
|
-
import { computed, provide } from 'vue'
|
|
10
|
+
import { computed, onMounted, onUnmounted, provide, ref, shallowRef } from 'vue'
|
|
11
11
|
|
|
12
12
|
const props = withDefaults(
|
|
13
13
|
defineProps<{
|
|
@@ -33,7 +33,36 @@ const emit = defineEmits<{
|
|
|
33
33
|
'update:selected': [value: string | number | null]
|
|
34
34
|
}>()
|
|
35
35
|
|
|
36
|
+
// Segmented items need to know whether they open or close their run of items (SegmentedListItem's
|
|
37
|
+
// segmentedShapes(index, count)). A subheader or any other non-item child starts a new run.
|
|
38
|
+
const listEl = ref<HTMLElement>()
|
|
39
|
+
const positions = shallowRef(new Map<Element, 'single' | 'first' | 'middle' | 'last'>())
|
|
40
|
+
function measure() {
|
|
41
|
+
const map = new Map<Element, 'single' | 'first' | 'middle' | 'last'>()
|
|
42
|
+
let run: Element[] = []
|
|
43
|
+
const flush = () => {
|
|
44
|
+
run.forEach((el, i) => map.set(el, run.length === 1 ? 'single' : i === 0 ? 'first' : i === run.length - 1 ? 'last' : 'middle'))
|
|
45
|
+
run = []
|
|
46
|
+
}
|
|
47
|
+
for (const child of listEl.value?.children ?? []) {
|
|
48
|
+
if (child.getAttribute('role') === 'listitem') run.push(child)
|
|
49
|
+
else flush()
|
|
50
|
+
}
|
|
51
|
+
flush()
|
|
52
|
+
positions.value = map
|
|
53
|
+
}
|
|
54
|
+
let observer: MutationObserver | undefined
|
|
55
|
+
onMounted(() => {
|
|
56
|
+
measure()
|
|
57
|
+
if (listEl.value) {
|
|
58
|
+
observer = new MutationObserver(measure)
|
|
59
|
+
observer.observe(listEl.value, { childList: true })
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
onUnmounted(() => observer?.disconnect())
|
|
63
|
+
|
|
36
64
|
provide('m-list', {
|
|
65
|
+
segmentPosition: (el: Element | null | undefined) => (el ? positions.value.get(el) : undefined),
|
|
37
66
|
dense: computed(() => props.dense),
|
|
38
67
|
nav: computed(() => props.nav),
|
|
39
68
|
segmented: computed(() => props.segmented),
|
|
@@ -46,13 +75,14 @@ provide('m-list', {
|
|
|
46
75
|
|
|
47
76
|
const classes = computed(() => [
|
|
48
77
|
'flex flex-col',
|
|
49
|
-
|
|
78
|
+
// ListTokens.SegmentedGap = 2dp
|
|
79
|
+
props.segmented ? 'gap-0.5 p-2' : 'py-2',
|
|
50
80
|
props.nav && !props.segmented && 'gap-0.5 px-3',
|
|
51
81
|
])
|
|
52
82
|
</script>
|
|
53
83
|
|
|
54
84
|
<template>
|
|
55
|
-
<ul role="list" :class="classes">
|
|
85
|
+
<ul ref="listEl" role="list" :class="classes">
|
|
56
86
|
<slot />
|
|
57
87
|
</ul>
|
|
58
88
|
</template>
|
|
@@ -13,11 +13,13 @@
|
|
|
13
13
|
* @event update:expanded Fires when an expandable item is toggled open/closed
|
|
14
14
|
*/
|
|
15
15
|
import { computed, inject, ref, useAttrs, watch } from 'vue'
|
|
16
|
+
import type { ComponentPublicInstance } from 'vue'
|
|
16
17
|
import type { ComputedRef } from 'vue'
|
|
17
18
|
import MIcon from './MIcon.vue'
|
|
18
19
|
import MAvatar from './MAvatar.vue'
|
|
19
20
|
import MCheckbox from './MCheckbox.vue'
|
|
20
21
|
import MSwitch from './MSwitch.vue'
|
|
22
|
+
import { useSpring } from '../composables/_useSpring'
|
|
21
23
|
|
|
22
24
|
export type ListItemLeading = 'icon' | 'avatar' | 'checkbox' | 'radio' | 'image' | 'icon-container'
|
|
23
25
|
export type ListItemTrailing = 'icon' | 'text' | 'switch' | 'checkbox'
|
|
@@ -87,6 +89,7 @@ watch(() => props.expanded, (v) => { if (v !== undefined) internalExpanded.value
|
|
|
87
89
|
const isExpanded = computed(() => internalExpanded.value)
|
|
88
90
|
|
|
89
91
|
const list = inject<{
|
|
92
|
+
segmentPosition: (el: Element | null | undefined) => 'single' | 'first' | 'middle' | 'last' | undefined
|
|
90
93
|
dense: ComputedRef<boolean>
|
|
91
94
|
nav: ComputedRef<boolean>
|
|
92
95
|
segmented: ComputedRef<boolean>
|
|
@@ -157,9 +160,8 @@ const minHeightClass = computed(() => {
|
|
|
157
160
|
|
|
158
161
|
const containerClasses = computed(() => [
|
|
159
162
|
'mli-row relative flex w-full items-center gap-4 text-left',
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
: isNav.value ? 'rounded-full px-4' : 'px-4',
|
|
163
|
+
// Corner radius: a pill in nav lists, otherwise sprung by expressiveRadii below
|
|
164
|
+
isSegmented.value ? 'bg-surface-container px-4' : isNav.value ? 'rounded-full px-4' : 'px-4',
|
|
163
165
|
isDense.value
|
|
164
166
|
? 'py-1'
|
|
165
167
|
: resolvedLines.value === 3 ? 'py-3' : 'py-2',
|
|
@@ -171,6 +173,57 @@ const containerClasses = computed(() => [
|
|
|
171
173
|
props.disabled && 'opacity-[0.38] pointer-events-none',
|
|
172
174
|
])
|
|
173
175
|
|
|
176
|
+
// ── Expressive shape morph ──────────────────────────────────────────────────────────────────
|
|
177
|
+
// The current (non-deprecated) ListItem overloads morph the container's corners by interaction, with
|
|
178
|
+
// ListItemDefaults.shapes(): ListTokens.ItemContainerExpressiveShape CornerExtraSmall (4dp) at rest,
|
|
179
|
+
// ItemHovered… CornerMedium (8dp), ItemPressed/Focused/Selected… CornerLarge (16dp), priority
|
|
180
|
+
// pressed > selected > focused > hovered (shapeForInteraction). SegmentedListItem's segmentedShapes() swaps
|
|
181
|
+
// only the resting shape's outer corners for ListTokens.ContainerShape (CornerLarge) on the first and last
|
|
182
|
+
// item of a run; the interaction shapes stay the same. Animated with MotionSchemeKeyTokens.FastSpatial.
|
|
183
|
+
// Nav lists keep their pill (that's NavigationDrawerItem's shape, which doesn't morph).
|
|
184
|
+
const rootEl = ref<Element | ComponentPublicInstance | null>(null)
|
|
185
|
+
const shapeEl = ref<HTMLElement | null>(null)
|
|
186
|
+
const el = (r: Element | ComponentPublicInstance | null) => (r && '$el' in r ? (r.$el as Element) : r)
|
|
187
|
+
const hovered = ref(false)
|
|
188
|
+
const pressed = ref(false)
|
|
189
|
+
const focused = ref(false)
|
|
190
|
+
|
|
191
|
+
const REST = 4
|
|
192
|
+
const HOVERED = 8
|
|
193
|
+
const LARGE = 16
|
|
194
|
+
|
|
195
|
+
const segmentPosition = computed(() => (isSegmented.value ? list?.segmentPosition(el(rootEl.value)) : undefined))
|
|
196
|
+
|
|
197
|
+
const expressiveRadii = computed<number[]>(() => {
|
|
198
|
+
if (isNav.value) return []
|
|
199
|
+
const interactive = isClickable.value && !props.disabled
|
|
200
|
+
const r = interactive && pressed.value ? LARGE
|
|
201
|
+
: isActive.value ? LARGE
|
|
202
|
+
: interactive && focused.value ? LARGE
|
|
203
|
+
: interactive && hovered.value ? HOVERED
|
|
204
|
+
: null
|
|
205
|
+
if (r !== null) return [r, r, r, r]
|
|
206
|
+
const pos = segmentPosition.value
|
|
207
|
+
const top = pos === 'first' || pos === 'single' ? LARGE : REST
|
|
208
|
+
const bottom = pos === 'last' || pos === 'single' ? LARGE : REST
|
|
209
|
+
return [top, top, bottom, bottom]
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
const { snap } = useSpring(() => expressiveRadii.value, (v) => {
|
|
213
|
+
const target = shapeEl.value ?? (el(rootEl.value) as HTMLElement | null)
|
|
214
|
+
if (!target) return
|
|
215
|
+
target.style.borderRadius = v.length ? v.map((n) => `${n}px`).join(' ') : ''
|
|
216
|
+
})
|
|
217
|
+
// A change of place in the list (or of list style) isn't an interaction: jump there
|
|
218
|
+
watch([segmentPosition, isNav], () => snap())
|
|
219
|
+
|
|
220
|
+
function onPointerEnter(e: PointerEvent) { if (e.pointerType !== 'touch') hovered.value = true }
|
|
221
|
+
function onPointerLeave() { hovered.value = false; pressed.value = false }
|
|
222
|
+
function onPointerDown(e: PointerEvent) { if (e.button === 0) pressed.value = true }
|
|
223
|
+
function onPointerUp() { pressed.value = false }
|
|
224
|
+
function onFocus(e: FocusEvent) { focused.value = (e.currentTarget as Element).matches(':focus-visible') }
|
|
225
|
+
function onBlur() { focused.value = false }
|
|
226
|
+
|
|
174
227
|
const tag = computed(() => {
|
|
175
228
|
if (props.href) return 'a'
|
|
176
229
|
if (props.to) return 'router-link'
|
|
@@ -209,8 +262,17 @@ function handleTrailingToggle() {
|
|
|
209
262
|
</script>
|
|
210
263
|
|
|
211
264
|
<template>
|
|
212
|
-
<li v-if="expandable" role="listitem">
|
|
213
|
-
<div
|
|
265
|
+
<li v-if="expandable" ref="rootEl" role="listitem">
|
|
266
|
+
<div
|
|
267
|
+
ref="shapeEl"
|
|
268
|
+
:class="containerClasses"
|
|
269
|
+
@click="handleClick"
|
|
270
|
+
@pointerenter="onPointerEnter"
|
|
271
|
+
@pointerleave="onPointerLeave"
|
|
272
|
+
@pointerdown="onPointerDown"
|
|
273
|
+
@pointerup="onPointerUp"
|
|
274
|
+
@pointercancel="onPointerUp"
|
|
275
|
+
>
|
|
214
276
|
<!-- Leading -->
|
|
215
277
|
<slot name="leading">
|
|
216
278
|
<MIcon v-if="resolvedLeading === 'icon'" :name="icon!" :size="24" class="shrink-0" :class="activeIconClass" />
|
|
@@ -252,9 +314,17 @@ function handleTrailingToggle() {
|
|
|
252
314
|
v-else
|
|
253
315
|
:is="tag"
|
|
254
316
|
:class="containerClasses"
|
|
317
|
+
ref="rootEl"
|
|
255
318
|
v-bind="linkProps"
|
|
256
319
|
role="listitem"
|
|
257
320
|
@click="handleClick"
|
|
321
|
+
@pointerenter="onPointerEnter"
|
|
322
|
+
@pointerleave="onPointerLeave"
|
|
323
|
+
@pointerdown="onPointerDown"
|
|
324
|
+
@pointerup="onPointerUp"
|
|
325
|
+
@pointercancel="onPointerUp"
|
|
326
|
+
@focus="onFocus"
|
|
327
|
+
@blur="onBlur"
|
|
258
328
|
>
|
|
259
329
|
<!-- Divider -->
|
|
260
330
|
<div
|
|
@@ -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
|
|
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:
|
|
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
|
-
|
|
124
|
-
:
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
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" />
|