Convert Figma logo to code with AI

brainhubeu logoreact-carousel

A pure extendable React carousel, powered by Brainhub (craftsmen who ❤️ JS)

1,070
164
1,070
121

Top Related Projects

39,745

Most modern mobile touch slider with hardware accelerated transitions

React.js Responsive Carousel (with Swipe)

React carousel component

Small, fast, and accessibility-first React carousel library with an easily customizable UI and behavior to fit your brand and site.

A library to use idangerous Swiper as a ReactJs component which allows Swiper's modules custom build

Quick Overview

React-carousel is a lightweight and customizable carousel component for React applications. It provides a simple way to create responsive and touch-enabled carousels with various animation options and customizable controls.

Pros

  • Easy to integrate and use in React projects
  • Highly customizable with numerous configuration options
  • Supports touch gestures and responsive design
  • Lightweight with minimal dependencies

Cons

  • Limited built-in styling options, requiring custom CSS for advanced designs
  • Documentation could be more comprehensive
  • Some users report occasional performance issues with large numbers of slides
  • Limited accessibility features out of the box

Code Examples

Creating a basic carousel:

import Carousel from '@brainhubeu/react-carousel';
import '@brainhubeu/react-carousel/lib/style.css';

function MyCarousel() {
  return (
    <Carousel>
      <img src="image1.jpg" alt="Slide 1" />
      <img src="image2.jpg" alt="Slide 2" />
      <img src="image3.jpg" alt="Slide 3" />
    </Carousel>
  );
}

Adding custom navigation buttons:

import Carousel from '@brainhubeu/react-carousel';
import '@brainhubeu/react-carousel/lib/style.css';

function MyCarousel() {
  return (
    <Carousel
      arrows
      arrowLeft={<button>Previous</button>}
      arrowRight={<button>Next</button>}
    >
      <img src="image1.jpg" alt="Slide 1" />
      <img src="image2.jpg" alt="Slide 2" />
      <img src="image3.jpg" alt="Slide 3" />
    </Carousel>
  );
}

Implementing infinite loop and autoplay:

import Carousel from '@brainhubeu/react-carousel';
import '@brainhubeu/react-carousel/lib/style.css';

function MyCarousel() {
  return (
    <Carousel
      infinite
      autoPlay={3000}
      animationSpeed={1000}
    >
      <img src="image1.jpg" alt="Slide 1" />
      <img src="image2.jpg" alt="Slide 2" />
      <img src="image3.jpg" alt="Slide 3" />
    </Carousel>
  );
}

Getting Started

  1. Install the package:

    npm install @brainhubeu/react-carousel
    
  2. Import the component and styles in your React file:

    import Carousel from '@brainhubeu/react-carousel';
    import '@brainhubeu/react-carousel/lib/style.css';
    
  3. Use the Carousel component in your JSX:

    <Carousel>
      <img src="image1.jpg" alt="Slide 1" />
      <img src="image2.jpg" alt="Slide 2" />
      <img src="image3.jpg" alt="Slide 3" />
    </Carousel>
    
  4. Customize the carousel by adding props as needed:

    <Carousel
      arrows
      infinite
      slidesPerPage={3}
      animationSpeed={500}
      centered
      offset={50}
      itemWidth={250}
    >
      {/* Your slides here */}
    </Carousel>
    

Competitor Comparisons

39,745

Most modern mobile touch slider with hardware accelerated transitions

Pros of Swiper

  • More feature-rich with advanced functionality like parallax effects, zoom, and lazy loading
  • Better performance and smoother animations, especially for mobile devices
  • Larger community and more frequent updates

Cons of Swiper

  • Steeper learning curve due to more complex API and configuration options
  • Larger file size, which may impact page load times for simpler carousel needs

Code Comparison

React Carousel:

import Carousel from '@brainhubeu/react-carousel';

<Carousel
  slidesPerPage={3}
  arrows
  infinite
>
  <img src="image1.jpg" />
  <img src="image2.jpg" />
  <img src="image3.jpg" />
</Carousel>

Swiper:

import { Swiper, SwiperSlide } from 'swiper/react';

<Swiper
  slidesPerView={3}
  navigation
  loop
>
  <SwiperSlide><img src="image1.jpg" /></SwiperSlide>
  <SwiperSlide><img src="image2.jpg" /></SwiperSlide>
  <SwiperSlide><img src="image3.jpg" /></SwiperSlide>
</Swiper>

Both libraries offer similar basic functionality, but Swiper provides more customization options and advanced features. React Carousel has a simpler API, making it easier to set up for basic use cases. Swiper's code is more verbose but offers greater flexibility for complex implementations.

React.js Responsive Carousel (with Swipe)

Pros of react-responsive-carousel

  • More comprehensive documentation and examples
  • Built-in responsive design features
  • Wider range of customization options

