New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cevad-tokatli/slider-react

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cevad-tokatli/slider-react

React version of Slider

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Slider React

React integration for Slider.

Installation

It is available as a package on NPM for use with a module bundler.

# NPM
$ npm install --save @cevad-tokatli/slider-react

# Yarn
$ yarn add @cevad-tokatli/slider-react

Usage

import '@cevad-tokatli/slider/style.css'
import React from 'react'
import Slider, { Element } from '@cevad-tokatli/slider-react'

export default class App extends React.Component {
  render() {
    return(
      <div>
        <Slider>                
          <Element>
            <img src="img1.jpg" />
          </Element>
          <Element>
            <img src="img2.jpg" />
          </Element>
          <Element>
            <img src="img3.jpg" />
          </Element>
        </Slider>
      </div>
    )
  }
}

Options

OptionTypeDefaultDescription
timingstring"ease"Specifies the speed curve of an animation. Takes all the values CSS3 can take. (like ease, linear, cubic-bezier, step)
durationnumber800Defines how long an animation should take to complete one cycle. (as milliseconds)
sliderTypeSliderTypeCarouselSpecifies the animation type. It can be customized for each image element by passing as prop to the element component.
touchMovebooleantrueEnables slide transitive with touch.
listbooleantrueDisplays a list at the bottom of the slider.
asListstring | HTMLUListElement | HTMLOListElement*nullDeclares the given list as the slider list.
arrowsbooleantrueDisplays right and left arrows to change the index.
asPrevArrowstring | HTMLElement*nullDeclares the given element as the prev arrow.
asNextArrowstring | HTMLElement*nullDeclares the given element as the next arrow.
autoPlaybooleanfalseEnables auto play of slides.
autoPlaySpeednumber5000Sets auto play interval. (as milliseconds)

*: You can give an HTML element or a CSS selector (like #carousel, .container > div:first-child)

  import Slider, { Element, SliderType } from '@cevad-tokatli/slider-react'

  render() {
    return (
      <div>
        <Slider
            timing="linear"
            sliderType={SliderType.Fade}
        >                
          <Element
              sliderType={SliderType.Flow}
          >
              <img src="img1.jpg" />
          </Element>
          <Element>
              <img src="img2.jpg" />
          </Element>
          <Element
              sliderType={SliderType.Carousel}
          >
              <img src="img3.jpg" />
          </Element>
          <Element>
              <img src="img4.jpg" />
          </Element>
        </Slider>
      </div>
    )
  }

Slider Element

It is a object which specifies one single slider element. It has the following attributes.

  • el: HTMLElement
  • wrapperEl: HTMLDivElement
  • sliderType: SliderType
  • before: (el:SliderElement, active:boolean) => Promise
  • after: (el:SliderElement, active:boolean) => Promise
Slider Type

Specfies the slider animation type.

  • Carousel
  • Flow
  • Fade
As List

You can declare your list as a slider list.

  • It can be a ul or ol element.
  • It can be anywhere in the body.
  • List is updated when index is changed.
  • Assigns ct-s-active class to list element that holds the current index.
Callbacks

before(current: SliderElement, next: SliderElement): Promise
It is invoked before animation runs. It returns a promise so that animation waits for the mehtod to complete.

after(current: SliderElement, prev: SliderElement): Promise
It is invoked after animation runs. It returns a promise so before the method completes running, another animation cannot run.

You can pass callbacks as props Slider component or to specify for one element to Element component.

  before(current, next) {
    return new Promise(resolve => {
      // ...
      resolve()
    })
  }

  render() {
    return (
      <div>
        <Slider
          before={this.before}
        >                
          <Element>
              <img src="img1.jpg" />
          </Element>
          <Element>
              <img src="img2.jpg" />
          </Element>
          <Element>
              <img src="img3.jpg" />
          </Element>
        </Slider>
      </div>
    )
  }
Callbacks For Specified Elements

before(el:SliderElement, active:boolean): Promise
It is invoked before animation runs. It returns a promise so that animation waits for the mehtod to complete. It is only invoked when it is the current or next element. If it is the next element, active is true.

after(el:SliderElement, active:boolean): Promise
It is invoked after animation runs. It returns a promise so before the method completes runing, another animation cannot run. It is only invoked when it is the current or previous element. If it is the current element, active is true.

  after(current, active) {
    return new Promise(resolve => {
        // ...
        resolve()
    })
  }

  render() {
    return (
        <div>
            <Slider>                
                <Element
                  after={this.after}
                >
                  <img src="img1.jpg" />
                </Element>
                <Element>
                  <img src="img2.jpg" />
                </Element>
                <Element>
                  <img src="img3.jpg" />
                </Element>
            </Slider>
        </div>
      )
    }

Events

EventDescription
touchStartFires when touching starts.
touchEndFires when touching ends.
changeFires when index changes.
playFires when autoplay starts.
stopFires when autoplay stops.
destroyFires when the slider is destroyed.
  componentDidMount() {
    this.slider.el.addEventListener('touchStart', () => {
        console.log('touching starts')
    })

    this.slider.el.addEventListener('touchEnd', () => {
        console.log('touching ends')
    })
  }

  render() {
    return (
      <div>
        <Slider ref={node => this.slider = node}>                
            // ...
        </Slider>
      </div>
    )
  }

Methods

MethodParamsReturnDescription
prevPromise<boolean>Triggers the previous image. Returns false if the slider is in animation.
nextPromise<boolean>Triggers the next image. Returns false if the slider is in animation.
playvoidStarts autoplay.
stopvoidStops autoplay.
togglevoidToggles autoplay.
destroyvoidDestroys the slider.
getIndexnumberReturns index.
setIndexindex: numberPromise<boolean>Sets index and animates the slider. Returns false if the slider is in animation.
getTotalnumberReturns total number of images.
getCurrentSliderElementReturns the current element.
getTimingstringReturns timing value.
setTimingtiming: stringvoidSets timing value.
getDurationnumberReturns duration.
setDurationduration: numbervoidSets duration.
getAutoPlaySpeednumberReturns auto play speed.
setAutoPlaySpeedspeed: numbervoidSets auto play speed.

*: You can give an HTML element or a CSS selector (like #carousel, .container > div:first-child)

License

Slider React is provided under the MIT License.

Keywords

FAQs

Package last updated on 15 Mar 2023

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