Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@farbenmeer/react-spring-slider

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@farbenmeer/react-spring-slider

[![Hits-of-Code](https://hitsofcode.com/github/farbenmeer/react-spring-slider)](https://hitsofcode.com/view/github/farbenmeer/react-spring-slider) ![Version](https://img.shields.io/npm/v/@farbenmeer/react-spring-slider?style=flat-square) [![Minified Size]

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
242
decreased by-66.06%
Maintainers
2
Weekly downloads
 
Created
Source

react-spring-slider

Hits-of-Code Version Minified Size Minified Zipped Size License

  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:

NameTypeDefaultDescription
activeIndexnumber0Controlles the shown index
ArrowComponentfunction-A custom component for the arrows
autonumber00 = disabled auto sliding. Indicates the pausing time in milliseconds per slide before next slide is shown.
BulletComponentfunction-A custom component for the bullets
bulletStyleobject{ }custom styles for the bullets
childrennode[ ]The children of the slider, every child is a single slide
hasArrowsbooleanfalseWhether the slider should have arrows or not
hasBulletsbooleanfalseWhether the slider should have bullets or not
onSlideChangefunction-Callback which is triggered when the slides changed either manually or automatically
setSlideCustomfunction-A function to overwrite the default setSlide behavior.

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 setSlideCustom = () => 1 ;

	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}
			setSlideCustom={setSlideCustom}
			>
				<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

FAQs

Package last updated on 08 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc