1.13.5 • Published 11 months ago

@fil1pe/react-slider v1.13.5

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

React Slider

npm version npm downloads license build status

This is a simple slider implementation in React. Make your own carousels of images, texts or whatever you need easily with this component and some stylesheet.

Installation

npm

$ npm install @fil1pe/react-slider

yarn

$ yarn add @fil1pe/react-slider

Usage

In your JSX file, import the slider component and the CSS file as in the example below. You are free to customize it using the prop className and the classes that follow.

Usage with Next.js

If you are using this package with Next.js, you need to add the following configuration to your next.config.js (or next.config.mjs) file to ensure the package is transpiled correctly:

module.exports = {
  transpilePackages: ['@fil1pe/react-slider'],
}

Classes

Class nameDescription
.maindiv wrapping the track and arrows
.arrowprev/next button
.disabledif arrow is disabled
.trackwraps the ul containing the slides
.dotsul with the dots
.activeactive slide/dot
.pagespagination info

Component props

PropertyDefault valueRequiredDescription
classNamenonefalseClass name of your slider component wrapper
slidesToShow1falseNumber of slides per page
slidesToScrollslidesToShowfalseNumber of slides to scroll on click on prev/next
finitefalsefalseDefines whether the slider should have finite scrolling or not
slidableWithMousefalsefalseDefines whether it can be slid with the mouse
renderArrow(props, type) => <button {...props}>{type === ArrowType.Next ? 'Next' : 'Previous'}</button>falseAllows customizing the arrow buttons
renderControllernonefalseFunction that renders additional controllers in the wrapper div .main (e.g. full-screen button). Receives the current slide index as argument
autoplayTimeoutnone (∞)falseAutoplay interval in milliseconds
slidesToAppendnonefalseAdditional number of slides to append before and after
adaptiveHeightfalsefalseVariable height
pagination0falseShows current slide index alongside the total number of slides(1 for no spacing, 2 otherwise)
onSlideChange(int)nonefalseFunction triggered on slide change
initialSlide0falseNumber of the first slide to show

Methods

Referencing the slider allows you to manually change the current slide through the methods below.

MethodArgumentsDescription
slickGoToslide indexNavigates to the specified slide
slickNextnoneGoes to the next slide
slickPrevnoneGoes to the previous slide

Provider

The SliderProvider exported by this package is used to adjust the slides positioning during screen resizing, preventing visual bugs.

Example

import React from 'react'
import Slider from '@fil1pe/react-slider'
import '@fil1pe/react-slider/style.css'

function App() {
  return (
    <SliderProvider>
      <Slider slidesToShow={2} slidesToScroll={1} className="slider">
        <div class="slide">1</div>
        <div class="slide">2</div>
        <div class="slide">3</div>
        <div class="slide">4</div>
        <div class="slide">5</div>
      </Slider>
    </SliderProvider>
  )
}

export default App
1.13.1

11 months ago

1.13.0

11 months ago

1.12.1

12 months ago

1.12.0

1 year ago

1.13.5

11 months ago

1.13.4

11 months ago

1.11.0

1 year ago

1.10.2

1 year ago

1.10.1

1 year ago

1.10.0

1 year ago

1.9.8

1 year ago

1.9.7

1 year ago

1.9.6

2 years ago

1.9.5

2 years ago

1.9.4

2 years ago

1.9.3

2 years ago

1.9.1

2 years ago

1.9.2

2 years ago

1.9.0

2 years ago

1.7.3

3 years ago

1.7.2

3 years ago

1.8.0

3 years ago

1.7.1

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.0

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.0.0

3 years ago

0.7.1

3 years ago

0.6.0

3 years ago

0.3.0

3 years ago

0.2.0

3 years ago

0.5.0

3 years ago

0.4.1

3 years ago

0.1.4

3 years ago

0.4.0

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago