Command palette

@yasinsensoy/web

Web · Components

Carousel

Scrolling slideshow: from a single image to product strips, from story-style intros to a seamless logo ticker.

9 exports

Live example

Preview

Code

import { Carousel, Image } from "@yasinsensoy/web";

<Carousel loop indicatorsPlacement="inside">
  {fotograflar.map((f) => (
    <Image key={f.id} src={f.src} alt={f.name} ratio={16 / 9} />
  ))}
</Carousel>

Events

  1. Events appear here when you interact with the preview.

Seamless loop: keep swiping past the end

Story style: bars fill up, holding pauses

Product strip: 1.5 / 3 / 4 cards by width, page by page

1 of 11

Logo stream (marquee): slows to a stop on hover, draggable

Controlled from outside (ref) and a custom active state

ref.current.next()

Import

import { Carousel } from "@yasinsensoy/web";

Value that changes with the container width: a single value or a { min_width_px: value } object. Breakpoints look at the carousel's own width, not the screen (container query), so it works correctly in a sidebar and on a full page, and renders correctly on the server.

type ResponsiveValue = T | { readonly [minWidth: number]: T; }

Examples

slidesPerView={{ 0: 1.2, 640: 2, 1024: 4 }}

Slide transition look.

  • "slide": slides side by side.
  • "fade": stacked, cross-fading while dragging (one slide).
  • "scale": slides; slides moving away from the center shrink and fade.
  • Function: called every frame for each slide; receives the slide's distance from its aligned position (in slides, signed: -1 the previous, 0.5 halfway) and returns the style for the inner box.
type CarouselEffect = "slide" | "fade" | "scale" | ((distance: number) => CSSProperties)

Indicators.

  • "dots": dots; the active one stretches (fills during autoplay).
  • "lines": story-style lines; the active line fills during autoplay.
  • "count": a 3 / 8 counter.
  • "thumbnails": a thumbnail strip (with thumbnails).
  • false: none.
type CarouselIndicators = "dots" | "lines" | "count" | "thumbnails" | false

Autoplay settings.

NameTypeDefaultDescription
delay?number5000Time spent on a slide (ms).
pauseOnHover?booleantruePauses while the pointer is over it.
stopOnInteraction?booleanfalseStops permanently when the user drags or presses an arrow or a dot (restarts with the play button). With false only the timer restarts.

For controlling Carousel from outside (ref).

NameTypeDescription
next() => voidNext slide(s). In a loop it moves seamlessly from the last to the first slide.
prev() => voidPrevious slide(s).
goTo(index: number, options?: { instant?: boolean; }) => voidGo to a slide; without animation with instant.
play() => voidStart autoplay.
pause() => voidStop autoplay.
indexnumberSelected slide.

Classes added to the parts.

NameTypeDescription
viewport?stringThe visible (clipping) area.
track?stringTrack carrying the slides.
slide?stringBox of each slide.
arrow?stringArrow buttons.
indicators?stringIndicator bar.

CarouselProps

interface

Props of the Carousel component.

NameTypeDefaultDescription
childrenReactNodeSlides: every top-level child is a slide.
label?string"Karusel"Screen reader name.
loop?booleanfalseInfinite loop. Keep scrolling after the last slide and the first slide comes right after it; the track never rewinds or jumps to the start. Arrows, autoplay, wheel and dragging work the same way. Slides are cloned automatically when there aren't enough to fill the area.
slidesPerView?ResponsiveValue<number | "auto">1Number of visible slides. Can be fractional (1.2 shows the edge of the next one). "auto": every slide has its own width. See ResponsiveValue.
gap?ResponsiveValue<number | string>16Gap between slides: px or a CSS length.
align?CarouselAlign"start"Alignment of a slide in the visible area.
step?number | "page"1How many slides one move advances; "page" as many as are visible.
orientation?"horizontal" | "vertical""horizontal"Direction. height must be given for vertical.
height?number | stringHeight of a vertical carousel: px or a CSS length.
index?numberSelected slide in controlled use.
defaultIndex?number0First slide in uncontrolled use.
onIndexChange?(index: number) => voidCalled when the selected slide changes (also while dragging).
onSettle?(index: number) => voidCalled when motion ends and the slide settles.
autoplay?boolean | number | CarouselAutoplayAutoplay: true, a delay (ms) or settings. Pauses while hovered, on keyboard focus, while dragging, while the tab is hidden and while the carousel is off screen. A play/pause button is added. Starts paused when "reduce motion" is on. See CarouselAutoplay.
marquee?boolean | numberContinuous flow (logo/news ticker): the track scrolls constantly at this speed (px/s); negative values go the other way. true = 40. Turns the loop on automatically; draggable, returns to flowing on release; slows to a stop on hover.
effect?CarouselEffect"slide"Transition look. See CarouselEffect.
arrows?boolean | "always"truePrevious/next arrows. true: visible on mouse hover, hidden on touch (swipe instead). "always": always visible.
indicators?CarouselIndicators"dots"Indicators. See CarouselIndicators.
indicatorsPlacement?"inside" | "outside""outside"Whether the indicators are over the slide ("inside") or below it.
thumbnails?readonly (string | ReactNode)[]Thumbnails (indicators="thumbnails"): a URL or an element, in slide order.
draggable?booleantrueDraggable with mouse and touch.
snap?booleantrueSnaps to slides. false: scrolls freely and glides to a slow stop on release.
skipSnaps?booleanfalseA fast flick can skip multiple slides.
wheel?booleantrueScrolling with the touchpad and a horizontal wheel (a vertical wheel keeps scrolling the page; Shift+wheel scrolls the carousel).
rewind?booleanfalseWithout a loop, the arrow at an edge goes to the other end (rewinds). Autoplay without a loop always returns to the start at the end.
duration?number500Approximate duration of the settle animation (ms).
ref?Ref<CarouselHandle>Control from outside. See CarouselHandle.
className?stringClasses added to the root element.
classNames?CarouselClassNamesClasses added to the parts. See CarouselClassNames.
style?CSSPropertiesStyle of the root element.

Where a slide aligns within the visible area.

type CarouselAlign = "start" | "center" | "end"