react-sled is a carousel made with react-spring.
npm install react-sledreact-sled is a carousel made with react-spring.

- 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!
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 all dependencies via Yarn or NPM.
``bash`
yarn add react-sled react-spring@next react-use-gesture react react-dom
`jsx
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 (
{images.map((image, index) => (
My Image #${index}
} />
))}
{images.map((image, index) => (
))}
);
};
export default App;
`
Sled is the wrapper-component. It takes no props.
Render all your views into this component.
It takes these optional props:
| Name | Type | Default | Description |
| :------------------- | :--------------- | :----------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| width | String | '100%' | Sets the viewpager’s width. Allowed units: all CSS-units |null
| height | String | | Sets the viewpager’s height. |2:1
| proportion | String | | Provide either a width or height and set the other dimension proportional to it. If you provide a height and a width proportion is disabled. |1
| showElements | Number | | Determines how many Slides/Views fit in the Sled’s viewport. |1
| slideBy | Number | | Determines how many Slides/Views the Sled’s slides with one movement . |undefined
| select | Number | | Select certain view. |null
| style | Object | | Add inline styles to the view-wrapper. |true
| keyboard | Boolean | | Set Keyboard controls. |true
| dragging | Boolean | | Set Mouse- and Touch-Dragging. |40
| dragDistance | Number or String | | Distance 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". |undefined
| autoPlay | Number | | Activates automatic Sliding-Interval in Milliseconds. |{ mass: 1, tension: 210, friction: 20, clamp: true }
| config | Number | | react-spring animation-settings. |false
| pause | Boolean | | autoPlay (if activated) gets paused. |true
| pauseOnMouseOver | Boolean | | autoPlay (if activated) gets paused, as long as the user hovers over the sled. |false
| stopOnInteraction | Boolean | | autoPlay (if activated) gets stopped, after the user interacted with the sled. |false
| rewind | Boolean | | Rewind sled, when you want to go beyond the first or last view. |null
| onSledEnd | function | | Callback, that gets triggered after last view. |null
| onAnimationStart | function | | Callback, that gets triggered when a sliding-animation starts. |null
| onAnimationEnd | function | | Callback, that gets triggered when a sliding-animation ends. |
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. className
If you give it a custom -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:
| Name | Type | Default | Description |
| :--------- | :--------------- | :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| select | String 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' |select
| className | String | Default depends on | |''
| style | String | | 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:
`jsx`
/>
Your Custom-Design:
`jsx`
className="custom"
style={{
background: 'red'
}}
>
My custom arrow!
Selection-Dot:
`jsx`
/>
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.className
If you give it a custom -prop, the Progress will be completely unstyled. You can copy the default-styles from here as a starting-point.
Progress Props Overview:
| Name | Type | Default | Description |
| :--------- | :--------------- | :------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| className | String | Default depends on select | |''
| style | String | | 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. |
`jsx`
className="my-progress"
style={{ background: 'red' }}
/>
A hook, that exposes the plugin’s state-management.
useSledStore is only useable inside the Sled-Component.Array
It returns an with 2 elements:
1. state of type objectfunction`
2. dispatch of type
- [ ] Control animation by frame on drag
- [ ] Infinity-Mode
- [ ] Nice documentation with live examples (using Docz)
- [ ] automated testing
Every contribution is very much appreciated.
If you like react-sled, don't hesitate to star it on GitHub.
MIT © AndreasFaust
This library is derived from the great work and especially this code-sandbox-example provided by Paul Henschel and the react-spring-team.