@m3ui-vue/m3ui-vue 0.9.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +26 -29
- package/dist/API.md +242 -22
- package/dist/{MIcon-CaEooCmZ.js → MIcon-DLOkQduI.js} +10 -3
- package/dist/MIcon-DLOkQduI.js.map +1 -0
- package/dist/{MTextField-Ck0oWDMk.js → MTextField-TZ7lfr09.js} +551 -216
- package/dist/MTextField-TZ7lfr09.js.map +1 -0
- package/dist/THIRD_PARTY_LICENSES.md +547 -0
- package/dist/api.json +1 -1
- package/dist/code-editor.js +2 -2
- package/dist/components/MAppBarWithSearch.vue.d.ts +70 -0
- package/dist/components/MBottomAppBar.vue.d.ts +37 -0
- package/dist/components/MBottomSheetScaffold.vue.d.ts +40 -0
- package/dist/components/MButton.vue.d.ts +4 -2
- package/dist/components/MButtonGroup.vue.d.ts +2 -0
- package/dist/components/MChatBubble.vue.d.ts +1 -1
- package/dist/components/MChip.vue.d.ts +19 -2
- package/dist/components/MContainer.vue.d.ts +1 -1
- package/dist/components/MDataTable.vue.d.ts +1 -1
- package/dist/components/MDialog.vue.d.ts +1 -1
- package/dist/components/MFab.vue.d.ts +15 -4
- package/dist/components/MIcon.vue.d.ts +3 -0
- package/dist/components/MIconButton.vue.d.ts +15 -1
- package/dist/components/MListItem.vue.d.ts +2 -2
- package/dist/components/MLoadingOverlay.vue.d.ts +1 -1
- package/dist/components/MMenuItem.vue.d.ts +17 -4
- package/dist/components/MNavigationRail.vue.d.ts +6 -0
- package/dist/components/MSearchBar.vue.d.ts +5 -3
- package/dist/components/MShortNavigationBar.vue.d.ts +1 -1
- package/dist/components/MSplitButton.vue.d.ts +2 -0
- package/dist/components/MTable.vue.d.ts +1 -1
- package/dist/components/MTabs.vue.d.ts +6 -0
- package/dist/components/MTimePickerModal.vue.d.ts +3 -0
- package/dist/components/MTimeScroll.vue.d.ts +22 -0
- package/dist/components/MToggleButton.vue.d.ts +2 -0
- package/dist/components/MTopAppBar.vue.d.ts +33 -2
- package/dist/components/MTree.vue.d.ts +2 -2
- package/dist/components/_MDrawerItemList.vue.d.ts +3 -0
- package/dist/composables/_searchAppBar.d.ts +6 -0
- package/dist/composables/_themeTransition.d.ts +2 -0
- package/dist/composables/_useSpring.d.ts +5 -5
- package/dist/composables/motion.d.ts +101 -0
- package/dist/composables/useColorPalette.d.ts +10 -0
- package/dist/composables/useLocale.d.ts +9 -0
- package/dist/directives/vRipple.d.ts +16 -0
- package/dist/emoji-names-de-BphO5XpV.js.map +1 -1
- package/dist/emoji-names-en-9ZvMRvzi.js.map +1 -1
- package/dist/emoji-names-es-DvfWU3Pj.js.map +1 -1
- package/dist/emoji-names-fr-B-jhUlsP.js.map +1 -1
- package/dist/emoji-names-ja-l8cMFJo1.js.map +1 -1
- package/dist/emoji-names-ko-YP-o9G0c.js.map +1 -1
- package/dist/emoji-names-pt-DGj_Js4M.js.map +1 -1
- package/dist/emoji-names-zh-Dzecwtw_.js.map +1 -1
- package/dist/index.d.ts +11 -1
- package/dist/locales/index.js +63 -0
- package/dist/locales/index.js.map +1 -1
- package/dist/m3ui-vue.css +1 -1
- package/dist/m3ui.js +7716 -6768
- package/dist/m3ui.js.map +1 -1
- package/dist/plugin.d.ts +7 -0
- package/dist/rich-text-editor.js +22 -22
- package/dist/styles/palettes-contrast.css +7764 -0
- package/dist/styles/theme.css +59 -2
- package/dist/styles.css +1 -1
- package/dist/terminal.js +1 -1
- package/dist/{useLocale-CFW8cIzL.js → useLocale-CuvWRZ1h.js} +10 -1
- package/dist/useLocale-CuvWRZ1h.js.map +1 -0
- package/package.json +4 -2
- package/src/__tests__/MAppBarWithSearch.test.ts +96 -0
- package/src/__tests__/MBottomAppBar.test.ts +71 -0
- package/src/__tests__/MBottomSheetScaffold.test.ts +101 -0
- package/src/__tests__/MChip.test.ts +63 -0
- package/src/__tests__/MFab.test.ts +36 -0
- package/src/__tests__/MIconButton.test.ts +60 -0
- package/src/__tests__/MMenuItem.test.ts +84 -0
- package/src/__tests__/MNavigationRail.test.ts +77 -0
- package/src/__tests__/MScrollField.test.ts +28 -0
- package/src/__tests__/MTabs.test.ts +39 -0
- package/src/__tests__/MTimePickerModal.test.ts +52 -0
- package/src/__tests__/MTimeScroll.test.ts +44 -0
- package/src/__tests__/MTopAppBar.test.ts +99 -0
- package/src/__tests__/contrast.test.ts +64 -0
- package/src/__tests__/dynamicColor.test.ts +17 -0
- package/src/__tests__/motion.test.ts +37 -0
- package/src/__tests__/themeTransition.test.ts +119 -0
- package/src/__tests__/vRipple.test.ts +92 -0
- package/src/components/MAppBarWithSearch.vue +236 -0
- package/src/components/MBottomAppBar.vue +181 -0
- package/src/components/MBottomSheetScaffold.vue +296 -0
- package/src/components/MBreadcrumbs.vue +1 -1
- package/src/components/MButton.vue +4 -13
- package/src/components/MButtonGroup.vue +4 -11
- package/src/components/MChip.vue +137 -5
- package/src/components/MFab.vue +81 -27
- package/src/components/MIcon.vue +4 -2
- package/src/components/MIconButton.vue +96 -24
- package/src/components/MMenuItem.vue +115 -13
- package/src/components/MNavigationDrawer.vue +2 -2
- package/src/components/MNavigationRail.vue +135 -8
- package/src/components/MScrollField.vue +10 -2
- package/src/components/MSearchBar.vue +28 -12
- package/src/components/MSplitButton.vue +5 -12
- package/src/components/MTabs.vue +16 -5
- package/src/components/MTimePickerModal.vue +48 -8
- package/src/components/MTimeScroll.vue +161 -0
- package/src/components/MToggleButton.vue +5 -12
- package/src/components/MTopAppBar.vue +252 -28
- package/src/composables/_carouselStrategy.ts +3 -0
- package/src/composables/_searchAppBar.ts +9 -0
- package/src/composables/_themeColor.ts +11 -4
- package/src/composables/_themeTransition.ts +71 -0
- package/src/composables/_useSpring.ts +12 -20
- package/src/composables/motion.ts +73 -0
- package/src/composables/useColorPalette.ts +103 -20
- package/src/composables/useLocale.ts +18 -0
- package/src/composables/useTheme.ts +4 -12
- package/src/data/emoji-names/emoji-names-de.ts +1 -0
- package/src/data/emoji-names/emoji-names-en.ts +1 -0
- package/src/data/emoji-names/emoji-names-es.ts +1 -0
- package/src/data/emoji-names/emoji-names-fr.ts +1 -0
- package/src/data/emoji-names/emoji-names-ja.ts +1 -0
- package/src/data/emoji-names/emoji-names-ko.ts +1 -0
- package/src/data/emoji-names/emoji-names-pt.ts +1 -0
- package/src/data/emoji-names/emoji-names-zh.ts +1 -0
- package/src/data/emojis.ts +1 -0
- package/src/directives/vRipple.ts +73 -0
- package/src/index.ts +13 -1
- package/src/locales/de.ts +9 -0
- package/src/locales/es.ts +9 -0
- package/src/locales/fr.ts +9 -0
- package/src/locales/ja.ts +9 -0
- package/src/locales/ko.ts +9 -0
- package/src/locales/pt.ts +9 -0
- package/src/locales/zh.ts +9 -0
- package/src/plugin.ts +11 -1
- package/src/styles/palettes-contrast.css +7764 -0
- package/src/styles/theme.css +59 -2
- package/dist/MIcon-CaEooCmZ.js.map +0 -1
- package/dist/MTextField-Ck0oWDMk.js.map +0 -1
- package/dist/useLocale-CFW8cIzL.js.map +0 -1
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* M3 Expressive's time scroll picker (a port of Compose's `TimeScroll`): an hour wheel and a minute wheel
|
|
4
|
+
* side by side, plus an AM/PM toggle in 12-hour mode. It updates as the wheels turn; put it in a dialog or a
|
|
5
|
+
* form for the confirm step.
|
|
6
|
+
*
|
|
7
|
+
* @event update:modelValue Emitted with the time as HH:MM (24-hour) whenever a wheel or AM/PM changes
|
|
8
|
+
*/
|
|
9
|
+
import { computed, ref, watch } from 'vue'
|
|
10
|
+
import MScrollField from './MScrollField.vue'
|
|
11
|
+
import { useLocale } from '../composables/useLocale'
|
|
12
|
+
import { FAST_SPATIAL, useSpring } from '../composables/_useSpring'
|
|
13
|
+
|
|
14
|
+
const props = withDefaults(defineProps<{
|
|
15
|
+
/** Selected time in HH:MM, 24-hour (v-model); null shows 12:00 AM (00:00 in 24-hour mode) */
|
|
16
|
+
modelValue: string | null
|
|
17
|
+
/** 24-hour wheel (00–23) instead of 1–12 with AM/PM */
|
|
18
|
+
use24h?: boolean
|
|
19
|
+
/** Minute increment step; the minute wheel shows only multiples of it */
|
|
20
|
+
minuteStep?: number
|
|
21
|
+
/** Disables the wheels and the AM/PM toggle */
|
|
22
|
+
disabled?: boolean
|
|
23
|
+
}>(), {
|
|
24
|
+
modelValue: null,
|
|
25
|
+
use24h: false,
|
|
26
|
+
minuteStep: 1,
|
|
27
|
+
disabled: false,
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const emit = defineEmits<{ 'update:modelValue': [string] }>()
|
|
31
|
+
const locale = useLocale()
|
|
32
|
+
|
|
33
|
+
function parse(t: string | null) {
|
|
34
|
+
const [h, m] = (t ?? '').split(':').map(Number)
|
|
35
|
+
return { h: Number.isFinite(h) ? Math.min(23, Math.max(0, h!)) : 0, m: Number.isFinite(m) ? Math.min(59, Math.max(0, m!)) : 0 }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const step = computed(() => Math.min(30, Math.max(1, Math.floor(props.minuteStep))))
|
|
39
|
+
const hour = ref(0)
|
|
40
|
+
const minute = ref(0)
|
|
41
|
+
|
|
42
|
+
function sync() {
|
|
43
|
+
const { h, m } = parse(props.modelValue)
|
|
44
|
+
hour.value = h
|
|
45
|
+
minute.value = Math.floor(m / step.value) * step.value
|
|
46
|
+
}
|
|
47
|
+
sync()
|
|
48
|
+
watch(() => [props.modelValue, step.value], sync)
|
|
49
|
+
|
|
50
|
+
const isPm = computed(() => hour.value >= 12)
|
|
51
|
+
|
|
52
|
+
// TimeScrollImpl's mapping: in 12-hour mode index 0..11 shows 1..12, and 12 o'clock is the last item
|
|
53
|
+
const hourCount = computed(() => (props.use24h ? 24 : 12))
|
|
54
|
+
const hourIndex = computed(() => (props.use24h ? hour.value : (hour.value % 12 || 12) - 1))
|
|
55
|
+
const minuteIndex = computed(() => Math.round(minute.value / step.value))
|
|
56
|
+
|
|
57
|
+
function commit(h: number, m: number) {
|
|
58
|
+
hour.value = h
|
|
59
|
+
minute.value = m
|
|
60
|
+
const value = `${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}`
|
|
61
|
+
if (value !== props.modelValue) emit('update:modelValue', value)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function onHour(index: number) {
|
|
65
|
+
const h = props.use24h ? index : ((index + 1) % 12) + (isPm.value ? 12 : 0)
|
|
66
|
+
commit(h, minute.value)
|
|
67
|
+
}
|
|
68
|
+
function onMinute(index: number) {
|
|
69
|
+
commit(hour.value, index * step.value)
|
|
70
|
+
}
|
|
71
|
+
function setPm(pm: boolean) {
|
|
72
|
+
if (props.disabled || pm === isPm.value) return
|
|
73
|
+
commit(hour.value + (pm ? 12 : -12), minute.value)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const pad = (n: number) => String(n).padStart(2, '0')
|
|
77
|
+
const formatHour = (i: number) => pad(props.use24h ? i : i + 1)
|
|
78
|
+
const formatMinute = (i: number) => pad(i * step.value)
|
|
79
|
+
|
|
80
|
+
// AM/PM in the app language, from Intl (no locale keys: every language already has them there)
|
|
81
|
+
const periods = computed(() => {
|
|
82
|
+
const label = (h: number) => {
|
|
83
|
+
try {
|
|
84
|
+
return new Intl.DateTimeFormat(locale.lang, { hour: 'numeric', hour12: true })
|
|
85
|
+
.formatToParts(new Date(2000, 0, 1, h))
|
|
86
|
+
.find((p) => p.type === 'dayPeriod')?.value ?? (h < 12 ? 'AM' : 'PM')
|
|
87
|
+
} catch {
|
|
88
|
+
return h < 12 ? 'AM' : 'PM'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return [label(9), label(21)] as const
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
// The period toggle is two ToggleButtons (TimePicker.kt's ToggleItem): a circle that becomes a 12dp
|
|
95
|
+
// rounded square when checked or pressed, on the ToggleButton's FastSpatial spring.
|
|
96
|
+
const periodEls: (HTMLElement | null)[] = [null, null]
|
|
97
|
+
const pressedPeriod = ref(-1)
|
|
98
|
+
const SIZE = 56
|
|
99
|
+
useSpring(
|
|
100
|
+
() => [0, 1].map((i) => (pressedPeriod.value === i || (i === 1) === isPm.value ? 12 : SIZE / 2)),
|
|
101
|
+
(v) => periodEls.forEach((el, i) => { if (el) el.style.borderRadius = `${v[i]}px` }),
|
|
102
|
+
FAST_SPATIAL,
|
|
103
|
+
)
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<template>
|
|
107
|
+
<div class="inline-flex items-start select-none" :aria-disabled="disabled || undefined">
|
|
108
|
+
<MScrollField
|
|
109
|
+
:model-value="hourIndex"
|
|
110
|
+
:count="hourCount"
|
|
111
|
+
:height="120"
|
|
112
|
+
:format="formatHour"
|
|
113
|
+
:label="locale.timeHourSelection"
|
|
114
|
+
:disabled="disabled"
|
|
115
|
+
class="w-[100px]"
|
|
116
|
+
@update:model-value="onHour"
|
|
117
|
+
/>
|
|
118
|
+
<span
|
|
119
|
+
aria-hidden="true"
|
|
120
|
+
class="flex h-[120px] w-4 items-center justify-center pb-2 text-display-large text-on-surface"
|
|
121
|
+
:class="disabled ? 'opacity-38' : ''"
|
|
122
|
+
>:</span>
|
|
123
|
+
<MScrollField
|
|
124
|
+
:model-value="minuteIndex"
|
|
125
|
+
:count="Math.ceil(60 / step)"
|
|
126
|
+
:height="120"
|
|
127
|
+
:format="formatMinute"
|
|
128
|
+
:label="locale.timeMinuteSelection"
|
|
129
|
+
:disabled="disabled"
|
|
130
|
+
class="w-[100px]"
|
|
131
|
+
@update:model-value="onMinute"
|
|
132
|
+
/>
|
|
133
|
+
<div
|
|
134
|
+
v-if="!use24h"
|
|
135
|
+
role="radiogroup"
|
|
136
|
+
:aria-label="locale.timePeriodToggle"
|
|
137
|
+
class="ml-2 flex h-[120px] w-14 flex-col gap-2"
|
|
138
|
+
>
|
|
139
|
+
<button
|
|
140
|
+
v-for="(text, i) in periods"
|
|
141
|
+
:key="i"
|
|
142
|
+
:ref="(el) => { periodEls[i] = el as HTMLElement | null }"
|
|
143
|
+
type="button"
|
|
144
|
+
role="radio"
|
|
145
|
+
:aria-checked="(i === 1) === isPm"
|
|
146
|
+
:disabled="disabled"
|
|
147
|
+
class="relative flex h-14 w-14 cursor-pointer items-center justify-center overflow-hidden text-title-medium transition-colors duration-150 disabled:cursor-default disabled:opacity-38 before:pointer-events-none before:absolute before:inset-0 before:bg-current before:opacity-0 before:transition-opacity before:content-[''] enabled:hover:before:opacity-[0.08] enabled:active:before:opacity-[0.12]"
|
|
148
|
+
:class="(i === 1) === isPm
|
|
149
|
+
? 'bg-primary-container font-bold text-on-primary-container'
|
|
150
|
+
: 'bg-surface-container-lowest text-on-surface-variant'"
|
|
151
|
+
@pointerdown="pressedPeriod = i"
|
|
152
|
+
@pointerup="pressedPeriod = -1"
|
|
153
|
+
@pointerleave="pressedPeriod = -1"
|
|
154
|
+
@pointercancel="pressedPeriod = -1"
|
|
155
|
+
@click="setPm(i === 1)"
|
|
156
|
+
>
|
|
157
|
+
{{ text }}
|
|
158
|
+
</button>
|
|
159
|
+
</div>
|
|
160
|
+
</div>
|
|
161
|
+
</template>
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
|
|
11
11
|
import MIcon from './MIcon.vue'
|
|
12
|
+
import { vRipple } from '../directives/vRipple'
|
|
12
13
|
|
|
13
14
|
const props = withDefaults(
|
|
14
15
|
defineProps<{
|
|
@@ -22,6 +23,8 @@ const props = withDefaults(
|
|
|
22
23
|
icon?: string
|
|
23
24
|
/** Same 5-tier expressive sizing as MButton */
|
|
24
25
|
size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'
|
|
26
|
+
/** Any CSS color for the press ripple; defaults to the button's content color */
|
|
27
|
+
rippleColor?: string
|
|
25
28
|
}>(),
|
|
26
29
|
{
|
|
27
30
|
variant: 'filled',
|
|
@@ -106,23 +109,12 @@ const disabledContainerClasses = computed(() => {
|
|
|
106
109
|
const rootEl = ref<HTMLElement | null>(null)
|
|
107
110
|
const pressed = ref(false)
|
|
108
111
|
|
|
109
|
-
function onPointerDown(
|
|
112
|
+
function onPointerDown() {
|
|
110
113
|
if (props.disabled) return
|
|
111
114
|
pressed.value = true
|
|
112
|
-
createRipple(e)
|
|
113
115
|
}
|
|
114
116
|
function onPointerUp() { pressed.value = false }
|
|
115
117
|
|
|
116
|
-
function createRipple(event: PointerEvent) {
|
|
117
|
-
const button = event.currentTarget as HTMLElement
|
|
118
|
-
const rect = button.getBoundingClientRect()
|
|
119
|
-
const d = Math.max(rect.width, rect.height) * 2
|
|
120
|
-
const el = document.createElement('span')
|
|
121
|
-
el.className = 'm3-ripple'
|
|
122
|
-
el.style.cssText = `width:${d}px;height:${d}px;top:${event.clientY - rect.top - d / 2}px;left:${event.clientX - rect.left - d / 2}px`
|
|
123
|
-
button.appendChild(el)
|
|
124
|
-
el.addEventListener('animationend', () => el.remove(), { once: true })
|
|
125
|
-
}
|
|
126
118
|
|
|
127
119
|
function toggle() {
|
|
128
120
|
if (props.disabled) return
|
|
@@ -188,6 +180,7 @@ onUnmounted(() => cancelAnimationFrame(rafId))
|
|
|
188
180
|
:aria-pressed="checked"
|
|
189
181
|
:disabled="disabled"
|
|
190
182
|
:class="[base, sizeClasses, containerClasses, disabledContainerClasses]"
|
|
183
|
+
v-ripple="{ disabled, color: rippleColor }"
|
|
191
184
|
@pointerdown="onPointerDown"
|
|
192
185
|
@pointerup="onPointerUp"
|
|
193
186
|
@pointerleave="onPointerUp"
|
|
@@ -1,22 +1,36 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
/**
|
|
3
3
|
* A top app bar in four M3 layouts — center-aligned, small, medium, and large — with a leading navigation icon
|
|
4
|
-
* and trailing actions.
|
|
4
|
+
* and trailing actions. Medium and large can be M3 Expressive's flexible bars (bigger titles, a subtitle), and
|
|
5
|
+
* any of them can react to scrolling: change color, hide, or collapse to the small bar.
|
|
5
6
|
*
|
|
6
7
|
* @slot navigation Custom leading area (default: an MIconButton built from the navigationIcon prop)
|
|
7
8
|
* @slot title Custom title content (default: renders the title prop)
|
|
9
|
+
* @slot subtitle Custom subtitle content (default: renders the subtitle prop)
|
|
8
10
|
* @slot actions Trailing action buttons
|
|
9
11
|
* @event navigation Emitted when the default navigation icon button is clicked (not emitted when the
|
|
10
12
|
* #navigation slot is overridden — that content is fully custom)
|
|
11
13
|
*/
|
|
14
|
+
import { computed, onMounted, onUnmounted, ref, useSlots, watch } from 'vue'
|
|
12
15
|
import MIconButton from './MIconButton.vue'
|
|
13
16
|
import { useLocale } from '../composables/useLocale'
|
|
17
|
+
import { DEFAULT_EFFECTS } from '../composables/_useSpring'
|
|
18
|
+
import { cubicBezier } from '../composables/motion'
|
|
14
19
|
|
|
15
|
-
withDefaults(defineProps<{
|
|
20
|
+
const props = withDefaults(defineProps<{
|
|
16
21
|
/** App bar title */
|
|
17
22
|
title?: string
|
|
23
|
+
/** A line below the title (Compose's `subtitle`): small, center-aligned and flexible medium/large bars */
|
|
24
|
+
subtitle?: string
|
|
18
25
|
/** 64dp small/center-aligned row, or a 112dp medium / 152dp large two-row layout with the title below */
|
|
19
26
|
variant?: 'center' | 'small' | 'medium' | 'large'
|
|
27
|
+
/**
|
|
28
|
+
* Medium/large only: M3 Expressive's MediumFlexibleTopAppBar / LargeFlexibleTopAppBar, with a
|
|
29
|
+
* headline-medium / display-small title and room for a subtitle (112/136dp and 120/152dp tall)
|
|
30
|
+
*/
|
|
31
|
+
flexible?: boolean
|
|
32
|
+
/** Medium/large only: where the title row sits (Compose's `titleHorizontalAlignment`) */
|
|
33
|
+
titleAlignment?: 'start' | 'center'
|
|
20
34
|
/** Leading icon (e.g. menu, arrow_back) */
|
|
21
35
|
navigationIcon?: string
|
|
22
36
|
/** Accessible label for the navigation icon button — defaults to the
|
|
@@ -30,30 +44,216 @@ withDefaults(defineProps<{
|
|
|
30
44
|
elevated?: boolean
|
|
31
45
|
/** Add a bottom border (border-outline-variant) */
|
|
32
46
|
bordered?: boolean
|
|
33
|
-
|
|
47
|
+
/**
|
|
48
|
+
* How the bar reacts to `scrollTarget` scrolling (Compose's TopAppBarDefaults scroll behaviors). `pinned`
|
|
49
|
+
* stays put and takes the scrolled container color once the content moves under it; `enter-always` hides
|
|
50
|
+
* (a medium/large bar collapses to the small one) while the content scrolls down and comes back as soon as
|
|
51
|
+
* it scrolls up; `exit-until-collapsed` collapses a medium/large bar as the content scrolls and expands it
|
|
52
|
+
* only back at the top. The last two make the bar sticky over the content: put it at the top of the
|
|
53
|
+
* scrolling element (or of the page)
|
|
54
|
+
*/
|
|
55
|
+
scrollBehavior?: 'pinned' | 'enter-always' | 'exit-until-collapsed'
|
|
56
|
+
/** What `scrollBehavior` follows: an element or a CSS selector for it. Defaults to the window */
|
|
57
|
+
scrollTarget?: HTMLElement | string | null
|
|
58
|
+
}>(), { variant: 'small', flexible: false, titleAlignment: 'start', scrollTarget: null })
|
|
34
59
|
|
|
35
60
|
defineEmits<{ navigation: [] }>()
|
|
36
61
|
|
|
37
62
|
const locale = useLocale()
|
|
63
|
+
const slots = useSlots()
|
|
64
|
+
|
|
65
|
+
const twoRow = computed(() => props.variant === 'medium' || props.variant === 'large')
|
|
66
|
+
const hasSubtitle = computed(() => !!(props.subtitle || slots.subtitle))
|
|
67
|
+
const COLLAPSED = 64
|
|
68
|
+
// AppBarMedium/Large(Flexible)Tokens container heights
|
|
69
|
+
const expandedHeight = computed(() => {
|
|
70
|
+
if (!twoRow.value) return COLLAPSED
|
|
71
|
+
if (!props.flexible) return props.variant === 'large' ? 152 : 112
|
|
72
|
+
if (props.variant === 'large') return hasSubtitle.value ? 152 : 120
|
|
73
|
+
return hasSubtitle.value ? 136 : 112
|
|
74
|
+
})
|
|
75
|
+
const titleClass = computed(() => {
|
|
76
|
+
if (props.variant === 'large') return props.flexible ? 'text-display-small' : 'text-headline-medium'
|
|
77
|
+
return props.flexible ? 'text-headline-medium' : 'text-headline-small'
|
|
78
|
+
})
|
|
79
|
+
const subtitleClass = computed(() => (props.variant === 'large' ? 'text-title-medium' : 'text-label-large'))
|
|
80
|
+
|
|
81
|
+
// ── Scroll behaviors ─────────────────────────────────────────────────────────────────────────────
|
|
82
|
+
// TopAppBarState: heightOffset from 0 (expanded) to heightOffsetLimit (the bottom row gone for a two-row bar,
|
|
83
|
+
// the whole bar for a single row). Compose shrinks the bar in the layout and consumes the scroll first (the
|
|
84
|
+
// nested scroll's pre-scroll), so the content doesn't move while the bar collapses. A web page scrolls
|
|
85
|
+
// natively, so instead the bar is sticky over the content and, as it shrinks, its bottom margin grows by the
|
|
86
|
+
// same amount: it keeps taking its expanded height in the layout, and its bottom edge stays on the content's
|
|
87
|
+
// top edge, one-to-one with the finger.
|
|
88
|
+
const overlay = computed(() => props.scrollBehavior === 'enter-always' || props.scrollBehavior === 'exit-until-collapsed')
|
|
89
|
+
const limit = () => -(twoRow.value ? expandedHeight.value - COLLAPSED : COLLAPSED)
|
|
90
|
+
|
|
91
|
+
const barEl = ref<HTMLElement>()
|
|
92
|
+
const bottomRowEl = ref<HTMLElement>()
|
|
93
|
+
const smallTitleEl = ref<HTMLElement>()
|
|
94
|
+
const bigTitleEl = ref<HTMLElement>()
|
|
95
|
+
const scrolled = ref(false)
|
|
96
|
+
const collapsedHalf = ref(false)
|
|
97
|
+
|
|
98
|
+
let offset = 0
|
|
99
|
+
let vel = 0
|
|
100
|
+
let snapTarget: number | null = null
|
|
101
|
+
let raf = 0
|
|
102
|
+
let last = 0
|
|
103
|
+
let settleTimer = 0
|
|
104
|
+
let lastScroll = 0
|
|
105
|
+
let target: HTMLElement | Window | null = null
|
|
106
|
+
|
|
107
|
+
// TopTitleAlphaEasing = CubicBezierEasing(.8, 0, .8, .15); the container lerps on FastOutLinearInEasing
|
|
108
|
+
const topTitleAlpha = cubicBezier(0.8, 0, 0.8, 0.15)
|
|
109
|
+
const fastOutLinearIn = cubicBezier(0.4, 0, 1, 1)
|
|
110
|
+
|
|
111
|
+
function write() {
|
|
112
|
+
const f = offset === 0 ? 0 : offset / limit()
|
|
113
|
+
collapsedHalf.value = f >= 0.5
|
|
114
|
+
if (barEl.value) {
|
|
115
|
+
barEl.value.style.height = props.scrollBehavior && offset !== 0 ? `${expandedHeight.value + offset}px` : ''
|
|
116
|
+
barEl.value.style.marginBottom = overlay.value && offset !== 0 ? `${-offset}px` : ''
|
|
117
|
+
}
|
|
118
|
+
if (!twoRow.value) return
|
|
119
|
+
if (bottomRowEl.value) bottomRowEl.value.style.height = `${expandedHeight.value - COLLAPSED + offset}px`
|
|
120
|
+
if (smallTitleEl.value) smallTitleEl.value.style.opacity = String(topTitleAlpha(f))
|
|
121
|
+
if (bigTitleEl.value) bigTitleEl.value.style.opacity = String(1 - f)
|
|
122
|
+
// A two-row bar's container follows the collapse continuously (TwoRowsTopAppBar's colorTransitionFraction)
|
|
123
|
+
if (barEl.value) {
|
|
124
|
+
barEl.value.style.backgroundColor = props.elevated || f === 0
|
|
125
|
+
? ''
|
|
126
|
+
: `color-mix(in srgb, var(--color-surface-container) ${(fastOutLinearIn(f) * 100).toFixed(1)}%, var(--color-surface))`
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const scrollTop = () => (target instanceof Window ? target.scrollY : target?.scrollTop ?? 0)
|
|
131
|
+
|
|
132
|
+
function stopSnap() {
|
|
133
|
+
cancelAnimationFrame(raf)
|
|
134
|
+
raf = 0
|
|
135
|
+
snapTarget = null
|
|
136
|
+
vel = 0
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function onScroll() {
|
|
140
|
+
const y = Math.max(0, scrollTop())
|
|
141
|
+
const dy = y - lastScroll
|
|
142
|
+
lastScroll = y
|
|
143
|
+
// SingleRowTopAppBar: the scrolled color as soon as content sits under the bar (overlappedFraction)
|
|
144
|
+
scrolled.value = y > 0
|
|
145
|
+
if (props.scrollBehavior === 'exit-until-collapsed') {
|
|
146
|
+
// Collapses with the content and expands only as the content comes back to its top
|
|
147
|
+
offset = Math.max(limit(), -y)
|
|
148
|
+
write()
|
|
149
|
+
return
|
|
150
|
+
}
|
|
151
|
+
if (props.scrollBehavior !== 'enter-always' || !dy) return
|
|
152
|
+
stopSnap()
|
|
153
|
+
offset = Math.min(0, Math.max(limit(), offset - dy))
|
|
154
|
+
write()
|
|
155
|
+
clearTimeout(settleTimer)
|
|
156
|
+
settleTimer = window.setTimeout(settle, 150)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// settleAppBar: a bar left half-way snaps to the closer end (TopAppBarDefaults.snapAnimationSpec, DefaultEffects)
|
|
160
|
+
function settle() {
|
|
161
|
+
const lim = limit()
|
|
162
|
+
if (offset === 0 || offset === lim) return
|
|
163
|
+
snapTarget = offset / lim < 0.5 ? 0 : lim
|
|
164
|
+
last = performance.now()
|
|
165
|
+
raf = requestAnimationFrame(frame)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function frame(now: number) {
|
|
169
|
+
if (snapTarget === null) return
|
|
170
|
+
let dt = Math.min((now - last) / 1000, 1 / 30)
|
|
171
|
+
last = now
|
|
172
|
+
const k = DEFAULT_EFFECTS.stiffness
|
|
173
|
+
const c = 2 * DEFAULT_EFFECTS.dampingRatio * Math.sqrt(k)
|
|
174
|
+
while (dt > 0) {
|
|
175
|
+
const h = Math.min(dt, 0.004)
|
|
176
|
+
dt -= h
|
|
177
|
+
vel += (-k * (offset - snapTarget) - c * vel) * h
|
|
178
|
+
offset += vel * h
|
|
179
|
+
}
|
|
180
|
+
if (Math.abs(offset - snapTarget) < 0.5 && Math.abs(vel) < 0.5) {
|
|
181
|
+
offset = snapTarget
|
|
182
|
+
write()
|
|
183
|
+
stopSnap()
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
write()
|
|
187
|
+
raf = requestAnimationFrame(frame)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function resolveTarget(): HTMLElement | Window | null {
|
|
191
|
+
if (typeof window === 'undefined') return null
|
|
192
|
+
if (!props.scrollTarget) return window
|
|
193
|
+
if (typeof props.scrollTarget === 'string') return document.querySelector<HTMLElement>(props.scrollTarget)
|
|
194
|
+
return props.scrollTarget
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function attach() {
|
|
198
|
+
detach()
|
|
199
|
+
if (!props.scrollBehavior) return
|
|
200
|
+
target = resolveTarget()
|
|
201
|
+
if (!target) return
|
|
202
|
+
lastScroll = Math.max(0, scrollTop())
|
|
203
|
+
target.addEventListener('scroll', onScroll, { passive: true })
|
|
204
|
+
onScroll()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function detach() {
|
|
208
|
+
target?.removeEventListener('scroll', onScroll)
|
|
209
|
+
target = null
|
|
210
|
+
clearTimeout(settleTimer)
|
|
211
|
+
stopSnap()
|
|
212
|
+
offset = 0
|
|
213
|
+
scrolled.value = false
|
|
214
|
+
write()
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
onMounted(() => {
|
|
218
|
+
write()
|
|
219
|
+
attach()
|
|
220
|
+
})
|
|
221
|
+
onUnmounted(detach)
|
|
222
|
+
watch(() => [props.scrollBehavior, props.scrollTarget], attach)
|
|
223
|
+
watch(() => [props.variant, props.flexible, hasSubtitle.value], () => {
|
|
224
|
+
offset = Math.min(0, Math.max(limit(), offset))
|
|
225
|
+
write()
|
|
226
|
+
}, { flush: 'post' })
|
|
227
|
+
|
|
228
|
+
// Single row: elevated, or scrolled under while a scroll behavior is set
|
|
229
|
+
const scrolledLook = computed(() => props.elevated || (!twoRow.value && scrolled.value))
|
|
38
230
|
</script>
|
|
39
231
|
|
|
40
232
|
<template>
|
|
233
|
+
<!-- Direct children are the rows (consumers target `header > div > button` for the navigation button) -->
|
|
41
234
|
<header
|
|
235
|
+
ref="barEl"
|
|
42
236
|
class="flex w-full flex-col transition-[background-color,box-shadow]"
|
|
43
237
|
:class="[
|
|
44
238
|
// AppBarTokens: ContainerColor=Surface/Elevation=Level0 at rest, but
|
|
45
239
|
// OnScrollContainerColor=SurfaceContainer/OnScrollContainerElevation=Level2 together once
|
|
46
|
-
// scrolled — `elevated` swaps both, not just the shadow.
|
|
47
|
-
|
|
240
|
+
// scrolled — `elevated` swaps both, not just the shadow. Scrolling only changes the color, as
|
|
241
|
+
// Compose's TopAppBarColors do.
|
|
242
|
+
scrolledLook ? 'bg-surface-container' : 'bg-surface',
|
|
243
|
+
elevated ? 'shadow-elevation-2' : '',
|
|
48
244
|
bordered ? 'border-b border-outline-variant' : '',
|
|
245
|
+
// Clipped only while it can shrink, so nothing that overflows a static bar today gets cut
|
|
246
|
+
scrollBehavior ? 'overflow-hidden' : '',
|
|
247
|
+
overlay ? 'sticky top-0 z-10' : '',
|
|
49
248
|
]"
|
|
50
249
|
>
|
|
51
250
|
<!-- Top row — 64dp per M3's TopAppBarSmall/collapsed-Medium/collapsed-Large tokens.
|
|
52
251
|
px-2: TopAppBarHorizontalPadding (4dp) + the 4dp IconButton() gets for free from
|
|
53
252
|
Modifier.minimumInteractiveComponentSize() centering its 40dp visible container inside
|
|
54
253
|
a 48dp touch target — MIconButton doesn't implement that invisible expansion, so it's
|
|
55
|
-
folded into this row padding instead to land the icon glyph at the real 16dp inset.
|
|
56
|
-
|
|
254
|
+
folded into this row padding instead to land the icon glyph at the real 16dp inset.
|
|
255
|
+
A single-row bar's row is capped by the (shrinking) bar, keeping its content centered as it hides. -->
|
|
256
|
+
<div class="flex h-16 shrink-0 items-center gap-1 px-2" :class="twoRow ? '' : 'max-h-full'">
|
|
57
257
|
<!-- Navigation -->
|
|
58
258
|
<slot name="navigation">
|
|
59
259
|
<MIconButton
|
|
@@ -65,17 +265,36 @@ const locale = useLocale()
|
|
|
65
265
|
/>
|
|
66
266
|
</slot>
|
|
67
267
|
|
|
68
|
-
<!-- Title: center or small variant -->
|
|
69
|
-
<
|
|
70
|
-
v-if="
|
|
71
|
-
class="flex flex-1
|
|
72
|
-
:class="variant === 'center' ? '
|
|
268
|
+
<!-- Title: center or small variant, with an optional subtitle -->
|
|
269
|
+
<div
|
|
270
|
+
v-if="!twoRow"
|
|
271
|
+
class="flex min-w-0 flex-1 flex-col justify-center px-4"
|
|
272
|
+
:class="variant === 'center' ? 'items-center text-center' : ''"
|
|
73
273
|
>
|
|
74
|
-
<
|
|
75
|
-
|
|
274
|
+
<h1 class="w-full truncate text-title-large text-on-surface">
|
|
275
|
+
<slot name="title">{{ title }}</slot>
|
|
276
|
+
</h1>
|
|
277
|
+
<p v-if="hasSubtitle" class="w-full truncate text-label-medium text-on-surface-variant">
|
|
278
|
+
<slot name="subtitle">{{ subtitle }}</slot>
|
|
279
|
+
</p>
|
|
280
|
+
</div>
|
|
76
281
|
|
|
77
|
-
<!--
|
|
78
|
-
<div
|
|
282
|
+
<!-- Two-row bars: the small title fades in as the bar collapses (TopTitleAlphaEasing) -->
|
|
283
|
+
<div
|
|
284
|
+
v-else
|
|
285
|
+
ref="smallTitleEl"
|
|
286
|
+
class="flex min-w-0 flex-1 flex-col justify-center px-4"
|
|
287
|
+
:class="titleAlignment === 'center' ? 'items-center text-center' : ''"
|
|
288
|
+
style="opacity: 0"
|
|
289
|
+
:aria-hidden="!collapsedHalf || undefined"
|
|
290
|
+
>
|
|
291
|
+
<span class="w-full truncate text-title-large text-on-surface">
|
|
292
|
+
<slot name="title">{{ title }}</slot>
|
|
293
|
+
</span>
|
|
294
|
+
<span v-if="flexible && hasSubtitle" class="w-full truncate text-label-medium text-on-surface-variant">
|
|
295
|
+
<slot name="subtitle">{{ subtitle }}</slot>
|
|
296
|
+
</span>
|
|
297
|
+
</div>
|
|
79
298
|
|
|
80
299
|
<!-- Trailing actions -->
|
|
81
300
|
<div v-if="$slots.actions" class="flex items-center gap-1">
|
|
@@ -84,20 +303,25 @@ const locale = useLocale()
|
|
|
84
303
|
</div>
|
|
85
304
|
|
|
86
305
|
<!-- Large title row for medium/large variants — total container height
|
|
87
|
-
112dp (medium) / 152dp (large) per M3's AppBarMedium/LargeTokens,
|
|
88
|
-
|
|
89
|
-
|
|
306
|
+
112dp (medium) / 152dp (large) per M3's AppBarMedium/LargeTokens, 112/136dp and 120/152dp for the
|
|
307
|
+
flexible ones (without/with a subtitle). Bottom padding is MediumTitleBottomPadding=24dp /
|
|
308
|
+
LargeTitleBottomPadding=28dp. It shrinks from the top while collapsing, the title anchored to its
|
|
309
|
+
bottom and clipped as it goes. Its height is only ever written by write(): a reactive :style here
|
|
310
|
+
would be re-applied on every re-render and undo the collapse. -->
|
|
90
311
|
<div
|
|
91
|
-
v-if="
|
|
92
|
-
|
|
93
|
-
|
|
312
|
+
v-if="twoRow"
|
|
313
|
+
ref="bottomRowEl"
|
|
314
|
+
class="flex shrink-0 items-end overflow-hidden px-4"
|
|
315
|
+
:class="[variant === 'large' ? 'pb-7' : 'pb-6', titleAlignment === 'center' ? 'justify-center text-center' : '']"
|
|
94
316
|
>
|
|
95
|
-
<
|
|
96
|
-
class="truncate text-on-surface"
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
<
|
|
100
|
-
|
|
317
|
+
<div ref="bigTitleEl" class="min-w-0" :aria-hidden="collapsedHalf || undefined">
|
|
318
|
+
<h1 class="truncate text-on-surface" :class="titleClass">
|
|
319
|
+
<slot name="title">{{ title }}</slot>
|
|
320
|
+
</h1>
|
|
321
|
+
<p v-if="flexible && hasSubtitle" class="truncate text-on-surface-variant" :class="subtitleClass">
|
|
322
|
+
<slot name="subtitle">{{ subtitle }}</slot>
|
|
323
|
+
</p>
|
|
324
|
+
</div>
|
|
101
325
|
</div>
|
|
102
326
|
</header>
|
|
103
327
|
</template>
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
|
+
* Portions Copyright The Android Open Source Project, licensed under the Apache License, Version 2.0
|
|
3
|
+
* (dist/THIRD_PARTY_LICENSES.md). Translated from Kotlin to TypeScript and modified for this library.
|
|
4
|
+
*
|
|
2
5
|
* Port of the Compose Material3 carousel engine (androidx compose/material3/carousel:
|
|
3
6
|
* Arrangement.kt, KeylineList.kt, Keylines.kt, Strategy.kt, KeylineSnapPosition.kt), kept close to
|
|
4
7
|
* the original so it can be diffed against upstream. Pure functions, no DOM: MCarousel feeds it the
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Internal (not exported from index.ts): what MAppBarWithSearch hands the MSearchBar inside it
|
|
2
|
+
import type { InjectionKey, Ref } from 'vue'
|
|
3
|
+
|
|
4
|
+
export interface SearchAppBarContext {
|
|
5
|
+
/** Content is scrolled under the app bar: the search bar takes its scrolled container color */
|
|
6
|
+
scrolled: Ref<boolean>
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const searchAppBarKey: InjectionKey<SearchAppBarContext> = Symbol('m-search-app-bar')
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// role of the active palette, dark mode and seed included. Started by createM3UI({ themeColor }).
|
|
3
3
|
|
|
4
4
|
let observer: MutationObserver | undefined
|
|
5
|
+
// useColorPalette's <style> for generated palettes
|
|
6
|
+
const PALETTE_STYLE_ID = 'm3-dynamic-palette'
|
|
5
7
|
|
|
6
8
|
function metas(): HTMLMetaElement[] {
|
|
7
9
|
const found = Array.from(document.querySelectorAll<HTMLMetaElement>('meta[name="theme-color"]'))
|
|
@@ -26,8 +28,13 @@ export function syncThemeColor(role: string) {
|
|
|
26
28
|
if (typeof document === 'undefined') return
|
|
27
29
|
observer?.disconnect()
|
|
28
30
|
update(role)
|
|
29
|
-
// Palette (data-palette),
|
|
30
|
-
// a
|
|
31
|
-
|
|
32
|
-
observer
|
|
31
|
+
// Palette (data-palette), contrast (data-contrast) and dark mode (class) land on <html>; a generated palette
|
|
32
|
+
// (a seed, or the same seed at another contrast) only rewrites the <style> it lives in, inside <head>
|
|
33
|
+
const isPaletteStyle = (node: Node | null) => (node instanceof Element ? node : node?.parentElement)?.id === PALETTE_STYLE_ID
|
|
34
|
+
observer = new MutationObserver((records) => {
|
|
35
|
+
if (records.some((r) => r.target === document.documentElement || isPaletteStyle(r.target)
|
|
36
|
+
|| Array.from(r.addedNodes).some(isPaletteStyle))) update(role)
|
|
37
|
+
})
|
|
38
|
+
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['class', 'data-palette', 'data-contrast'] })
|
|
39
|
+
observer.observe(document.head, { childList: true, characterData: true, subtree: true })
|
|
33
40
|
}
|