CollapsibleHeader
Included in RC.12
Available in Mavis 0.1.0-rc.12 for Vue + Vite, Nuxt and NativeScript. Keep the Mavis packages at the same version.
<MCollapsibleHeader title="Field notes" :image="cover" :height="540">
<MColumn padding="lg"><Stories /></MColumn>
</MCollapsibleHeader>| Prop | Type | Default | Contract |
|---|---|---|---|
title / subtitle / image | string | — | Heading, supporting text and optional decorative artwork. |
height / expandedHeight / collapsedHeight | number | 540 / 240 / 64 | Finite region height; expanded must exceed collapsed, which must be positive. |
parallax / sectionHeight | number | 0.35 / 0 | Parallax fraction 0–1 and pinned section height. |
back / backLabel / topLabel | boolean / string | false / Go back / Back to top | Opt-in back action and translatable controls. |
A retained scroll header with artwork and two title presentations. The content scrolls inside a bounded region; this component does not create a native Page. Use inside MScreen, and avoid giving this region and its parent the same scrolling responsibility. Jolt owns collapse, parallax and cleanup. Slots: default, artwork, leading, actions and section. When using section, set sectionHeight to its measured design height. The back event belongs to the application; the top button returns this region to its beginning.
Pass stable string keys through itemKeys and render each row in #item="{ itemKey, index }". Use the component handle’s preserveAnchor(change) for prepends. A refresh already preserves the visible row when you update the feed inside context.commit(change). When switching feeds, change sourceKey to cancel the outgoing request and reset the scroll position.
Rows added after the first render arrive in sequence while the visible row keeps its place; reduced motion skips the arrival. The Back to top button stays dimmed while the header is expanded and wakes to full strength as it collapses, following the scroll with opacity only.
Reduced motion keeps the structure working: the header, title handoff and pinned section still follow the scroll, because they are where the content is, while the artwork parallax and row arrivals settle. On Web the header follows the effective setting of the region around it, so an app region configured with configureMavisWebMotion(region, { reducedMotion: 'always' }) settles the parallax even when the system allows motion, and 'never' keeps it. Every link in the header (collapse, pinned section, Back to top) reads the same scroll source; resizing the header or switching sourceKey rebinds them without adding observers. In the demo, the itinerary switch changes sourceKey: the outgoing feed returns to the top, its anchor transaction ends, and the new feed binds its header again.
<script setup lang="ts">
import { computed, ref } from 'vue'
import { coast, mountains } from '../atlas/photos'
import { useCatalogLocale } from '../locale'
const props = defineProps<{ lang?: 'en' | 'pt' }>()
const { locale } = useCatalogLocale(() => props.lang)
const pt = computed(() => (props.lang ?? locale.value) === 'pt')
const t = (en: string, br: string) => (pt.value ? br : en)
type Route = 'mountains' | 'coast'
const routes = {
mountains: {
title: ['Above the everyday.', 'Acima da rotina.'],
subtitle: ['A slower kind of escape', 'Uma pausa em outro ritmo'],
image: mountains,
names: [
['First light', 'Primeira luz'],
['The hidden trail', 'A trilha escondida'],
['Lunch with a view', 'Almoço com vista'],
['An afternoon outside', 'Uma tarde lá fora'],
['The blue hour', 'A hora azul'],
['A place to return', 'Um lugar para voltar'],
],
},
coast: {
title: ['Where the tide turns.', 'Onde a maré vira.'],
subtitle: ['Salt air and slow mornings', 'Maresia e manhãs sem pressa'],
image: coast,
names: [
['Low tide walk', 'Caminhada na maré baixa'],
['The lighthouse path', 'O caminho do farol'],
['Fish market lunch', 'Almoço no mercado de peixe'],
['A swim before sunset', 'Um mergulho antes do pôr do sol'],
['Harbour lights', 'Luzes do porto'],
['A place to return', 'Um lugar para voltar'],
],
},
} as const
const route = ref<Route>('mountains')
const current = computed(() => routes[route.value])
const large = ref(false)
const header = ref<{ preserveAnchor(change: () => void): Promise<void> }>()
const stops = ref(['1', '2', '3', '4', '5', '6'])
const inserting = ref(false)
function choose(value: Route) {
route.value = value
stops.value = ['1', '2', '3', '4', '5', '6']
}
async function prepend() {
if (!header.value || inserting.value) return
inserting.value = true
try {
await header.value.preserveAnchor(() => {
stops.value = [String(stops.value.length + 1), ...stops.value]
})
} finally {
inserting.value = false
}
}
const name = (key: string) => {
const [en, br] = current.value.names[(Number(key) - 1) % 6]!
return t(en, br)
}
</script>
<template>
<MColumn gap="md">
<MText text="FIELD NOTES / 01" variant="overline" tone="primary" />
<MSegmentedControl
:modelValue="route"
:options="[
{ value: 'mountains', label: t('Mountains', 'Montanhas') },
{ value: 'coast', label: t('Coast', 'Litoral') },
]"
:label="t('Itinerary', 'Roteiro')"
@update:modelValue="(value) => choose(value as Route)"
/>
<MCollapsibleHeader
ref="header"
:itemKeys="stops"
:sourceKey="route"
:title="t(current.title[0], current.title[1])"
:subtitle="t(current.subtitle[0], current.subtitle[1])"
:image="current.image"
:height="560"
:expandedHeight="large ? 310 : 240"
:sectionHeight="48"
:topLabel="t('Back to top', 'Voltar ao topo')"
>
<template #section
><MRow paddingX="md" align="center" justify="between"
><MText :text="t('THE ITINERARY', 'O ROTEIRO')" variant="overline" /><MBadge
:text="String(stops.length).padStart(2, '0')" /></MRow
></template>
<template #default
><MColumn padding="lg" gap="lg">
<MText
:text="t('Less rush. More horizon.', 'Menos pressa. Mais horizonte.')"
variant="heading"
/> </MColumn
></template>
<template #item="{ itemKey }"
><MColumn paddingX="lg" paddingY="sm"
><MCard :id="'stop-' + itemKey" gap="sm">
<MText
:text="`${itemKey.padStart(2, '0')} / ${t('EXPLORE', 'EXPLORAR')}`"
variant="overline"
tone="primary"
/>
<MText :text="name(itemKey)" variant="heading" />
<MText
:text="
t(
'Leave a little room for whatever the day brings.',
'Deixe um espaço para o que o dia trouxer.',
)
"
tone="muted"
/>
</MCard> </MColumn
></template>
</MCollapsibleHeader>
<MButton
:text="t('Insert a stop', 'Inserir uma parada')"
:disabled="inserting"
variant="secondary"
@click="prepend"
/>
<MButton
:text="t('Change header size', 'Mudar tamanho do cabeçalho')"
variant="secondary"
@click="large = !large"
/>
</MColumn>
</template>Desktop
On the desktop hosts the header, the title handoff and the pinned section follow the scroll offset of the content, as on the other hosts, and the artwork parallax settles when the system reduces motion. Back to top and scrollToTop move the native scroll view. See Desktop components.