@m3ui-vue/m3ui-vue 0.9.2 → 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 +2 -0
- package/dist/API.md +69 -8
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-Ck0oWDMk.js → MTextField-DKtgPymd.js} +416 -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/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MFab.vue.d.ts +4 -2
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MSplitButton.vue.d.ts +2 -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/MTree.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_useSpring.d.ts +2 -0
- package/dist/composables/useLocale.d.ts +6 -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 +3 -0
- package/dist/locales/index.js +42 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +5741 -5634
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/theme.css +13 -0
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CFW8cIzL.js → useLocale-Cn9MVIdw.js} +7 -1
- package/dist/useLocale-Cn9MVIdw.js.map +1 -0
- package/package.json +2 -2
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MScrollField.test.ts +28 -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__/vRipple.test.ts +92 -0
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +4 -11
- package/src/components/MFab.vue +8 -15
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MScrollField.vue +10 -2
- package/src/components/MSplitButton.vue +5 -12
- 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/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_useSpring.ts +2 -0
- package/src/composables/useLocale.ts +12 -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 +5 -0
- package/src/locales/de.ts +6 -0
- package/src/locales/es.ts +6 -0
- package/src/locales/fr.ts +6 -0
- package/src/locales/ja.ts +6 -0
- package/src/locales/ko.ts +6 -0
- package/src/locales/pt.ts +6 -0
- package/src/locales/zh.ts +6 -0
- package/src/plugin.ts +2 -0
- package/src/styles/theme.css +13 -0
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-Ck0oWDMk.js.map +0 -1
- package/dist/useLocale-CFW8cIzL.js.map +0 -1
|
@@ -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" />
|
|
@@ -95,13 +95,18 @@ function write() {
|
|
|
95
95
|
let raf = 0
|
|
96
96
|
let last = 0
|
|
97
97
|
let dragging = false
|
|
98
|
+
// The value this wheel itself last emitted: v-model hands it back while the wheel is still moving
|
|
99
|
+
let lastEmitted: number | null = null
|
|
98
100
|
|
|
99
101
|
function setSelected() {
|
|
100
102
|
const page = Math.round(pos)
|
|
101
103
|
if (page === selectedPage.value) return
|
|
102
104
|
selectedPage.value = page
|
|
103
105
|
updatePages()
|
|
104
|
-
if (props.count > 0)
|
|
106
|
+
if (props.count > 0) {
|
|
107
|
+
lastEmitted = mod(page)
|
|
108
|
+
emit('update:modelValue', lastEmitted)
|
|
109
|
+
}
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
function frame(now: number) {
|
|
@@ -164,7 +169,10 @@ watch(selectedPage, (page, prev) => {
|
|
|
164
169
|
|
|
165
170
|
// Outside changes take the short way around the wheel
|
|
166
171
|
watch(() => props.modelValue, (v) => {
|
|
167
|
-
|
|
172
|
+
// Our own value coming back through v-model mid-fling isn't an outside change. Treating it as one
|
|
173
|
+
// retargeted the snap toward an item the wheel had already passed, and on a short wheel (4 items)
|
|
174
|
+
// the shortest-way-around math flipped the target back and forth forever.
|
|
175
|
+
if (props.count <= 0 || v === lastEmitted) return
|
|
168
176
|
const current = target ?? Math.round(pos)
|
|
169
177
|
let d = mod(v) - mod(current)
|
|
170
178
|
if (d > props.count / 2) d -= props.count
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
|
10
10
|
import MIcon from './MIcon.vue'
|
|
11
|
+
import { vRipple } from '../directives/vRipple'
|
|
11
12
|
|
|
12
13
|
export interface SplitButtonItem {
|
|
13
14
|
label: string
|
|
@@ -33,6 +34,8 @@ const props = withDefaults(defineProps<{
|
|
|
33
34
|
disabled?: boolean
|
|
34
35
|
/** Dropdown menu items; see `SplitButtonItem` */
|
|
35
36
|
items?: SplitButtonItem[]
|
|
37
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
38
|
+
rippleColor?: string
|
|
36
39
|
}>(), {
|
|
37
40
|
variant: 'tonal',
|
|
38
41
|
color: 'primary',
|
|
@@ -134,16 +137,6 @@ function toggleMenu() {
|
|
|
134
137
|
open.value = !open.value
|
|
135
138
|
}
|
|
136
139
|
|
|
137
|
-
function createRipple(event: PointerEvent) {
|
|
138
|
-
const button = event.currentTarget as HTMLElement
|
|
139
|
-
const rect = button.getBoundingClientRect()
|
|
140
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
141
|
-
const el = document.createElement('span')
|
|
142
|
-
el.className = 'm3-ripple'
|
|
143
|
-
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`
|
|
144
|
-
button.appendChild(el)
|
|
145
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
146
|
-
}
|
|
147
140
|
|
|
148
141
|
function selectItem(item: SplitButtonItem) {
|
|
149
142
|
if (item.disabled) return
|
|
@@ -187,7 +180,7 @@ onUnmounted(() => {
|
|
|
187
180
|
]"
|
|
188
181
|
:style="{ borderRadius: `${sizeConfig.r}px ${sizeConfig.ri}px ${sizeConfig.ri}px ${sizeConfig.r}px` }"
|
|
189
182
|
:disabled="disabled"
|
|
190
|
-
|
|
183
|
+
v-ripple="rippleColor"
|
|
191
184
|
@click="emit('click', $event)"
|
|
192
185
|
>
|
|
193
186
|
<MIcon v-if="icon" :name="icon" :size="sizeConfig.icon" />
|
|
@@ -205,7 +198,7 @@ onUnmounted(() => {
|
|
|
205
198
|
]"
|
|
206
199
|
:style="{ borderRadius: open ? `${sizeConfig.r}px` : `${sizeConfig.ri}px ${sizeConfig.r}px ${sizeConfig.r}px ${sizeConfig.ri}px` }"
|
|
207
200
|
:disabled="disabled"
|
|
208
|
-
|
|
201
|
+
v-ripple="rippleColor"
|
|
209
202
|
@click="toggleMenu"
|
|
210
203
|
>
|
|
211
204
|
<MIcon
|
package/src/components/MTabs.vue
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @event update:modelValue Emitted with the value of the tab you picked.
|
|
7
7
|
*/
|
|
8
|
-
import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
8
|
+
import { computed, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
10
|
|
|
11
11
|
interface Tab {
|
|
@@ -27,8 +27,16 @@ const props = withDefaults(defineProps<{
|
|
|
27
27
|
variant?: 'primary' | 'secondary'
|
|
28
28
|
/** Fixed (default, M3 `TabRow`): tabs evenly share the available width, no scrolling — use for 2-5 tabs. Scrollable (M3 `ScrollableTabRow`): tabs keep their natural width and the row scrolls horizontally when they overflow — use for many tabs. */
|
|
29
29
|
scrollable?: boolean
|
|
30
|
+
/**
|
|
31
|
+
* Where a tab's icon goes: `top`, stacked above the label in a 64px tab (Compose's `Tab`), or `leading`,
|
|
32
|
+
* beside the label in a 48px tab (Compose's `LeadingIconTab`). Defaults to `top` for primary tabs and
|
|
33
|
+
* `leading` for secondary ones.
|
|
34
|
+
*/
|
|
35
|
+
iconPosition?: 'top' | 'leading'
|
|
30
36
|
}>(), { variant: 'primary', scrollable: false })
|
|
31
37
|
|
|
38
|
+
const leading = computed(() => (props.iconPosition ?? (props.variant === 'primary' ? 'top' : 'leading')) === 'leading')
|
|
39
|
+
|
|
32
40
|
const emit = defineEmits<{ 'update:modelValue': [string | number] }>()
|
|
33
41
|
|
|
34
42
|
const tabEls = ref<HTMLElement[]>([])
|
|
@@ -125,6 +133,7 @@ watch(() => props.modelValue, () => updateIndicator(true))
|
|
|
125
133
|
// modelValue-triggered animation. Re-running the same animated update is a
|
|
126
134
|
// no-op when the target hasn't actually moved, so this is safe either way.
|
|
127
135
|
watch(() => props.tabs, () => updateIndicator(true), { deep: true })
|
|
136
|
+
watch(leading, () => updateIndicator(true))
|
|
128
137
|
|
|
129
138
|
function select(tab: Tab) {
|
|
130
139
|
if (!tab.disabled) emit('update:modelValue', tab.value)
|
|
@@ -140,10 +149,11 @@ function select(tab: Tab) {
|
|
|
140
149
|
:key="tab.value"
|
|
141
150
|
:ref="(el) => { if (el) tabEls[tabs.indexOf(tab)] = el as HTMLElement }"
|
|
142
151
|
type="button"
|
|
143
|
-
class="relative flex
|
|
152
|
+
class="relative flex items-center justify-center pb-1.5 text-title-small transition-colors duration-150 focus-visible:outline-none"
|
|
144
153
|
:class="[
|
|
145
154
|
scrollable ? 'shrink-0' : 'flex-1 min-w-0',
|
|
146
|
-
|
|
155
|
+
// LeadingIconTab: 48dp row, 16dp side padding, 8dp from the icon to the label
|
|
156
|
+
leading ? 'h-12 flex-row gap-2 px-4' : ['flex-col gap-1 px-6', tab.icon ? 'h-16' : 'h-12'],
|
|
147
157
|
tab.value === modelValue
|
|
148
158
|
? 'text-primary'
|
|
149
159
|
: tab.disabled
|
|
@@ -171,9 +181,10 @@ function select(tab: Tab) {
|
|
|
171
181
|
:key="tab.value"
|
|
172
182
|
:ref="(el) => { if (el) tabEls[tabs.indexOf(tab)] = el as HTMLElement }"
|
|
173
183
|
type="button"
|
|
174
|
-
class="relative flex
|
|
184
|
+
class="relative flex items-center justify-center text-title-small transition-colors duration-150 focus-visible:outline-none"
|
|
175
185
|
:class="[
|
|
176
186
|
scrollable ? 'shrink-0' : 'flex-1 min-w-0',
|
|
187
|
+
leading ? 'h-12 flex-row gap-2 px-4' : ['flex-col gap-1 px-6', tab.icon ? 'h-16' : 'h-12'],
|
|
177
188
|
tab.value === modelValue
|
|
178
189
|
? 'text-on-surface'
|
|
179
190
|
: tab.disabled
|
|
@@ -184,7 +195,7 @@ function select(tab: Tab) {
|
|
|
184
195
|
@click="select(tab)"
|
|
185
196
|
>
|
|
186
197
|
<MIcon v-if="tab.icon" :name="tab.icon" :size="24" />
|
|
187
|
-
{{ tab.label }}
|
|
198
|
+
<span>{{ tab.label }}</span>
|
|
188
199
|
</button>
|
|
189
200
|
<div
|
|
190
201
|
class="absolute bottom-0 h-[3px] bg-primary"
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
|
-
* A modal, centered time picker with a clock dial
|
|
4
|
-
* format — the sibling of MTimePicker, a
|
|
3
|
+
* A modal, centered time picker with a clock dial (or, with `mode="scroll"`, M3 Expressive's scroll wheels from
|
|
4
|
+
* MTimeScroll) and a keyboard input mode. Supports AM/PM toggle and 24h format — the sibling of MTimePicker, a
|
|
5
|
+
* fully separate component rather than a shared internal.
|
|
5
6
|
*
|
|
6
7
|
* @event update:modelValue Emitted when a time is confirmed — powers v-model
|
|
7
8
|
* @event update:show Emitted when the dialog opens or closes — powers v-model:show
|
|
@@ -9,6 +10,7 @@
|
|
|
9
10
|
import { computed, ref, watch } from 'vue'
|
|
10
11
|
import MButton from './MButton.vue'
|
|
11
12
|
import MIconButton from './MIconButton.vue'
|
|
13
|
+
import MTimeScroll from './MTimeScroll.vue'
|
|
12
14
|
import { useLocale } from '../composables/useLocale'
|
|
13
15
|
|
|
14
16
|
const props = withDefaults(defineProps<{
|
|
@@ -22,11 +24,14 @@ const props = withDefaults(defineProps<{
|
|
|
22
24
|
minuteStep?: number
|
|
23
25
|
/** Dialog title */
|
|
24
26
|
title?: string
|
|
27
|
+
/** How the time is picked before switching to keyboard input: a clock `dial`, or `scroll` wheels (MTimeScroll) */
|
|
28
|
+
mode?: 'dial' | 'scroll'
|
|
25
29
|
}>(), {
|
|
26
30
|
modelValue: null,
|
|
27
31
|
show: false,
|
|
28
32
|
use24h: false,
|
|
29
33
|
minuteStep: 5,
|
|
34
|
+
mode: 'dial',
|
|
30
35
|
})
|
|
31
36
|
|
|
32
37
|
const locale = useLocale()
|
|
@@ -36,7 +41,7 @@ const emit = defineEmits<{
|
|
|
36
41
|
}>()
|
|
37
42
|
|
|
38
43
|
const step = ref<'hour' | 'minute'>('hour')
|
|
39
|
-
const inputMode = ref<'dial' | 'input'>('dial')
|
|
44
|
+
const inputMode = ref<'dial' | 'scroll' | 'input'>('dial')
|
|
40
45
|
const period = ref<'AM' | 'PM'>('AM')
|
|
41
46
|
const selectedHour = ref(12)
|
|
42
47
|
const selectedMinute = ref(0)
|
|
@@ -61,9 +66,10 @@ watch(() => props.show, (open) => {
|
|
|
61
66
|
period.value = h >= 12 ? 'PM' : 'AM'
|
|
62
67
|
selectedHour.value = h % 12 || 12
|
|
63
68
|
}
|
|
64
|
-
|
|
69
|
+
// The minute wheel only has multiples of minuteStep: start on the one it shows
|
|
70
|
+
selectedMinute.value = props.mode === 'scroll' ? Math.floor(m / props.minuteStep) * props.minuteStep : m
|
|
65
71
|
step.value = 'hour'
|
|
66
|
-
inputMode.value =
|
|
72
|
+
inputMode.value = props.mode
|
|
67
73
|
document.addEventListener('keydown', onKeydown)
|
|
68
74
|
document.body.style.overflow = 'hidden'
|
|
69
75
|
} else {
|
|
@@ -199,6 +205,35 @@ function selectHour(h: number) {
|
|
|
199
205
|
step.value = 'minute'
|
|
200
206
|
}
|
|
201
207
|
|
|
208
|
+
// ── Scroll mode ────────────────────────────────────────────────────
|
|
209
|
+
// MTimeScroll speaks 24-hour HH:MM; the dialog keeps a 1–12 hour plus period in 12-hour mode
|
|
210
|
+
const scrollTime = computed({
|
|
211
|
+
get() {
|
|
212
|
+
let h = selectedHour.value
|
|
213
|
+
if (!props.use24h) h = (h % 12) + (period.value === 'PM' ? 12 : 0)
|
|
214
|
+
return `${pad(h)}:${pad(selectedMinute.value)}`
|
|
215
|
+
},
|
|
216
|
+
set(t: string) {
|
|
217
|
+
const { h, m } = parseTime(t)
|
|
218
|
+
if (props.use24h) {
|
|
219
|
+
selectedHour.value = h
|
|
220
|
+
} else {
|
|
221
|
+
period.value = h >= 12 ? 'PM' : 'AM'
|
|
222
|
+
selectedHour.value = h % 12 || 12
|
|
223
|
+
}
|
|
224
|
+
selectedMinute.value = m
|
|
225
|
+
},
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
const toggleIcon = computed(() =>
|
|
229
|
+
inputMode.value !== 'input' ? 'keyboard' : props.mode === 'scroll' ? 'swipe_vertical' : 'schedule',
|
|
230
|
+
)
|
|
231
|
+
const toggleLabel = computed(() =>
|
|
232
|
+
inputMode.value !== 'input'
|
|
233
|
+
? locale.timeToggleKeyboard
|
|
234
|
+
: props.mode === 'scroll' ? locale.timeToggleScroll : locale.timeToggleDial,
|
|
235
|
+
)
|
|
236
|
+
|
|
202
237
|
// ── Input mode ─────────────────────────────────────────────────────
|
|
203
238
|
const inputHour = ref('')
|
|
204
239
|
const inputMinute = ref('')
|
|
@@ -384,6 +419,11 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
384
419
|
</div>
|
|
385
420
|
</template>
|
|
386
421
|
|
|
422
|
+
<!-- ── Scroll mode ─────────────────────────────────── -->
|
|
423
|
+
<div v-else-if="inputMode === 'scroll'" class="flex justify-center pb-4">
|
|
424
|
+
<MTimeScroll v-model="scrollTime" :use24h="use24h" :minute-step="minuteStep" />
|
|
425
|
+
</div>
|
|
426
|
+
|
|
387
427
|
<!-- ── Input mode ──────────────────────────────────── -->
|
|
388
428
|
<div v-else class="mx-auto flex items-center justify-center gap-2 py-8">
|
|
389
429
|
<input
|
|
@@ -435,9 +475,9 @@ function onKeydown(e: KeyboardEvent) { if (e.key === 'Escape') cancel() }
|
|
|
435
475
|
<!-- Footer -->
|
|
436
476
|
<div class="mt-2 flex items-center justify-between">
|
|
437
477
|
<MIconButton
|
|
438
|
-
:icon="
|
|
439
|
-
:label="
|
|
440
|
-
@click="inputMode = inputMode === '
|
|
478
|
+
:icon="toggleIcon"
|
|
479
|
+
:label="toggleLabel"
|
|
480
|
+
@click="inputMode = inputMode === 'input' ? mode : 'input'"
|
|
441
481
|
/>
|
|
442
482
|
<div class="flex gap-2">
|
|
443
483
|
<MButton variant="text" @click="cancel">{{ locale.cancel }}</MButton>
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* M3 Expressive's time scroll picker (a port of Compose's `TimeScroll`): an hour wheel and a minute wheel
|
|
4
|
+
* side by side, plus an AM/PM toggle in 12-hour mode. It updates as the wheels turn; put it in a dialog or a
|
|
5
|
+
* form for the confirm step.
|
|
6
|
+
*
|
|
7
|
+
* @event update:modelValue Emitted with the time as HH:MM (24-hour) whenever a wheel or AM/PM changes
|
|
8
|
+
*/
|
|
9
|
+
import { computed, ref, watch } from 'vue'
|
|
10
|
+
import MScrollField from './MScrollField.vue'
|
|
11
|
+
import { useLocale } from '../composables/useLocale'
|
|
12
|
+
import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
13
|
+
|
|
14
|
+
const props = withDefaults(defineProps<{
|
|
15
|
+
/** Selected time in HH:MM, 24-hour (v-model); null shows 12:00 AM (00:00 in 24-hour mode) */
|
|
16
|
+
modelValue: string | null
|
|
17
|
+
/** 24-hour wheel (00–23) instead of 1–12 with AM/PM */
|
|
18
|
+
use24h?: boolean
|
|
19
|
+
/** Minute increment step; the minute wheel shows only multiples of it */
|
|
20
|
+
minuteStep?: number
|
|
21
|
+
/** Disables the wheels and the AM/PM toggle */
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
}>(), {
|
|
24
|
+
modelValue: null,
|
|
25
|
+
use24h: false,
|
|
26
|
+
minuteStep: 1,
|
|
27
|
+
disabled: false,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{ 'update:modelValue': [string] }>()
|
|
31
|
+
const locale = useLocale()
|
|
32
|
+
|
|
33
|
+
function parse(t: string | null) {
|
|
34
|
+
const [h, m] = (t ?? '').split(':').map(Number)
|
|
35
|
+
return { h: Number.isFinite(h) ? Math.min(23, Math.max(0, h!)) : 0, m: Number.isFinite(m) ? Math.min(59, Math.max(0, m!)) : 0 }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const step = computed(() => Math.min(30, Math.max(1, Math.floor(props.minuteStep))))
|
|
39
|
+
const hour = ref(0)
|
|
40
|
+
const minute = ref(0)
|
|
41
|
+
|
|
42
|
+
function sync() {
|
|
43
|
+
const { h, m } = parse(props.modelValue)
|
|
44
|
+
hour.value = h
|
|
45
|
+
minute.value = Math.floor(m / step.value) * step.value
|
|
46
|
+
}
|
|
47
|
+
sync()
|
|
48
|
+
watch(() => [props.modelValue, step.value], sync)
|
|
49
|
+
|
|
50
|
+
const isPm = computed(() => hour.value >= 12)
|
|
51
|
+
|
|
52
|
+
// TimeScrollImpl's mapping: in 12-hour mode index 0..11 shows 1..12, and 12 o'clock is the last item
|
|
53
|
+
const hourCount = computed(() => (props.use24h ? 24 : 12))
|
|
54
|
+
const hourIndex = computed(() => (props.use24h ? hour.value : (hour.value % 12 || 12) - 1))
|
|
55
|
+
const minuteIndex = computed(() => Math.round(minute.value / step.value))
|
|
56
|
+
|
|
57
|
+
function commit(h: number, m: number) {
|
|
58
|
+
hour.value = h
|
|
59
|
+
minute.value = m
|
|
60
|
+
const value = `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`
|
|
61
|
+
if (value !== props.modelValue) emit('update:modelValue', value)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function onHour(index: number) {
|
|
65
|
+
const h = props.use24h ? index : ((index + 1) % 12) + (isPm.value ? 12 : 0)
|
|
66
|
+
commit(h, minute.value)
|
|
67
|
+
}
|
|
68
|
+
function onMinute(index: number) {
|
|
69
|
+
commit(hour.value, index * step.value)
|
|
70
|
+
}
|
|
71
|
+
function setPm(pm: boolean) {
|
|
72
|
+
if (props.disabled || pm === isPm.value) return
|
|
73
|
+
commit(hour.value + (pm ? 12 : -12), minute.value)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
77
|
+
const formatHour = (i: number) => pad(props.use24h ? i : i + 1)
|
|
78
|
+
const formatMinute = (i: number) => pad(i * step.value)
|
|
79
|
+
|
|
80
|
+
// AM/PM in the app language, from Intl (no locale keys: every language already has them there)
|
|
81
|
+
const periods = computed(() => {
|
|
82
|
+
const label = (h: number) => {
|
|
83
|
+
try {
|
|
84
|
+
return new Intl.DateTimeFormat(locale.lang, { hour: 'numeric', hour12: true })
|
|
85
|
+
.formatToParts(new Date(2000, 0, 1, h))
|
|
86
|
+
.find((p) => p.type === 'dayPeriod')?.value ?? (h < 12 ? 'AM' : 'PM')
|
|
87
|
+
} catch {
|
|
88
|
+
return h < 12 ? 'AM' : 'PM'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return [label(9), label(21)] as const
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// The period toggle is two ToggleButtons (TimePicker.kt's ToggleItem): a circle that becomes a 12dp
|
|
95
|
+
// rounded square when checked or pressed, on the ToggleButton's FastSpatial spring.
|
|
96
|
+
const periodEls: (HTMLElement | null)[] = [null, null]
|
|
97
|
+
const pressedPeriod = ref(-1)
|
|
98
|
+
const SIZE = 56
|
|
99
|
+
useSpring(
|
|
100
|
+
() => [0, 1].map((i) => (pressedPeriod.value === i || (i === 1) === isPm.value ? 12 : SIZE / 2)),
|
|
101
|
+
(v) => periodEls.forEach((el, i) => { if (el) el.style.borderRadius = `${v[i]}px` }),
|
|
102
|
+
FAST_SPATIAL,
|
|
103
|
+
)
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<template>
|
|
107
|
+
<div class="inline-flex items-start select-none" :aria-disabled="disabled || undefined">
|
|
108
|
+
<MScrollField
|
|
109
|
+
:model-value="hourIndex"
|
|
110
|
+
:count="hourCount"
|
|
111
|
+
:height="120"
|
|
112
|
+
:format="formatHour"
|
|
113
|
+
:label="locale.timeHourSelection"
|
|
114
|
+
:disabled="disabled"
|
|
115
|
+
class="w-[100px]"
|
|
116
|
+
@update:model-value="onHour"
|
|
117
|
+
/>
|
|
118
|
+
<span
|
|
119
|
+
aria-hidden="true"
|
|
120
|
+
class="flex h-[120px] w-4 items-center justify-center pb-2 text-display-large text-on-surface"
|
|
121
|
+
:class="disabled ? 'opacity-38' : ''"
|
|
122
|
+
>:</span>
|
|
123
|
+
<MScrollField
|
|
124
|
+
:model-value="minuteIndex"
|
|
125
|
+
:count="Math.ceil(60 / step)"
|
|
126
|
+
:height="120"
|
|
127
|
+
:format="formatMinute"
|
|
128
|
+
:label="locale.timeMinuteSelection"
|
|
129
|
+
:disabled="disabled"
|
|
130
|
+
class="w-[100px]"
|
|
131
|
+
@update:model-value="onMinute"
|
|
132
|
+
/>
|
|
133
|
+
<div
|
|
134
|
+
v-if="!use24h"
|
|
135
|
+
role="radiogroup"
|
|
136
|
+
:aria-label="locale.timePeriodToggle"
|
|
137
|
+
class="ml-2 flex h-[120px] w-14 flex-col gap-2"
|
|
138
|
+
>
|
|
139
|
+
<button
|
|
140
|
+
v-for="(text, i) in periods"
|
|
141
|
+
:key="i"
|
|
142
|
+
:ref="(el) => { periodEls[i] = el as HTMLElement | null }"
|
|
143
|
+
type="button"
|
|
144
|
+
role="radio"
|
|
145
|
+
:aria-checked="(i === 1) === isPm"
|
|
146
|
+
:disabled="disabled"
|
|
147
|
+
class="relative flex h-14 w-14 cursor-pointer items-center justify-center overflow-hidden text-title-medium transition-colors duration-150 disabled:cursor-default disabled:opacity-38 before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:content-[''] enabled:hover:before:opacity-[0.08] enabled:active:before:opacity-[0.12]"
|
|
148
|
+
:class="(i === 1) === isPm
|
|
149
|
+
? 'bg-primary-container font-bold text-on-primary-container'
|
|
150
|
+
: 'bg-surface-container-lowest text-on-surface-variant'"
|
|
151
|
+
@pointerdown="pressedPeriod = i"
|
|
152
|
+
@pointerup="pressedPeriod = -1"
|
|
153
|
+
@pointerleave="pressedPeriod = -1"
|
|
154
|
+
@pointercancel="pressedPeriod = -1"
|
|
155
|
+
@click="setPm(i === 1)"
|
|
156
|
+
>
|
|
157
|
+
{{ text }}
|
|
158
|
+
</button>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
</template>
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
11
11
|
import MIcon from './MIcon.vue'
|
|
12
|
+
import { vRipple } from '../directives/vRipple'
|
|
12
13
|
|
|
13
14
|
const props = withDefaults(
|
|
14
15
|
defineProps<{
|
|
@@ -22,6 +23,8 @@ const props = withDefaults(
|
|
|
22
23
|
icon?: string
|
|
23
24
|
/** Same 5-tier expressive sizing as MButton */
|
|
24
25
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
26
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
27
|
+
rippleColor?: string
|
|
25
28
|
}>(),
|
|
26
29
|
{
|
|
27
30
|
variant: 'filled',
|
|
@@ -106,23 +109,12 @@ const disabledContainerClasses = computed(() => {
|
|
|
106
109
|
const rootEl = ref<HTMLElement | null>(null)
|
|
107
110
|
const pressed = ref(false)
|
|
108
111
|
|
|
109
|
-
function onPointerDown(
|
|
112
|
+
function onPointerDown() {
|
|
110
113
|
if (props.disabled) return
|
|
111
114
|
pressed.value = true
|
|
112
|
-
createRipple(e)
|
|
113
115
|
}
|
|
114
116
|
function onPointerUp() { pressed.value = false }
|
|
115
117
|
|
|
116
|
-
function createRipple(event: PointerEvent) {
|
|
117
|
-
const button = event.currentTarget as HTMLElement
|
|
118
|
-
const rect = button.getBoundingClientRect()
|
|
119
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
120
|
-
const el = document.createElement('span')
|
|
121
|
-
el.className = 'm3-ripple'
|
|
122
|
-
el.style.cssText = `width:${d}px;height:${d}px;top:${event.clientY - rect.top - d / 2}px;left:${event.clientX - rect.left - d / 2}px`
|
|
123
|
-
button.appendChild(el)
|
|
124
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
125
|
-
}
|
|
126
118
|
|
|
127
119
|
function toggle() {
|
|
128
120
|
if (props.disabled) return
|
|
@@ -188,6 +180,7 @@ onUnmounted(() => cancelAnimationFrame(rafId))
|
|
|
188
180
|
:aria-pressed="checked"
|
|
189
181
|
:disabled="disabled"
|
|
190
182
|
:class="[base, sizeClasses, containerClasses, disabledContainerClasses]"
|
|
183
|
+
v-ripple="{ disabled, color: rippleColor }"
|
|
191
184
|
@pointerdown="onPointerDown"
|
|
192
185
|
@pointerup="onPointerUp"
|
|
193
186
|
@pointerleave="onPointerUp"
|