Extra
Carousel
A FormaUI carousel — a horizontally scrolling, snapping strip of items — one entry point covering both Material 3 horizontal carousel families (multi-browse and uncontained) via a variant enum, with hoisted M3 CarouselState and an indexed item slot.
dev.formaui.components.carousel
Preview
This toggle is site chrome only — the preview has its own light/dark switch inside.
Live preview
Live preview — ~37 MB development build
Usage
val state = rememberCarouselState(itemCount = { photos.size })
FormaCarousel(
state = state,
itemWidth = 220.dp,
modifier = Modifier.height(200.dp),
) { index ->
Image(
painter = photos[index].painter,
contentDescription = photos[index].description,
modifier = Modifier.fillMaxSize().maskClip(FormaTheme.shapes.lg),
contentScale = ContentScale.Crop,
)
}FormaCarousel
One entry point for both M3 horizontal carousels; a single itemWidth maps to preferredItemWidth (MultiBrowse) or the exact itemWidth (Uncontained), with an opinionated default item spacing and per-variant default fling.
Supporting API
- FormaCarouselVariantenum
- Layout strategy of a FormaCarousel: MultiBrowse (default; flexing large/medium/small items), Uncontained (every item keeps the exact width).
- FormaCarouselDefaultsobject
- Defaults for FormaCarousel: itemSpacing (FormaTheme.spacing.xs — a small opinionated gap, vs Material 3's 0.dp).
- rememberCarouselStatefunction (Material 3)
- The component defines no state type of its own — callers create and own the state via Material 3's rememberCarouselState(initialItem, itemCount).
Accessibility
The carousel is a horizontally scrollable container; supply a meaningful contentDescription on each item's own content (e.g. the Image inside the slot). Material 3 handles the scroll/snap semantics.