All Projects → yaodingyd → react-flickity-component

yaodingyd / react-flickity-component

Licence: other
A React.js component for using @desandro's Flickity

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to react-flickity-component

pinar
🌲☀️ Customizable, lightweight React Native carousel component with accessibility support.
Stars: ✭ 214 (-17.05%)
Mutual labels:  slider, carousel, carousel-component
Embla Carousel
A lightweight carousel library with fluid motion and great swipe precision.
Stars: ✭ 1,874 (+626.36%)
Mutual labels:  slider, carousel, carousel-component
vue-splide
The Splide component for Vue.
Stars: ✭ 257 (-0.39%)
Mutual labels:  slider, carousel, carousel-component
vue3-carousel
Vue 3 carousel component
Stars: ✭ 379 (+46.9%)
Mutual labels:  slider, carousel
MediaSliderView
Pure java based, highly customizable media slider gallery supporting both images and videos for android.
Stars: ✭ 85 (-67.05%)
Mutual labels:  slider, carousel
react-instagram-zoom-slider
🌄↔️ A slider component with pinch to zoom capabilities inspired by Instagram
Stars: ✭ 67 (-74.03%)
Mutual labels:  slider, carousel
Vue Glide
A slider and carousel as vue component on top of the Glide.js
Stars: ✭ 225 (-12.79%)
Mutual labels:  slider, carousel
vue-barousel
Carousel component mimics NetEase Cloud Music
Stars: ✭ 13 (-94.96%)
Mutual labels:  slider, carousel
angular-simple-slider
An AngularJS directive providing a simple slider functionality
Stars: ✭ 15 (-94.19%)
Mutual labels:  slider, carousel
SimpleSlider
Simple responsive slider created in pure javascript.
Stars: ✭ 21 (-91.86%)
Mutual labels:  slider, carousel
svelte-slidy
📸 Sliding action script
Stars: ✭ 211 (-18.22%)
Mutual labels:  slider, carousel
react-carousel-minimal
React.js Responsive Minimal Carousel
Stars: ✭ 76 (-70.54%)
Mutual labels:  slider, carousel
Keen Slider
The HTML touch slider carousel with the most native feeling
Stars: ✭ 3,097 (+1100.39%)
Mutual labels:  slider, carousel
flexbox-carousel
CSS3 Animated Carousel with Flexbox
Stars: ✭ 23 (-91.09%)
Mutual labels:  carousel, carousel-component
React Flickity Component
A React.js component for using @desandro's Flickity
Stars: ✭ 232 (-10.08%)
Mutual labels:  slider, carousel
jquery.circular-carousel
[ABANDONED] A 3D-like circular carousel plugin for jQuery.
Stars: ✭ 49 (-81.01%)
Mutual labels:  carousel, carousel-component
vue-piece-slider
animated slides in a fragmented look 🐞🌳✡️📐
Stars: ✭ 95 (-63.18%)
Mutual labels:  slider, carousel
Slider
Touch swipe image slider/slideshow/gallery/carousel/banner mobile responsive bootstrap
Stars: ✭ 2,046 (+693.02%)
Mutual labels:  slider, carousel
React Native Swiper Flatlist
👆 Swiper component implemented with FlatList using Hooks & Typescript + strict automation tests with Detox
Stars: ✭ 217 (-15.89%)
Mutual labels:  slider, carousel
v-owl-carousel
🦉 VueJS wrapper for Owl Carousel
Stars: ✭ 46 (-82.17%)
Mutual labels:  carousel, carousel-component

React Flickity Component

Greenkeeper badge styled with prettier

Introduction:

A React.js Flickity component.

Install:

# you need to install flickity as peer dependency, please use v2.3.0 for best experience
npm install [email protected]
npm install react-flickity-component

Usage:

// Commonjs
const Flickity = require('react-flickity-component');
// Or for ES2015 module
import Flickity from 'react-flickity-component'

const flickityOptions = {
    initialIndex: 2
}

function Carousel() {
  return (
    <Flickity
      className={'carousel'} // default ''
      elementType={'div'} // default 'div'
      options={flickityOptions} // takes flickity options {}
      disableImagesLoaded={false} // default false
      reloadOnUpdate // default false
      static // default false
    >
      <img src="/images/placeholder.png"/>
      <img src="/images/placeholder.png"/>
      <img src="/images/placeholder.png"/>
    </Flickity>
  )
}

Example Usage:

See a codesandbox example here: https://codesandbox.io/s/qlz12m4oj6

See an example with server side rendering:

https://github.com/theolampert/react-flickity-component-example

And with typescript:

https://github.com/theolampert/react-flickity-component-example/tree/typescript

Props:

Property Type Default Description
className String '' Applied to top level wrapper
elementType String 'div' Wrapper's element type
options Object {} Flickity initialization opions
disableImagesLoaded Boolean false Disable call reloadCells images are loaded
flickityRef Function Like ref function, get Flickity instance in parent component
reloadOnUpdate Boolean false Read next section before you set this prop. Run reloadCells and resize on componentDidUpdate
static Boolean false Read next section before you set this prop. Carousel contents are static and not updated at runtime. Useful for smoother server-side rendering however the carousel contents cannot be updated dynamically.

How it works

Under the hood, react-flickity-component uses a React Portal to render children slides inside a Flickity instance. The need for a portal is because after Flickity is initialized, new DOM nodes (mostly Flickity wrapper elements) would be created, this changes the DOM hierarchy of the parent component, thus any future update, whether it's originated from Flickity, like adding/removing slides, or from parent, like a prop changes, will make React fail to reconcile for the DOM snapshot is out of sync.

#64 introduced a new prop to change the underlying render method: instead of portal, react-flickity-component will directly render children. This is create a smoother server-side rendering experience, but please be aware using static prop possibly will cause all your future update to fail, which means adding/removing slides will definitely fail to render, so use with caution.

However there is a fail-safe option reloadOnUpdate. It means every time there is a update, we tear down and set up Flickity. This will ensure that Flickity is always rendered correctly, but it's a rather costly operation and it will cause a flicker since DOM nodes are destroyed and recreated.

Use Flickity's API and events

You can access the Flickity instance with flickityRef prop just like ref, and use this instance to register events and use API.

class Carousel extends React.Component {

  componentDidMount = () => {
    // You can register events in componentDidMount hook
    this.flkty.on('settle', () => {
      console.log(`current index is ${this.flkty.selectedIndex}`)
    })
  }

  myCustomNext = () => {
    // You can use Flickity API
    this.flkty.next()
  }

  render() {
    return (
      <Flickity flickityRef={c => this.flkty = c}>
        <img src="/images/placeholder.png"/>
        <img src="/images/placeholder.png"/>
        <img src="/images/placeholder.png"/>
      </Flickity>
      <Button onClick={myCustomNext}>My custom next button</Button>
    )
  }
}

License Information:

GPLv3

Flickity may be used in commercial projects and applications with the one-time purchase of a commercial license. http://flickity.metafizzy.co/license.html

See this issue for more information

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].