All components
MotionPager
Swipeable pages from data: onboarding, carousels and tab panels.
WebReact NativeSelection and paging
Try it
Shortest usage
Onboarding.jsx<MotionPager
items={slides}
index={page}
onIndexChange={setPage}
gap={16}
renderItem={(slide) => <Slide slide={slide} />}
/>;
What it handles for you
- Pages follow swipes and mouse drags, resist past the ends and settle with your release speed.
- A flick always turns a page, and one gesture never turns more than one.
- Horizontal trackpad scrolling turns pages too, and its momentum tail is ignored.
- Arrow keys, Home and End work when the pager is focused, and vertical scrolling keeps working.
- Pages other than the active one are inert.
Use it for
- An onboarding flow.
- A photo carousel.
- Swipeable tab panels paired with
MotionHighlight.
Props
| Prop | Type | Default | Description |
|---|
items | readonly T[] | —required | Your data array. |
|---|
index | number | | The page shown. Leave it out to let the pager keep its own. |
|---|
defaultIndex | number | 0 | Starting page when index is not controlled. |
|---|
onIndexChange | (index, item) => void | | Runs with the index and item as soon as a swipe, key or wheel gesture settles. |
|---|
getKey | (item) => string | number | item.id | Returns a unique, stable key for an item. Defaults to item.id, or the item itself for strings and numbers. |
|---|
renderItem | (item, { index, active }) => ReactNode | item.label | Draws a page; receives its index and whether it is active. |
|---|
gap | number | 0 | Space between pages in pixels. |
|---|
itemClassName | string | | Class for each item element; itemStyle sets its inline style. |
|---|
transition | Transition | spring | A timing curve { duration, easing } or a spring { tempo: 'spring', spring }. Springs keep their momentum when interrupted. |
|---|
Other props go to the rendered element, so className, style and event handlers work as usual.