Skip to content

Commit

Permalink
Merge pull request #100 from erichbehrens/chore/release
Browse files Browse the repository at this point in the history
Release 2.0.0
  • Loading branch information
erichbehrens authored Dec 2, 2019
2 parents 5632a19 + ec06442 commit f26ddda
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 87 deletions.
130 changes: 54 additions & 76 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
[![CircleCI](https://circleci.com/gh/erichbehrens/react-animated-slider/tree/master.svg?style=shield)](https://circleci.com/gh/erichbehrens/react-animated-slider/tree/master)
[![dependencies](https://david-dm.org/erichbehrens/react-animated-slider.svg)](https://david-dm.org/erichbehrens/react-animated-slider)
[![devDependencies](https://david-dm.org/erichbehrens/react-animated-slider/dev-status.svg)](https://david-dm.org/erichbehrens/react-animated-slider?type=dev)
[![minified size](https://badgen.net/bundlephobia/min/react-animated-slider)](https://bundlephobia.com/result?p=react-animated-slider)
[![minified + gzipped size](https://badgen.net/bundlephobia/minzip/react-animated-slider)](https://bundlephobia.com/result?p=react-animated-slider)

A Slider/Carousel component for React supporting custom css animations.

[Demo](https://erichbehrens.github.io/react-animated-slider/) - [Codesandbox Playground](https://codesandbox.io/s/p582xl40j)
[Demo](https://erichbehrens.github.io/react-animated-slider/) - [Codesandbox Playground](https://codesandbox.io/s/react-animated-slider-q8rdo)

![Preview](https://res.cloudinary.com/riangle/image/upload/v1511700118/react-animated-slider_qqedfm.png)

## Features:
## Features

- Ready to use slider component with animations
- Easy customization
Expand All @@ -27,71 +29,51 @@ A Slider/Carousel component for React supporting custom css animations.
- Works with SSR
- Works on IE11

## Install:
## Install

```sh
npm install react-animated-slider
```
npm install react-animated-slider --save

**Note**: this component relies on `getDerivedStateFromProps` and requires `[email protected]` or newer. For older react versions please install `react-animated-slider` version 1:

```sh
npm install react-animated-slider@^1
```

## Most Simple Use:
## Most Simple Use

```jsx
import Slider from 'react-animated-slider';
import 'react-animated-slider/build/horizontal.css';

const slides = [
{ title: 'First item', description: 'Lorem ipsum'}
{ title: 'Second item', description: 'Lorem ipsum'}
];

<Slider>
{content.map((article, index) => <div key={index}>
<h2>{article.title}</h2>
<div>{article.description}</div>
{slides.map((slide, index) => <div key={index}>
<h2>{slide.title}</h2>
<div>{slide.description}</div>
</div>)}
</Slider>
```

## Properties:

**slideIndex** - `number`, default `0`

Index of the slide that will be initially displayed.

**duration** - `number`, default `2000`(ms)

Duration of the animation in milliseconds. It is used to remove the `animateIn` and `animateOut` classNames and assign `current` after the transition has completed.

**disabled** - `boolean`, default `false`

Disable slider navigation

**infinite** - `boolean`, default `true`

Enable or disable infinite loop through slides. Sliders with only 2 children will have this option set to `false`

**autoplay** - `number`, default `undefined`

Autoplay interval in miliseconds. If `undefined` the slider will not play automatically. The timer will be paused and reset during user interactions such as mouse over or touch, to avoid sliding away the elements when the user wants to click them.

**touchDisabled** `boolean`, default `false`

Disable slider navigation through touch events

**minSwipeOffset** - `number`, default `15`(px)

Minimum distance to swipe for triggering a navigation event

**previousButton** - `ReactElement`, default is an arrow svg

Will be rendered inside the previous button

**nextButton** - `ReactElement`, default is an arrow svg

Will be rendered inside the next button

**onSlideChange** - `function`, called after the current slide has changed; receives an object with the new slide index as argument:

```js
<Slider onSlideChange={event => console.log(event.slideIndex)}>
```

**classNames** `object`, default
## Properties

| property | type | default | description |
|-|-|-|-|-|
| **slideIndex** | `number` | `0` | Index of the slide that will be initially displayed. |
| **duration** | `number` | `2000`(ms) | Duration of the animation in milliseconds. It is used to remove the `animateIn` and `animateOut` classNames and assign `current` after the transition has completed. |
| **disabled** | `boolean` | `false` | Disable slider navigation |
| **infinite** | `boolean` | `true` | Enable or disable infinite loop through slides. Sliders with only 2 children will have this option set to `false` |
| **autoplay** | `number` | `undefined` | Autoplay interval in miliseconds. If `undefined` the slider will not play automatically. The timer will be paused and reset during user interactions such as mouse over or touch, to avoid sliding away the elements when the user wants to click them. |
| **touchDisabled** | `boolean` | `false` | Disable slider navigation through touch events |
| **minSwipeOffset** | `number` | `15`(px) | Minimum distance in pixels to swipe for triggering a navigation event |
| **previousButton** | `ReactElement` | arrow svg | Will be rendered inside the previous button |
| **nextButton** | `ReactElement` | arrow svg | Will be rendered inside the next button |
| **classNames** | `object` | _see below_ | Object representing the CSS classNames that will be apllied to the slides. |

```js
{
Expand All @@ -110,28 +92,24 @@ Will be rendered inside the next button
}
```

Object representing the CSS classNames that will be apllied to the slides.

### Classnames

**slider** the classname for the whole Slider element

**previousButton** previous button

**nextButton** next button

**buttonDisabled** disabled state for previous and next button

**track** element wrapping all slides

**slide** apllied to every item (child)

**hidden** a slide that is not visible and is not adjacent to the current slide, therefore no animation will be usually needed

**previous** the slide that will appear or is appearing when the slider navigated back

**next** the slide that will appear or is appearing when the slider navigated forward

**animateIn** the slide moving into the view

**animateOut** the slide moving out of the view
| class | description |
|-|-|
| **slider** | element wrapping the whole Slider |
| **previousButton** | previous button |
| **nextButton** | next button |
| **buttonDisabled** | disabled state for previous and next button |
| **track** | element wrapping all slides |
| **slide** | apllied to every child item |
| **hidden** | a slide that is not visible and is not adjacent to the current slide, therefore no animation will be applied |
| **previous** | the slide that will appear or is appearing when the slider navigated back |
| **next** | the slide that will appear or is appearing when the slider navigated forward |
| **animateIn** | the slide moving into the view |
| **animateOut** | the slide moving out of the view |

## Events

| property | description |
|-|-|
| **onSlideChange** | called after a slide change animation has ended. Receives an object with the new slide index as argument: <br > `<Slider onSlideChange={event => console.log(event.slideIndex)}>` |
15 changes: 11 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-animated-slider",
"version": "1.1.4",
"version": "2.0.0",
"description": "Animated slider component for react",
"main": "build/index.js",
"files": [
Expand Down Expand Up @@ -41,11 +41,9 @@
"url": "https://github.com/erichbehrens/react-animated-slider/issues"
},
"homepage": "https://github.com/erichbehrens/react-animated-slider#readme",
"dependencies": {
"react": "^16.12.0"
},
"peerDependencies": {
"react": "^16.4.0"
"react": "^16.4.0",
"react-dom": "^16.4.0"
},
"devDependencies": {
"@babel/cli": "^7.7.4",
Expand Down Expand Up @@ -76,8 +74,9 @@
"postcss-cssnext": "^3.1.0",
"postcss-loader": "^3.0.0",
"raw-loader": "^4.0.0",
"react-dom": "^16.12.0",
"react-test-renderer": "^16.12.0",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-test-renderer": "^16.4.0",
"webpack": "^4.41.2",
"webpack-cli": "^3.3.10",
"webpack-dev-server": "^3.9.0"
Expand Down

0 comments on commit f26ddda

Please sign in to comment.