skip section navigation

Carousel

Carousel puts illustrated choices in a horizontally scrolling row. use selection to update your app, then let the arrows move through choices that don’t fit on screen.

Selected flavor: field notes

usage

svelte
<script>
	import { Carousel } from '@ciabi/loafkit-ui';
	import alabastaArt from '$lib/assets/flavorartwork/alabasta.jpg';
	import romanceDawnArt from '$lib/assets/flavorartwork/romance-dawn.webp';
	import elbafArt from '$lib/assets/flavorartwork/elbaf.jpg';
	const items = [
		{ title: 'weekend reads', description: 'a few things to come back to', imageSrc: alabastaArt },
		{ title: 'field notes', description: 'small details worth keeping', imageSrc: romanceDawnArt },
		{ title: 'new arrivals', description: 'fresh additions to the shelf', imageSrc: elbafArt }
	];
	let selected = $state('field notes');
</script>

<Carousel id="collection-topics" defaultSelected={1} {items} onSelect={item => selected = item.title} />
<p role="status">Selected flavor: {selected}</p>

items and selection

choose an item to change the active choice. scrolling alone keeps the current selection.

this isn’t a bindable selected-value API. keep a separate app value when the chosen item affects something else. use a stable items array and a valid starting index.

API reference

Component
id

unique carousel ID.

items
Default: []

illustrated choices in the scrolling row.

onSelect

called with the item when a choice is selected.

defaultSelected
Default: 0

the initial selected item index.

class
Default: ''

extra classes on the outer carousel.

style

inline styles on the outer carousel.

Type

one item in Carousel.items.

title

the visible choice title.

description

supporting text for the choice.

imageSrc

optional choice image.