All Projects → dbismut → React Soft Slider

dbismut / React Soft Slider

Licence: mit
Simple, fast and impartial slider

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Soft Slider

Swiper
Most modern mobile touch slider with hardware accelerated transitions
Stars: ✭ 29,519 (+54564.81%)
Mutual labels:  swipe, slider, carousel
React Native Swiper Flatlist
👆 Swiper component implemented with FlatList using Hooks & Typescript + strict automation tests with Detox
Stars: ✭ 217 (+301.85%)
Mutual labels:  swipe, slider, carousel
React Responsive Carousel
React.js Responsive Carousel (with Swipe)
Stars: ✭ 1,962 (+3533.33%)
Mutual labels:  swipe, slider, carousel
skeleton-carousel
Carousel component. Horizontal and vertical swipe navigation
Stars: ✭ 31 (-42.59%)
Mutual labels:  slider, carousel, swipe
Slider
Touch swipe image slider/slideshow/gallery/carousel/banner mobile responsive bootstrap
Stars: ✭ 2,046 (+3688.89%)
Mutual labels:  swipe, slider, carousel
Splide
Splide is a lightweight, powerful and flexible slider and carousel, written in pure JavaScript without any dependencies.
Stars: ✭ 786 (+1355.56%)
Mutual labels:  swipe, slider, carousel
Nanogallery2
a modern photo / video gallery and lightbox [JS library]
Stars: ✭ 488 (+803.7%)
Mutual labels:  swipe, gesture
Hooper
🎠 A customizable accessible carousel slider optimized for Vue
Stars: ✭ 561 (+938.89%)
Mutual labels:  slider, carousel
Tiny Swiper
Ingenious JavaScript Carousel powered by wonderful plugins. Lightweight yet extensible. Import plugins as needed, No more, no less.
Stars: ✭ 1,061 (+1864.81%)
Mutual labels:  slider, carousel
Discretescrollview
A scrollable list of items that centers the current element and provides easy-to-use APIs for cool item animations.
Stars: ✭ 5,533 (+10146.3%)
Mutual labels:  swipe, carousel
Vue Gallery
📷 Responsive and customizable image and video gallery, carousel and lightbox, optimized for both mobile and desktop web browsers.
Stars: ✭ 405 (+650%)
Mutual labels:  slider, carousel
Simple Slider
🎠 The 1kb JavaScript Carousel
Stars: ✭ 583 (+979.63%)
Mutual labels:  slider, carousel
Glide
A dependency-free JavaScript ES6 slider and carousel. It’s lightweight, flexible and fast. Designed to slide. No less, no more
Stars: ✭ 6,256 (+11485.19%)
Mutual labels:  slider, carousel
Comfortable Swipe
Comfortable 3-finger and 4-finger swipe gesture using Xdotool in native C++
Stars: ✭ 483 (+794.44%)
Mutual labels:  swipe, gesture
React Native Swipe Gestures
4-directional swipe gestures for react-native
Stars: ✭ 471 (+772.22%)
Mutual labels:  swipe, gesture
Any Touch
👋 手势库, 按需2kb~5kb, 兼容PC / 移动端
Stars: ✭ 567 (+950%)
Mutual labels:  swipe, gesture
Vue Slick Carousel
🚥Vue Slick Carousel with True SSR Written for ⚡Faster Luxstay
Stars: ✭ 447 (+727.78%)
Mutual labels:  slider, carousel
React Whirligig
A react carousel/slider like component for sequentially displaying slides or sets of slides
Stars: ✭ 20 (-62.96%)
Mutual labels:  slider, carousel
Egjs Flicking
🎠 ♻️ Everyday 30 million people experience. It's reliable, flexible and extendable carousel.
Stars: ✭ 937 (+1635.19%)
Mutual labels:  slider, carousel
Hammer Slider
DISCONTINUED - HammerSlider touch is a lightweight infinite carousel plugin.
Stars: ✭ 21 (-61.11%)
Mutual labels:  slider, carousel

react-soft-slider

npm (tag) npm bundle size GitHub

Demo [Source]

React-soft-slider is a minimally-featured carousel. It focuses on providing the best user experience for manipulating slides. It doesn't try to implement additional features such as pagination dots, next and previous buttons, autoplay. If you're looking for a slider that has all this, there's plenty of alternatives out there.

This allows react-soft-slider to be highly impartial when it comes to styling, so you shouldn't be fighting too hard to making the slider slider look the way you want.

  • Touch-gesture compatible: handles swipe and drag on mobile and desktop devices
  • Spring animations: driven by high-performance springs
  • Impartial styling: you are responsible for the styling of your slides
  • Fully responsive: as long as your slides styling is responsive as well!
  • Dynamic number of slides: you can add or remove slides on the fly

