@m3ui-vue/m3ui-vue 1.1.3 → 1.2.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 +1 -1
- package/dist/API.md +579 -40
- package/dist/MMenuItem-DI351kIf.js +929 -0
- package/dist/MMenuItem-DI351kIf.js.map +1 -0
- package/dist/MSlider-BnEy5ieZ.js +1500 -0
- package/dist/MSlider-BnEy5ieZ.js.map +1 -0
- package/dist/MTextField-BBmkaIbO.js +633 -0
- package/dist/MTextField-BBmkaIbO.js.map +1 -0
- package/dist/api.json +1 -1
- package/dist/chart.js +83 -49
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MAnimatedNumber.vue.d.ts +3 -1
- package/dist/components/MButton.vue.d.ts +9 -1
- package/dist/components/MButtonGroup.vue.d.ts +40 -31
- package/dist/components/MCarousel.vue.d.ts +2 -0
- package/dist/components/MChart.vue.d.ts +6 -0
- package/dist/components/MCircleProgressBar.vue.d.ts +5 -3
- package/dist/components/MContainerTransform.vue.d.ts +59 -0
- package/dist/components/MContextMenu.vue.d.ts +2 -2
- package/dist/components/MCopyButton.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +8 -5
- package/dist/components/MExportButton.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +2 -2
- package/dist/components/MFabMenu.vue.d.ts +1 -1
- package/dist/components/MFlex.vue.d.ts +1 -1
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MInfiniteScroll.vue.d.ts +1 -1
- package/dist/components/MListItem.vue.d.ts +5 -5
- package/dist/components/MMap.vue.d.ts +20 -2
- package/dist/components/MMapBaseLayers.vue.d.ts +3 -0
- package/dist/components/MMapFilter.vue.d.ts +3 -0
- package/dist/components/MMapLayers.vue.d.ts +3 -0
- package/dist/components/MMenu.vue.d.ts +2 -2
- package/dist/components/MMenuItem.vue.d.ts +7 -3
- package/dist/components/MNavigationDrawer.vue.d.ts +13 -2
- package/dist/components/MNavigationRail.vue.d.ts +1 -1
- package/dist/components/MOverlay.vue.d.ts +12 -1
- package/dist/components/MProgressBar.vue.d.ts +5 -3
- package/dist/components/MPullToRefresh.vue.d.ts +7 -2
- package/dist/components/MRichTextEditor.vue.d.ts +7 -1
- package/dist/components/MSearchField.vue.d.ts +58 -0
- package/dist/components/MSegmentedButton.vue.d.ts +31 -23
- package/dist/components/MSimpleCarousel.vue.d.ts +2 -0
- package/dist/components/MSkeleton.vue.d.ts +6 -3
- package/dist/components/MSplitter.vue.d.ts +1 -1
- package/dist/components/MStack.vue.d.ts +1 -1
- package/dist/components/MSwipeToDismiss.vue.d.ts +1 -1
- package/dist/components/MSwitch.vue.d.ts +1 -1
- package/dist/components/MTextField.vue.d.ts +5 -1
- package/dist/components/MTimeline.vue.d.ts +85 -22
- package/dist/components/MToolbar.vue.d.ts +32 -5
- package/dist/components/MTooltip.vue.d.ts +1 -1
- package/dist/components/_MDrawerItemList.vue.d.ts +2 -0
- package/dist/components/_MToolbarFab.vue.d.ts +16 -0
- package/dist/composables/_containerTransform.d.ts +48 -0
- package/dist/composables/_mapStyle.d.ts +13 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_tooltipTrigger.d.ts +22 -0
- package/dist/composables/_useMenuNav.d.ts +28 -0
- package/dist/composables/useAutoGrow.d.ts +21 -0
- package/dist/composables/useColorPalette.d.ts +1 -1
- package/dist/composables/useContainerTransform.d.ts +30 -0
- package/dist/composables/useLocale.d.ts +6 -0
- package/dist/composables/useMap.d.ts +19 -3
- package/dist/composables/useMapFilter.d.ts +4 -1
- package/dist/composables/useMapLayers.d.ts +5 -2
- package/dist/composables/useScrollReveal.d.ts +44 -0
- package/dist/composables/useThemeTokens.d.ts +21 -0
- package/dist/composables/viewportHints.d.ts +27 -0
- package/dist/directives/vClickOutside.d.ts +25 -0
- package/dist/directives/vFocusRing.d.ts +22 -0
- package/dist/directives/vLongPress.d.ts +27 -0
- package/dist/directives/vReveal.d.ts +10 -0
- package/dist/directives/vScrollElevation.d.ts +31 -0
- package/dist/directives/vSkeleton.d.ts +19 -0
- package/dist/directives/vStateLayer.d.ts +20 -0
- package/dist/directives/vSwipe.d.ts +45 -0
- package/dist/directives/vTooltip.d.ts +23 -0
- package/dist/index.d.ts +31 -1
- package/dist/locales/index.js +35 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7692 -6273
- package/dist/m3ui.js.map +1 -1
- package/dist/map.d.ts +1 -1
- package/dist/map.js +823 -793
- package/dist/map.js.map +1 -1
- package/dist/motion-DZiXG09o.js +150 -0
- package/dist/motion-DZiXG09o.js.map +1 -0
- package/dist/plugin.d.ts +24 -0
- package/dist/rich-text-editor.js +20 -16
- package/dist/rich-text-editor.js.map +1 -1
- package/dist/styles/theme.css +63 -0
- package/dist/styles.css +1 -1
- package/dist/{useLocale-SfQHnJfp.js → useLocale-JYxDDeXC.js} +6 -2
- package/dist/useLocale-JYxDDeXC.js.map +1 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js +135 -0
- package/dist/useThemeTokens-Bv-Uv8eX.js.map +1 -0
- package/package.json +2 -1
- package/src/__tests__/MAnimatedNumber.test.ts +24 -2
- package/src/__tests__/MButton.test.ts +22 -0
- package/src/__tests__/MCarousel.test.ts +9 -0
- package/src/__tests__/MChart.test.ts +77 -5
- package/src/__tests__/MContainerTransform.test.ts +279 -0
- package/src/__tests__/MDialog.test.ts +27 -0
- package/src/__tests__/MIconButton.test.ts +33 -0
- package/src/__tests__/MListItemExpandable.test.ts +48 -0
- package/src/__tests__/MListItemShape.test.ts +9 -6
- package/src/__tests__/MListKeyboard.test.ts +90 -0
- package/src/__tests__/MMap.test.ts +53 -1
- package/src/__tests__/MMapLayers.test.ts +46 -2
- package/src/__tests__/MMapTools.test.ts +2 -1
- package/src/__tests__/MMenu.test.ts +104 -1
- package/src/__tests__/MMenuItem.test.ts +18 -0
- package/src/__tests__/MNavigationDrawer.test.ts +80 -0
- package/src/__tests__/MNavigationRail.test.ts +33 -0
- package/src/__tests__/MOverlay.test.ts +49 -0
- package/src/__tests__/MProgressBar.test.ts +41 -0
- package/src/__tests__/MPullToRefresh.test.ts +33 -0
- package/src/__tests__/MRichTextEditor.test.ts +22 -0
- package/src/__tests__/MSearchField.test.ts +71 -0
- package/src/__tests__/MSkeleton.test.ts +38 -0
- package/src/__tests__/MSlider.test.ts +161 -0
- package/src/__tests__/MTimeline.test.ts +238 -0
- package/src/__tests__/MToolbar.test.ts +157 -0
- package/src/__tests__/_fakeMaplibre.ts +3 -1
- package/src/__tests__/attrsFallthrough.test.ts +9 -0
- package/src/__tests__/escapeStack.test.ts +93 -0
- package/src/__tests__/hydration.test.ts +25 -0
- package/src/__tests__/ssr.test.ts +21 -2
- package/src/__tests__/useAutoGrow.test.ts +103 -0
- package/src/__tests__/useScrollReveal.test.ts +102 -0
- package/src/__tests__/useThemeTokens.test.ts +114 -0
- package/src/__tests__/vClickOutside.test.ts +82 -0
- package/src/__tests__/vFocusRing.test.ts +36 -0
- package/src/__tests__/vLongPress.test.ts +81 -0
- package/src/__tests__/vScrollElevation.test.ts +89 -0
- package/src/__tests__/vSkeleton.test.ts +48 -0
- package/src/__tests__/vStateLayer.test.ts +53 -0
- package/src/__tests__/vSwipe.test.ts +93 -0
- package/src/__tests__/vTooltip.test.ts +95 -0
- package/src/__tests__/viewportHints.test.ts +41 -0
- package/src/components/MAnimatedNumber.vue +32 -6
- package/src/components/MAutocomplete.vue +5 -0
- package/src/components/MBottomSheet.vue +4 -1
- package/src/components/MButton.vue +19 -3
- package/src/components/MButtonGroup.vue +22 -17
- package/src/components/MCarousel.vue +7 -1
- package/src/components/MChart.vue +74 -34
- package/src/components/MCircleProgressBar.vue +14 -9
- package/src/components/MCommandPalette.vue +3 -2
- package/src/components/MContainerTransform.vue +321 -0
- package/src/components/MContextMenu.vue +19 -60
- package/src/components/MDialog.vue +31 -6
- package/src/components/MDragDropList.vue +2 -0
- package/src/components/MFab.vue +10 -5
- package/src/components/MIconButton.vue +43 -2
- package/src/components/MKanban.vue +2 -0
- package/src/components/MLightbox.vue +7 -2
- package/src/components/MList.vue +26 -2
- package/src/components/MListItem.vue +138 -84
- package/src/components/MMap.vue +38 -5
- package/src/components/MMapBaseLayers.vue +7 -3
- package/src/components/MMapFilter.vue +7 -4
- package/src/components/MMapGeoJson.vue +1 -1
- package/src/components/MMapLayers.vue +6 -2
- package/src/components/MMapMeasure.vue +5 -2
- package/src/components/MMenu.vue +18 -59
- package/src/components/MMenuItem.vue +11 -2
- package/src/components/MMultiAutocomplete.vue +5 -0
- package/src/components/MNavigationDrawer.vue +96 -11
- package/src/components/MNavigationRail.vue +44 -25
- package/src/components/MOverlay.vue +32 -13
- package/src/components/MProgressBar.vue +25 -27
- package/src/components/MPullToRefresh.vue +20 -1
- package/src/components/MRichTextEditor.vue +19 -5
- package/src/components/MSearchBar.vue +5 -0
- package/src/components/MSearchField.vue +142 -0
- package/src/components/MSegmentedButton.vue +19 -17
- package/src/components/MSelect.vue +10 -1
- package/src/components/MSideSheet.vue +5 -2
- package/src/components/MSimpleCarousel.vue +10 -1
- package/src/components/MSkeleton.vue +30 -8
- package/src/components/MSlider.vue +161 -42
- package/src/components/MSpotlightSearch.vue +3 -2
- package/src/components/MTextField.vue +15 -2
- package/src/components/MTimeline.vue +370 -81
- package/src/components/MToolbar.vue +256 -15
- package/src/components/MTooltip.vue +20 -152
- package/src/components/_MDrawerItemList.vue +25 -6
- package/src/components/_MToolbarFab.vue +14 -0
- package/src/composables/_containerTransform.ts +179 -0
- package/src/composables/_mapStyle.ts +45 -0
- package/src/composables/_themeTransition.ts +2 -0
- package/src/composables/_tooltipTrigger.ts +184 -0
- package/src/composables/_useEscapeStack.ts +2 -0
- package/src/composables/_useMenuNav.ts +209 -0
- package/src/composables/useAutoGrow.ts +78 -0
- package/src/composables/useContainerTransform.ts +59 -0
- package/src/composables/useLocale.ts +10 -0
- package/src/composables/useMap.ts +43 -5
- package/src/composables/useMapFilter.ts +6 -5
- package/src/composables/useMapLayers.ts +7 -6
- package/src/composables/useScrollReveal.ts +151 -0
- package/src/composables/useThemeTokens.ts +116 -0
- package/src/composables/viewportHints.ts +80 -0
- package/src/directives/vClickOutside.ts +90 -0
- package/src/directives/vFocusRing.ts +60 -0
- package/src/directives/vLongPress.ts +134 -0
- package/src/directives/vReveal.ts +57 -0
- package/src/directives/vScrollElevation.ts +116 -0
- package/src/directives/vSkeleton.ts +87 -0
- package/src/directives/vStateLayer.ts +83 -0
- package/src/directives/vSwipe.ts +197 -0
- package/src/directives/vTooltip.ts +128 -0
- package/src/index.ts +31 -1
- package/src/locales/de.ts +4 -0
- package/src/locales/es.ts +4 -0
- package/src/locales/fr.ts +4 -0
- package/src/locales/ja.ts +4 -0
- package/src/locales/ko.ts +4 -0
- package/src/locales/pt.ts +4 -0
- package/src/locales/zh.ts +4 -0
- package/src/map.ts +1 -1
- package/src/plugin.ts +34 -0
- package/src/styles/theme.css +63 -0
- package/dist/MMenuItem-BckcR0nW.js +0 -809
- package/dist/MMenuItem-BckcR0nW.js.map +0 -1
- package/dist/MSlider-LyH_gy8D.js +0 -1411
- package/dist/MSlider-LyH_gy8D.js.map +0 -1
- package/dist/MTextField-FCPOTB0o.js +0 -672
- package/dist/MTextField-FCPOTB0o.js.map +0 -1
- package/dist/composables/_useThemeTokens.d.ts +0 -7
- package/dist/useLocale-SfQHnJfp.js.map +0 -1
- package/src/composables/_useThemeTokens.ts +0 -42
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
<script setup lang="ts" generic="T = unknown">
|
|
2
|
+
/**
|
|
3
|
+
* Material's container transform: an element (a card, a list item, an image, a FAB…) grows into an expanded view
|
|
4
|
+
* and shrinks back into it, morphing its bounds and shape while its content fades into the new one. The expanded
|
|
5
|
+
* view opens over the page, full screen, as a centered panel, or wherever your classes put it (`custom`), with a
|
|
6
|
+
* scrim (optional), Escape and scroll lock; focus goes to it and back to the element on close. A port of Android's
|
|
7
|
+
* MaterialContainerTransform, played on the compositor. For elements that live apart from the expanded view (a grid
|
|
8
|
+
* of cards, one detail), pass a `useContainerTransform()` controller instead of the default slot.
|
|
9
|
+
*
|
|
10
|
+
* @slot default The element that opens it, with `{ open, isOpen }`: call `open()` from its click
|
|
11
|
+
* @slot expanded The expanded view, with `{ close, item }` (`item` is what the controller's `open` was given)
|
|
12
|
+
* @event update:open The expanded view opened or closed (v-model:open)
|
|
13
|
+
*/
|
|
14
|
+
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
|
15
|
+
import { useContainerTransform, type ContainerTransformController } from '../composables/useContainerTransform'
|
|
16
|
+
import {
|
|
17
|
+
CLOSE_MS, OPEN_MS, SCRIM_OPACITY, boxOf, containerFrames, playContainerFrames, radiusOf, type Box,
|
|
18
|
+
} from '../composables/_containerTransform'
|
|
19
|
+
import { prefersReducedMotion } from '../composables/_springAnimation'
|
|
20
|
+
import { useScrollLock } from '../composables/_useScrollLock'
|
|
21
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
22
|
+
|
|
23
|
+
defineOptions({ inheritAttrs: false })
|
|
24
|
+
|
|
25
|
+
const props = withDefaults(defineProps<{
|
|
26
|
+
/** A `useContainerTransform()` controller, to open it from elements elsewhere (`controller.open($event, item)`) */
|
|
27
|
+
controller?: ContainerTransformController<T>
|
|
28
|
+
/**
|
|
29
|
+
* Where the expanded view opens: over the whole screen, as a centered panel (wider screens), or `custom`: the
|
|
30
|
+
* classes you give the component place and size it (`bottom-4 right-4 w-80 h-96`, `inset-y-0 right-0 w-96`…),
|
|
31
|
+
* anywhere over the page
|
|
32
|
+
*/
|
|
33
|
+
mode?: 'fullscreen' | 'dialog' | 'custom'
|
|
34
|
+
/** The centered panel's maximum width (`dialog` mode) */
|
|
35
|
+
maxWidth?: string
|
|
36
|
+
/** Accessible name of the expanded view */
|
|
37
|
+
label?: string
|
|
38
|
+
/**
|
|
39
|
+
* Dims the page behind it, which makes it modal (scroll lock, `aria-modal`). Without one the page stays usable:
|
|
40
|
+
* a click outside closes it instead (unless `persistent`)
|
|
41
|
+
*/
|
|
42
|
+
scrim?: boolean
|
|
43
|
+
/** A click on the scrim, or outside without one, doesn't close it */
|
|
44
|
+
persistent?: boolean
|
|
45
|
+
/**
|
|
46
|
+
* Android's back (button or gesture) closes it, like an expanded view in an app, where the browser has the
|
|
47
|
+
* CloseWatcher API (Chrome, Edge); the history and the router are left alone. Default `true`
|
|
48
|
+
*/
|
|
49
|
+
closeOnBack?: boolean
|
|
50
|
+
}>(), { mode: 'fullscreen', maxWidth: '560px', scrim: true, persistent: false, closeOnBack: true })
|
|
51
|
+
|
|
52
|
+
/** Whether the expanded view is open; opening it from here grows it from the default slot's element */
|
|
53
|
+
const openModel = defineModel<boolean>('open', { default: false })
|
|
54
|
+
|
|
55
|
+
const own = useContainerTransform<T>()
|
|
56
|
+
const ctl = computed(() => props.controller ?? own)
|
|
57
|
+
|
|
58
|
+
const anchor = ref<HTMLElement>()
|
|
59
|
+
const scrimEl = ref<HTMLElement>()
|
|
60
|
+
const clip = ref<HTMLElement>()
|
|
61
|
+
const shadowEl = ref<HTMLElement>()
|
|
62
|
+
const panel = ref<HTMLElement>()
|
|
63
|
+
const mounted = ref(false)
|
|
64
|
+
|
|
65
|
+
const anchorElement = () => (anchor.value?.firstElementChild as HTMLElement | null) ?? null
|
|
66
|
+
const openFromSlot = () => ctl.value.open(anchorElement())
|
|
67
|
+
|
|
68
|
+
let anims: Animation[] = []
|
|
69
|
+
let ghost: HTMLElement | null = null
|
|
70
|
+
let hidden: HTMLElement | null = null
|
|
71
|
+
let returnFocus = false
|
|
72
|
+
|
|
73
|
+
// The element it opens from, cloned into the transition (it stays hidden in the page meanwhile). The clone keeps
|
|
74
|
+
// what it inherited there: text styles and the custom properties (an MScheme's colors, for one)
|
|
75
|
+
function makeGhost(src: HTMLElement, box: Box) {
|
|
76
|
+
const g = src.cloneNode(true) as HTMLElement
|
|
77
|
+
g.removeAttribute('id')
|
|
78
|
+
g.querySelectorAll('[id]').forEach((el) => el.removeAttribute('id'))
|
|
79
|
+
g.setAttribute('aria-hidden', 'true')
|
|
80
|
+
g.inert = true
|
|
81
|
+
const cs = getComputedStyle(src)
|
|
82
|
+
for (let i = 0; i < cs.length; i++) {
|
|
83
|
+
const name = cs[i]!
|
|
84
|
+
if (name.startsWith('--')) g.style.setProperty(name, cs.getPropertyValue(name))
|
|
85
|
+
}
|
|
86
|
+
for (const p of ['color', 'font-family', 'font-size', 'font-weight', 'line-height', 'letter-spacing', 'direction', 'text-align']) {
|
|
87
|
+
g.style.setProperty(p, cs.getPropertyValue(p))
|
|
88
|
+
}
|
|
89
|
+
Object.assign(g.style, {
|
|
90
|
+
position: 'absolute', left: `${box.left}px`, top: `${box.top}px`, width: `${box.width}px`, height: `${box.height}px`,
|
|
91
|
+
margin: '0', boxSizing: 'border-box', transformOrigin: '0 0', pointerEvents: 'none', visibility: 'visible',
|
|
92
|
+
})
|
|
93
|
+
clip.value!.insertBefore(g, panel.value!)
|
|
94
|
+
return g
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function clearRun() {
|
|
98
|
+
for (const a of anims) a.cancel()
|
|
99
|
+
anims = []
|
|
100
|
+
ghost?.remove()
|
|
101
|
+
ghost = null
|
|
102
|
+
if (shadowEl.value) shadowEl.value.style.filter = ''
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The clip would cut the panel's own shadow off until the end, so while it morphs a drop shadow on the layer
|
|
106
|
+
// around it (which follows the clipped shape) stands in for it: elevation 3's two layers, as drop-shadow can't spread
|
|
107
|
+
function shadeTransition() {
|
|
108
|
+
if (!shadowEl.value || !panel.value || getComputedStyle(panel.value).boxShadow === 'none') return
|
|
109
|
+
shadowEl.value.style.filter = 'drop-shadow(0 1px 3px rgb(0 0 0 / 0.3)) drop-shadow(0 4px 8px rgb(0 0 0 / 0.15))'
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function hideSource(src: HTMLElement | null) {
|
|
113
|
+
if (hidden && hidden !== src) hidden.style.visibility = ''
|
|
114
|
+
hidden = src
|
|
115
|
+
if (src) src.style.visibility = 'hidden'
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function opened() {
|
|
119
|
+
clearRun()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function closed() {
|
|
123
|
+
clearRun()
|
|
124
|
+
mounted.value = false
|
|
125
|
+
const src = hidden
|
|
126
|
+
hideSource(null)
|
|
127
|
+
if (returnFocus) src?.focus?.({ preventScroll: true })
|
|
128
|
+
returnFocus = false
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// A box with no size (an element that isn't rendered) can't be scaled from: open or close without the transform
|
|
132
|
+
const sized = (b: Box) => b.width > 0 && b.height > 0
|
|
133
|
+
|
|
134
|
+
// When the running animations end (whichever way they were last turned), settle in the state asked for now. Every
|
|
135
|
+
// waiter on a run calls this; the first one clears the run, so the others find it replaced and do nothing. (Each
|
|
136
|
+
// waiter used to settle in its own direction: closing mid-opening, the opening's waiter could win, jump open and
|
|
137
|
+
// leave the controller closed with the view still on screen.)
|
|
138
|
+
function whenDone(run: Animation[]) {
|
|
139
|
+
Promise.all(run.map((a) => a.finished)).then(() => {
|
|
140
|
+
if (anims !== run) return
|
|
141
|
+
if (ctl.value.isOpen.value) opened()
|
|
142
|
+
else closed()
|
|
143
|
+
}, () => {})
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// Plays the running animations the other way. They hold their last frame meanwhile, so an opening turned into a
|
|
147
|
+
// closing doesn't show the open view for a frame between its end and the layer going away
|
|
148
|
+
function turnAround() {
|
|
149
|
+
for (const a of anims) {
|
|
150
|
+
a.effect?.updateTiming({ fill: 'both' })
|
|
151
|
+
a.reverse()
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// Plays a run, settling when it ends (see whenDone)
|
|
156
|
+
function play(entering: boolean, start: Box, end: Box, startRadius: number, endRadius: number, done: () => void) {
|
|
157
|
+
const frames = containerFrames(start, end, startRadius, endRadius, entering, entering ? OPEN_MS : CLOSE_MS)
|
|
158
|
+
shadeTransition()
|
|
159
|
+
// The views' resting boxes: the clone sits on the element's, the panel on its own
|
|
160
|
+
anims = playContainerFrames(
|
|
161
|
+
frames,
|
|
162
|
+
{ clip: clip.value!, start: entering ? ghost : panel.value!, end: entering ? panel.value! : ghost!, scrim: scrimEl.value },
|
|
163
|
+
window.innerWidth,
|
|
164
|
+
window.innerHeight,
|
|
165
|
+
entering ? undefined : 'forwards',
|
|
166
|
+
)
|
|
167
|
+
if (!anims.length) return done()
|
|
168
|
+
whenDone(anims)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async function show() {
|
|
172
|
+
// Closing: turn around and grow back
|
|
173
|
+
if (anims.length && mounted.value) {
|
|
174
|
+
turnAround()
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
const src = ctl.value.source.value
|
|
178
|
+
mounted.value = true
|
|
179
|
+
await nextTick()
|
|
180
|
+
if (!panel.value || !ctl.value.isOpen.value) return
|
|
181
|
+
returnFocus = true
|
|
182
|
+
panel.value.focus({ preventScroll: true })
|
|
183
|
+
if (!src || !src.isConnected || prefersReducedMotion()) return hideSource(src)
|
|
184
|
+
const start = boxOf(src)
|
|
185
|
+
const end = boxOf(panel.value)
|
|
186
|
+
if (!sized(start) || !sized(end)) return hideSource(src)
|
|
187
|
+
ghost = makeGhost(src, start)
|
|
188
|
+
hideSource(src)
|
|
189
|
+
play(true, start, end, radiusOf(src), radiusOf(panel.value), opened)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function hide() {
|
|
193
|
+
if (!mounted.value) return
|
|
194
|
+
// Opening: turn around and shrink back
|
|
195
|
+
if (anims.length) {
|
|
196
|
+
turnAround()
|
|
197
|
+
return
|
|
198
|
+
}
|
|
199
|
+
const src = hidden
|
|
200
|
+
if (!panel.value || !src || !src.isConnected || prefersReducedMotion()) return closed()
|
|
201
|
+
returnFocus = !!panel.value.contains(document.activeElement) || document.activeElement === document.body
|
|
202
|
+
const start = boxOf(panel.value)
|
|
203
|
+
const end = boxOf(src)
|
|
204
|
+
if (!sized(start) || !sized(end)) return closed()
|
|
205
|
+
ghost = makeGhost(src, end)
|
|
206
|
+
play(false, start, end, radiusOf(panel.value), radiusOf(src), closed)
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// Android's back closes it through a CloseWatcher (the platform's own close request, which also gets Escape where
|
|
210
|
+
// nothing handled it), so the history isn't touched: pushing an entry made a router navigate on every close
|
|
211
|
+
interface CloseWatcherLike { onclose: (() => void) | null; destroy: () => void }
|
|
212
|
+
let closeWatcher: CloseWatcherLike | null = null
|
|
213
|
+
function watchClose() {
|
|
214
|
+
if (!props.closeOnBack || closeWatcher || typeof window === 'undefined') return
|
|
215
|
+
const Watcher = (window as unknown as { CloseWatcher?: new () => CloseWatcherLike }).CloseWatcher
|
|
216
|
+
if (!Watcher) return
|
|
217
|
+
const w = new Watcher()
|
|
218
|
+
w.onclose = () => {
|
|
219
|
+
closeWatcher = null
|
|
220
|
+
ctl.value.close()
|
|
221
|
+
}
|
|
222
|
+
closeWatcher = w
|
|
223
|
+
}
|
|
224
|
+
function unwatchClose() {
|
|
225
|
+
closeWatcher?.destroy()
|
|
226
|
+
closeWatcher = null
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
watch(() => ctl.value.isOpen.value, (open) => {
|
|
230
|
+
if (openModel.value !== open) openModel.value = open
|
|
231
|
+
if (open) {
|
|
232
|
+
watchClose()
|
|
233
|
+
show()
|
|
234
|
+
} else {
|
|
235
|
+
unwatchClose()
|
|
236
|
+
hide()
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
watch(openModel, (open) => {
|
|
240
|
+
if (open === ctl.value.isOpen.value) return
|
|
241
|
+
if (open) ctl.value.open(ctl.value.source.value ?? anchorElement())
|
|
242
|
+
else ctl.value.close()
|
|
243
|
+
}, { immediate: true })
|
|
244
|
+
|
|
245
|
+
useScrollLock(() => mounted.value && props.scrim)
|
|
246
|
+
useEscapeStack(() => mounted.value && ctl.value.isOpen.value, () => ctl.value.close())
|
|
247
|
+
|
|
248
|
+
// Without a scrim the page stays usable: a press outside the expanded view (and the element it came from) closes it
|
|
249
|
+
function onOutside(e: PointerEvent) {
|
|
250
|
+
const target = e.target as Node | null
|
|
251
|
+
if (!target || panel.value?.contains(target) || hidden?.contains(target)) return
|
|
252
|
+
ctl.value.close()
|
|
253
|
+
}
|
|
254
|
+
watch(() => mounted.value && ctl.value.isOpen.value && !props.scrim && !props.persistent, (on) => {
|
|
255
|
+
if (typeof document === 'undefined') return
|
|
256
|
+
if (on) document.addEventListener('pointerdown', onOutside, true)
|
|
257
|
+
else document.removeEventListener('pointerdown', onOutside, true)
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
onBeforeUnmount(() => {
|
|
261
|
+
clearRun()
|
|
262
|
+
hideSource(null)
|
|
263
|
+
unwatchClose()
|
|
264
|
+
if (typeof document !== 'undefined') document.removeEventListener('pointerdown', onOutside, true)
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
const close = () => ctl.value.close()
|
|
268
|
+
const panelStyle = computed(() => (props.mode === 'dialog' ? { width: `min(${props.maxWidth}, calc(100% - 48px))` } : undefined))
|
|
269
|
+
</script>
|
|
270
|
+
|
|
271
|
+
<template>
|
|
272
|
+
<span v-if="$slots.default" ref="anchor" class="contents">
|
|
273
|
+
<slot :open="openFromSlot" :is-open="ctl.isOpen.value" />
|
|
274
|
+
</span>
|
|
275
|
+
<Teleport to="body">
|
|
276
|
+
<div v-if="mounted" class="fixed inset-0 z-50" :class="!scrim && 'pointer-events-none'">
|
|
277
|
+
<div
|
|
278
|
+
v-if="scrim"
|
|
279
|
+
ref="scrimEl"
|
|
280
|
+
class="absolute inset-0 bg-black"
|
|
281
|
+
:style="{ opacity: SCRIM_OPACITY }"
|
|
282
|
+
@click="mode !== 'fullscreen' && !persistent && close()"
|
|
283
|
+
/>
|
|
284
|
+
<!-- The container: its clip morphs between the two boxes during a transition; the views move inside it. The
|
|
285
|
+
layer around it draws the panel's shadow meanwhile -->
|
|
286
|
+
<div ref="shadowEl" class="pointer-events-none absolute inset-0">
|
|
287
|
+
<div ref="clip" class="pointer-events-none absolute inset-0">
|
|
288
|
+
<div
|
|
289
|
+
ref="panel"
|
|
290
|
+
v-bind="$attrs"
|
|
291
|
+
role="dialog"
|
|
292
|
+
:aria-modal="scrim ? 'true' : undefined"
|
|
293
|
+
:aria-label="label"
|
|
294
|
+
tabindex="-1"
|
|
295
|
+
class="m3-ct-panel pointer-events-auto absolute overflow-y-auto outline-none"
|
|
296
|
+
:class="mode === 'dialog' ? 'm3-ct-dialog inset-0 m-auto h-fit max-h-[calc(100%-48px)]' : mode === 'fullscreen' ? 'inset-0' : ''"
|
|
297
|
+
:style="panelStyle"
|
|
298
|
+
style="transform-origin: 0 0"
|
|
299
|
+
>
|
|
300
|
+
<slot name="expanded" :close="close" :item="ctl.item.value" />
|
|
301
|
+
</div>
|
|
302
|
+
</div>
|
|
303
|
+
</div>
|
|
304
|
+
</div>
|
|
305
|
+
</Teleport>
|
|
306
|
+
</template>
|
|
307
|
+
|
|
308
|
+
<style>
|
|
309
|
+
/* The expanded surface's look, in the base layer so the consumer's classes on the component win (see MShape) */
|
|
310
|
+
@layer base {
|
|
311
|
+
.m3-ct-panel {
|
|
312
|
+
background-color: var(--color-surface);
|
|
313
|
+
color: var(--color-on-surface);
|
|
314
|
+
}
|
|
315
|
+
.m3-ct-dialog {
|
|
316
|
+
background-color: var(--color-surface-container-high);
|
|
317
|
+
border-radius: 28px;
|
|
318
|
+
box-shadow: var(--shadow-elevation-3);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
</style>
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
import { computed, Fragment, inject, nextTick, onMounted, onUnmounted, provide, ref, useSlots, watch, type VNode } from 'vue'
|
|
11
11
|
import MIcon from './MIcon.vue'
|
|
12
12
|
import MMenuDivider from './MMenuDivider.vue'
|
|
13
|
+
import { useEscapeStack } from '../composables/_useEscapeStack'
|
|
14
|
+
import { useMenuNav } from '../composables/_useMenuNav'
|
|
13
15
|
import { POPUP_MARGIN, fitPopup } from '../composables/_popupPosition'
|
|
14
16
|
|
|
15
17
|
defineOptions({ inheritAttrs: false })
|
|
@@ -101,41 +103,7 @@ onUnmounted(() => {
|
|
|
101
103
|
const siblingGroup = inject<{ current: (() => void) | null } | null>('m-menu-sibling-group', null)
|
|
102
104
|
provide('m-menu-sibling-group', { current: null })
|
|
103
105
|
|
|
104
|
-
|
|
105
|
-
const navStack = ref<NavEntry[]>([])
|
|
106
|
-
const currentNav = computed(() => navStack.value[navStack.value.length - 1])
|
|
107
|
-
const navDirection = ref<'forward' | 'backward'>('forward')
|
|
108
|
-
|
|
109
|
-
// See MMenu.vue: driven by the Web Animations API rather than Vue's
|
|
110
|
-
// CSS-class transition hooks, which never reliably completed here with
|
|
111
|
-
// dynamic (direction-dependent) enter/leave classes on a mode-less Transition.
|
|
112
|
-
const slideDuration = 220
|
|
113
|
-
function navSlideEnter(el: Element, done: () => void) {
|
|
114
|
-
const dir = navDirection.value === 'forward' ? 1 : -1
|
|
115
|
-
const anim = (el as HTMLElement).animate(
|
|
116
|
-
[
|
|
117
|
-
{ transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
|
|
118
|
-
{ transform: 'translateX(0%)', opacity: 1 },
|
|
119
|
-
],
|
|
120
|
-
{ duration: slideDuration, easing: 'cubic-bezier(0.05,0.7,0.1,1)' },
|
|
121
|
-
)
|
|
122
|
-
anim.onfinish = done
|
|
123
|
-
}
|
|
124
|
-
function navSlideLeave(el: Element, done: () => void) {
|
|
125
|
-
const dir = navDirection.value === 'forward' ? -1 : 1
|
|
126
|
-
const htmlEl = el as HTMLElement
|
|
127
|
-
htmlEl.style.position = 'absolute'
|
|
128
|
-
htmlEl.style.insetInline = '0'
|
|
129
|
-
htmlEl.style.top = '0'
|
|
130
|
-
const anim = htmlEl.animate(
|
|
131
|
-
[
|
|
132
|
-
{ transform: 'translateX(0%)', opacity: 1 },
|
|
133
|
-
{ transform: `translateX(${dir * 100}%)`, opacity: 0.4 },
|
|
134
|
-
],
|
|
135
|
-
{ duration: slideDuration, easing: 'cubic-bezier(0.3,0,0.8,0.15)' },
|
|
136
|
-
)
|
|
137
|
-
anim.onfinish = done
|
|
138
|
-
}
|
|
106
|
+
const { navStack, currentNav, navBox, navSlideEnter, navSlideLeave, pushNav, popNav, onNavPointerDown } = useMenuNav(() => focusableItems()[0]?.focus())
|
|
139
107
|
|
|
140
108
|
// See MMenu.vue: the real Menu.kt animates the panel's scale/alpha with
|
|
141
109
|
// actual springs (StandardMotionTokens: scale dampingRatio 0.9/stiffness
|
|
@@ -244,18 +212,6 @@ function panelLeave(el: Element, done: () => void) {
|
|
|
244
212
|
playTrajectory(el, done, false)
|
|
245
213
|
}
|
|
246
214
|
|
|
247
|
-
function pushNav(entry: NavEntry) {
|
|
248
|
-
navDirection.value = 'forward'
|
|
249
|
-
navStack.value.push(entry)
|
|
250
|
-
nextTick(() => focusableItems()[0]?.focus())
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
function popNav() {
|
|
254
|
-
navDirection.value = 'backward'
|
|
255
|
-
navStack.value.pop()
|
|
256
|
-
nextTick(() => focusableItems()[0]?.focus())
|
|
257
|
-
}
|
|
258
|
-
|
|
259
215
|
async function showAt(x: number, y: number) {
|
|
260
216
|
origin.value = 'left top'
|
|
261
217
|
if (siblingGroup && siblingGroup.current && siblingGroup.current !== hide) {
|
|
@@ -325,12 +281,11 @@ function onDocMouseDown(e: MouseEvent) {
|
|
|
325
281
|
hide()
|
|
326
282
|
}
|
|
327
283
|
|
|
284
|
+
// Escape goes through the library's stack, so a menu open in a dialog or an overlay closes alone (a pushed
|
|
285
|
+
// submenu steps back first)
|
|
286
|
+
useEscapeStack(() => visible.value, () => (navStack.value.length ? popNav() : hide()))
|
|
287
|
+
|
|
328
288
|
function onKeydown(e: KeyboardEvent) {
|
|
329
|
-
if (e.key === 'Escape') {
|
|
330
|
-
if (navStack.value.length) popNav()
|
|
331
|
-
else hide()
|
|
332
|
-
return
|
|
333
|
-
}
|
|
334
289
|
if (!visible.value) return
|
|
335
290
|
if (e.key === 'ArrowDown') { e.preventDefault(); moveFocus(1) }
|
|
336
291
|
else if (e.key === 'ArrowUp') { e.preventDefault(); moveFocus(-1) }
|
|
@@ -380,31 +335,35 @@ onUnmounted(() => {
|
|
|
380
335
|
:style="{ left: `${adjustedPos.x}px`, top: `${adjustedPos.y}px`, transformOrigin: origin, maxWidth: `calc(100vw - ${2 * POPUP_MARGIN}px)` }"
|
|
381
336
|
@contextmenu.prevent
|
|
382
337
|
>
|
|
383
|
-
<!-- overflow
|
|
338
|
+
<!-- The overflow clip (for the rounded corners and to clip the push
|
|
384
339
|
submenu's slide) lives on this inner wrapper, never together with
|
|
385
340
|
shadow-elevation-2 on the same box — overflow-hidden clips an
|
|
386
341
|
element's own box-shadow too, so the two have to be on separate
|
|
387
342
|
elements or the shadow gets cut off -->
|
|
388
|
-
<!-- Scrolls when taller than the window
|
|
343
|
+
<!-- Scrolls when taller than the window. overflow-y is a class, not :style: a :style object sets every key again
|
|
344
|
+
on each patch, which undid the push transition's inline overflow-y: hidden (the scrollbar flashed) -->
|
|
389
345
|
<div
|
|
390
|
-
|
|
391
|
-
|
|
346
|
+
ref="navBox"
|
|
347
|
+
class="relative overflow-x-hidden overflow-y-auto overscroll-contain py-1"
|
|
348
|
+
:style="{ maxHeight: `calc(100vh - ${2 * POPUP_MARGIN}px)`, touchAction: currentNav ? 'pan-y' : undefined }"
|
|
349
|
+
@pointerdown="onNavPointerDown"
|
|
392
350
|
:class="[
|
|
393
351
|
variant === 'expressive' ? 'rounded-lg' : 'rounded-xs',
|
|
394
352
|
isGrouped ? '' : 'bg-surface-container',
|
|
395
353
|
]"
|
|
396
354
|
>
|
|
397
355
|
<Transition :css="false" @enter="navSlideEnter" @leave="navSlideLeave">
|
|
398
|
-
<div v-if="currentNav" :key="navStack.length">
|
|
356
|
+
<div v-if="currentNav" :key="navStack.length" :data-menu-level="navStack.length">
|
|
357
|
+
<!-- Back: a header row in the menu's own item metrics, labelled like an M3 menu group, then a divider -->
|
|
399
358
|
<button
|
|
400
359
|
type="button"
|
|
401
|
-
class="flex w-full items-center gap-3
|
|
360
|
+
class="flex w-full items-center gap-3 px-4 py-2.5 text-left text-label-large text-on-surface-variant outline-none transition-colors hover:bg-on-surface/8 focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-secondary"
|
|
402
361
|
@click="popNav"
|
|
403
362
|
>
|
|
404
|
-
<MIcon name="
|
|
405
|
-
<MIcon v-if="currentNav.icon" :name="currentNav.icon" :size="20" class="shrink-0 text-on-surface-variant" />
|
|
363
|
+
<MIcon name="arrow_back" :size="20" class="shrink-0" />
|
|
406
364
|
<span class="flex-1 truncate"><component :is="() => currentNav?.header?.()" /></span>
|
|
407
365
|
</button>
|
|
366
|
+
<hr class="my-1 border-outline-variant" />
|
|
408
367
|
<component :is="() => currentNav?.content?.()" />
|
|
409
368
|
</div>
|
|
410
369
|
<div v-else key="root">
|
|
@@ -51,7 +51,8 @@ const props = withDefaults(
|
|
|
51
51
|
/**
|
|
52
52
|
* Just the dialog's box (surface, shape, elevation), scrim, Escape, scroll lock and animation, with the default
|
|
53
53
|
* slot filling it: no title row, padding, close button or actions. For dialogs that draw everything themselves
|
|
54
|
-
* (the date and time pickers). `
|
|
54
|
+
* (the date and time pickers). With `fullscreen`, the slot fills the screen and draws its own top bar. `title`
|
|
55
|
+
* then only names it for assistive technology
|
|
55
56
|
*/
|
|
56
57
|
bare?: boolean
|
|
57
58
|
}>(),
|
|
@@ -66,6 +67,9 @@ const props = withDefaults(
|
|
|
66
67
|
},
|
|
67
68
|
)
|
|
68
69
|
|
|
70
|
+
// The root is a Teleport, which can't take the consumer's class/style/attrs: they go on the dialog's surface
|
|
71
|
+
defineOptions({ inheritAttrs: false })
|
|
72
|
+
|
|
69
73
|
const locale = useLocale()
|
|
70
74
|
|
|
71
75
|
// maxWidth/maxHeight take either a Tailwind class or a CSS value: a bare length or a CSS function
|
|
@@ -145,7 +149,8 @@ onUnmounted(() => {
|
|
|
145
149
|
@click.self="close"
|
|
146
150
|
>
|
|
147
151
|
<div
|
|
148
|
-
|
|
152
|
+
v-bind="$attrs"
|
|
153
|
+
class="dialog-box m3-dialog-surface flex min-w-[280px] w-full flex-col"
|
|
149
154
|
:class="sizeClasses"
|
|
150
155
|
:style="sizeStyle"
|
|
151
156
|
role="dialog"
|
|
@@ -226,12 +231,18 @@ onUnmounted(() => {
|
|
|
226
231
|
<Transition v-else name="m3-dialog-fs" appear>
|
|
227
232
|
<div
|
|
228
233
|
v-if="modelValue"
|
|
229
|
-
|
|
234
|
+
v-bind="$attrs"
|
|
235
|
+
class="dialog-fs m3-dialog-fs-surface fixed inset-0 z-50 flex flex-col"
|
|
230
236
|
role="dialog"
|
|
231
237
|
aria-modal="true"
|
|
232
|
-
:aria-labelledby="$slots.title || title ? titleId : undefined"
|
|
238
|
+
:aria-labelledby="!bare && ($slots.title || title) ? titleId : undefined"
|
|
239
|
+
:aria-label="bare ? title : undefined"
|
|
233
240
|
>
|
|
234
|
-
|
|
241
|
+
<!-- Bare: the content is the whole screen, top bar included, in whatever colors it draws -->
|
|
242
|
+
<div v-if="bare" class="min-h-0 flex-1 overflow-y-auto">
|
|
243
|
+
<slot />
|
|
244
|
+
</div>
|
|
245
|
+
<div v-else class="flex h-14 shrink-0 items-center gap-2 px-2">
|
|
235
246
|
<MIconButton v-if="!persistent" icon="close" :label="closeLabel ?? locale.close" @click="close" />
|
|
236
247
|
<h2 :id="titleId" class="flex-1 text-title-large font-medium text-on-surface">
|
|
237
248
|
<slot name="title">{{ title }}</slot>
|
|
@@ -240,7 +251,7 @@ onUnmounted(() => {
|
|
|
240
251
|
<slot name="actions" />
|
|
241
252
|
</div>
|
|
242
253
|
</div>
|
|
243
|
-
<div class="flex-1 overflow-y-auto px-6 py-4 text-body-medium text-on-surface-variant">
|
|
254
|
+
<div v-if="!bare" class="flex-1 overflow-y-auto px-6 py-4 text-body-medium text-on-surface-variant">
|
|
244
255
|
<slot />
|
|
245
256
|
</div>
|
|
246
257
|
</div>
|
|
@@ -279,3 +290,17 @@ onUnmounted(() => {
|
|
|
279
290
|
opacity: 0;
|
|
280
291
|
}
|
|
281
292
|
</style>
|
|
293
|
+
|
|
294
|
+
<style>
|
|
295
|
+
/* The surfaces' look, in the base layer so the consumer's classes on MDialog win (see MShape) */
|
|
296
|
+
@layer base {
|
|
297
|
+
.m3-dialog-surface {
|
|
298
|
+
background-color: var(--color-surface-container-high);
|
|
299
|
+
border-radius: var(--radius-xl);
|
|
300
|
+
box-shadow: var(--shadow-elevation-3);
|
|
301
|
+
}
|
|
302
|
+
.m3-dialog-fs-surface {
|
|
303
|
+
background-color: var(--color-surface);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
</style>
|
|
@@ -397,7 +397,9 @@ function onKeydown(e: KeyboardEvent, index: number) {
|
|
|
397
397
|
commit(index, to)
|
|
398
398
|
say(t.reorderMoved, to)
|
|
399
399
|
} else if (grabbed && e.key === 'Escape') {
|
|
400
|
+
// Cancelling the move uses the key: a dialog around the list stays open
|
|
400
401
|
e.preventDefault()
|
|
402
|
+
e.stopPropagation()
|
|
401
403
|
cancelKeyboard(index)
|
|
402
404
|
}
|
|
403
405
|
}
|
package/src/components/MFab.vue
CHANGED
|
@@ -99,7 +99,10 @@ const isExpandable = computed(() => hasItems.value || hasContent.value)
|
|
|
99
99
|
|
|
100
100
|
// Inside an MBottomAppBar: secondary and flat (bottomAppBarFabColor, bottomAppBarFabElevation)
|
|
101
101
|
const inBottomAppBar = inject('m-bottom-app-bar', false)
|
|
102
|
-
|
|
102
|
+
// In MToolbar's #fab slot: the toolbar sizes it (56 → 80px as it collapses), with the floating toolbar FAB's color
|
|
103
|
+
// and elevation (FloatingToolbarDefaults.StandardFloatingActionButton / VibrantFloatingActionButton)
|
|
104
|
+
const inToolbar = inject<{ color: 'primary' | 'tertiary' } | null>('m-toolbar-fab', null)
|
|
105
|
+
const color = computed(() => props.color ?? inToolbar?.color ?? (inBottomAppBar ? 'secondary' : 'primary'))
|
|
103
106
|
|
|
104
107
|
const colorMap: Record<string, string> = {
|
|
105
108
|
primary: 'bg-primary-container text-on-primary-container',
|
|
@@ -119,10 +122,12 @@ const EXTENDED = {
|
|
|
119
122
|
medium: { px: 80, icon: 28, lead: 26, gap: 'pl-3', box: 'h-20 min-w-20 rounded-lg-increased px-[26px]', text: 'text-title-large' },
|
|
120
123
|
large: { px: 96, icon: 32, lead: 28, gap: 'pl-4', box: 'h-24 min-w-24 rounded-xl px-7', text: 'text-headline-small' },
|
|
121
124
|
} as const
|
|
122
|
-
|
|
125
|
+
// In a toolbar the FAB is always the square one: its label only names it
|
|
126
|
+
const extended = computed(() => (props.label && !inToolbar ? EXTENDED[props.size] : null))
|
|
123
127
|
|
|
124
128
|
const fabSizeClasses = computed(() => {
|
|
125
129
|
if (extended.value) return extended.value.box
|
|
130
|
+
if (inToolbar) return 'h-full w-full rounded-2xl'
|
|
126
131
|
switch (props.size) {
|
|
127
132
|
case 'small': return 'h-10 w-10 rounded-md'
|
|
128
133
|
case 'medium': return 'h-20 w-20 rounded-lg-increased'
|
|
@@ -359,16 +364,16 @@ onUnmounted(() => {
|
|
|
359
364
|
</script>
|
|
360
365
|
|
|
361
366
|
<template>
|
|
362
|
-
<div ref="fabEl" v-bind="$attrs" class="relative inline-flex items-center justify-center">
|
|
367
|
+
<div ref="fabEl" v-bind="$attrs" class="relative inline-flex items-center justify-center" :class="inToolbar && !extended && 'h-full w-full'">
|
|
363
368
|
<component
|
|
364
369
|
:is="fabTag"
|
|
365
370
|
ref="fabButton"
|
|
366
371
|
:to="to || undefined"
|
|
367
372
|
:type="to ? undefined : 'button'"
|
|
368
373
|
class="relative inline-flex cursor-pointer items-center overflow-hidden transition-shadow duration-150 disabled:cursor-not-allowed disabled:opacity-[0.38] before:content-[''] before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:duration-150 hover:before:opacity-[0.08] active:before:opacity-[0.12]"
|
|
369
|
-
:class="[colorMap[color], fabSizeClasses, extended ? 'justify-start' : 'justify-center', inBottomAppBar ? '' : 'shadow-elevation-3 hover:shadow-elevation-4 active:shadow-elevation-3']"
|
|
374
|
+
:class="[colorMap[color], fabSizeClasses, extended ? 'justify-start' : 'justify-center', inBottomAppBar ? '' : inToolbar ? 'shadow-elevation-2 hover:shadow-elevation-3 active:shadow-elevation-2' : 'shadow-elevation-3 hover:shadow-elevation-4 active:shadow-elevation-3']"
|
|
370
375
|
:disabled="disabled"
|
|
371
|
-
:aria-label="label && !expanded ? label : undefined"
|
|
376
|
+
:aria-label="label && (!extended || !expanded) ? label : undefined"
|
|
372
377
|
:style="initialButtonStyle"
|
|
373
378
|
v-ripple="{ disabled, color: rippleColor }"
|
|
374
379
|
@click="handleFabClick"
|
|
@@ -18,6 +18,18 @@ const props = withDefaults(
|
|
|
18
18
|
label?: string
|
|
19
19
|
/** Visual style */
|
|
20
20
|
variant?: 'standard' | 'filled' | 'tonal' | 'outlined'
|
|
21
|
+
/**
|
|
22
|
+
* An M3 role or any CSS color (`#fff` over a photo, `rgb(0 0 0 / 0.3)` for a scrim-like filled button,
|
|
23
|
+
* `currentColor` to follow the surrounding text). Standard and outlined use it for the icon; filled for the
|
|
24
|
+
* container with white (or the role's on-color) on it; tonal for a 20% container with the color on it.
|
|
25
|
+
* Disabled buttons and toggles keep their own colors
|
|
26
|
+
*/
|
|
27
|
+
color?: 'primary' | 'secondary' | 'tertiary' | 'error' | (string & {})
|
|
28
|
+
/**
|
|
29
|
+
* Icon color over what the variant and `color` give: an M3 role (`on-surface`…) or any CSS color (`#000` on a
|
|
30
|
+
* white filled button). Disabled buttons and toggles keep their own
|
|
31
|
+
*/
|
|
32
|
+
contentColor?: string
|
|
21
33
|
/**
|
|
22
34
|
* Button shape — rounded (pill, always) or squared (corner radius scales with size: 12px xs/sm, 16px md,
|
|
23
35
|
* 28px lg/xl)
|
|
@@ -38,6 +50,8 @@ const props = withDefaults(
|
|
|
38
50
|
checked?: boolean
|
|
39
51
|
/** Icon shown while checked, when it differs from `icon` (e.g. 'pause' for 'play_arrow') */
|
|
40
52
|
checkedIcon?: string
|
|
53
|
+
/** Draw the icon filled (Material Symbols' FILL axis) without making it a toggle, e.g. media controls */
|
|
54
|
+
iconFilled?: boolean
|
|
41
55
|
}>(),
|
|
42
56
|
{
|
|
43
57
|
variant: 'standard',
|
|
@@ -51,6 +65,33 @@ const props = withDefaults(
|
|
|
51
65
|
const emit = defineEmits<{ 'update:checked': [boolean] }>()
|
|
52
66
|
|
|
53
67
|
const isToggle = computed(() => props.checked !== undefined)
|
|
68
|
+
|
|
69
|
+
const ROLES = ['primary', 'secondary', 'tertiary', 'error']
|
|
70
|
+
// Color-role names (`on-surface`…) read the theme's token; anything else is a CSS color
|
|
71
|
+
const ROLE = /^(on-)?(primary|secondary|tertiary|error|surface|surface-variant|inverse-surface|inverse-primary)(-container|-variant)?$/
|
|
72
|
+
const colorStyle = computed(() => {
|
|
73
|
+
const base = paintStyle()
|
|
74
|
+
const cc = props.contentColor
|
|
75
|
+
if (!cc || props.disabled || isToggle.value) return base
|
|
76
|
+
return { ...base, color: ROLE.test(cc) ? `var(--color-${cc})` : cc }
|
|
77
|
+
})
|
|
78
|
+
// `color` as inline styles over the variant's classes, so the default look stays class-only
|
|
79
|
+
function paintStyle() {
|
|
80
|
+
const c = props.color
|
|
81
|
+
if (!c || props.disabled || isToggle.value) return undefined
|
|
82
|
+
const role = ROLES.includes(c)
|
|
83
|
+
const main = role ? `var(--color-${c})` : c
|
|
84
|
+
switch (props.variant) {
|
|
85
|
+
case 'filled':
|
|
86
|
+
return { backgroundColor: main, color: role ? `var(--color-on-${c})` : '#fff' }
|
|
87
|
+
case 'tonal':
|
|
88
|
+
return role
|
|
89
|
+
? { backgroundColor: `var(--color-${c}-container)`, color: `var(--color-on-${c}-container)` }
|
|
90
|
+
: { backgroundColor: `color-mix(in srgb, ${c} 20%, transparent)`, color: c }
|
|
91
|
+
default:
|
|
92
|
+
return { color: main }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
54
95
|
const tag = computed(() => props.to && !isToggle.value ? 'RouterLink' : 'button')
|
|
55
96
|
|
|
56
97
|
// Container height/width (icon buttons are always square by default — real
|
|
@@ -191,7 +232,7 @@ const variantClasses = computed(() => {
|
|
|
191
232
|
:aria-pressed="isToggle ? checked : undefined"
|
|
192
233
|
:disabled="disabled"
|
|
193
234
|
:class="[base, shapeClass, variantClasses, disabledContainerClasses]"
|
|
194
|
-
:style="{ width: `${resolved.px}px`, height: `${resolved.px}px` }"
|
|
235
|
+
:style="[{ width: `${resolved.px}px`, height: `${resolved.px}px` }, colorStyle]"
|
|
195
236
|
v-ripple="{ disabled, color: rippleColor }"
|
|
196
237
|
@pointerdown="onPointerDown"
|
|
197
238
|
@pointerup="onPointerUp"
|
|
@@ -199,6 +240,6 @@ const variantClasses = computed(() => {
|
|
|
199
240
|
@pointercancel="onPointerUp"
|
|
200
241
|
@click="onClick"
|
|
201
242
|
>
|
|
202
|
-
<MIcon :name="checked && checkedIcon ? checkedIcon : icon" :size="resolved.icon" :filled="!!checked" />
|
|
243
|
+
<MIcon :name="checked && checkedIcon ? checkedIcon : icon" :size="resolved.icon" :filled="!!checked || iconFilled" />
|
|
203
244
|
</component>
|
|
204
245
|
</template>
|