Socket
Book a DemoInstallSign in
Socket

react-sled

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-sled

react-sled is a carousel made with react-spring.

2.0.4
latest
Source
npmnpm
Version published
Weekly downloads
11
-68.57%
Maintainers
1
Weekly downloads
 
Created
Source

react-sled Logo

react-sled is a carousel made with react-spring.

NPM

  • Super-smooth spring animations (thanks to react-spring)
  • Lightweight and performant architecture
  • Touch- and Mousedrag (thanks to react-with-gesture)
  • Easy to style
  • Ready for server-side-rendering
  • All props are dynamically changeable
  • (Should be) Compatible with older Browsers from Internet Explorer 11 (Needs testing!)

🛷 Have a look at the example!

New Major release 2.0

Breaking Changes:

  • Removed styled-components
  • Removed custom ow-unit
  • Use react-spring Version 9 and react-with-gesture Version 7

New Features:

  • Full Type-Script support
  • Vertical Sliding
  • Set fixed proportion
  • Show multiple elements at once (showElements)
  • Move by multiple elements (slideBy)

Install

Install all dependencies via Yarn or NPM.

yarn add react-sled react-spring@next react-use-gesture react react-dom

Usage

import React from "react";
import { Sled, Views, Progress, Control } from "react-sled";
import "react-sled/dist/main.css";

const images = ["my-image-1.jpg", "my-image-2.jpg"];

const App = () => {
  return (
    <Sled>
      <Views>
        {images.map((image, index) => (
          <img key={image} src={image} alt={`My Image #${index}`} />
        ))}
      </Views>
      <Progress />
      <div className="controls arrows">
        <Control select="prev" />
        <Control select="next" />
      </div>
      <div className="controls dots">
        {images.map((image, index) => (
          <Control key={image} select={index} />
        ))}
      </div>
    </Sled>
  );
};

export default App;

Sled

Sled is the wrapper-component. It takes no props.

Views

Render all your views into this component. It takes these optional props:

NameTypeDefaultDescription
widthString'100%'Sets the viewpager’s width. Allowed units: all CSS-units
heightStringnullSets the viewpager’s height.
proportionString2:1Provide either a width or height and set the other dimension proportional to it. If you provide a height and a width proportion is disabled.
showElementsNumber1Determines how many Slides/Views fit in the Sled’s viewport.
slideByNumber1Determines how many Slides/Views the Sled’s slides with one movement .
selectNumberundefinedSelect certain view.
styleObjectnullAdd inline styles to the view-wrapper. 
keyboardBooleantrueSet Keyboard controls. 
draggingBooleantrueSet Mouse- and Touch-Dragging. 
dragDistanceNumber or String40Distance the user has to drag the slider to trigger action. A number is calculated in Pixel. A string is converted to a number unless it has the unit %, which means "percent of Sled’s width". 
autoPlayNumberundefinedActivates automatic Sliding-Interval in Milliseconds. 
configNumber{ mass: 1, tension: 210, friction: 20, clamp: true }react-spring animation-settings. 
pauseBooleanfalseautoPlay (if activated) gets paused. 
pauseOnMouseOverBooleantrueautoPlay (if activated) gets paused, as long as the user hovers over the sled. 
stopOnInteractionBooleanfalseautoPlay (if activated) gets stopped, after the user interacted with the sled. 
rewindBooleanfalseRewind sled, when you want to go beyond the first or last view. 
onSledEndfunctionnullCallback, that gets triggered after last view.
onAnimationStartfunctionnullCallback, that gets triggered when a sliding-animation starts.
onAnimationEndfunctionnullCallback, that gets triggered when a sliding-animation ends.

Controls

There is only one control-component for Arrows and Selecting-Dots. The prop select decides what the Control-element is: A string called next or prev will activate Arrow-functionality, a number Select-functionality.

You can easily style it via CSS. The default-styles are scoped to the class-name sled-progress-default. They are contained in the file dist/index.css. If you give it a custom className-prop, the default-class will be overridden and the Progress will be completely unstyled. Then you can copy the default-styles from here as a starting-point.

Control Props Overview:

NameTypeDefaultDescription
selectString or Number'next'Defines, if the Control has arrow- or dot-functionality. A number is the index of the target-view. A string can be 'prev' or 'next'
classNameStringDefault depends on select
styleString''If you provide a style and no preset, the default preset gets completely replaced. If you provide a style and a preset, the preset gets extended.

Arrow: Default-Design:

<Control
  select="next"
/>

Your Custom-Design:

<Control
  select="next"
  className="custom"
  style={{
    background: 'red'
  }}
>
  My custom arrow!
</Control>

Selection-Dot:

<Control
  select={1}
/>

Progress

react-sled has an Instagram-like progress-bar. You can easily style it via CSS. The default-styles are scoped to the class-name sled-progress-default. If you give it a custom className-prop, the Progress will be completely unstyled. You can copy the default-styles from here as a starting-point.

Progress Props Overview:

NameTypeDefaultDescription
classNameStringDefault depends on select
styleString''If you provide a style and no preset, the default preset gets completely replaced. If you provide a style and a preset, the preset gets extended.
<Progress
  className="my-progress"
  style={{ background: 'red' }}
/>

useSledStore

A hook, that exposes the plugin’s state-management. useSledStore is only useable inside the Sled-Component. It returns an Array with 2 elements:

  • state of type object
  • dispatch of type function

To-Do

  • Control animation by frame on drag
  • Infinity-Mode
  • Nice documentation with live examples (using Docz)
  • automated testing

Contributing

Every contribution is very much appreciated.

If you like react-sled, don't hesitate to star it on GitHub.

License

MIT © AndreasFaust

Thanks

This library is derived from the great work and especially this code-sandbox-example provided by Paul Henschel and the react-spring-team.

Keywords

React

FAQs

Package last updated on 02 Feb 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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.