1.0.3 • Published 5 years ago

@davistran86/carousel v1.0.3

Weekly downloads
4
License
MIT
Repository
github
Last release
5 years ago

Simple Carousel

npm.io

A simple react carousel with infinite loop 🎉

https://www.npmjs.com/package/@davistran86/carousel

Demo

Please visit: https://davistran86.github.io/react-simple-carousel/

Installation

npm

npm i @davistran86/carousel

yarn

yarn add @davistran86/carousel

Basic Usage

Simply import the package to your react web app and start using it.

import React from "react";
import ReactDOM from "react-dom";
import Carousel from "@davistran86/carousel";

const images = [
  "https://scontent-iad3-1.cdninstagram.com/vp/ccde6818ebdfd3c3b7adc7560c530acb/5E4E076F/t51.2885-15/e35/p1080x1080/70689682_376385253254078_5229751774392621716_n.jpg?_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=102",
  "https://scontent-iad3-1.cdninstagram.com/vp/abcdbf2da90524f3a86c2df4ec3833e5/5E59BF8E/t51.2885-15/e35/p1080x1080/69866420_1201968029995574_3061494835534077307_n.jpg?_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=102",
  "https://scontent-iad3-1.cdninstagram.com/vp/92c9ca9081e1acfb632a6d62dbbea6f8/5E5E3670/t51.2885-15/e35/p1080x1080/70890914_170814634050132_6309691029590448199_n.jpg?_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=100",
  "https://scontent-iad3-1.cdninstagram.com/vp/df768c309299c9c4a9b5f15a42e7f7d4/5E5D3206/t51.2885-15/e35/p1080x1080/67897824_113471973161444_1774742288689415740_n.jpg?_nc_ht=scontent-iad3-1.cdninstagram.com&_nc_cat=108"
];

function App() {
  return (
    <div className="App">
      <Carousel>
        {images.map((image, index) => {
          return <img key={index} alt="images" src={image} />;
        })}
      </Carousel>
    </div>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Advanced Usage

Effect

There are 2 effects can be used: slide, fade.

<Carousel effect="fade">...</Carousel>
OptionTypeDefaultValueInfo
effectstringslideslide,fadeEffect showing when go to other slide

Speed

<Carousel speed={500}>...</Carousel>
OptionTypeDefaultInfo
speednumber250Changing slide speed. Default 250 means 250ms or 0.25s (Animation speed)

Width & height

<Carousel width="800px" height="600px">
  ...
</Carousel>
OptionTypeDefaultInfo
widthstring100%Carousel width. Support any value can be used with width in css
heightstring100%Carousel height. Support any value can be used with height in css

Fit width & height

Show content in full width or full height. In default, the content will be showed in full height.

OptionTypeDefaultInfo
fitWidthbooleanfalseFull width
fitHeightbooleantrueFull height

Background

OptionTypeDefaultInfo
backgroundstring#ffffffBackground color of slides. Support any value can be used with background in css

Autoplay

<Carousel autoplay={true} pauseOnMouseOver={true} delay={3000}>
  ...
</Carousel>
OptionTypeDefaultInfo
autoplaybooleanfalseAuto go to next slide
delaynumber5000Waiting time before go to next slide. Default 5000 means 5000ms or 5s
pauseOnMouseOverbooleanfalsePause autoplay when mouse over the Carousel

Controller

<Carousel
  useArrowKey={true}
  useMouseWheel={true}
  hideController={true}
  buttonColor="red"
  buttonPosition="outside"
>
  ...
</Carousel>
OptionTypeDefaultValueInfo
useArrowKeybooleanfalsetrue,falseUse arrow key to move to next or previous slide
useMouseWheelbooleanfalsetrue,falseUse mouse wheel to move to next or previous slide
hideControllerbooleanfalsetrue,falseHide next and previous button
buttonColorstring#000anySupport any value can be used with color in css
buttonPositionstringinsideinside,outsideNext and previous button are inside or outside the carousel

Indicators

<Carousel hideIndicators={true} indicatorsColor="red">
  ...
</Carousel>
OptionTypeDefaultValueInfo
hideIndicatorsbooleanfalsetrue,falseHide the indicators
indicatorsColorstring#000anySupport any value can be used with color in css

Other react components

Checkout my other react components:

Notification

https://www.npmjs.com/package/@davistran86/notification