# @salmonui/navigation/carousel API reference

> 18 exported symbols of @salmonui/navigation/carousel: 2 functions, 11 interfaces, 4 types and 1 constant.

Canonical: https://salmonui.dev/docs/reference/navigation/carousel

```ts
import { … } from '@salmonui/navigation/carousel';
```

## Functions

### Carousel

Kind: function

Page: https://salmonui.dev/docs/reference/navigation/carousel/Carousel

```ts
function Carousel(props: CarouselProps): ReactElement;
```

Carousel (APG Carousel). `ref` is a `CarouselApi`. Styling hooks:
`.salmon-carousel` with `data-effect`, `data-controls`, `data-peek`,
`data-playing`, `data-ready` (after mount); parts `-viewport`, `-track`,
`-slide` (`data-active`, `data-position`), `-previous`, `-next`, `-play`,
`-indicators` (`data-type`), `-indicator`, `-progress`.

### CarouselSlide

Kind: function

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselSlide

```ts
function CarouselSlide(props: CarouselSlideProps): ReactElement;
```

One slide: `role="group"`, `aria-roledescription="slide"`, named "N of M".

## Interfaces

### CarouselApi

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselApi

```ts
interface CarouselApi {
    readonly element: HTMLElement | null;
    readonly index: number;
    readonly playing: boolean;
    next(): void;
    previous(): void;
    goTo(index: number): void;
    play(): void;
    pause(): void;
}
```

The `ref` instance.

Members (8):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `element` | `readonly element: HTMLElement \| null;` |  |  |
| `index` | `readonly index: number;` |  |  |
| `playing` | `readonly playing: boolean;` |  |  |
| `next` | `next(): void;` |  |  |
| `previous` | `previous(): void;` |  |  |
| `goTo` | `goTo(index: number): void;` |  |  |
| `play` | `play(): void;` |  |  |
| `pause` | `pause(): void;` |  |  |

### CarouselAutoPlay

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselAutoPlay

