@m3ui-vue/m3ui-vue 0.8.5 → 0.8.7
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 +5 -1
- package/dist/{MMenuItem-BXIxwIdM.js → MMenuItem-DmrsQrK7.js} +2 -2
- package/dist/{MMenuItem-BXIxwIdM.js.map → MMenuItem-DmrsQrK7.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/MChatBubble.vue.d.ts +4 -2
- package/dist/components/MCheckbox.vue.d.ts +2 -0
- package/dist/components/MDragDropList.vue.d.ts +19 -6
- package/dist/components/MFileUpload.vue.d.ts +16 -4
- package/dist/components/MKanban.vue.d.ts +15 -6
- 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 +57 -30
- package/dist/components/MWindow.vue.d.ts +39 -1
- package/dist/components/_MTransferPane.vue.d.ts +46 -0
- package/dist/composables/_useItemLink.d.ts +30 -0
- package/dist/composables/_useSheetMotion.d.ts +7 -0
- package/dist/composables/useLocale.d.ts +27 -0
- package/dist/composables/useWindowSizeClass.d.ts +19 -0
- package/dist/index.d.ts +6 -0
- package/dist/locales/index.js +196 -7
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +4331 -2945
- package/dist/m3ui.js.map +1 -1
- package/dist/rich-text-editor.js +2 -2
- package/dist/styles.css +1 -1
- package/dist/{useLocale-DbREg9Zn.js → useLocale-Bircp823.js} +29 -2
- package/dist/useLocale-Bircp823.js.map +1 -0
- package/package.json +1 -1
- package/src/__tests__/MChart.test.ts +28 -0
- package/src/__tests__/MChatBubble.test.ts +33 -0
- package/src/__tests__/MDragDropList.test.ts +194 -0
- package/src/__tests__/MFileUpload.test.ts +78 -0
- package/src/__tests__/MKanban.test.ts +150 -0
- package/src/__tests__/MPullToRefresh.test.ts +67 -0
- package/src/__tests__/MRating.test.ts +72 -0
- package/src/__tests__/MShortNavigationBar.test.ts +25 -0
- package/src/__tests__/MTransferList.test.ts +149 -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/MChatBubble.vue +107 -20
- package/src/components/MCheckbox.vue +3 -0
- package/src/components/MDragDropList.vue +485 -56
- package/src/components/MFileUpload.vue +56 -20
- package/src/components/MKanban.vue +720 -78
- package/src/components/MListDetail.vue +103 -0
- package/src/components/MNavigationRail.vue +48 -31
- package/src/components/MNavigationSuite.vue +89 -0
- package/src/components/MPullToRefresh.vue +101 -35
- package/src/components/MRating.vue +163 -67
- package/src/components/MResult.vue +19 -9
- 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 +174 -137
- package/src/components/MWindow.vue +507 -108
- package/src/components/_MTransferPane.vue +260 -0
- package/src/composables/_useItemLink.ts +19 -0
- package/src/composables/_useSheetMotion.ts +181 -0
- package/src/composables/useLocale.ts +75 -0
- package/src/composables/useWindowSizeClass.ts +93 -0
- package/src/index.ts +6 -0
- package/src/locales/de.ts +37 -0
- package/src/locales/es.ts +37 -0
- package/src/locales/fr.ts +37 -0
- package/src/locales/ja.ts +37 -0
- package/src/locales/ko.ts +37 -0
- package/src/locales/pt.ts +37 -0
- package/src/locales/zh.ts +37 -0
- package/dist/useLocale-DbREg9Zn.js.map +0 -1
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
import { computed, ref } from 'vue'
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
4
|
|
|
5
|
+
// Not part of the official M3 spec — built from M3 primitives instead: filled/outlined
|
|
6
|
+
// Material Symbol pairs, on-surface-variant for the unselected icon, a 40px circular
|
|
7
|
+
// hover/press state layer (8%/10%) tinted with the active color, and a secondary focus ring.
|
|
5
8
|
const props = withDefaults(defineProps<{
|
|
6
9
|
modelValue: number
|
|
7
10
|
max?: number
|
|
@@ -15,94 +18,187 @@ const props = withDefaults(defineProps<{
|
|
|
15
18
|
|
|
16
19
|
const emit = defineEmits<{ 'update:modelValue': [number] }>()
|
|
17
20
|
|
|
18
|
-
const
|
|
21
|
+
const ROLE_COLORS: Record<string, string> = {
|
|
22
|
+
primary: 'text-primary',
|
|
23
|
+
secondary: 'text-secondary',
|
|
24
|
+
tertiary: 'text-tertiary',
|
|
25
|
+
error: 'text-error',
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const colorClass = computed(() => ROLE_COLORS[props.color] ?? '')
|
|
29
|
+
const customStyle = computed(() => (props.color in ROLE_COLORS ? undefined : { color: props.color }))
|
|
30
|
+
|
|
31
|
+
const interactive = computed(() => !props.readonly && !props.disabled)
|
|
32
|
+
const step = computed(() => (props.halfIncrements ? 0.5 : 1))
|
|
33
|
+
|
|
34
|
+
const rootEl = ref<HTMLElement | null>(null)
|
|
35
|
+
const itemEls: HTMLElement[] = []
|
|
36
|
+
|
|
37
|
+
// Pointer preview: `value` is what the rating would become, `index` is the item under the
|
|
38
|
+
// pointer (drives the state layer). Null when the pointer isn't over the component.
|
|
39
|
+
const hover = ref<{ index: number; value: number } | null>(null)
|
|
40
|
+
const pressed = ref(false)
|
|
41
|
+
|
|
42
|
+
const clamp = (v: number) => Math.min(props.max, Math.max(0, v))
|
|
43
|
+
|
|
44
|
+
const displayValue = computed(() =>
|
|
45
|
+
!pressed.value && hover.value ? hover.value.value : clamp(props.modelValue || 0),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
// Per-item fill fraction (0..1). Arbitrary fractions render exactly (e.g. a readonly 4.3
|
|
49
|
+
// average shows 30% of the 5th icon), not just whole/half steps.
|
|
50
|
+
const fills = computed(() =>
|
|
51
|
+
Array.from({ length: props.max }, (_, i) => Math.min(1, Math.max(0, displayValue.value - i))),
|
|
52
|
+
)
|
|
19
53
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
54
|
+
function pointerTarget(e: PointerEvent): { index: number; value: number } | null {
|
|
55
|
+
if (!itemEls.length) return null
|
|
56
|
+
const rtl = rootEl.value ? getComputedStyle(rootEl.value).direction === 'rtl' : false
|
|
57
|
+
const first = itemEls[0]!.getBoundingClientRect()
|
|
58
|
+
// Dragging past the start edge clears to 0 — the only pointer path to an empty rating.
|
|
59
|
+
if (pressed.value && (rtl ? e.clientX > first.right : e.clientX < first.left)) {
|
|
60
|
+
return { index: 0, value: 0 }
|
|
26
61
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
|
|
62
|
+
for (let i = 0; i < itemEls.length; i++) {
|
|
63
|
+
const r = itemEls[i]!.getBoundingClientRect()
|
|
64
|
+
const isLast = i === itemEls.length - 1
|
|
65
|
+
if (!isLast && (rtl ? e.clientX < r.left : e.clientX > r.right)) continue
|
|
66
|
+
const frac = rtl ? (r.right - e.clientX) / r.width : (e.clientX - r.left) / r.width
|
|
67
|
+
const value = props.halfIncrements && frac < 0.5 ? i + 0.5 : i + 1
|
|
68
|
+
return { index: i, value }
|
|
69
|
+
}
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function commit(v: number) {
|
|
74
|
+
const next = clamp(v)
|
|
75
|
+
if (next !== props.modelValue) emit('update:modelValue', next)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function onPointerDown(e: PointerEvent) {
|
|
79
|
+
if (!interactive.value || e.button !== 0) return
|
|
80
|
+
pressed.value = true
|
|
81
|
+
rootEl.value?.setPointerCapture(e.pointerId)
|
|
82
|
+
const t = pointerTarget(e)
|
|
83
|
+
hover.value = t
|
|
84
|
+
if (t) commit(t.value)
|
|
41
85
|
}
|
|
42
86
|
|
|
43
|
-
function
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
87
|
+
function onPointerMove(e: PointerEvent) {
|
|
88
|
+
if (!interactive.value) return
|
|
89
|
+
if (!pressed.value && e.pointerType !== 'mouse') return
|
|
90
|
+
const t = pointerTarget(e)
|
|
91
|
+
hover.value = t
|
|
92
|
+
if (pressed.value && t) commit(t.value)
|
|
47
93
|
}
|
|
48
94
|
|
|
49
|
-
function
|
|
50
|
-
if (
|
|
51
|
-
|
|
95
|
+
function onPointerUp(e: PointerEvent) {
|
|
96
|
+
if (!pressed.value) return
|
|
97
|
+
pressed.value = false
|
|
98
|
+
rootEl.value?.releasePointerCapture(e.pointerId)
|
|
99
|
+
if (e.pointerType !== 'mouse') hover.value = null
|
|
52
100
|
}
|
|
53
101
|
|
|
54
|
-
function
|
|
55
|
-
|
|
102
|
+
function onPointerLeave() {
|
|
103
|
+
if (!pressed.value) hover.value = null
|
|
56
104
|
}
|
|
57
105
|
|
|
58
|
-
function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
106
|
+
function onKeydown(e: KeyboardEvent) {
|
|
107
|
+
if (!interactive.value) return
|
|
108
|
+
const rtl = rootEl.value ? getComputedStyle(rootEl.value).direction === 'rtl' : false
|
|
109
|
+
const current = clamp(props.modelValue || 0)
|
|
110
|
+
let next: number
|
|
111
|
+
switch (e.key) {
|
|
112
|
+
case 'ArrowUp':
|
|
113
|
+
next = current + step.value
|
|
114
|
+
break
|
|
115
|
+
case 'ArrowDown':
|
|
116
|
+
next = current - step.value
|
|
117
|
+
break
|
|
118
|
+
case 'ArrowRight':
|
|
119
|
+
next = current + (rtl ? -step.value : step.value)
|
|
120
|
+
break
|
|
121
|
+
case 'ArrowLeft':
|
|
122
|
+
next = current + (rtl ? step.value : -step.value)
|
|
123
|
+
break
|
|
124
|
+
case 'Home':
|
|
125
|
+
next = 0
|
|
126
|
+
break
|
|
127
|
+
case 'End':
|
|
128
|
+
next = props.max
|
|
129
|
+
break
|
|
130
|
+
default:
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
e.preventDefault()
|
|
134
|
+
// Snap to the step grid so an off-grid modelValue (e.g. 3.7) moves to a valid value.
|
|
135
|
+
commit(Math.round(next / step.value) * step.value)
|
|
63
136
|
}
|
|
64
137
|
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
return
|
|
138
|
+
function stateLayerClass(i: number) {
|
|
139
|
+
if (!interactive.value || hover.value?.index !== i) return 'opacity-0'
|
|
140
|
+
return pressed.value ? 'opacity-[0.10]' : 'opacity-[0.08]'
|
|
68
141
|
}
|
|
142
|
+
|
|
143
|
+
const valueText = computed(() => `${clamp(props.modelValue || 0)} / ${props.max}`)
|
|
69
144
|
</script>
|
|
70
145
|
|
|
71
146
|
<template>
|
|
72
147
|
<div
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
148
|
+
ref="rootEl"
|
|
149
|
+
class="inline-flex select-none items-center gap-0.5 rounded-full outline-none ring-secondary focus-visible:ring-2"
|
|
150
|
+
:class="interactive ? 'cursor-pointer touch-pan-y' : 'cursor-default'"
|
|
151
|
+
:role="readonly ? 'img' : 'slider'"
|
|
152
|
+
:tabindex="interactive ? 0 : undefined"
|
|
153
|
+
:aria-label="readonly ? valueText : undefined"
|
|
154
|
+
:aria-valuemin="readonly ? undefined : 0"
|
|
155
|
+
:aria-valuemax="readonly ? undefined : max"
|
|
156
|
+
:aria-valuenow="readonly ? undefined : clamp(modelValue || 0)"
|
|
157
|
+
:aria-valuetext="readonly ? undefined : valueText"
|
|
158
|
+
:aria-disabled="disabled || undefined"
|
|
159
|
+
@pointerdown="onPointerDown"
|
|
160
|
+
@pointermove="onPointerMove"
|
|
161
|
+
@pointerup="onPointerUp"
|
|
162
|
+
@pointercancel="onPointerUp"
|
|
163
|
+
@pointerleave="onPointerLeave"
|
|
164
|
+
@keydown="onKeydown"
|
|
76
165
|
>
|
|
77
|
-
<
|
|
78
|
-
v-for="i in
|
|
166
|
+
<span
|
|
167
|
+
v-for="(fill, i) in fills"
|
|
79
168
|
:key="i"
|
|
80
|
-
|
|
81
|
-
class="relative inline-flex
|
|
82
|
-
:
|
|
83
|
-
readonly || disabled ? 'cursor-default' : 'cursor-pointer hover:scale-110',
|
|
84
|
-
]"
|
|
85
|
-
:style="customStyle"
|
|
86
|
-
:disabled="disabled"
|
|
87
|
-
@click="onClick(i - 1, $event)"
|
|
88
|
-
@mousemove="onMove(i - 1, $event)"
|
|
169
|
+
:ref="(el) => { if (el) itemEls[i] = el as HTMLElement }"
|
|
170
|
+
class="relative inline-flex shrink-0"
|
|
171
|
+
:style="{ width: `${size + 4}px`, height: `${size + 4}px` }"
|
|
89
172
|
>
|
|
90
|
-
<!--
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
:
|
|
95
|
-
:class="colorClass"
|
|
173
|
+
<!-- State layer: overhangs the item by 4px per side (size 28 → 40px circle) without
|
|
174
|
+
changing the component's footprint; only one is visible at a time. -->
|
|
175
|
+
<span
|
|
176
|
+
class="pointer-events-none absolute -inset-1 rounded-full bg-current transition-opacity duration-150"
|
|
177
|
+
:class="[colorClass, stateLayerClass(i)]"
|
|
96
178
|
:style="customStyle"
|
|
97
|
-
style="font-variation-settings: 'FILL' 1"
|
|
98
|
-
/>
|
|
99
|
-
<!-- Empty star -->
|
|
100
|
-
<MIcon
|
|
101
|
-
v-else
|
|
102
|
-
:name="icon"
|
|
103
|
-
:size="size"
|
|
104
|
-
class="text-on-surface-variant/40"
|
|
105
179
|
/>
|
|
106
|
-
|
|
180
|
+
<span class="absolute inset-0.5">
|
|
181
|
+
<!-- Unfilled part (outlined glyph), clipped from the end side -->
|
|
182
|
+
<span class="absolute inset-y-0 end-0 overflow-hidden" :style="{ width: `${(1 - fill) * 100}%` }">
|
|
183
|
+
<MIcon
|
|
184
|
+
:name="icon"
|
|
185
|
+
:size="size"
|
|
186
|
+
class="absolute end-0 top-0"
|
|
187
|
+
:class="disabled ? 'text-on-surface/38' : 'text-on-surface-variant'"
|
|
188
|
+
/>
|
|
189
|
+
</span>
|
|
190
|
+
<!-- Filled part (FILL 1 glyph), clipped from the start side — this is what renders
|
|
191
|
+
half (or any fractional) values with any icon, not just `star`. -->
|
|
192
|
+
<span class="absolute inset-y-0 start-0 overflow-hidden" :style="{ width: `${fill * 100}%` }">
|
|
193
|
+
<MIcon
|
|
194
|
+
:name="icon"
|
|
195
|
+
:size="size"
|
|
196
|
+
class="absolute start-0 top-0"
|
|
197
|
+
:class="disabled ? 'text-on-surface/38' : colorClass"
|
|
198
|
+
:style="[disabled ? undefined : customStyle, { fontVariationSettings: `'FILL' 1` }]"
|
|
199
|
+
/>
|
|
200
|
+
</span>
|
|
201
|
+
</span>
|
|
202
|
+
</span>
|
|
107
203
|
</div>
|
|
108
204
|
</template>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { computed } from 'vue'
|
|
3
3
|
import MIcon from './MIcon.vue'
|
|
4
|
+
import { useLocale, type M3Locale } from '../composables/useLocale'
|
|
4
5
|
|
|
5
6
|
const props = withDefaults(defineProps<{
|
|
6
7
|
status: 'success' | 'error' | 'warning' | 'info' | '404' | '403' | '500'
|
|
@@ -8,16 +9,25 @@ const props = withDefaults(defineProps<{
|
|
|
8
9
|
description?: string
|
|
9
10
|
}>(), {})
|
|
10
11
|
|
|
12
|
+
const t = useLocale()
|
|
13
|
+
|
|
14
|
+
const STATUS_STYLE = {
|
|
15
|
+
success: { icon: 'check_circle', bg: 'bg-success-container', text: 'text-on-success-container' },
|
|
16
|
+
error: { icon: 'error', bg: 'bg-error-container', text: 'text-on-error-container' },
|
|
17
|
+
warning: { icon: 'warning', bg: 'bg-tertiary-container', text: 'text-on-tertiary-container' },
|
|
18
|
+
info: { icon: 'info', bg: 'bg-primary-container', text: 'text-on-primary-container' },
|
|
19
|
+
'404': { icon: 'search_off', bg: 'bg-surface-container-high', text: 'text-on-surface-variant' },
|
|
20
|
+
'403': { icon: 'lock', bg: 'bg-error-container', text: 'text-on-error-container' },
|
|
21
|
+
'500': { icon: 'cloud_off', bg: 'bg-error-container', text: 'text-on-error-container' },
|
|
22
|
+
} as const
|
|
23
|
+
|
|
24
|
+
// Locale keys follow the status: success → resultSuccessTitle, 404 → result404Title, …
|
|
11
25
|
const config = computed(() => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
case '404': return { icon: 'search_off', bg: 'bg-surface-container-high', text: 'text-on-surface-variant', defaultTitle: 'Página no encontrada', defaultDesc: 'La página que buscas no existe o fue movida.' }
|
|
18
|
-
case '403': return { icon: 'lock', bg: 'bg-error-container', text: 'text-on-error-container', defaultTitle: 'Acceso denegado', defaultDesc: 'No tienes permisos para ver este recurso.' }
|
|
19
|
-
case '500': return { icon: 'cloud_off', bg: 'bg-error-container', text: 'text-on-error-container', defaultTitle: 'Error del servidor', defaultDesc: 'El servidor no pudo procesar la solicitud.' }
|
|
20
|
-
default: return { icon: 'info', bg: 'bg-surface-container-high', text: 'text-on-surface-variant', defaultTitle: '', defaultDesc: '' }
|
|
26
|
+
const key = props.status.charAt(0).toUpperCase() + props.status.slice(1)
|
|
27
|
+
return {
|
|
28
|
+
...STATUS_STYLE[props.status],
|
|
29
|
+
defaultTitle: t[`result${key}Title` as keyof M3Locale],
|
|
30
|
+
defaultDesc: t[`result${key}Desc` as keyof M3Locale],
|
|
21
31
|
}
|
|
22
32
|
})
|
|
23
33
|
|
|
@@ -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>
|