Skip to content
A slider component for react
TypeScript Makefile JavaScript HTML
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.github
.storybook
docs
src
.ecrc
.editorconfig
.gitignore
.nvmrc
CHANGELOG.md
CONTRIBUTING.md
LICENSE
Makefile
README.md
commitlint.config.js
package-lock.json
package.json
renovate.json
tsconfig.json

README.md

react-spring-slider

CircleCI

  1. General
  2. Installation
  3. Usage
  4. Configuration
  5. More Examples
  6. Contribution

General

This is a slider which uses react-spring under the hood.

This project aims to be flexible through configuration as well as be easy to use by sane and reasonable defaults.

You can have a real life look how this can be used within storybook at: farbenmeer.github.io/react-spring-slider.

Installation

yarn add @farbenmeer/react-spring-slider
// OR
npm install --save @farbenmeer/react-spring-slider

Usage

The module provides a default export which you can import and use in your own component.

import Slider from '@farbenmeer/react-spring-slider';

const App = () => {
	return (
		<Slider>
			<div>child 1</div>
			<div>child 2</div>
			<div>child 3</div>
		</Slider>
	)
}

The slider can gain any children as long as there are a react node, so you can show images, text or some more complex components.

You can also use Typescript as the package contains type definitions.

Configuration

The slider currently provides the following interface:

Name Type Default Description
activeIndex number 0 Controlles the shown index
ArrowComponent function - A custom component for the arrows
auto number 0 0 = disabled auto sliding. Indicates the pausing time in milliseconds per slide before next slide is shown.
BulletComponent function - A custom component for the bullets
bulletStyle object { } custom styles for the bullets
children node [ ] The children of the slider, every child is a single slide
hasArrows boolean false Whether the slider should have arrows or not
hasBullets boolean false Whether the slider should have bullets or not
onSlideChange function - Callback which is triggered when the slides changed either manually or automatically

More examples

Custom bulletStyle

<Slider hasBullets bulletStyle={{backgroundColor: '#fff'}}>
	<MySlide />
	<MySlide />
	<MySlide />
</Slider>

Fully customized

import Slider from '@farbenmeer/react-spring-slider';

const App = () => {
	const onSlideChange = index => console.log(`changed to slide ${index}`);

	const BulletComponent = ({onClick, isActive}) => (
		<li
			style={{
				width: '25px',
				height: '25px',
				backgroundColor: 'red',
				margin: '0 2px',
				opacity: isActive && '0.5'
			}}
			onClick={onClick}
		/>
	);

	BulletComponent.propTypes = {
		onClick: PropTypes.func.isRequired,
		isActive: PropTypes.bool.isRequired
	};

	const ArrowComponent = ({onClick, direction}) => {
		return (
			<div
				style={{
					border: '1px solid black',
					padding: '1em',
					backgroundColor: 'white'
				}}
				onClick={onClick}
			>
				{direction}
			</div>
		);
	};

	ArrowComponent.propTypes = {
		onClick: PropTypes.func.isRequired,
		direction: PropTypes.string.isRequired
	};


	return (
		<Slider 
			activeIndex={2} 
			auto 
			hasBullets 
			BulletComponent={BulletComponent}
			ArrowComponent={ArrowComponent}
			onSlideChange={onSlideChange}
			>
				<div>child 1</div>
				<div>child 2</div>
				<div>child 3</div>
		</Slider>
	)
}

For more examples have a look at storybook.

Contribution

See CONTRIBUTING.md

You can’t perform that action at this time.