```ts
interface CarouselAutoPlay {
    readonly interval?: number | undefined;
    readonly pauseOnHover?: boolean | undefined;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `interval` | `readonly interval?: number \| undefined;` | optional | Milliseconds per slide. Default 5000; a slide's `interval` wins. |
| `pauseOnHover` | `readonly pauseOnHover?: boolean \| undefined;` | optional | Pause while a mouse pointer is over the carousel. Default `true`. |

### CarouselBeforeIndexChangeEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselBeforeIndexChangeEvent

```ts
interface CarouselBeforeIndexChangeEvent extends CarouselIndexChangeEvent {
    preventDefault(): void;
    readonly defaultPrevented: boolean;
}
```

`onBeforeIndexChange` event: `preventDefault()` keeps the current slide.

Members (5):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `preventDefault` | `preventDefault(): void;` |  |  |
| `defaultPrevented` | `readonly defaultPrevented: boolean;` |  |  |
| `index` | `index: number;` | inherited |  |
| `previousIndex` | `previousIndex: number;` | inherited |  |
| `source` | `source: CarouselChangeSource;` | inherited |  |

### CarouselButtonContext

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselButtonContext

```ts
interface CarouselButtonContext {
    readonly disabled: boolean;
    readonly label: string;
    go(event?: SourceEvent): void;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `disabled` | `readonly disabled: boolean;` |  |  |
| `label` | `readonly label: string;` |  |  |
| `go` | `go(event?: SourceEvent): void;` |  |  |

### CarouselIndexChangeEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselIndexChangeEvent

```ts
interface CarouselIndexChangeEvent {
    readonly index: number;
    readonly previousIndex: number;
    readonly source: CarouselChangeSource;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `index` | `readonly index: number;` |  |  |
| `previousIndex` | `readonly previousIndex: number;` |  |  |
| `source` | `readonly source: CarouselChangeSource;` |  |  |

### CarouselIndicatorContext

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselIndicatorContext

```ts
interface CarouselIndicatorContext {
    readonly index: number;
    readonly selected: boolean;
    readonly label: string;
    go(event?: SourceEvent): void;
}
```

Members (4):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `index` | `readonly index: number;` |  |  |
| `selected` | `readonly selected: boolean;` |  |  |
| `label` | `readonly label: string;` |  |  |
| `go` | `go(event?: SourceEvent): void;` |  |  |

### CarouselLocaleText

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselLocaleText

```ts
interface CarouselLocaleText {
    readonly carousel: string;
    readonly slide: string;
    readonly slideLabel: (index: number, total: number, label?: string) => string;
    readonly previous: string;
    readonly next: string;
    readonly play: string;
    readonly pause: string;
    readonly indicators: string;
    readonly indicator: (index: number, total: number, label?: string) => string;
    readonly fraction: (index: number, total: number) => string;
}
```

Static texts; every value has a default in `CAROUSEL_DEFAULT_LOCALE_TEXT`.

Members (10):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `carousel` | `readonly carousel: string;` |  | `aria-roledescription` of the root. |
| `slide` | `readonly slide: string;` |  | `aria-roledescription` of each slide. |
| `slideLabel` | `readonly slideLabel: (index: number, total: number, label?: string) => string;` |  | Accessible name of a slide ("1 of 5"); `label` is the slide's own label. |
| `previous` | `readonly previous: string;` |  |  |
| `next` | `readonly next: string;` |  |  |
| `play` | `readonly play: string;` |  |  |
| `pause` | `readonly pause: string;` |  |  |
| `indicators` | `readonly indicators: string;` |  | Name of the indicator group. |
| `indicator` | `readonly indicator: (index: number, total: number, label?: string) => string;` |  |  |
| `fraction` | `readonly fraction: (index: number, total: number) => string;` |  |  |

### CarouselPlayButtonContext

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselPlayButtonContext

```ts
interface CarouselPlayButtonContext {
    readonly playing: boolean;
    readonly label: string;
    toggle(event?: SourceEvent): void;
}
```

Members (3):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `playing` | `readonly playing: boolean;` |  |  |
| `label` | `readonly label: string;` |  |  |
| `toggle` | `toggle(event?: SourceEvent): void;` |  |  |

### CarouselPlayingChangeEvent

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselPlayingChangeEvent

```ts
interface CarouselPlayingChangeEvent {
    readonly source: 'pointer' | 'keyboard' | 'autoPlay' | 'api' | 'reducedMotion';
}
```

Members (1):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `source` | `readonly source: 'pointer' \| 'keyboard' \| 'autoPlay' \| 'api' \| 'reducedMotion';` |  |  |

### CarouselProps

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselProps

```ts
interface CarouselProps extends Omit<HTMLAttributes<HTMLElement>, 'children'> {
    children?: ReactNode;
    index?: number | undefined;
    defaultIndex?: number | undefined;
    onIndexChange?: ((index: number, event: CarouselIndexChangeEvent) => void) | undefined;
    onBeforeIndexChange?: ((event: CarouselBeforeIndexChangeEvent) => void) | undefined;
    autoPlay?: boolean | CarouselAutoPlay | undefined;
    playing?: boolean | undefined;
    defaultPlaying?: boolean | undefined;
    onPlayingChange?: ((playing: boolean, event: CarouselPlayingChangeEvent) => void) | undefined;
    loop?: boolean | undefined;
    effect?: CarouselEffect | undefined;
    peek?: boolean | string | undefined;
    controls?: CarouselControls | undefined;
    indicators?: CarouselIndicators | false | undefined;
    renderPreviousButton?: ((ctx: CarouselButtonContext) => ReactNode) | undefined;
    renderNextButton?: ((ctx: CarouselButtonContext) => ReactNode) | undefined;
    renderPlayButton?: ((ctx: CarouselPlayButtonContext) => ReactNode) | undefined;
    renderIndicator?: ((ctx: CarouselIndicatorContext) => ReactNode) | undefined;
    localeText?: Partial<CarouselLocaleText> | undefined;
    ref?: Ref<CarouselApi> | undefined;
}
```

Members (20):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `children` | `children?: ReactNode;` | optional | `CarouselSlide` elements. |
| `index` | `index?: number \| undefined;` | optional | Selected slide (controlled). |
| `defaultIndex` | `defaultIndex?: number \| undefined;` | optional | Initial slide (uncontrolled). Default 0. |
| `onIndexChange` | `onIndexChange?: ((index: number, event: CarouselIndexChangeEvent) => void) \| undefined;` | optional |  |
| `onBeforeIndexChange` | `onBeforeIndexChange?: ((event: CarouselBeforeIndexChangeEvent) => void) \| undefined;` | optional | Synchronous; `event.preventDefault()` cancels the change. |
| `autoPlay` | `autoPlay?: boolean \| CarouselAutoPlay \| undefined;` | optional | Automatic rotation. Default `false`. A play/pause button is always shown while on. |
| `playing` | `playing?: boolean \| undefined;` | optional | Whether auto-play runs (controlled). |
| `defaultPlaying` | `defaultPlaying?: boolean \| undefined;` | optional | Initial `playing`. Default `true` when `autoPlay` is on, unless the user prefers reduced motion. |
| `onPlayingChange` | `onPlayingChange?: ((playing: boolean, event: CarouselPlayingChangeEvent) => void) \| undefined;` | optional |  |
| `loop` | `loop?: boolean \| undefined;` | optional | Past the last slide comes the first (jump back, no clones). Default `true`. |
| `effect` | `effect?: CarouselEffect \| undefined;` | optional | Default `'slide'`; reduced motion behaves as `'none'`. |
| `peek` | `peek?: boolean \| string \| undefined;` | optional | Previous and next slides peek in; a string sets the peek width (CSS length). |
| `controls` | `controls?: CarouselControls \| undefined;` | optional | Previous / next buttons. Default `'visible'`; `'hover'` also shows on focus and on touch devices. |
| `indicators` | `indicators?: CarouselIndicators \| false \| undefined;` | optional | Default `'dots'`. |
| `renderPreviousButton` | `renderPreviousButton?: ((ctx: CarouselButtonContext) => ReactNode) \| undefined;` | optional |  |
| `renderNextButton` | `renderNextButton?: ((ctx: CarouselButtonContext) => ReactNode) \| undefined;` | optional |  |
| `renderPlayButton` | `renderPlayButton?: ((ctx: CarouselPlayButtonContext) => ReactNode) \| undefined;` | optional |  |
| `renderIndicator` | `renderIndicator?: ((ctx: CarouselIndicatorContext) => ReactNode) \| undefined;` | optional | Replaces each `'dots'` / `'dynamic'` indicator button. |
| `localeText` | `localeText?: Partial<CarouselLocaleText> \| undefined;` | optional |  |
| `ref` | `ref?: Ref<CarouselApi> \| undefined;` | optional |  |

### CarouselSlideProps

Kind: interface

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselSlideProps

```ts
interface CarouselSlideProps extends HTMLAttributes<HTMLDivElement> {
    label?: string | undefined;
    interval?: number | undefined;
}
```

Members (2):

| Name | Signature | Flags | Description |
| --- | --- | --- | --- |
| `label` | `label?: string \| undefined;` | optional | Prepended to the "N of M" slide name and used by the indicator name. |
| `interval` | `interval?: number \| undefined;` | optional | Auto-play milliseconds for this slide. |

## Types

### CarouselChangeSource

Kind: type

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselChangeSource

```ts
type CarouselChangeSource = 'pointer' | 'keyboard' | 'autoPlay' | 'scroll' | 'api';
```

What moved the carousel.

### CarouselControls

Kind: type

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselControls

```ts
type CarouselControls = 'visible' | 'hover' | 'hidden';
```

### CarouselEffect

Kind: type

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselEffect

```ts
type CarouselEffect = 'slide' | 'fade' | 'none';
```

### CarouselIndicators

Kind: type

Page: https://salmonui.dev/docs/reference/navigation/carousel/CarouselIndicators

```ts
type CarouselIndicators = 'dots' | 'dynamic' | 'fraction' | 'progress';
```

## Constants

### CAROUSEL_DEFAULT_LOCALE_TEXT

Kind: const

Page: https://salmonui.dev/docs/reference/navigation/carousel/CAROUSEL_DEFAULT_LOCALE_TEXT

```ts
const CAROUSEL_DEFAULT_LOCALE_TEXT: CarouselLocaleText;
```
