0.1.15 • Published 1 month ago

react-whirlpool v0.1.15

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

React Whirlpool Carousel

https://github.com/A7ALABS/react-whirlpool/assets/60537632/0e27a034-7582-431d-95b3-263f224c9048

https://github.com/A7ALABS/react-whirlpool/assets/60537632/d5f3ba93-56ca-4ff5-8467-dc10b4f72be2

Features

  • Responsive
  • Customize previous and next buttons
  • Bi-directional - horizontal and vertical
  • Auto play

Installing

yarn add react-whirlpool

Important

Make sure to import the css file with import 'react-whirlpool/dist/cjs/component/SimpleCarousel.css'

Usage

import React, { useRef, useState } from "react";
import { SimpleCarousel } from "react-whirlpool";
import 'react-whirlpool/dist/cjs/component/SimpleCarousel.css' // => important

function App() {
  const [list, setList] = useState(["A", "B", "C", "D", "E"]);
  const simpleCarouselRef = useRef<any>();
  const [activeIndex, setActiveIndex] = useState(0);

  return (
    <div >
      <SimpleCarousel
        isHorizontal={true}
        gap={20}
        autoPlay={false}
        minHeight="254px"
        ref={simpleCarouselRef}
        hideArrows={true}
        onActiveIndexUpdate={(index: number) => setActiveIndex(index)}
      >
        {list.map((item: string, key) => (
          <div key={key}>
            {item}
          </div>
        ))}
      </SimpleCarousel>
      //custom prev and next buttons
      <button
        onClick={() => {
          simpleCarouselRef.current &&
            simpleCarouselRef.current.handlePrevEvent();
        }}
      >
        Prev
      </button>
      <button
        onClick={() => {
          simpleCarouselRef.current &&
            simpleCarouselRef.current.handleNextEvent();
        }}
      >
        Next
      </button>
    </div>
  );
}

export default App;

Props

NameValueDescription
isHorizontalbooleanDefine the direction of the slider, defaults to 'horizontal'.
childrenJSX ElementPass any number of JSX elements (carousel cards) which are to be rendered in the carousel
gapnumberDefine gap (in px) between two carousel cards
minHeightstring, optionalDefine the minimum height of the carousel container
minWidthstring, optionalDefine the minimum width of the carousel container
onActiveIndexUpdatefunction, optionalTakes an active index (number) as argument to update selected index in SimpleCarousel
autoplayboolean, default false, optionalEnable auto rotation of carousel, rotation interval is set to 3000ms
autoPlayIntervalnumber, default 3000, optionalAuto-play interval in milliseconds
hideArrowsboolean, default true, optionalHide default arrows
hideDevPanelboolean, default true, optionalHide dev panel
hideInitGapboolean, default true, optionalHide initial gap between the first card and carousel container
refany, optionalCreate and pass reference to access the handler methods - 1. handlePrevEvent() to handle previous button clicking event and 2. handleNextEvent() to handle next button clicking event

Common Issues

  1. CJS WARNING - Failed to parse source map => Workaround - Link
0.1.15

1 month ago

0.1.12

7 months ago

0.1.13

7 months ago

0.1.14

6 months ago

0.1.11

1 year ago

0.1.10

1 year ago

0.1.9

1 year ago

0.1.8

1 year ago

0.1.7

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago