@m3ui-vue/m3ui-vue 0.8.6 → 0.8.8
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 +4 -0
- package/dist/{MMenuItem-BmPLAyv5.js → MMenuItem-5xojJYAL.js} +2 -2
- package/dist/{MMenuItem-BmPLAyv5.js.map → MMenuItem-5xojJYAL.js.map} +1 -1
- package/dist/chart.js +5 -1
- package/dist/chart.js.map +1 -1
- package/dist/code-editor.js +1 -1
- package/dist/components/MBottomSheet.vue.d.ts +3 -3
- package/dist/components/MListDetail.vue.d.ts +31 -0
- package/dist/components/MNavigationRail.vue.d.ts +6 -3
- package/dist/components/MNavigationSuite.vue.d.ts +46 -0
- package/dist/components/MShortNavigationBar.vue.d.ts +6 -1
- package/dist/components/MSideSheet.vue.d.ts +4 -4
- package/dist/components/MSupportingPane.vue.d.ts +34 -0
- package/dist/components/MTransferList.vue.d.ts +55 -34
- package/dist/components/MWindow.vue.d.ts +39 -1
- package/dist/components/_MTransferPane.vue.d.ts +10 -3
- package/dist/composables/_useItemLink.d.ts +30 -0
- package/dist/composables/_useSheetMotion.d.ts +7 -0
- package/dist/composables/useLocale.d.ts +7 -0
- package/dist/composables/useWindowSizeClass.d.ts +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/locales/index.js +56 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +2399 -1899
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-4afAzuuP.js → useLocale-D3ZWZ8jY.js} +9 -2
- package/dist/useLocale-D3ZWZ8jY.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MChart.test.ts +28 -0
- package/src/__tests__/MPagination.test.ts +37 -0
- package/src/__tests__/MPullToRefresh.test.ts +39 -0
- package/src/__tests__/MShortNavigationBar.test.ts +25 -0
- package/src/__tests__/MTransferList.test.ts +73 -0
- package/src/__tests__/MWindow.test.ts +258 -0
- package/src/__tests__/adaptiveLayouts.test.ts +191 -0
- package/src/__tests__/sheets.test.ts +76 -0
- package/src/components/MBottomSheet.vue +11 -57
- package/src/components/MChart.vue +2 -1
- package/src/components/MListDetail.vue +103 -0
- package/src/components/MNavigationRail.vue +18 -10
- package/src/components/MNavigationSuite.vue +89 -0
- package/src/components/MPagination.vue +8 -5
- package/src/components/MPullToRefresh.vue +13 -1
- package/src/components/MShortNavigationBar.vue +37 -17
- package/src/components/MSideSheet.vue +11 -56
- package/src/components/MSupportingPane.vue +70 -0
- package/src/components/MTransferList.vue +43 -9
- package/src/components/MWindow.vue +507 -108
- package/src/components/_MTransferPane.vue +113 -35
- package/src/composables/_useItemLink.ts +19 -0
- package/src/composables/_useSheetMotion.ts +181 -0
- package/src/composables/useLocale.ts +17 -0
- package/src/composables/useWindowSizeClass.ts +93 -0
- package/src/index.ts +6 -0
- package/src/locales/de.ts +8 -0
- package/src/locales/es.ts +8 -0
- package/src/locales/fr.ts +8 -0
- package/src/locales/ja.ts +8 -0
- package/src/locales/ko.ts +8 -0
- package/src/locales/pt.ts +8 -0
- package/src/locales/zh.ts +8 -0
- package/dist/useLocale-4afAzuuP.js.map +0 -1
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import { useWindowSizeClass } from '../composables/useWindowSizeClass'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* M3 list-detail canonical layout, after androidx ListDetailPaneScaffold +
|
|
7
|
+
* calculatePaneScaffoldDirective: from the expanded width class (840px) up, list and detail
|
|
8
|
+
* sit side by side with a 24dp spacer and the list at its preferred width (360dp, 412dp from
|
|
9
|
+
* large); below that only one pane shows, the detail when it's the current destination
|
|
10
|
+
* (`showDetail`), the list otherwise. Measured on the component itself, not the window.
|
|
11
|
+
*/
|
|
12
|
+
const props = withDefaults(defineProps<{
|
|
13
|
+
/** Whether the detail is the current destination. One-pane layouts show it instead of the list. */
|
|
14
|
+
showDetail?: boolean
|
|
15
|
+
/** List pane width in the two-pane layout. Defaults to M3's 360px (412px from the large width class). */
|
|
16
|
+
listWidth?: string
|
|
17
|
+
}>(), { showDetail: false })
|
|
18
|
+
|
|
19
|
+
const emit = defineEmits<{ 'update:showDetail': [boolean] }>()
|
|
20
|
+
|
|
21
|
+
defineSlots<{
|
|
22
|
+
list?: (props: { twoPane: boolean }) => unknown
|
|
23
|
+
/** `back()` returns to the list (sets `showDetail` to false). */
|
|
24
|
+
detail?: (props: { twoPane: boolean; back: () => void }) => unknown
|
|
25
|
+
}>()
|
|
26
|
+
|
|
27
|
+
const root = ref<HTMLElement>()
|
|
28
|
+
const { widthClass } = useWindowSizeClass(root)
|
|
29
|
+
const twoPane = computed(() => widthClass.value !== 'compact' && widthClass.value !== 'medium')
|
|
30
|
+
const width = computed(() =>
|
|
31
|
+
props.listWidth ?? (widthClass.value === 'large' || widthClass.value === 'extra-large' ? '412px' : '360px'),
|
|
32
|
+
)
|
|
33
|
+
const back = () => emit('update:showDetail', false)
|
|
34
|
+
|
|
35
|
+
// One pane: both stay mounted (the list keeps its scroll position and the detail its state),
|
|
36
|
+
// the hidden one is moved aside, made invisible and `inert`.
|
|
37
|
+
const listHidden = computed(() => !twoPane.value && props.showDetail)
|
|
38
|
+
const detailHidden = computed(() => !twoPane.value && !props.showDetail)
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<div ref="root" class="relative flex overflow-hidden" :class="twoPane ? 'gap-6' : ''">
|
|
43
|
+
<!-- No default size: give it a height so each pane scrolls on its own. -->
|
|
44
|
+
<div
|
|
45
|
+
class="min-h-0 overflow-auto"
|
|
46
|
+
:class="twoPane ? 'shrink-0' : ['m3-ld-pane absolute inset-0', listHidden && 'm3-ld-list-hidden']"
|
|
47
|
+
:style="twoPane ? { width } : undefined"
|
|
48
|
+
:inert="listHidden || undefined"
|
|
49
|
+
:aria-hidden="listHidden || undefined"
|
|
50
|
+
>
|
|
51
|
+
<slot name="list" :two-pane="twoPane" />
|
|
52
|
+
</div>
|
|
53
|
+
<div
|
|
54
|
+
class="min-h-0 min-w-0 flex-1 overflow-auto"
|
|
55
|
+
:class="twoPane ? '' : ['m3-ld-pane absolute inset-0', detailHidden && 'm3-ld-detail-hidden']"
|
|
56
|
+
:inert="detailHidden || undefined"
|
|
57
|
+
:aria-hidden="detailHidden || undefined"
|
|
58
|
+
>
|
|
59
|
+
<slot name="detail" :two-pane="twoPane" :back="back" />
|
|
60
|
+
</div>
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
63
|
+
|
|
64
|
+
<style scoped>
|
|
65
|
+
/* Visibility flips at the end of a hide (and at the start of a show) so the pane fades out first. */
|
|
66
|
+
.m3-ld-pane {
|
|
67
|
+
transition:
|
|
68
|
+
transform 0.4s cubic-bezier(0.2, 0, 0, 1),
|
|
69
|
+
opacity 0.2s linear,
|
|
70
|
+
visibility 0s;
|
|
71
|
+
}
|
|
72
|
+
.m3-ld-list-hidden {
|
|
73
|
+
transform: translateX(-12%);
|
|
74
|
+
opacity: 0;
|
|
75
|
+
visibility: hidden;
|
|
76
|
+
transition:
|
|
77
|
+
transform 0.4s cubic-bezier(0.2, 0, 0, 1),
|
|
78
|
+
opacity 0.2s linear,
|
|
79
|
+
visibility 0s 0.4s;
|
|
80
|
+
}
|
|
81
|
+
.m3-ld-detail-hidden {
|
|
82
|
+
transform: translateX(100%);
|
|
83
|
+
opacity: 0;
|
|
84
|
+
visibility: hidden;
|
|
85
|
+
transition:
|
|
86
|
+
transform 0.4s cubic-bezier(0.2, 0, 0, 1),
|
|
87
|
+
opacity 0.2s linear 0.2s,
|
|
88
|
+
visibility 0s 0.4s;
|
|
89
|
+
}
|
|
90
|
+
:global([dir='rtl']) .m3-ld-list-hidden {
|
|
91
|
+
transform: translateX(12%);
|
|
92
|
+
}
|
|
93
|
+
:global([dir='rtl']) .m3-ld-detail-hidden {
|
|
94
|
+
transform: translateX(-100%);
|
|
95
|
+
}
|
|
96
|
+
@media (prefers-reduced-motion: reduce) {
|
|
97
|
+
.m3-ld-pane,
|
|
98
|
+
.m3-ld-list-hidden,
|
|
99
|
+
.m3-ld-detail-hidden {
|
|
100
|
+
transition: visibility 0s;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
</style>
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { computed, ref, watch, onUnmounted } from 'vue'
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
4
|
import MBadge from './MBadge.vue'
|
|
5
|
+
import { useItemLink, type ItemLink } from '../composables/_useItemLink'
|
|
5
6
|
|
|
6
7
|
export interface NavRailItem {
|
|
7
8
|
value: string | number
|
|
@@ -10,6 +11,8 @@ export interface NavRailItem {
|
|
|
10
11
|
badge?: number
|
|
11
12
|
badgeDot?: boolean
|
|
12
13
|
disabled?: boolean
|
|
14
|
+
/** Makes the item a link: a vue-router location (rendered as RouterLink), or a URL without vue-router. */
|
|
15
|
+
to?: ItemLink
|
|
13
16
|
}
|
|
14
17
|
|
|
15
18
|
const props = withDefaults(defineProps<{
|
|
@@ -47,6 +50,8 @@ const railExpanded = computed(() => !props.modal && props.expanded)
|
|
|
47
50
|
* collapsed -> expanded change to animate, running alongside (not instead of) the panel's
|
|
48
51
|
* own width spring.
|
|
49
52
|
*/
|
|
53
|
+
const itemLink = useItemLink()
|
|
54
|
+
|
|
50
55
|
const panelExpanded = ref(false)
|
|
51
56
|
|
|
52
57
|
function close() {
|
|
@@ -177,9 +182,12 @@ onUnmounted(() => {
|
|
|
177
182
|
would re-center against the *header's own* width, which changes a lot between collapsed
|
|
178
183
|
(80px rail) and expanded (220px rail), making the button visibly jump sideways when toggling.
|
|
179
184
|
A fixed-width box pinned to the same left inset as the items below stays put regardless.
|
|
185
|
+
The box is a *minimum* (40×56, an icon button or small FAB): a regular FAB (56dp) or an
|
|
186
|
+
extended one in the expanded rail grows it instead of overflowing it, which used to push
|
|
187
|
+
the FAB past the rail's top and left edges.
|
|
180
188
|
-->
|
|
181
189
|
<div v-if="$slots.fab" class="flex shrink-0 flex-col items-start gap-2 px-3 pt-3 pb-2">
|
|
182
|
-
<div class="flex h-10 w-14 shrink-0 items-center justify-center">
|
|
190
|
+
<div class="flex min-h-10 min-w-14 shrink-0 items-center justify-center">
|
|
183
191
|
<slot name="fab" />
|
|
184
192
|
</div>
|
|
185
193
|
</div>
|
|
@@ -193,13 +201,13 @@ onUnmounted(() => {
|
|
|
193
201
|
'justify-end': alignment === 'bottom',
|
|
194
202
|
}"
|
|
195
203
|
>
|
|
196
|
-
<
|
|
204
|
+
<component
|
|
205
|
+
:is="itemLink(item).tag"
|
|
197
206
|
v-for="item in items"
|
|
198
207
|
:key="item.value"
|
|
199
|
-
|
|
208
|
+
v-bind="itemLink(item).attrs"
|
|
200
209
|
class="group relative block h-16 w-full cursor-pointer focus-visible:outline-none"
|
|
201
210
|
:class="item.disabled ? 'cursor-not-allowed opacity-[0.38]' : ''"
|
|
202
|
-
:disabled="item.disabled"
|
|
203
211
|
@click="!item.disabled && $emit('update:modelValue', item.value)"
|
|
204
212
|
>
|
|
205
213
|
<!--
|
|
@@ -289,7 +297,7 @@ onUnmounted(() => {
|
|
|
289
297
|
>
|
|
290
298
|
{{ item.label }}
|
|
291
299
|
</span>
|
|
292
|
-
</
|
|
300
|
+
</component>
|
|
293
301
|
</div>
|
|
294
302
|
</nav>
|
|
295
303
|
|
|
@@ -314,7 +322,7 @@ onUnmounted(() => {
|
|
|
314
322
|
class="wnr-panel fixed inset-y-0 left-0 z-10 flex flex-col overflow-hidden rounded-r-lg bg-surface-container shadow-elevation-2"
|
|
315
323
|
>
|
|
316
324
|
<div v-if="$slots.fab" class="flex shrink-0 flex-col items-start gap-2 px-3 pt-3 pb-2">
|
|
317
|
-
<div class="flex h-10 w-14 shrink-0 items-center justify-center">
|
|
325
|
+
<div class="flex min-h-10 min-w-14 shrink-0 items-center justify-center">
|
|
318
326
|
<slot name="fab" />
|
|
319
327
|
</div>
|
|
320
328
|
</div>
|
|
@@ -334,13 +342,13 @@ onUnmounted(() => {
|
|
|
334
342
|
can't just bind to `expanded` directly. Keep any pill/label fix in sync
|
|
335
343
|
between the two copies.
|
|
336
344
|
-->
|
|
337
|
-
<
|
|
345
|
+
<component
|
|
346
|
+
:is="itemLink(item).tag"
|
|
338
347
|
v-for="item in items"
|
|
339
348
|
:key="item.value"
|
|
340
|
-
|
|
349
|
+
v-bind="itemLink(item).attrs"
|
|
341
350
|
class="group relative block h-16 w-full shrink-0 cursor-pointer focus-visible:outline-none"
|
|
342
351
|
:class="item.disabled ? 'cursor-not-allowed opacity-[0.38]' : ''"
|
|
343
|
-
:disabled="item.disabled"
|
|
344
352
|
@click="selectModal(item)"
|
|
345
353
|
>
|
|
346
354
|
<span
|
|
@@ -383,7 +391,7 @@ onUnmounted(() => {
|
|
|
383
391
|
>
|
|
384
392
|
{{ item.label }}
|
|
385
393
|
</span>
|
|
386
|
-
</
|
|
394
|
+
</component>
|
|
387
395
|
</div>
|
|
388
396
|
</nav>
|
|
389
397
|
</div>
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref } from 'vue'
|
|
3
|
+
import MNavigationRail from './MNavigationRail.vue'
|
|
4
|
+
import MShortNavigationBar from './MShortNavigationBar.vue'
|
|
5
|
+
import { useWindowSizeClass } from '../composables/useWindowSizeClass'
|
|
6
|
+
import type { ItemLink } from '../composables/_useItemLink'
|
|
7
|
+
|
|
8
|
+
export interface NavigationSuiteItem {
|
|
9
|
+
value: string | number
|
|
10
|
+
label: string
|
|
11
|
+
icon: string
|
|
12
|
+
badge?: number
|
|
13
|
+
badgeDot?: boolean
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
/** Makes the item a link: a vue-router location (rendered as RouterLink), or a URL without vue-router. */
|
|
16
|
+
to?: ItemLink
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The navigation component in use: a short bar (icons over labels, or beside them), or a rail. */
|
|
20
|
+
export type NavigationSuiteLayout = 'bar' | 'bar-medium' | 'rail' | 'rail-expanded' | 'none'
|
|
21
|
+
|
|
22
|
+
const props = withDefaults(defineProps<{
|
|
23
|
+
modelValue: string | number
|
|
24
|
+
items: NavigationSuiteItem[]
|
|
25
|
+
/**
|
|
26
|
+
* 'auto' picks by the component's own size, as M3's NavigationSuiteScaffold does
|
|
27
|
+
* (`navigationSuiteType`): compact width → short bar; compact height (a phone in landscape)
|
|
28
|
+
* → short bar with icons beside labels; anything else → collapsed rail. Set it to force one.
|
|
29
|
+
*/
|
|
30
|
+
layout?: 'auto' | NavigationSuiteLayout
|
|
31
|
+
}>(), { layout: 'auto' })
|
|
32
|
+
|
|
33
|
+
defineEmits<{ 'update:modelValue': [string | number] }>()
|
|
34
|
+
|
|
35
|
+
defineSlots<{
|
|
36
|
+
/** The app's content. Scrolls on its own, next to or above the navigation. */
|
|
37
|
+
default?: (props: { layout: NavigationSuiteLayout }) => unknown
|
|
38
|
+
/** Primary action (e.g. a FAB): the rail's header, or floating above the bar at the bottom end. */
|
|
39
|
+
fab?: () => unknown
|
|
40
|
+
}>()
|
|
41
|
+
|
|
42
|
+
const root = ref<HTMLElement>()
|
|
43
|
+
const { widthClass, heightClass } = useWindowSizeClass(root)
|
|
44
|
+
|
|
45
|
+
const resolved = computed<NavigationSuiteLayout>(() => {
|
|
46
|
+
if (props.layout !== 'auto') return props.layout
|
|
47
|
+
if (widthClass.value === 'compact') return 'bar'
|
|
48
|
+
if (heightClass.value === 'compact') return 'bar-medium'
|
|
49
|
+
return 'rail'
|
|
50
|
+
})
|
|
51
|
+
const isRail = computed(() => resolved.value === 'rail' || resolved.value === 'rail-expanded')
|
|
52
|
+
const isBar = computed(() => resolved.value === 'bar' || resolved.value === 'bar-medium')
|
|
53
|
+
</script>
|
|
54
|
+
|
|
55
|
+
<template>
|
|
56
|
+
<div ref="root" class="flex overflow-hidden bg-surface" :class="isBar ? 'flex-col' : 'flex-row'">
|
|
57
|
+
<!-- No default size: give it the app's height (e.g. h-dvh) so the bar sits at the bottom. -->
|
|
58
|
+
<MNavigationRail
|
|
59
|
+
v-if="isRail"
|
|
60
|
+
:model-value="modelValue"
|
|
61
|
+
:items="items"
|
|
62
|
+
:expanded="resolved === 'rail-expanded'"
|
|
63
|
+
class="shrink-0"
|
|
64
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
65
|
+
>
|
|
66
|
+
<template v-if="$slots.fab" #fab><slot name="fab" /></template>
|
|
67
|
+
</MNavigationRail>
|
|
68
|
+
|
|
69
|
+
<!-- Same element in every layout, so the content keeps its state when the navigation swaps. -->
|
|
70
|
+
<div class="relative flex min-h-0 min-w-0 flex-1 flex-col">
|
|
71
|
+
<div class="min-h-0 flex-1 overflow-auto">
|
|
72
|
+
<slot :layout="resolved" />
|
|
73
|
+
</div>
|
|
74
|
+
<div v-if="!isRail && $slots.fab" class="absolute right-4 bottom-4">
|
|
75
|
+
<slot name="fab" />
|
|
76
|
+
</div>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
<MShortNavigationBar
|
|
80
|
+
v-if="isBar"
|
|
81
|
+
:model-value="modelValue"
|
|
82
|
+
:items="items"
|
|
83
|
+
:arrangement="resolved === 'bar-medium' ? 'centered' : 'equal'"
|
|
84
|
+
:icon-position="resolved === 'bar-medium' ? 'start' : 'top'"
|
|
85
|
+
class="shrink-0"
|
|
86
|
+
@update:model-value="$emit('update:modelValue', $event)"
|
|
87
|
+
/>
|
|
88
|
+
</div>
|
|
89
|
+
</template>
|
|
@@ -1,34 +1,37 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed } from 'vue'
|
|
3
3
|
import MIconButton from './MIconButton.vue'
|
|
4
|
+
import { useLocale } from '../composables/useLocale'
|
|
4
5
|
|
|
5
6
|
const props = defineProps<{ page: number; perPage: number; total: number }>()
|
|
6
7
|
const emit = defineEmits<{ 'update:page': [number] }>()
|
|
8
|
+
const t = useLocale()
|
|
7
9
|
|
|
8
10
|
const totalPages = computed(() => Math.max(1, Math.ceil(props.total / props.perPage)))
|
|
9
11
|
|
|
10
12
|
const rangeLabel = computed(() => {
|
|
11
|
-
if (props.total === 0) return
|
|
13
|
+
if (props.total === 0) return t.noResults
|
|
12
14
|
const from = (props.page - 1) * props.perPage + 1
|
|
13
15
|
const to = Math.min(props.page * props.perPage, props.total)
|
|
14
|
-
return
|
|
16
|
+
return t.paginationRange.replace('{from}', String(from)).replace('{to}', String(to)).replace('{total}', String(props.total))
|
|
15
17
|
})
|
|
18
|
+
const pageLabel = computed(() => t.paginationPage.replace('{page}', String(props.page)).replace('{pages}', String(totalPages.value)))
|
|
16
19
|
</script>
|
|
17
20
|
|
|
18
21
|
<template>
|
|
19
22
|
<div class="flex flex-wrap items-center justify-between gap-4 text-body-medium text-on-surface-variant">
|
|
20
23
|
<span>{{ rangeLabel }}</span>
|
|
21
24
|
<div class="flex items-center gap-2">
|
|
22
|
-
<span>
|
|
25
|
+
<span>{{ pageLabel }}</span>
|
|
23
26
|
<MIconButton
|
|
24
27
|
icon="chevron_left"
|
|
25
|
-
label="
|
|
28
|
+
:label="t.previousPage"
|
|
26
29
|
:disabled="page <= 1"
|
|
27
30
|
@click="emit('update:page', page - 1)"
|
|
28
31
|
/>
|
|
29
32
|
<MIconButton
|
|
30
33
|
icon="chevron_right"
|
|
31
|
-
label="
|
|
34
|
+
:label="t.nextPage"
|
|
32
35
|
:disabled="page >= totalPages"
|
|
33
36
|
@click="emit('update:page', page + 1)"
|
|
34
37
|
/>
|
|
@@ -116,15 +116,27 @@ function finishPull() {
|
|
|
116
116
|
// browser starts a native pan and fires pointercancel, snapping the indicator
|
|
117
117
|
// back. The only reliable way to own a touch drag is a non-passive touchmove
|
|
118
118
|
// that calls preventDefault().
|
|
119
|
+
//
|
|
120
|
+
// The pointer is only captured once the mouse has dragged down a few pixels. Capturing on
|
|
121
|
+
// pointerdown retargets pointerup to the scroller, so the browser fires the click there and
|
|
122
|
+
// a plain click on an item at the top of the list never reached the item.
|
|
123
|
+
const POINTER_SLOP = 4;
|
|
124
|
+
let pointerClaimed = false;
|
|
125
|
+
|
|
119
126
|
function onPointerDown(e: PointerEvent) {
|
|
120
127
|
if (e.pointerType === "touch" || e.button !== 0 || !canStart()) return;
|
|
121
128
|
pointerId = e.pointerId;
|
|
129
|
+
pointerClaimed = false;
|
|
122
130
|
beginPull(e.clientY);
|
|
123
|
-
scrollEl.value!.setPointerCapture(e.pointerId);
|
|
124
131
|
}
|
|
125
132
|
|
|
126
133
|
function onPointerMove(e: PointerEvent) {
|
|
127
134
|
if (!pulling || e.pointerId !== pointerId) return;
|
|
135
|
+
if (!pointerClaimed) {
|
|
136
|
+
if (e.clientY - startY < POINTER_SLOP) return;
|
|
137
|
+
pointerClaimed = true;
|
|
138
|
+
scrollEl.value!.setPointerCapture(e.pointerId);
|
|
139
|
+
}
|
|
128
140
|
movePull(e.clientY);
|
|
129
141
|
}
|
|
130
142
|
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { computed } from 'vue'
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
4
|
import MBadge from './MBadge.vue'
|
|
5
|
+
import { useItemLink, type ItemLink } from '../composables/_useItemLink'
|
|
5
6
|
|
|
6
7
|
export interface ShortNavBarItem {
|
|
7
8
|
value: string | number
|
|
@@ -9,6 +10,10 @@ export interface ShortNavBarItem {
|
|
|
9
10
|
icon: string
|
|
10
11
|
badge?: number
|
|
11
12
|
badgeDot?: boolean
|
|
13
|
+
/** Not selectable: icon and label at 38% of the unselected color, no hover. */
|
|
14
|
+
disabled?: boolean
|
|
15
|
+
/** Makes the item a link: a vue-router location (rendered as RouterLink), or a URL without vue-router. */
|
|
16
|
+
to?: ItemLink
|
|
12
17
|
}
|
|
13
18
|
|
|
14
19
|
const props = withDefaults(
|
|
@@ -37,6 +42,28 @@ const props = withDefaults(
|
|
|
37
42
|
|
|
38
43
|
defineEmits<{ 'update:modelValue': [string | number] }>()
|
|
39
44
|
|
|
45
|
+
const itemLink = useItemLink()
|
|
46
|
+
|
|
47
|
+
// ShortNavigationBarItemDefaults.colors(): disabled icon/text = unselected color at
|
|
48
|
+
// DisabledAlpha (0.38), whether or not the item is selected; no hover state layer.
|
|
49
|
+
const DISABLED = 'text-on-surface-variant/38'
|
|
50
|
+
function topPillClass(item: ShortNavBarItem) {
|
|
51
|
+
const selected = item.value === props.modelValue
|
|
52
|
+
if (item.disabled) return selected ? `w-14 bg-secondary-container ${DISABLED}` : `w-0 ${DISABLED}`
|
|
53
|
+
return selected
|
|
54
|
+
? 'w-14 bg-secondary-container text-on-secondary-container'
|
|
55
|
+
: 'w-0 bg-secondary-container/0 text-on-surface-variant group-hover:w-14 group-hover:bg-on-surface/8'
|
|
56
|
+
}
|
|
57
|
+
function labelClass(item: ShortNavBarItem) {
|
|
58
|
+
if (item.disabled) return DISABLED
|
|
59
|
+
return item.value === props.modelValue ? 'text-secondary' : 'text-on-surface-variant'
|
|
60
|
+
}
|
|
61
|
+
function startPillClass(item: ShortNavBarItem) {
|
|
62
|
+
const selected = item.value === props.modelValue
|
|
63
|
+
if (item.disabled) return selected ? `bg-secondary-container ${DISABLED}` : DISABLED
|
|
64
|
+
return selected ? 'bg-secondary-container text-on-secondary-container' : 'text-on-surface-variant group-hover:bg-on-surface/8'
|
|
65
|
+
}
|
|
66
|
+
|
|
40
67
|
// calculateCenteredContentHorizontalPadding: 3 items -> 20% each side, 4 -> 15%, 5 -> 10%,
|
|
41
68
|
// 6 -> 5%, 7+ -> 0. Matches the real formula verbatim: ((100 - 10*(n+3)) / 2) / 100.
|
|
42
69
|
const centeredPadding = computed(() => {
|
|
@@ -51,23 +78,20 @@ const centeredPadding = computed(() => {
|
|
|
51
78
|
class="flex h-16 w-full items-center border-t border-outline-variant bg-surface-container shadow-elevation-2"
|
|
52
79
|
:style="arrangement === 'centered' ? { paddingLeft: `${centeredPadding}%`, paddingRight: `${centeredPadding}%` } : undefined"
|
|
53
80
|
>
|
|
54
|
-
<
|
|
81
|
+
<component
|
|
82
|
+
:is="itemLink(item).tag"
|
|
55
83
|
v-for="item in items"
|
|
56
84
|
:key="item.value"
|
|
57
|
-
|
|
58
|
-
class="group flex flex-1
|
|
59
|
-
:class="iconPosition === 'top' ? 'flex-col gap-1' : 'flex-row gap-1 py-1.5'"
|
|
60
|
-
@click="$emit('update:modelValue', item.value)"
|
|
85
|
+
v-bind="itemLink(item).attrs"
|
|
86
|
+
class="group flex flex-1 items-center justify-center self-stretch transition-colors focus-visible:outline-none"
|
|
87
|
+
:class="[iconPosition === 'top' ? 'flex-col gap-1' : 'flex-row gap-1 py-1.5', item.disabled ? 'cursor-not-allowed' : 'cursor-pointer']"
|
|
88
|
+
@click="!item.disabled && $emit('update:modelValue', item.value)"
|
|
61
89
|
>
|
|
62
90
|
<template v-if="iconPosition === 'top'">
|
|
63
91
|
<!-- Top icon position: 56x32dp pill above a separate label, matching MNavigationBar -->
|
|
64
92
|
<span
|
|
65
93
|
class="inline-flex h-8 items-center justify-center rounded-2xl transition-all duration-200"
|
|
66
|
-
:class="
|
|
67
|
-
item.value === modelValue
|
|
68
|
-
? 'w-14 bg-secondary-container text-on-secondary-container'
|
|
69
|
-
: 'w-0 bg-secondary-container/0 text-on-surface-variant group-hover:w-14 group-hover:bg-on-surface/8'
|
|
70
|
-
"
|
|
94
|
+
:class="topPillClass(item)"
|
|
71
95
|
>
|
|
72
96
|
<MBadge v-if="item.badge != null" :count="item.badge">
|
|
73
97
|
<MIcon :name="item.icon" :size="24" />
|
|
@@ -79,7 +103,7 @@ const centeredPadding = computed(() => {
|
|
|
79
103
|
</span>
|
|
80
104
|
<span
|
|
81
105
|
class="text-label-medium font-medium"
|
|
82
|
-
:class="item
|
|
106
|
+
:class="labelClass(item)"
|
|
83
107
|
>
|
|
84
108
|
{{ item.label }}
|
|
85
109
|
</span>
|
|
@@ -92,11 +116,7 @@ const centeredPadding = computed(() => {
|
|
|
92
116
|
separate Secondary label color (ShortNavigationBarItemDefaults.colors() doc comment). -->
|
|
93
117
|
<span
|
|
94
118
|
class="inline-flex h-10 items-center justify-center gap-1 rounded-2xl px-4 transition-colors duration-200"
|
|
95
|
-
:class="
|
|
96
|
-
item.value === modelValue
|
|
97
|
-
? 'bg-secondary-container text-on-secondary-container'
|
|
98
|
-
: 'text-on-surface-variant group-hover:bg-on-surface/8'
|
|
99
|
-
"
|
|
119
|
+
:class="startPillClass(item)"
|
|
100
120
|
>
|
|
101
121
|
<MBadge v-if="item.badge != null" :count="item.badge">
|
|
102
122
|
<MIcon :name="item.icon" :size="24" />
|
|
@@ -108,6 +128,6 @@ const centeredPadding = computed(() => {
|
|
|
108
128
|
<span class="text-label-medium font-medium">{{ item.label }}</span>
|
|
109
129
|
</span>
|
|
110
130
|
</template>
|
|
111
|
-
</
|
|
131
|
+
</component>
|
|
112
132
|
</nav>
|
|
113
133
|
</template>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import { computed, ref } from 'vue'
|
|
3
2
|
import MIcon from './MIcon.vue'
|
|
3
|
+
import { useSheetMotion } from '../composables/_useSheetMotion'
|
|
4
4
|
|
|
5
5
|
withDefaults(defineProps<{
|
|
6
6
|
modelValue: boolean
|
|
@@ -11,51 +11,30 @@ withDefaults(defineProps<{
|
|
|
11
11
|
const emit = defineEmits<{ 'update:modelValue': [boolean] }>()
|
|
12
12
|
const close = () => emit('update:modelValue', false)
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
let startX = 0
|
|
17
|
-
|
|
18
|
-
function onEdgePointerDown(e: PointerEvent) {
|
|
19
|
-
dragging.value = true
|
|
20
|
-
startX = e.clientX
|
|
21
|
-
dragX.value = 0
|
|
22
|
-
;(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId)
|
|
23
|
-
}
|
|
24
|
-
function onEdgePointerMove(e: PointerEvent) {
|
|
25
|
-
if (!dragging.value) return
|
|
26
|
-
dragX.value = Math.max(0, e.clientX - startX)
|
|
27
|
-
}
|
|
28
|
-
function onEdgePointerUp() {
|
|
29
|
-
if (dragX.value > 100) close()
|
|
30
|
-
dragging.value = false
|
|
31
|
-
dragX.value = 0
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const panelStyle = computed(() => ({
|
|
35
|
-
transform: `translateX(${dragX.value}px)`,
|
|
36
|
-
transition: dragging.value ? 'none' : undefined,
|
|
37
|
-
}))
|
|
14
|
+
// Slide in/out and drag-to-dismiss, as springs (see _useSheetMotion).
|
|
15
|
+
const motion = useSheetMotion('x', close)
|
|
38
16
|
</script>
|
|
39
17
|
|
|
40
18
|
<template>
|
|
41
19
|
<Teleport to="body">
|
|
42
|
-
<Transition
|
|
20
|
+
<Transition :css="false" @enter="motion.onEnter" @leave="motion.onLeave">
|
|
43
21
|
<div v-if="modelValue" class="fixed inset-0 z-200 flex justify-end">
|
|
44
22
|
<!-- Scrim -->
|
|
45
|
-
<div class="
|
|
23
|
+
<div data-sheet-scrim class="absolute inset-0 bg-scrim/32" @click="close" />
|
|
46
24
|
|
|
47
25
|
<!-- Panel -->
|
|
48
26
|
<aside
|
|
49
|
-
|
|
27
|
+
data-sheet-panel
|
|
28
|
+
class="relative flex h-full flex-col bg-surface-container-low shadow-elevation-3"
|
|
50
29
|
:class="[width, 'max-w-[90vw]']"
|
|
51
|
-
:style="panelStyle"
|
|
52
30
|
>
|
|
53
31
|
<!-- Drag edge -->
|
|
54
32
|
<div
|
|
55
33
|
class="absolute top-0 left-0 h-full w-3 cursor-ew-resize touch-none"
|
|
56
|
-
@pointerdown="
|
|
57
|
-
@pointermove="
|
|
58
|
-
@pointerup="
|
|
34
|
+
@pointerdown="motion.onDragStart"
|
|
35
|
+
@pointermove="motion.onDragMove"
|
|
36
|
+
@pointerup="motion.onDragEnd"
|
|
37
|
+
@pointercancel="motion.onDragEnd"
|
|
59
38
|
/>
|
|
60
39
|
|
|
61
40
|
<!-- Header -->
|
|
@@ -86,27 +65,3 @@ const panelStyle = computed(() => ({
|
|
|
86
65
|
</Transition>
|
|
87
66
|
</Teleport>
|
|
88
67
|
</template>
|
|
89
|
-
|
|
90
|
-
<style scoped>
|
|
91
|
-
.ss-scrim {
|
|
92
|
-
transition: opacity 280ms ease;
|
|
93
|
-
}
|
|
94
|
-
.ss-enter-from .ss-scrim,
|
|
95
|
-
.ss-leave-to .ss-scrim {
|
|
96
|
-
opacity: 0;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.ss-panel {
|
|
100
|
-
transition:
|
|
101
|
-
transform 320ms cubic-bezier(0.2, 0, 0, 1),
|
|
102
|
-
opacity 240ms ease;
|
|
103
|
-
}
|
|
104
|
-
.ss-enter-from .ss-panel {
|
|
105
|
-
transform: translateX(40%);
|
|
106
|
-
opacity: 0;
|
|
107
|
-
}
|
|
108
|
-
.ss-leave-to .ss-panel {
|
|
109
|
-
transform: translateX(100%) !important;
|
|
110
|
-
opacity: 0;
|
|
111
|
-
}
|
|
112
|
-
</style>
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { computed, ref, watch } from 'vue'
|
|
3
|
+
import MBottomSheet from './MBottomSheet.vue'
|
|
4
|
+
import { useWindowSizeClass } from '../composables/useWindowSizeClass'
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* M3 supporting-pane canonical layout, after androidx SupportingPaneScaffold: from the
|
|
8
|
+
* expanded width class (840px) up, the supporting pane sits beside the main one with a 24dp
|
|
9
|
+
* spacer at its preferred width (360dp, 412dp from large). Below that, its default adapt
|
|
10
|
+
* strategy is `Reflow(Main)`: it moves under the main pane ('below' here). 'sheet' follows
|
|
11
|
+
* the `Levitate` bottom-sheet sample instead: hidden until opened, then in a bottom sheet.
|
|
12
|
+
* Measured on the component itself, not the window.
|
|
13
|
+
*/
|
|
14
|
+
const props = withDefaults(defineProps<{
|
|
15
|
+
/** Where the supporting pane goes when there's room for only one pane. */
|
|
16
|
+
singlePane?: 'below' | 'sheet'
|
|
17
|
+
/** With `singlePane="sheet"`: whether the sheet is open (v-model:open). */
|
|
18
|
+
open?: boolean
|
|
19
|
+
/** With `singlePane="sheet"`: the sheet's title. */
|
|
20
|
+
sheetTitle?: string
|
|
21
|
+
/** Supporting pane width in the two-pane layout. Defaults to M3's 360px (412px from the large width class). */
|
|
22
|
+
supportingWidth?: string
|
|
23
|
+
}>(), { singlePane: 'below', open: false })
|
|
24
|
+
|
|
25
|
+
const emit = defineEmits<{ 'update:open': [boolean] }>()
|
|
26
|
+
|
|
27
|
+
defineSlots<{
|
|
28
|
+
main?: (props: { twoPane: boolean }) => unknown
|
|
29
|
+
supporting?: (props: { twoPane: boolean }) => unknown
|
|
30
|
+
}>()
|
|
31
|
+
|
|
32
|
+
const root = ref<HTMLElement>()
|
|
33
|
+
const { widthClass } = useWindowSizeClass(root)
|
|
34
|
+
const twoPane = computed(() => widthClass.value !== 'compact' && widthClass.value !== 'medium')
|
|
35
|
+
const width = computed(() =>
|
|
36
|
+
props.supportingWidth ?? (widthClass.value === 'large' || widthClass.value === 'extra-large' ? '412px' : '360px'),
|
|
37
|
+
)
|
|
38
|
+
const inSheet = computed(() => !twoPane.value && props.singlePane === 'sheet')
|
|
39
|
+
// Once the pane fits beside the main one, an open sheet would pop back up on the next narrowing.
|
|
40
|
+
watch(twoPane, (two) => {
|
|
41
|
+
if (two && props.open) emit('update:open', false)
|
|
42
|
+
})
|
|
43
|
+
</script>
|
|
44
|
+
|
|
45
|
+
<template>
|
|
46
|
+
<div ref="root" class="flex gap-6" :class="twoPane ? 'overflow-hidden' : 'flex-col overflow-y-auto'">
|
|
47
|
+
<!--
|
|
48
|
+
Two panes: each scrolls on its own (give the component a height). One pane, 'below': the
|
|
49
|
+
whole thing scrolls as a single column.
|
|
50
|
+
-->
|
|
51
|
+
<div class="min-w-0" :class="twoPane ? 'min-h-0 flex-1 overflow-auto' : 'shrink-0'">
|
|
52
|
+
<slot name="main" :two-pane="twoPane" />
|
|
53
|
+
</div>
|
|
54
|
+
<div
|
|
55
|
+
v-if="!inSheet"
|
|
56
|
+
:class="twoPane ? 'min-h-0 shrink-0 overflow-auto' : 'shrink-0'"
|
|
57
|
+
:style="twoPane ? { width } : undefined"
|
|
58
|
+
>
|
|
59
|
+
<slot name="supporting" :two-pane="twoPane" />
|
|
60
|
+
</div>
|
|
61
|
+
<MBottomSheet
|
|
62
|
+
v-else
|
|
63
|
+
:model-value="open"
|
|
64
|
+
:title="sheetTitle"
|
|
65
|
+
@update:model-value="emit('update:open', $event)"
|
|
66
|
+
>
|
|
67
|
+
<slot name="supporting" :two-pane="false" />
|
|
68
|
+
</MBottomSheet>
|
|
69
|
+
</div>
|
|
70
|
+
</template>
|