@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.
- package/README.md +26 -29
- package/dist/API.md +242 -22
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-Ck0oWDMk.js → MTextField-TZ7lfr09.js} +551 -216
- package/dist/MTextField-TZ7lfr09.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/MAppBarWithSearch.vue.d.ts +70 -0
- package/dist/components/MBottomAppBar.vue.d.ts +37 -0
- package/dist/components/MBottomSheetScaffold.vue.d.ts +40 -0
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MChatBubble.vue.d.ts +1 -1
- package/dist/components/MChip.vue.d.ts +19 -2
- package/dist/components/MContainer.vue.d.ts +1 -1
- package/dist/components/MDataTable.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +15 -4
- 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 +2 -2
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MNavigationRail.vue.d.ts +6 -0
- package/dist/components/MSearchBar.vue.d.ts +5 -3
- package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MTable.vue.d.ts +1 -1
- 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/MTopAppBar.vue.d.ts +33 -2
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_searchAppBar.d.ts +6 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_useSpring.d.ts +5 -5
- package/dist/composables/motion.d.ts +101 -0
- package/dist/composables/useColorPalette.d.ts +10 -0
- package/dist/composables/useLocale.d.ts +9 -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 +11 -1
- package/dist/locales/index.js +63 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7716 -6768
- package/dist/m3ui.js.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/palettes-contrast.css +7764 -0
- package/dist/styles/theme.css +59 -2
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CFW8cIzL.js → useLocale-CuvWRZ1h.js} +10 -1
- package/dist/useLocale-CuvWRZ1h.js.map +1 -0
- package/package.json +4 -2
- package/src/__tests__/MAppBarWithSearch.test.ts +96 -0
- package/src/__tests__/MBottomAppBar.test.ts +71 -0
- package/src/__tests__/MBottomSheetScaffold.test.ts +101 -0
- package/src/__tests__/MChip.test.ts +63 -0
- package/src/__tests__/MFab.test.ts +36 -0
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MNavigationRail.test.ts +77 -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__/MTopAppBar.test.ts +99 -0
- package/src/__tests__/contrast.test.ts +64 -0
- package/src/__tests__/dynamicColor.test.ts +17 -0
- package/src/__tests__/motion.test.ts +37 -0
- package/src/__tests__/themeTransition.test.ts +119 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MAppBarWithSearch.vue +236 -0
- package/src/components/MBottomAppBar.vue +181 -0
- package/src/components/MBottomSheetScaffold.vue +296 -0
- package/src/components/MBreadcrumbs.vue +1 -1
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +4 -11
- package/src/components/MChip.vue +137 -5
- package/src/components/MFab.vue +81 -27
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MNavigationDrawer.vue +2 -2
- package/src/components/MNavigationRail.vue +135 -8
- package/src/components/MScrollField.vue +10 -2
- package/src/components/MSearchBar.vue +28 -12
- 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/components/MTopAppBar.vue +252 -28
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_searchAppBar.ts +9 -0
- package/src/composables/_themeColor.ts +11 -4
- package/src/composables/_themeTransition.ts +71 -0
- package/src/composables/_useSpring.ts +12 -20
- package/src/composables/motion.ts +73 -0
- package/src/composables/useColorPalette.ts +103 -20
- package/src/composables/useLocale.ts +18 -0
- package/src/composables/useTheme.ts +4 -12
- 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 +13 -1
- package/src/locales/de.ts +9 -0
- package/src/locales/es.ts +9 -0
- package/src/locales/fr.ts +9 -0
- package/src/locales/ja.ts +9 -0
- package/src/locales/ko.ts +9 -0
- package/src/locales/pt.ts +9 -0
- package/src/locales/zh.ts +9 -0
- package/src/plugin.ts +11 -1
- package/src/styles/palettes-contrast.css +7764 -0
- package/src/styles/theme.css +59 -2
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-Ck0oWDMk.js.map +0 -1
- package/dist/useLocale-CFW8cIzL.js.map +0 -1
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* A screen with M3's standard (non-modal) bottom sheet, a port of Compose's `BottomSheetScaffold`: the sheet
|
|
4
|
+
* sits over the bottom of the content without a scrim, peeking out when partially expanded, and the content
|
|
5
|
+
* stays usable. Drag it (or its content, which scrolls once the sheet is fully expanded) between its states,
|
|
6
|
+
* or tap the handle. For a sheet that blocks the screen behind a scrim, use MBottomSheet.
|
|
7
|
+
*
|
|
8
|
+
* @slot default The screen's content; it gets bottom padding equal to `peekHeight` so nothing hides under the
|
|
9
|
+
* peeking sheet
|
|
10
|
+
* @slot sheet The sheet's content, below the drag handle
|
|
11
|
+
* @slot top-bar An app bar above the content (the sheet can rise over it)
|
|
12
|
+
* @event update:modelValue Emitted when the sheet settles in another state after a drag or a handle tap —
|
|
13
|
+
* powers v-model
|
|
14
|
+
*/
|
|
15
|
+
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
16
|
+
import { useLocale } from '../composables/useLocale'
|
|
17
|
+
import { DEFAULT_SPATIAL, FAST_EFFECTS, type SpringSpec } from '../composables/_useSpring'
|
|
18
|
+
|
|
19
|
+
export type BottomSheetValue = 'hidden' | 'partial' | 'expanded'
|
|
20
|
+
|
|
21
|
+
const props = withDefaults(defineProps<{
|
|
22
|
+
/** The sheet's state (v-model): `partial` shows `peekHeight` of it, `expanded` all of it, `hidden` none */
|
|
23
|
+
modelValue?: BottomSheetValue
|
|
24
|
+
/** Height in px the partially expanded sheet shows (BottomSheetDefaults.SheetPeekHeight) */
|
|
25
|
+
peekHeight?: number
|
|
26
|
+
/** Leaves out the hidden state, so the sheet can't be swiped away (Compose's default for this sheet) */
|
|
27
|
+
skipHiddenState?: boolean
|
|
28
|
+
/** Lets the sheet be dragged; with false it only moves through v-model and the handle */
|
|
29
|
+
swipeEnabled?: boolean
|
|
30
|
+
/** Maximum width in px; the sheet is centered when the screen is wider */
|
|
31
|
+
maxWidth?: number
|
|
32
|
+
}>(), {
|
|
33
|
+
modelValue: 'partial',
|
|
34
|
+
peekHeight: 56,
|
|
35
|
+
skipHiddenState: true,
|
|
36
|
+
swipeEnabled: true,
|
|
37
|
+
maxWidth: 640,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
const emit = defineEmits<{ 'update:modelValue': [BottomSheetValue] }>()
|
|
41
|
+
const locale = useLocale()
|
|
42
|
+
|
|
43
|
+
const rootEl = ref<HTMLElement>()
|
|
44
|
+
const sheetEl = ref<HTMLElement>()
|
|
45
|
+
const contentEl = ref<HTMLElement>()
|
|
46
|
+
|
|
47
|
+
// ── Anchors ──────────────────────────────────────────────────────────────────────────────────────
|
|
48
|
+
// The sheet's translateY: 0 when expanded, its height minus the peek when partially expanded, its height
|
|
49
|
+
// when hidden. As in StandardBottomSheet's draggableAnchors, the partial anchor exists only with a peek
|
|
50
|
+
// shorter than the sheet, and the hidden one only without skipHiddenState (or with no peek).
|
|
51
|
+
let sheetHeight = 0
|
|
52
|
+
function anchors(): Partial<Record<BottomSheetValue, number>> {
|
|
53
|
+
const a: Partial<Record<BottomSheetValue, number>> = { expanded: 0 }
|
|
54
|
+
if (props.peekHeight > 0 && props.peekHeight < sheetHeight) a.partial = sheetHeight - props.peekHeight
|
|
55
|
+
if (!props.skipHiddenState || props.peekHeight <= 0) a.hidden = sheetHeight
|
|
56
|
+
return a
|
|
57
|
+
}
|
|
58
|
+
// A state with no anchor falls back the way Compose's reconciliation does
|
|
59
|
+
function resolve(value: BottomSheetValue): BottomSheetValue {
|
|
60
|
+
const a = anchors()
|
|
61
|
+
if (a[value] !== undefined) return value
|
|
62
|
+
if (value === 'hidden') return a.partial !== undefined ? 'partial' : 'expanded'
|
|
63
|
+
if (value === 'partial') return a.expanded !== undefined ? 'expanded' : 'hidden'
|
|
64
|
+
return a.hidden !== undefined ? 'hidden' : 'partial'
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// `wanted` is the state asked for; `settled` is where it actually lands with the current anchors (they can
|
|
68
|
+
// lack it for a moment, e.g. while the sheet hasn't been measured yet)
|
|
69
|
+
let wanted: BottomSheetValue = props.modelValue
|
|
70
|
+
const settled = ref<BottomSheetValue>(props.modelValue)
|
|
71
|
+
|
|
72
|
+
// ── Motion ───────────────────────────────────────────────────────────────────────────────────────
|
|
73
|
+
// Drags, flings and handle taps settle on DefaultSpatial (anchoredDraggableMotionSpec); hiding through
|
|
74
|
+
// v-model uses FastEffects (hideMotionSpec), as Compose's SheetState does.
|
|
75
|
+
let y = 0
|
|
76
|
+
let vel = 0
|
|
77
|
+
let target: number | null = null
|
|
78
|
+
let spec: SpringSpec = DEFAULT_SPATIAL
|
|
79
|
+
let raf = 0
|
|
80
|
+
let last = 0
|
|
81
|
+
|
|
82
|
+
function write() {
|
|
83
|
+
if (sheetEl.value) sheetEl.value.style.transform = `translateY(${y}px)`
|
|
84
|
+
// The content scrolls only once the sheet is fully up; until then a drag on it moves the sheet
|
|
85
|
+
if (contentEl.value) contentEl.value.style.overflowY = settled.value === 'expanded' && target === null ? 'auto' : 'hidden'
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function frame(now: number) {
|
|
89
|
+
if (target === null) return
|
|
90
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
91
|
+
last = now
|
|
92
|
+
const c = 2 * spec.dampingRatio * Math.sqrt(spec.stiffness)
|
|
93
|
+
while (dt > 0) {
|
|
94
|
+
const h = Math.min(dt, 0.004)
|
|
95
|
+
dt -= h
|
|
96
|
+
vel += (-spec.stiffness * (y - target) - c * vel) * h
|
|
97
|
+
y += vel * h
|
|
98
|
+
}
|
|
99
|
+
if (Math.abs(y - target) < 0.5 && Math.abs(vel) < 1) {
|
|
100
|
+
y = target
|
|
101
|
+
vel = 0
|
|
102
|
+
target = null
|
|
103
|
+
raf = 0
|
|
104
|
+
write()
|
|
105
|
+
return
|
|
106
|
+
}
|
|
107
|
+
write()
|
|
108
|
+
raf = requestAnimationFrame(frame)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function animateTo(value: BottomSheetValue, s: SpringSpec = DEFAULT_SPATIAL, velocity = vel) {
|
|
112
|
+
wanted = value
|
|
113
|
+
value = resolve(value)
|
|
114
|
+
settled.value = value
|
|
115
|
+
target = anchors()[value]!
|
|
116
|
+
spec = s
|
|
117
|
+
vel = velocity
|
|
118
|
+
if (!raf) {
|
|
119
|
+
last = performance.now()
|
|
120
|
+
raf = requestAnimationFrame(frame)
|
|
121
|
+
}
|
|
122
|
+
write()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function settleTo(value: BottomSheetValue, velocity = vel) {
|
|
126
|
+
animateTo(value, DEFAULT_SPATIAL, velocity)
|
|
127
|
+
if (settled.value !== props.modelValue) emit('update:modelValue', settled.value)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
watch(() => props.modelValue, (v) => {
|
|
131
|
+
if (resolve(v) !== settled.value || target !== null) animateTo(v, v === 'hidden' ? FAST_EFFECTS : DEFAULT_SPATIAL)
|
|
132
|
+
})
|
|
133
|
+
watch(() => [props.peekHeight, props.skipHiddenState], () => measure())
|
|
134
|
+
|
|
135
|
+
// Layout changes (content added, window resized) keep the sheet on its state, without animating
|
|
136
|
+
function measure() {
|
|
137
|
+
if (!sheetEl.value) return
|
|
138
|
+
sheetHeight = sheetEl.value.offsetHeight
|
|
139
|
+
const value = resolve(wanted)
|
|
140
|
+
settled.value = value
|
|
141
|
+
if (target !== null) target = anchors()[value]!
|
|
142
|
+
else y = anchors()[value]!
|
|
143
|
+
write()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// ── Dragging ─────────────────────────────────────────────────────────────────────────────────────
|
|
147
|
+
// AnchoredDraggable with BottomSheetDefaults' thresholds: released faster than 125px/s it goes to the next
|
|
148
|
+
// state that way, otherwise to the next one only when dragged 56px past the last state it crossed.
|
|
149
|
+
const POSITIONAL_THRESHOLD = 56
|
|
150
|
+
const VELOCITY_THRESHOLD = 125
|
|
151
|
+
let drag: { id: number; x: number; y: number; from: number; active: boolean; inContent: boolean; samples: { t: number; y: number }[] } | null = null
|
|
152
|
+
let suppressClick = false
|
|
153
|
+
|
|
154
|
+
function onPointerDown(e: PointerEvent) {
|
|
155
|
+
if (!props.swipeEnabled || e.button !== 0) return
|
|
156
|
+
const inContent = !!contentEl.value?.contains(e.target as Node)
|
|
157
|
+
drag = { id: e.pointerId, x: e.clientX, y: e.clientY, from: y, active: false, inContent, samples: [{ t: e.timeStamp, y: e.clientY }] }
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
function onPointerMove(e: PointerEvent) {
|
|
161
|
+
if (!drag || e.pointerId !== drag.id) return
|
|
162
|
+
const dy = e.clientY - drag.y
|
|
163
|
+
if (!drag.active) {
|
|
164
|
+
if (Math.abs(dy) < 4 || Math.abs(dy) < Math.abs(e.clientX - drag.x)) {
|
|
165
|
+
if (Math.abs(e.clientX - drag.x) > 8) drag = null
|
|
166
|
+
return
|
|
167
|
+
}
|
|
168
|
+
// ConsumeSwipeWithinBottomSheetBoundsNestedScrollConnection: an expanded sheet's content scrolls first,
|
|
169
|
+
// and the sheet only follows a downward drag once the content is back at its top
|
|
170
|
+
const content = contentEl.value
|
|
171
|
+
if (drag.inContent && settled.value === 'expanded' && content && content.scrollHeight > content.clientHeight
|
|
172
|
+
&& (dy < 0 || content.scrollTop > 0)) {
|
|
173
|
+
drag = null
|
|
174
|
+
return
|
|
175
|
+
}
|
|
176
|
+
drag.active = true
|
|
177
|
+
drag.y = e.clientY
|
|
178
|
+
drag.from = y
|
|
179
|
+
cancelAnimationFrame(raf)
|
|
180
|
+
raf = 0
|
|
181
|
+
target = null
|
|
182
|
+
vel = 0
|
|
183
|
+
sheetEl.value?.setPointerCapture?.(e.pointerId)
|
|
184
|
+
}
|
|
185
|
+
const a = Object.values(anchors())
|
|
186
|
+
y = Math.min(Math.max(...a), Math.max(Math.min(...a), drag.from + e.clientY - drag.y))
|
|
187
|
+
write()
|
|
188
|
+
drag.samples.push({ t: e.timeStamp, y: e.clientY })
|
|
189
|
+
drag.samples = drag.samples.filter((p) => e.timeStamp - p.t < 100)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function onPointerUp(e: PointerEvent) {
|
|
193
|
+
if (!drag || e.pointerId !== drag.id) return
|
|
194
|
+
const d = drag
|
|
195
|
+
drag = null
|
|
196
|
+
if (!d.active) return
|
|
197
|
+
suppressClick = true
|
|
198
|
+
setTimeout(() => { suppressClick = false })
|
|
199
|
+
const first = d.samples[0]!
|
|
200
|
+
const lastSample = d.samples[d.samples.length - 1]!
|
|
201
|
+
const dt = (lastSample.t - first.t) / 1000
|
|
202
|
+
const velocity = dt > 0 && e.timeStamp - lastSample.t <= 40 ? (lastSample.y - first.y) / dt : 0
|
|
203
|
+
settleTo(pickTarget(d.from, velocity), velocity)
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function pickTarget(from: number, velocity: number): BottomSheetValue {
|
|
207
|
+
const list = (Object.entries(anchors()) as [BottomSheetValue, number][]).sort((a, b) => a[1] - b[1])
|
|
208
|
+
const down = Math.abs(velocity) > VELOCITY_THRESHOLD ? velocity > 0 : y >= from
|
|
209
|
+
const ahead = down ? list.find(([, p]) => p > y) : [...list].reverse().find(([, p]) => p < y)
|
|
210
|
+
const behind = down ? [...list].reverse().find(([, p]) => p <= y) : list.find(([, p]) => p >= y)
|
|
211
|
+
if (!ahead) return behind![0]
|
|
212
|
+
if (!behind) return ahead[0]
|
|
213
|
+
if (Math.abs(velocity) > VELOCITY_THRESHOLD) return ahead[0]
|
|
214
|
+
return Math.abs(y - behind[1]) >= POSITIONAL_THRESHOLD ? ahead[0] : behind[0]
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
// Once the sheet is following the finger the browser must not scroll the page or the content with it
|
|
218
|
+
function onTouchMove(e: TouchEvent) {
|
|
219
|
+
if (drag?.active && e.cancelable) e.preventDefault()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function onClickCapture(e: MouseEvent) {
|
|
223
|
+
if (!suppressClick) return
|
|
224
|
+
e.preventDefault()
|
|
225
|
+
e.stopPropagation()
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// The handle: Expanded → partial (or hidden without a partial state), Partial → expanded, Hidden → shown
|
|
229
|
+
function onHandleClick() {
|
|
230
|
+
const a = anchors()
|
|
231
|
+
if (settled.value === 'expanded') settleTo(!props.skipHiddenState || a.partial === undefined ? 'hidden' : 'partial', 0)
|
|
232
|
+
else settleTo('expanded', 0)
|
|
233
|
+
}
|
|
234
|
+
const handleLabel = computed(() => {
|
|
235
|
+
if (settled.value !== 'expanded') return locale.sheetExpand
|
|
236
|
+
return !props.skipHiddenState || props.peekHeight <= 0 ? locale.sheetDismiss : locale.sheetCollapse
|
|
237
|
+
})
|
|
238
|
+
|
|
239
|
+
let observer: ResizeObserver | null = null
|
|
240
|
+
onMounted(() => {
|
|
241
|
+
measure()
|
|
242
|
+
sheetEl.value?.addEventListener('touchmove', onTouchMove, { passive: false })
|
|
243
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
244
|
+
observer = new ResizeObserver(() => measure())
|
|
245
|
+
if (sheetEl.value) observer.observe(sheetEl.value)
|
|
246
|
+
if (rootEl.value) observer.observe(rootEl.value)
|
|
247
|
+
}
|
|
248
|
+
})
|
|
249
|
+
onUnmounted(() => {
|
|
250
|
+
cancelAnimationFrame(raf)
|
|
251
|
+
observer?.disconnect()
|
|
252
|
+
sheetEl.value?.removeEventListener('touchmove', onTouchMove)
|
|
253
|
+
})
|
|
254
|
+
</script>
|
|
255
|
+
|
|
256
|
+
<template>
|
|
257
|
+
<div ref="rootEl" class="relative flex h-full flex-col overflow-hidden bg-surface text-on-surface">
|
|
258
|
+
<div v-if="$slots['top-bar']" class="shrink-0">
|
|
259
|
+
<slot name="top-bar" />
|
|
260
|
+
</div>
|
|
261
|
+
<div class="min-h-0 flex-1 overflow-auto" :style="{ paddingBottom: `${peekHeight}px` }">
|
|
262
|
+
<slot />
|
|
263
|
+
</div>
|
|
264
|
+
|
|
265
|
+
<!-- SheetBottomTokens: surface-container-low, 28dp top corners, elevation 1. The strip hanging below
|
|
266
|
+
(after:) fills the gap a spring overshoot past the expanded state would open at the bottom. -->
|
|
267
|
+
<div
|
|
268
|
+
ref="sheetEl"
|
|
269
|
+
role="region"
|
|
270
|
+
class="absolute inset-x-0 bottom-0 z-10 mx-auto flex max-h-full w-full touch-pan-y select-none flex-col rounded-t-[28px] bg-surface-container-low text-on-surface shadow-elevation-1 after:absolute after:inset-x-0 after:top-full after:h-24 after:bg-surface-container-low"
|
|
271
|
+
:style="{ maxWidth: `${maxWidth}px` }"
|
|
272
|
+
@pointerdown="onPointerDown"
|
|
273
|
+
@pointermove="onPointerMove"
|
|
274
|
+
@pointerup="onPointerUp"
|
|
275
|
+
@pointercancel="onPointerUp"
|
|
276
|
+
@click.capture="onClickCapture"
|
|
277
|
+
>
|
|
278
|
+
<!-- BottomSheetDefaults.DragHandle: 32×4dp in on-surface-variant, 22dp above and below -->
|
|
279
|
+
<div class="flex h-12 shrink-0 justify-center">
|
|
280
|
+
<button
|
|
281
|
+
type="button"
|
|
282
|
+
class="flex h-12 w-16 cursor-pointer items-center justify-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-secondary"
|
|
283
|
+
:aria-label="handleLabel"
|
|
284
|
+
:aria-expanded="settled === 'expanded'"
|
|
285
|
+
@click="onHandleClick"
|
|
286
|
+
>
|
|
287
|
+
<span class="h-1 w-8 rounded-full bg-on-surface-variant" />
|
|
288
|
+
</button>
|
|
289
|
+
</div>
|
|
290
|
+
<!-- touch-action stops at a scroll container, so the content needs its own pan-y -->
|
|
291
|
+
<div ref="contentEl" class="min-h-0 flex-1 touch-pan-y select-text overflow-y-hidden">
|
|
292
|
+
<slot name="sheet" />
|
|
293
|
+
</div>
|
|
294
|
+
</div>
|
|
295
|
+
</div>
|
|
296
|
+
</template>
|
|
@@ -24,7 +24,7 @@ defineEmits<{ select: [BreadcrumbItem, number] }>()
|
|
|
24
24
|
</script>
|
|
25
25
|
|
|
26
26
|
<template>
|
|
27
|
-
<nav aria-label="Breadcrumb" class="flex items-center gap-1 overflow-x-auto text-label-large">
|
|
27
|
+
<nav aria-label="Breadcrumb" class="scrollbar-none flex items-center gap-1 overflow-x-auto text-label-large">
|
|
28
28
|
<template v-for="(item, i) in items" :key="i">
|
|
29
29
|
<!-- Separator -->
|
|
30
30
|
<MIcon
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { computed } from 'vue'
|
|
8
8
|
import MSpinner from './MSpinner.vue'
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
|
+
import { vRipple } from '../directives/vRipple'
|
|
10
11
|
|
|
11
12
|
const NAMED_COLORS = ['primary', 'error'] as const
|
|
12
13
|
type NamedColor = (typeof NAMED_COLORS)[number]
|
|
@@ -46,6 +47,8 @@ const props = withDefaults(
|
|
|
46
47
|
shape?: 'rounded' | 'squared'
|
|
47
48
|
/** Vue Router destination — renders as RouterLink instead of button */
|
|
48
49
|
to?: string | Record<string, any>
|
|
50
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
51
|
+
rippleColor?: string
|
|
49
52
|
}>(),
|
|
50
53
|
{
|
|
51
54
|
variant: 'filled',
|
|
@@ -165,18 +168,6 @@ const variantClasses = computed(() => {
|
|
|
165
168
|
return ''
|
|
166
169
|
}
|
|
167
170
|
})
|
|
168
|
-
|
|
169
|
-
function createRipple(event: PointerEvent) {
|
|
170
|
-
if (props.disabled || props.loading) return
|
|
171
|
-
const button = event.currentTarget as HTMLElement
|
|
172
|
-
const rect = button.getBoundingClientRect()
|
|
173
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
174
|
-
const el = document.createElement('span')
|
|
175
|
-
el.className = 'm3-ripple'
|
|
176
|
-
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`
|
|
177
|
-
button.appendChild(el)
|
|
178
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
179
|
-
}
|
|
180
171
|
</script>
|
|
181
172
|
|
|
182
173
|
<template>
|
|
@@ -187,7 +178,7 @@ function createRipple(event: PointerEvent) {
|
|
|
187
178
|
:disabled="disabled || loading"
|
|
188
179
|
:class="[base, shapeClass, sizeClasses, px, variantClasses, disabledContainerClasses]"
|
|
189
180
|
:style="customStyle"
|
|
190
|
-
|
|
181
|
+
v-ripple="{ disabled: disabled || loading, color: rippleColor }"
|
|
191
182
|
>
|
|
192
183
|
<template v-if="iconPos === 'leading'">
|
|
193
184
|
<MSpinner v-if="loading" :size="spinnerSize" />
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { computed, ref } from 'vue'
|
|
9
9
|
import MIcon from './MIcon.vue'
|
|
10
10
|
import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
11
|
+
import { vRipple } from '../directives/vRipple'
|
|
11
12
|
|
|
12
13
|
export interface ButtonGroupOption {
|
|
13
14
|
value: unknown
|
|
@@ -31,6 +32,8 @@ const props = withDefaults(defineProps<{
|
|
|
31
32
|
selectionRequired?: boolean
|
|
32
33
|
/** Selected button color */
|
|
33
34
|
color?: 'primary' | 'secondary' | 'tertiary'
|
|
35
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
36
|
+
rippleColor?: string
|
|
34
37
|
}>(), {
|
|
35
38
|
variant: 'standard',
|
|
36
39
|
size: 'sm',
|
|
@@ -99,22 +102,11 @@ const selectedColors = computed(() => {
|
|
|
99
102
|
|
|
100
103
|
const unselectedColors = 'bg-surface-container-highest text-on-surface'
|
|
101
104
|
|
|
102
|
-
function createRipple(event: PointerEvent) {
|
|
103
|
-
const button = event.currentTarget as HTMLElement
|
|
104
|
-
const rect = button.getBoundingClientRect()
|
|
105
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
106
|
-
const el = document.createElement('span')
|
|
107
|
-
el.className = 'm3-ripple'
|
|
108
|
-
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`
|
|
109
|
-
button.appendChild(el)
|
|
110
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
111
|
-
}
|
|
112
105
|
|
|
113
106
|
const buttons: (HTMLElement | null)[] = []
|
|
114
107
|
const pressedIndex = ref(-1)
|
|
115
108
|
|
|
116
109
|
function onPointerDown(e: PointerEvent, i: number) {
|
|
117
|
-
createRipple(e)
|
|
118
110
|
if (e.button !== 0 || props.options[i]?.disabled) return
|
|
119
111
|
measureWidths()
|
|
120
112
|
pressedIndex.value = i
|
|
@@ -233,6 +225,7 @@ useSpring(
|
|
|
233
225
|
]"
|
|
234
226
|
:disabled="opt.disabled"
|
|
235
227
|
:aria-pressed="isSelected(opt.value)"
|
|
228
|
+
v-ripple="{ disabled: opt.disabled, color: rippleColor }"
|
|
236
229
|
@pointerdown="onPointerDown($event, i)"
|
|
237
230
|
@pointerup="onPointerUp"
|
|
238
231
|
@pointerleave="onPointerUp"
|
package/src/components/MChip.vue
CHANGED
|
@@ -1,14 +1,20 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
3
|
* Compact elements for filters, input, or actions — named semantic tones or any CSS color, with optional icon,
|
|
4
|
-
* click, selection, and removal support.
|
|
4
|
+
* click, selection, and removal support. With `type` it's one of M3's four chips instead (assist, filter,
|
|
5
|
+
* input, suggestion), styled by the spec and always interactive; `tone` then doesn't apply.
|
|
5
6
|
*
|
|
6
7
|
* @slot default The chip's label.
|
|
7
|
-
* @
|
|
8
|
+
* @slot avatar Input chips only: a 24px round avatar before the label (e.g. an MAvatar or an img)
|
|
9
|
+
* @event click Emitted when a clickable (or typed), non-disabled chip is clicked
|
|
8
10
|
* @event remove Emitted when the remove (X) button is clicked (removable only)
|
|
11
|
+
* @event update:selected Filter and input chips: emitted on click with the new selected state — powers
|
|
12
|
+
* v-model:selected
|
|
9
13
|
*/
|
|
10
|
-
import { computed } from 'vue'
|
|
14
|
+
import { computed, ref, useSlots } from 'vue'
|
|
11
15
|
import MIcon from './MIcon.vue'
|
|
16
|
+
import { useLocale } from '../composables/useLocale'
|
|
17
|
+
import { FAST_EFFECTS, FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
12
18
|
|
|
13
19
|
const NAMED_TONES = ['neutral', 'primary', 'success', 'error', 'tertiary', 'secondary'] as const
|
|
14
20
|
type NamedTone = (typeof NAMED_TONES)[number]
|
|
@@ -30,6 +36,16 @@ const props = withDefaults(
|
|
|
30
36
|
disabled?: boolean
|
|
31
37
|
/** Leading Material Symbol icon */
|
|
32
38
|
icon?: string
|
|
39
|
+
/**
|
|
40
|
+
* One of M3's chips: `assist` (an action), `filter` (on/off, v-model:selected; a check slides in while
|
|
41
|
+
* selected), `input` (a piece of user input, with an optional #avatar and `removable`), `suggestion`.
|
|
42
|
+
* Leave unset for the generic tone-colored chip
|
|
43
|
+
*/
|
|
44
|
+
type?: 'assist' | 'filter' | 'input' | 'suggestion'
|
|
45
|
+
/** Typed assist, filter and suggestion chips: surface-container-low with elevation 1 instead of an outline */
|
|
46
|
+
elevated?: boolean
|
|
47
|
+
/** Typed chips: a trailing Material Symbol icon (e.g. arrow_drop_down on a filter chip that opens a menu) */
|
|
48
|
+
trailingIcon?: string
|
|
33
49
|
}>(),
|
|
34
50
|
{
|
|
35
51
|
tone: 'neutral',
|
|
@@ -37,10 +53,13 @@ const props = withDefaults(
|
|
|
37
53
|
removable: false,
|
|
38
54
|
clickable: false,
|
|
39
55
|
disabled: false,
|
|
56
|
+
elevated: false,
|
|
40
57
|
},
|
|
41
58
|
)
|
|
42
59
|
|
|
43
|
-
const emit = defineEmits<{ click: []; remove: [] }>()
|
|
60
|
+
const emit = defineEmits<{ click: []; remove: []; 'update:selected': [boolean] }>()
|
|
61
|
+
const locale = useLocale()
|
|
62
|
+
const slots = useSlots()
|
|
44
63
|
|
|
45
64
|
const isCustomColor = computed(
|
|
46
65
|
() => !!props.tone && !(NAMED_TONES as readonly string[]).includes(props.tone),
|
|
@@ -95,6 +114,74 @@ const shapeClass = computed(() => props.selected ? 'rounded-full' : 'rounded-md'
|
|
|
95
114
|
// it. `ring-inset` on the focus ring (FocusedIndicatorColor = secondary) because `overflow-
|
|
96
115
|
// hidden` on this same element (needed to clip the state-layer to the chip's shape) would
|
|
97
116
|
// otherwise clip an outset ring's box-shadow too.
|
|
117
|
+
// ── Typed chips (Compose's AssistChip / FilterChip / InputChip / SuggestionChip) ─────────────────────
|
|
118
|
+
// 32dp, label-large, 18dp icons. Assist and suggestion keep CornerSmall (8dp); filter and input use the
|
|
119
|
+
// Expressive ChipShapes (CornerMedium 12dp, CornerFull while selected, CornerSmall while pressed) and the
|
|
120
|
+
// unified ChipsTokens colors.
|
|
121
|
+
const selectable = computed(() => props.type === 'filter' || props.type === 'input')
|
|
122
|
+
const hasAvatar = computed(() => props.type === 'input' && !!slots.avatar)
|
|
123
|
+
const hasTrailing = computed(() => !!props.trailingIcon || (props.type === 'input' && props.removable))
|
|
124
|
+
|
|
125
|
+
const typedContainer = computed(() => {
|
|
126
|
+
const on = selectable.value && props.selected
|
|
127
|
+
if (props.disabled) {
|
|
128
|
+
if (on) return 'bg-on-surface/12 text-on-surface/38'
|
|
129
|
+
return props.elevated && props.type !== 'input'
|
|
130
|
+
? 'bg-on-surface/12 text-on-surface/38'
|
|
131
|
+
: 'border border-on-surface/12 text-on-surface/38'
|
|
132
|
+
}
|
|
133
|
+
if (on) return ['bg-secondary-container text-on-secondary-container', props.elevated ? 'shadow-elevation-1 hover:shadow-elevation-2' : '']
|
|
134
|
+
const label = props.type === 'assist' ? 'text-on-surface' : 'text-on-surface-variant'
|
|
135
|
+
return props.elevated && props.type !== 'input'
|
|
136
|
+
? ['bg-surface-container-low shadow-elevation-1 hover:shadow-elevation-2', label]
|
|
137
|
+
: ['border border-outline-variant', label]
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
const leadingIconClass = computed(() => {
|
|
141
|
+
if (props.disabled) return ''
|
|
142
|
+
if (props.type === 'assist' || props.type === 'suggestion') return 'text-primary'
|
|
143
|
+
return props.selected ? 'text-on-secondary-container' : 'text-on-surface-variant'
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// Compose's chip paddings: 8dp next to a leading/trailing icon, 16dp otherwise; an input chip 4dp next to an
|
|
147
|
+
// avatar, 8dp next to an icon, 12dp (4 + the label's 8) otherwise
|
|
148
|
+
const typedPadding = computed(() => {
|
|
149
|
+
if (props.type === 'input') {
|
|
150
|
+
return [hasAvatar.value ? 'pl-1' : props.icon ? 'pl-2' : 'pl-3', hasTrailing.value ? 'pr-2' : 'pr-3']
|
|
151
|
+
}
|
|
152
|
+
// A filter chip's sliding check carries its own spacing (see checkEl), so its padding stays put
|
|
153
|
+
return [props.icon || slidingCheck.value ? 'pl-2' : 'pl-4', hasTrailing.value ? 'pr-2' : 'pr-4']
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
const pressed = ref(false)
|
|
157
|
+
const typedEl = ref<HTMLElement>()
|
|
158
|
+
const checkEl = ref<HTMLElement>()
|
|
159
|
+
// Filter chip without its own icon: the check expands in (FastSpatial) and fades in (FastEffects) as it gets
|
|
160
|
+
// selected, like Compose's animated chip content. Its slot runs from 8px (with the 8px padding: the label at
|
|
161
|
+
// 16px, an iconless chip's padding) to 26px (the check at 8px, the label 8px after it).
|
|
162
|
+
const slidingCheck = computed(() => props.type === 'filter' && !props.icon)
|
|
163
|
+
useSpring(
|
|
164
|
+
() => (props.type === 'filter' || props.type === 'input'
|
|
165
|
+
? [pressed.value ? 8 : props.selected ? 16 : 12, slidingCheck.value ? (props.selected ? 26 : 8) : 0]
|
|
166
|
+
: []),
|
|
167
|
+
([radius, width]) => {
|
|
168
|
+
if (typedEl.value && radius !== undefined) typedEl.value.style.borderRadius = `${radius}px`
|
|
169
|
+
if (checkEl.value && width !== undefined) checkEl.value.style.width = `${width}px`
|
|
170
|
+
},
|
|
171
|
+
FAST_SPATIAL,
|
|
172
|
+
)
|
|
173
|
+
useSpring(
|
|
174
|
+
() => (slidingCheck.value ? [props.selected ? 1 : 0] : []),
|
|
175
|
+
([opacity]) => { if (checkEl.value && opacity !== undefined) checkEl.value.style.opacity = String(opacity) },
|
|
176
|
+
FAST_EFFECTS,
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
function onTypedClick() {
|
|
180
|
+
if (props.disabled) return
|
|
181
|
+
if (selectable.value) emit('update:selected', !props.selected)
|
|
182
|
+
emit('click')
|
|
183
|
+
}
|
|
184
|
+
|
|
98
185
|
const interactiveClasses =
|
|
99
186
|
"relative cursor-pointer before:content-[''] before:pointer-events-none before:absolute before:inset-0 " +
|
|
100
187
|
'before:bg-current before:opacity-0 before:transition-opacity before:duration-150 ' +
|
|
@@ -103,8 +190,53 @@ const interactiveClasses =
|
|
|
103
190
|
</script>
|
|
104
191
|
|
|
105
192
|
<template>
|
|
193
|
+
<span
|
|
194
|
+
v-if="type"
|
|
195
|
+
ref="typedEl"
|
|
196
|
+
class="relative inline-flex h-8 items-center overflow-hidden align-middle text-label-large transition-[background-color,box-shadow,color] has-[button:focus-visible]:ring-2 has-[button:focus-visible]:ring-inset has-[button:focus-visible]:ring-secondary"
|
|
197
|
+
:class="[typedContainer, type === 'assist' || type === 'suggestion' ? 'rounded-sm' : 'rounded-md']"
|
|
198
|
+
>
|
|
199
|
+
<!-- Typed chip: the container is a span so an input chip's remove button can sit beside (not inside) the
|
|
200
|
+
main button; the main button's state layer (before:) covers the whole chip -->
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
class="flex h-full items-center gap-2 outline-none before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity"
|
|
204
|
+
:class="[typedPadding, disabled ? 'cursor-not-allowed' : 'cursor-pointer hover:before:opacity-[0.08] active:before:opacity-[0.12]']"
|
|
205
|
+
:disabled="disabled"
|
|
206
|
+
:aria-pressed="selectable ? selected : undefined"
|
|
207
|
+
@pointerdown="pressed = true"
|
|
208
|
+
@pointerup="pressed = false"
|
|
209
|
+
@pointerleave="pressed = false"
|
|
210
|
+
@pointercancel="pressed = false"
|
|
211
|
+
@click="onTypedClick"
|
|
212
|
+
>
|
|
213
|
+
<span v-if="hasAvatar" class="-my-1 flex h-6 w-6 shrink-0 items-center justify-center overflow-hidden rounded-full" :class="disabled ? 'opacity-38' : ''">
|
|
214
|
+
<slot name="avatar" />
|
|
215
|
+
</span>
|
|
216
|
+
<MIcon v-else-if="icon" :name="icon" :size="18" :filled="type === 'filter' && selected" class="shrink-0" :class="leadingIconClass" />
|
|
217
|
+
<!-- -mr-2 cancels the gap while the check is closed -->
|
|
218
|
+
<span v-else-if="slidingCheck" ref="checkEl" class="-mr-2 flex shrink-0 overflow-hidden" style="width: 8px; opacity: 0" aria-hidden="true">
|
|
219
|
+
<MIcon name="check" :size="18" class="shrink-0" :class="leadingIconClass" />
|
|
220
|
+
</span>
|
|
221
|
+
<span class="whitespace-nowrap"><slot /></span>
|
|
222
|
+
<MIcon v-if="trailingIcon" :name="trailingIcon" :size="18" class="shrink-0" :class="disabled ? '' : selected && selectable ? 'text-on-secondary-container' : 'text-on-surface-variant'" />
|
|
223
|
+
</button>
|
|
224
|
+
<button
|
|
225
|
+
v-if="type === 'input' && removable"
|
|
226
|
+
type="button"
|
|
227
|
+
class="relative -ml-1 mr-2 flex h-6 w-6 shrink-0 items-center justify-center rounded-full outline-none hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-secondary"
|
|
228
|
+
:class="disabled ? 'cursor-not-allowed' : 'cursor-pointer'"
|
|
229
|
+
:aria-label="locale.remove"
|
|
230
|
+
:disabled="disabled"
|
|
231
|
+
@click.stop="emit('remove')"
|
|
232
|
+
>
|
|
233
|
+
<MIcon name="close" :size="18" />
|
|
234
|
+
</button>
|
|
235
|
+
</span>
|
|
236
|
+
|
|
106
237
|
<component
|
|
107
238
|
:is="clickable ? 'button' : 'span'"
|
|
239
|
+
v-else
|
|
108
240
|
:type="clickable ? 'button' : undefined"
|
|
109
241
|
:disabled="clickable && disabled ? true : undefined"
|
|
110
242
|
class="inline-flex h-8 items-center gap-1.5 overflow-hidden px-3 text-label-large transition-colors"
|
|
@@ -123,7 +255,7 @@ const interactiveClasses =
|
|
|
123
255
|
v-if="removable"
|
|
124
256
|
type="button"
|
|
125
257
|
class="-mr-1 ml-0.5 inline-flex items-center justify-center rounded-full hover:bg-on-surface/12"
|
|
126
|
-
aria-label="
|
|
258
|
+
:aria-label="locale.remove"
|
|
127
259
|
:disabled="disabled"
|
|
128
260
|
@click.stop="emit('remove')"
|
|
129
261
|
>
|