Cons of react-responsive-carousel

  • Larger bundle size
  • Slightly more complex API

Code Comparison

react-responsive-carousel:

<Carousel showArrows={true} infiniteLoop={true} autoPlay={true}>
  <div>
    <img src="image1.jpg" alt="Image 1" />
    <p className="legend">Legend 1</p>
  </div>
  <div>
    <img src="image2.jpg" alt="Image 2" />
    <p className="legend">Legend 2</p>
  </div>
</Carousel>

react-carousel:

<Carousel plugins={['infinite', 'arrows']}>
  <img src="image1.jpg" alt="Image 1" />
  <img src="image2.jpg" alt="Image 2" />
</Carousel>

The code comparison shows that react-responsive-carousel offers more built-in features like legends and autoplay, while react-carousel has a simpler API with plugin-based functionality. react-responsive-carousel requires wrapping each slide in a div, whereas react-carousel allows direct use of img tags. Both libraries support infinite looping and arrow navigation, but react-responsive-carousel includes these features by default, while react-carousel implements them as plugins.

React carousel component

Pros of react-slick

  • More comprehensive feature set, including autoplay, lazy loading, and custom animations
  • Better documentation and examples, making it easier for developers to implement
  • Larger community and more frequent updates, ensuring better long-term support

Cons of react-slick

  • Larger bundle size, which may impact performance for smaller projects
  • More complex API, potentially requiring a steeper learning curve
  • Dependency on jQuery, which may not be ideal for modern React applications

Code Comparison

react-slick:

import Slider from "react-slick";

<Slider dots={true} infinite={true} speed={500} slidesToShow={3} slidesToScroll={1}>
  <div><img src="image1.jpg" alt="Slide 1" /></div>
  <div><img src="image2.jpg" alt="Slide 2" /></div>
  <div><img src="image3.jpg" alt="Slide 3" /></div>
</Slider>

react-carousel:

import Carousel from "@brainhubeu/react-carousel";

<Carousel dots infinite slidesPerPage={3}>
  <img src="image1.jpg" alt="Slide 1" />
  <img src="image2.jpg" alt="Slide 2" />
  <img src="image3.jpg" alt="Slide 3" />
</Carousel>

Both libraries offer similar basic functionality, but react-slick provides more customization options out of the box. react-carousel has a simpler API, which may be preferable for smaller projects or those with simpler requirements.

Small, fast, and accessibility-first React carousel library with an easily customizable UI and behavior to fit your brand and site.

Pros of nuka-carousel

  • More customizable with a wider range of props and options
  • Better support for responsive design and mobile devices
  • Smoother animations and transitions

Cons of nuka-carousel

  • Slightly larger bundle size
  • Less intuitive API for basic use cases
  • Requires more configuration for simple carousels

Code Comparison

nuka-carousel:

import Carousel from 'nuka-carousel';

<Carousel>
  <img src="image1.jpg" alt="Slide 1" />
  <img src="image2.jpg" alt="Slide 2" />
  <img src="image3.jpg" alt="Slide 3" />
</Carousel>

react-carousel:

import Carousel from '@brainhubeu/react-carousel';

<Carousel>
  <img src="image1.jpg" alt="Slide 1" />
  <img src="image2.jpg" alt="Slide 2" />
  <img src="image3.jpg" alt="Slide 3" />
</Carousel>

Both libraries offer similar basic usage, but nuka-carousel provides more advanced features and customization options out of the box. react-carousel has a simpler API for basic use cases, making it easier to set up quickly. nuka-carousel excels in responsive design and mobile support, while react-carousel is more lightweight and straightforward for simple implementations. The choice between the two depends on the specific requirements of your project and the level of customization needed.

A library to use idangerous Swiper as a ReactJs component which allows Swiper's modules custom build

Pros of react-id-swiper

  • Built on top of Swiper.js, providing a wide range of features and customization options
  • Supports both React and React Native
  • Offers touch-friendly swiping and advanced effects like parallax

Cons of react-id-swiper

  • Larger bundle size due to Swiper.js dependency
  • Steeper learning curve for complex configurations
  • Less frequently updated compared to react-carousel

Code Comparison

react-id-swiper:

import Swiper from 'react-id-swiper';

const MySwiper = () => (
  <Swiper>
    <div>Slide 1</div>
    <div>Slide 2</div>
    <div>Slide 3</div>
  </Swiper>
);

react-carousel:

import Carousel from '@brainhubeu/react-carousel';

const MyCarousel = () => (
  <Carousel>
    <img src="image1.jpg" />
    <img src="image2.jpg" />
    <img src="image3.jpg" />
  </Carousel>
);

Both libraries offer simple implementation for basic carousel functionality. react-id-swiper provides more advanced features out of the box, while react-carousel focuses on simplicity and ease of use. The choice between the two depends on project requirements, desired customization level, and performance considerations.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README



