1.1.0 • Published 12 months ago

react-fancy-carousel v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 months ago

react-fancy-carousel

NPM GitHub Workflow Status Coveralls npm bundle size npm

  • Built-in common different carousel effects and indicators.
  • Support theme extension.
  • Support indicator customization.
  • ARIA-ify, accessible to people with disabilities.
  • With complete test cases.

Demo Page

Installation

npm install react-fancy-carousel --save

Usage

Component

import Carousel from 'react-fancy-carousel'
import 'react-fancy-carousel/dist/style.css'

const Item = Carousel.Item
const ImgItem = Carousel.ImgItem

export default () => {
  return (
    <Carousel autoplay>
      <Item>{content1}</Item>
      <Item>{content2}</Item>
      <ImgItem src={imgSrc1} alt="" />
      <ImgItem src={imgSrc2} alt="" />
    </Carousel>
  )
}

Options

NameTypeDescriptionDefault
autoplaybooleanAutoplay.false
effect'slide' | 'fade'Change animation effect.'slide'
durationnumberAutoplay time duration.3000 (ms)
speednumberTransition speed.500 (ms)
timingFunctionstringTransition timing function, reference to css property 'transition-timing-function''ease'
infiniteLoopbooleanInfinite loop.true
pauseOnHoverbooleanPause autoplay on hoverfalse
indicator'solid' | 'dot' | React.ComponentType | nullUse built-in indicator or customized component, it will be hidden when set to null.'solid'
onChange(currIndex: number, prevIndex: number) => voidActive item change handler.() => {}

Ref instance methods (interface RefType)

NameTypeDescription
next() => voidChange to next item.
prev() => voidChange to prev item.
goTo(index: number) => voidChange to item given by index.

Customized indicator component options (interface IndicatorPropsType)

NameTypeDescription
uidstringCarousel instance uid, used for ARIA.
itemCountnumberCarousel item total count.
activeIndexnumberCurrent active index.
animationnumberShow animation.
durationnumberAnimation duration.
pausedbooleanAnimation paused.
next() => voidChange to next item.
prev() => voidChange to prev item.
goTo(index: number) => voidChange to item given by index.

Theme css vars

.default {
  --indicator-bg-color: rgba(0, 0, 0, 0.4);
  --indicator-active-bg-color: #fff;

  --indicator-items-gap: 10px;
  --indicator-surround-offset: 30px;

  --indicator-dot-diameter: 10px;

  --indicator-solid-width: 40px;
  --indicator-solid-height: 3px;
  --indicator-solid-padding-y: 5px;
  --indicator-solid-border-radius: 2px;
}

Test

git clone git@github.com:jackyr/react-fancy-carousel.git
cd react-fancy-carousel
npm install
npm test

Browser compatibility

Supports Chrome51+ / Edge15+ / Safari10+ / Firefox54+ / etc. ES6 environment.

Changelog

  • v1.1.0 - Add ImgItem component / fix style / fix type definition
  • v1.0.1 - Valid from v1.0.1
  • v1.0.0 - Invalid version, unpublished
1.1.0

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago

1.0.0-beta.7

12 months ago

1.0.0-beta.6

12 months ago

1.0.0-beta.5

1 year ago

1.0.0-beta.4

1 year ago

1.0.0-beta.3

1 year ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago

1.0.0-alpha.7

1 year ago

1.0.0-alpha.6

1 year ago

1.0.0-alpha.5

1 year ago

1.0.0-alpha.4

1 year ago

1.0.0-alpha.3

1 year ago

1.0.0-alpha.2

1 year ago

1.0.0-alpha.1

1 year ago

1.0.0-alpha.0

1 year ago