Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jiangbo2015/framer-motion-carousel

framer-motion carousel, simple & easy to use
https://github.com/jiangbo2015/framer-motion-carousel

carousel framer-motion react-carousel

Last synced: 8 days ago
JSON representation

framer-motion carousel, simple & easy to use

Awesome Lists containing this project

README

        

# framer-motion-carousel

A simple `framer-motion-carousel`, used for `framer-motion`, `chakra-ui`
support `click` and `swipe`, support custom `arrows`, `dots`, easy to use.

*2.x use `framer-motion@6` now*

## Basic Usage

```jsx
import * as React from "react";
import Carousel from "framer-motion-carousel";

const colors = ["#f90", "#ef0", "#e0f"];

const App = () => (



{colors.map((item, i) => (

))}


);
export default App;
```

## images carousel

`img` element should add `draggable=false`

```jsx



{[1, 2, 3, 4].map((item, i) => (

))}


```

## use external control button

```jsx
// set ref;
const carouselRef = React.useRef();



carouselRef.current.handlePrev()}>handlePrev
carouselRef.current.setIndex(2)}>goto index 2
carouselRef.current.handleNext()}>handleNext


{[1, 2, 3, 4].map((item, i) => (

))}


```

## Example

[Live Demo](https://carousel-app-772051431.vercel.app)

[example repo](https://github.com/jiangbo2015/framer-motion-carousel/tree/main/example)

![example](https://cdn.jsdelivr.net/gh/jiangbo2015/framer-motion-carousel/img.jpg)

## props

| props | type | default | description |
|------------------|--------------------------------------------------------------------------------------|---------|----------------------------------------------------------------------|
| loop | boolean | true | loop play |
| autoPlay | boolean | true | auto play |
| interval | number | 2000 | auto play interval |
| renderArrowLeft | ({handlePrev: () => void, activeIndex: number}) => React.ReactNode | null | custom your arrows, `activeIndex` is current index |
| renderArrowRight | ({handleNext: () => void, activeIndex: number}) => React.ReactNode | null | custom your arrows, `activeIndex` is current index |
| renderDots | ({activeIndex: number, setActiveIndex: (index: number) => void;}) => React.ReactNode | null | custom your dots, `activeIndex` is current index |
| ref | React.Ref | null | Carousel ref, support `handleNext`, `handlePrev`, `setIndex` method |

## example

```
cd example && yarn install

yarn dev
```