React-soft-slider is powered by react-spring for springs animation and react-use-gesture for handling the drag gesture.

Installation

npm install react-soft-slider

⚠️ You also want to add the intersection-observer and resize-observer polyfills for full browser support. Check out adding the polyfills for details about how you can include it.

Usage

<Slider /> has a very limited logic, and essentially does two things:

  1. it positions the slider to the slide matching the index you passed as a prop
  2. when the user changes the slide, it will then fire onIndexChange that will pass you the new index. You will usually respond by updating the slider index prop:
import { Slider } from 'react-soft-slider'

const slides = ['red', 'blue', 'yellow', 'orange']
const style = { width: 300, height: '100%', margin: '0 10px' }

function App() {
  const [index, setIndex] = React.useState(0)

  return (
    <Slider
      index={index}
      onIndexChange={setIndex}
      style={{ width: 400, height: 200 }}
    >
      {slides.map((color, i) => (
        <div key={i} style={{ ...style, background: color }} />
      ))}
    </Slider>
  )
}

As you can see from the example, any child of the <Slider /> component is considered as a slide. You are fully responsible for the appearance of the slides, and each slide can be styled independently.

Note: although the above example uses hooks, react-soft-slider is compatible with Class-based components. However, since it internally uses hooks, it requires React 16.8+.

Props

The <Slider /> component accepts the following props:

Name Type Description Default Value
children node elements you should pass to the slider and that will be considered as slides Required
index number the index of the slide that should be shown by the slider Required
onIndexChange() (newIndex: number) => void function called by the slider when the slide index should change Required
indexRange [number,number] sets the minimum and maximum index range the slider should slide through. If the maximum index is negative, then it's set relatively to the children length. See example here.
enabled boolean enables or disables the slider gestures true
vertical boolean enables vertical sliding mode false
draggedScale Number scale factor of the slides when dragged 1.0
draggedSpring object spring between the pointer and the dragged slide { tension: 1200, friction: 40 }
trailingSpring object spring of the other slides { tension: 120, friction: 30 }
releaseSpring object spring used when the slides rest (user releases the pointer) { tension: 120, friction: 30 }
trailingDelay Number delay of trailing slides (in ms) 50
onDragStart() (pressedIndex: number) => void function called when the drag starts, passing the index of the slide being dragged as an argument
onDragEnd() (pressedIndex: number) => void function called when the drag ends, passing the index of the slide being dragged as an argument
className string CSS class passed to the slider wrapper
style object style passed to the slider wrapper
slideStyle object or (i: number) => object style passed to the slides
slideClassName string CSS class passed to the slides
slideAlign string (align-items prop) slide alignment ('center', 'flex-start', 'flex-end') 'center'

Springs configuration

React-soft-slider uses two springs, one for the dragged slide, and one for the other slides, that you can configure to your liking. It accepts any options supported by react-spring, including durations if you're not happy with how springs feel see here for more info.

Gotchas

Sizing the slider

The slider wrapper has a default width set to 100%, so that it fills its container by default. You can override this behaviour by passing your own style or className props.

Sizing your slides relatively to the slider

If you want to size your slides relatively to the slider width (let's say width: 80%), you'll need to rely on slideStyle set to {{ minWidth: '80%' }} and styling your slide with width set to 100%. The same logic applies for height when in vertical sliding mode.

Don't use transform styling in slideStyle

React-soft-slider uses the transform attribute to make slides move so transform attributes in slideStyle will get overriden.

React-soft-slider is open to suggestions!

React-soft-slider will probably never include slider peripheral features, but is open to suggestions to make handling your slides easier!

Polyfills

You can import the IntersectionObserver polyfill and ResizeObserver polyfill directly or use a service like polyfill.io to add it when needed.

yarn add intersection-observer resize-observer-polyfill

Then import it in your app:

import 'intersection-observer'
import 'resize-observer-polyfill'

If you are using Webpack (or similar) you could use dynamic imports, to load the Polyfill only if needed. A basic implementation could look something like this:

/**
 * Do feature detection, to figure out which polyfills needs to be imported.
 **/
async function loadPolyfills() {
  if (typeof window.IntersectionObserver === 'undefined') {
    await import('intersection-observer')
  }
  if (typeof window.ResizeObserver === 'undefined') {
    await import('resize-observer-polyfill')
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].