react-carousel

A pure extendable React carousel, powered by Brainhub (craftsmen who ❤️ JS)

Live code demo | v1 migration guide | Hire us

CircleCI Last commit license PRs Welcome Renovate enabled

Coveralls github Downloads Activity Minified npm Contributors

Table of Contents

Why?

There are some great carousels (like slick) that do not have real React implementations. This library provides you with carousel that is not merely a wrapper for some jQuery solution, can be used as controlled or uncontrolled element (similar to inputs), and has tons of useful features.

Installation

Basic

npm i @brainhubeu/react-carousel

Typescript

npm i @types/brainhubeu__react-carousel -D

SSR

When using @brainhubeu/react-carousel with SSR (Server-side Rendering), we recommend Next.js as @brainhubeu/react-carousel currently doesn't work on the server side so it must be rendered on the client side (maybe we'll provide server-side working in the future).

import dynamic from 'next/dynamic';

const { default: Carousel, Dots } = dynamic(
 () => require('@brainhubeu/react-carousel'),
 { ssr: false },
);

Usage

By default, the component does not need anything except children to render a simple carousel. Remember that styles do not have to be imported every time you use carousel, you can do it once in an entry point of your bundle.

import React from 'react';
import Carousel from '@brainhubeu/react-carousel';
import '@brainhubeu/react-carousel/lib/style.css';

const MyCarousel = () => (
  <Carousel plugins={['arrows']}>
    <img src={imageOne} />
    <img src={imageTwo} />
    <img src={imageThree} />
  </Carousel>
);

export default MyCarousel;

gif

Showing dots or thumbnails

There is a separate Dots component that can be used to fully control navigation dots or add thumbnails.

import Carousel, { Dots } from '@brainhubeu/react-carousel';
import '@brainhubeu/react-carousel/lib/style.css'; import { useState } from 'react';

const MyCarouselWithDots = () => {
  const [value, setValue] = useState(0);

  const onChange = value => {
  setValue(value);
  }

  return (
    <div>
      <Carousel
        value={value}
        onChange={onChange}
      >
        <img className="img-example" src={someImage} />
        ...
        <img className="img-example" src={anotherImage} />
      </Carousel>
      <Dots
        value={this.state.value}
        onChange={this.onChange}
        thumbnails={[
          (<img key={1} className="img-example-small" src={abstractImage} />),
          ...
          (<img key={12} className="img-example-small" src={transportImage} />),
        ]}
      />
    </div>
  );
};

export default MyCarouselWithDots;

gif

Props

You can access a clickable demo with many examples and a live code editor by clicking on a Prop name.

Carousel props

PropTypeDefaultDescription
valueNumberundefinedCurrent slide's index (zero based, depends on the elements order)
onChangeFunctionundefinedHandler triggered when current slide is about to change (e.g. on arrow click or on swipe)
slidesArrayundefinedAlternative way to pass slides. This prop expects an array of JSX elements
itemWidthNumberundefinedDetermines custom width for every slide in the carousel
offsetNumber0Padding between items
animationSpeedNumber500Determines transition duration in milliseconds
draggableBooleantrueMakes it possible to drag to the next slide with mouse cursor
breakpointsObjectundefinedAll props can be set to different values on different screen resolutions

Plugins

You can extend react-carousel default behavior by applying plugins shipped within carousel

Plugins documentation

Dots props

PropTypeDefaultDescription
valueNumberslide position in the slides ArrayCurrent Carousel value
onChangeFunctionundefinedonChange callback (works the same way as onChange in Carousel component)
numberNumberAmount of slidesNumber of slides in the carousel you want to control
thumbnailsArray of ReactElementsundefinedArray of thumbnails to show. If not provided, default dots will be shown
rtlBooleanfalseIndicating if the dots should have direction from Right to Left

Setting up local development which means running the docs/demo locally:

  • git clone https://github.com/brainhubeu/react-carousel
  • cd react-carousel
  • yarn
  • yarn start-demo
  • open http://localhost:8000/

Tests

Each test command should be run from the root directory.

Unit tests

yarn test:unit:coverage

E2E tests

yarn test:e2e

Workflow

See the Workflow subsection in our docs

Labels

See the Labels subsection in our docs

Decision log

See the Decision log subsection in our docs

License

react-carousel is copyright © 2018-2020 Brainhub. It is free software and may be redistributed under the terms specified in the license.

About

react-carousel is maintained by the Brainhub development team. It is funded by Brainhub and the names and logos for Brainhub are trademarks of Brainhub Sp. z o.o.. You can check other open-source projects supported/developed by our teammates here.

Brainhub

We love open-source JavaScript software! See our other projects or hire us to build your next web, desktop and mobile application with JavaScript.

NPM DownloadsLast 30 Days