Carousel
Added in alpha.11
Included in Mavis 0.1.0-alpha.11 for Vue + Vite, Nuxt and NativeScript iOS/Android. Keep core and renderers on the same version.
<MCarousel
v-model="current"
:items="slides"
itemKey="id"
label="Stories"
><template #default="{ item }">…</template></MCarousel>| Prop | Type | Default | Description |
|---|---|---|---|
items / itemKey | readonly T[] / string or function | required / id | Slides with unique stable keys. |
modelValue / v-model | ChoiceValue or null | null | Active slide key; absent or removed selection displays the first. |
loop / disabled | boolean | false | Wrap around the ends; disable interaction. |
previousLabel / nextLabel / slideLabel / emptyLabel | string | Previous slide / Next slide / Slide / No slides | Localizable labels. |
gesture | MotionGesture | — | Experimental. Receives the current slide swipe, for gesture relations. |
Buttons, indicators, Web arrow keys and horizontal swipe change slides. Jolt animates entry and respects reduced motion. There is no autoplay. Only the active slide is mounted; keep drafts in the application by key. The slot receives item, index and itemKey. Web controls inside a slide do not start swipes, and vertical scrolling remains available. Give slides stable geometry to avoid layout jumps. Indicators are intended for small collections such as onboarding and featured stories.
Feel
A slide follows the finger and, once released past the threshold, the next one comes in from that side with a little depth: it starts slightly smaller and grows into place. A faster flick sends it in from further away, so a quick swipe feels quicker than a slow one. Without loop, the first and last slides resist being pulled toward a slide that does not exist and spring back. The counter rolls toward the direction you moved. All of this follows reading direction in right-to-left layouts, and under reduced motion the slide and counter change without travel. The active key, the counter text and its announcement change at once; the motion is decoration.
There is still no autoplay. Only the active slide is mounted, which is why neighboring slides do not peek in during the drag.
<script setup lang="ts">
import { computed, ref } from 'vue'
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)
import type { ChoiceValue } from '@getcortexlabs/mavis-core'
const current = ref<ChoiceValue>('explore')
const slides = computed(() => [
{
id: 'explore',
icon: 'compass' as const,
eyebrow: t('01 / EXPLORE', '01 / EXPLORE'),
title: t('Take the scenic route.', 'Escolha o caminho mais bonito.'),
detail: t(
'Small detours. Unexpected discoveries.',
'Pequenos desvios. Descobertas inesperadas.',
),
},
{
id: 'collect',
icon: 'layers' as const,
eyebrow: t('02 / COLLECT', '02 / GUARDE'),
title: t('Keep what moves you.', 'Guarde o que te inspira.'),
detail: t(
'Your favorite places, together at last.',
'Seus lugares favoritos, juntos por aqui.',
),
},
{
id: 'share',
icon: 'sparkles' as const,
eyebrow: t('03 / SHARE', '03 / COMPARTILHE'),
title: t('Good things travel.', 'Coisas boas vão mais longe.'),
detail: t('Make room for someone new.', 'Abra espaço para novas companhias.'),
},
])
</script>
<template>
<MCarousel
v-model="current"
:items="slides"
:label="t('A little inspiration', 'Um pouco de inspiração')"
>
<template #default="{ item }"
><MCard padding="xl" gap="lg" :height="340">
<MRow justify="between"
><MText :text="item.eyebrow" variant="overline" tone="primary" /><MIcon
:name="item.icon"
:size="32"
tone="primary"
/></MRow>
<MColumn :grow="1" justify="center" gap="md"
><MText :text="item.title" variant="title" /><MText :text="item.detail" tone="muted"
/></MColumn>
<MRow gap="sm"
><MBadge :text="t('Curated for you', 'Feito para você')" tone="primary" /><MText
text="✦"
tone="primary"
/></MRow> </MCard
></template>
</MCarousel>
<MText id="carousel-value" :text="String(current)" variant="caption" tone="muted" />
</template>On desktop, a horizontal drag can start over a button inside the slide. A click still activates the button. Once the gesture becomes a drag, releasing it turns the slide and suppresses the button click.
Desktop
On the Mac and on Windows the slides turn with the buttons, a sideways drag of at least 40 points, or the arrow keys, Home and End on the page indicators. gesture is accepted and has no effect there. See Desktop components.