CollapsibleHeader
Incluído na RC.12
Disponível no Mavis 0.1.0-rc.12 para Vue + Vite, Nuxt e NativeScript. Mantenha os pacotes Mavis na mesma versão.
<MCollapsibleHeader title="Field notes" :image="cover" :height="540">
<MColumn padding="lg"><Stories /></MColumn>
</MCollapsibleHeader>| Prop | Type | Default | Contract |
|---|---|---|---|
title / subtitle / image | string | — | Título, texto de apoio e imagem decorativa opcional. |
height / expandedHeight / collapsedHeight | number | 540 / 240 / 64 | Altura finita; expanded deve superar collapsed, que deve ser positivo. |
parallax / sectionHeight | number | 0.35 / 0 | Fração de parallax entre 0 e 1 e altura da seção fixa. |
back / backLabel / topLabel | boolean / string | false / Go back / Back to top | Ação de retorno opcional e controles traduzíveis. |
Cabeçalho com imagem e duas apresentações do título. O conteúdo rola em uma região com altura definida; o componente não cria uma Page nativa. Use dentro de MScreen, evitando dar a esta região e ao pai a mesma responsabilidade de rolagem. Jolt controla colapso, parallax e limpeza. Slots: default, artwork, leading, actions e section. Ao usar section, defina sectionHeight com a altura da composição. O evento back pertence à aplicação; o botão de topo retorna esta região ao início.
Passe chaves de texto estáveis em itemKeys e renderize cada linha no slot #item="{ itemKey, index }". Para inserir no início, use preserveAnchor(change) na referência do componente. Durante uma atualização, context.commit(change) já preserva a linha visível. Ao trocar de feed, mude sourceKey para cancelar a requisição anterior e voltar ao topo.
Linhas adicionadas depois da primeira renderização chegam em sequência enquanto a linha visível mantém o lugar; com movimento reduzido, a entrada é omitida. O botão Voltar ao topo fica esmaecido com o cabeçalho expandido e ganha força total à medida que ele recolhe, acompanhando a rolagem só com opacidade.
Com movimento reduzido, a estrutura continua funcionando: o cabeçalho, a troca de título e a seção fixa seguem a rolagem, porque indicam onde está o conteúdo, enquanto o parallax da imagem e a chegada das linhas assentam. Na Web o cabeçalho segue a configuração efetiva da região em volta, então uma região do app configurada com configureMavisWebMotion(region, { reducedMotion: 'always' }) assenta o parallax mesmo quando o sistema permite movimento, e 'never' o mantém. Todas as ligações do cabeçalho (colapso, seção fixa, Voltar ao topo) leem a mesma fonte de rolagem; redimensionar o cabeçalho ou trocar sourceKey refaz as ligações sem acrescentar observadores. Na demonstração, a troca de roteiro muda sourceKey: o feed que sai volta ao topo, encerra sua transação de âncora, e o novo feed liga o cabeçalho de novo.
<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
Nos hosts de desktop, o cabeçalho, a troca de título e a seção fixa acompanham a rolagem do conteúdo como nos outros hosts, e o parallax da imagem assenta quando o sistema reduz o movimento. Voltar ao topo e scrollToTop movem a view de rolagem nativa. Veja Componentes de desktop.