# @fil1pe/react-slider

> A slider component for React

Latest version **1.13.5** (published 2024-08-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @fil1pe/react-slider
pnpm add @fil1pe/react-slider
yarn add @fil1pe/react-slider
bun add @fil1pe/react-slider
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.13.5 |
| Published | 2024-08-22 |
| First published | 2022-04-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 26.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | fil1pe |
| Keywords | slider, react |

## Links

- npm: https://www.npmjs.com/package/@fil1pe/react-slider
- Repository: https://github.com/fil1pe/react-slider
- Homepage: https://github.com/fil1pe/react-slider#readme
- Issues: https://github.com/fil1pe/react-slider/issues
- npm.io page: https://npm.io/package/@fil1pe/react-slider

## Dependencies (2)

- [react](https://npm.io/package/react.md) ^18.1.0
- [classnames](https://npm.io/package/classnames.md) ^2.3.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.13.5 (latest) — 2024-08-22
- 1.13.4 — 2024-08-22
- 1.13.1 — 2024-08-06
- 1.13.0 — 2024-08-05
- 1.12.1 — 2024-07-10
- 1.12.0 — 2024-07-03
- 1.11.0 — 2024-05-23
- 1.10.2 — 2024-03-07
- 1.10.1 — 2024-03-07
- 1.10.0 — 2024-02-19
- 1.9.8 — 2024-01-19
- 1.9.7 — 2024-01-18
- 1.9.6 — 2023-12-12
- 1.9.5 — 2023-07-07
- 1.9.4 — 2023-06-21
- … 30 more at https://npm.io/package/@fil1pe/react-slider/versions

## README

# React Slider

![npm version](https://img.shields.io/npm/v/@fil1pe/react-slider)
![npm downloads](https://img.shields.io/npm/dm/@fil1pe/react-slider)
![license](https://img.shields.io/npm/l/@fil1pe/react-slider)
![build status](https://img.shields.io/github/actions/workflow/status/fil1pe/react-slider/build.yml)

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

```bash
$ npm install @fil1pe/react-slider
```

### yarn

```bash
$ yarn add @fil1pe/react-slider
```

## Usage

In your JSX file, import the slider component and the CSS file as in the [example below](#example). 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:

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

## Classes

| Class name | Description |
| :-: | :-: |
| .main | div wrapping the track and arrows |
| .arrow | prev/next button |
| .disabled | if arrow is disabled |
| .track | wraps the ul containing the slides |
| .dots | ul with the dots |
| .active | active slide/dot |
| .pages | pagination info |

## Component props

| Property | Default value | Required | Description |
| :-: | :-: | :-: | :--: |
| className | none | false | Class name of your slider component wrapper |
| slidesToShow | 1 | false | Number of slides per page |
| slidesToScroll | slidesToShow | false | Number of slides to scroll on click on prev/next |
| finite | false | false | Defines whether the slider should have finite scrolling or not |
| slidableWithMouse | false | false | Defines whether it can be slid with the mouse |
| renderArrow | `(props, type) => <button {...props}>{type === ArrowType.Next ? 'Next' : 'Previous'}</button>` | false | Allows customizing the arrow buttons |
| renderController | none | false | Function that renders additional controllers in the wrapper div .main (e.g. full-screen button). Receives the current slide index as argument |
| autoplayTimeout | none (∞) | false | Autoplay interval in milliseconds |
| slidesToAppend | none | false | Additional number of slides to append before and after |
| adaptiveHeight | false | false | Variable height |
| pagination | 0 | false | Shows current slide index alongside the total number of slides<br/>(1 for no spacing, 2 otherwise) |
| onSlideChange(int) | none | false | Function triggered on slide change |
| initialSlide | 0 | false | Number of the first slide to show |

## Methods

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

| Method | Arguments | Description |
| :-: | :-: | :-: |
| slickGoTo | slide index | Navigates to the specified slide |
| slickNext | none | Goes to the next slide |
| slickPrev | none | Goes 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

```js
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
```

---
_Source: https://npm.io/package/@fil1pe/react-slider · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
