Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nuka-carousel-qb

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nuka-carousel-qb

Pure React Carousel

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

A Pure ReactJS Carousel Component

Maintained by Sarah Meyer

Nuka Carousel Animated Example

Install

$ yarn add nuka-carousel

Example

import React from 'react';
import Carousel from 'nuka-carousel';

export default class extends React.Component {
  render() {
    return (
      <Carousel>
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide1" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide2" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide3" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide4" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide5" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide6" />
      </Carousel>
    );
  }
}

Running demo locally

The demo can be launched on local machine via webpack-dev-server. Run the following:

yarn start

Now, you can access the application on your localhost at following url: Demo

Props

NamePropTypeDescription
afterSlideReact.PropTypes.funcHook to be called after a slide is changed
autoGenerateStyleTagReact.PropTypes.boolWhen set to true, it will generate a style tag to help ensure images are displayed properly. Set to false if you don't want or need the style tag generated. Defaults to true
autoplayReact.PropTypes.boolAutoplay mode active. Defaults to false
autoplayIntervalReact.PropTypes.numberInterval for autoplay iteration. Defaults to 3000 milliseconds
beforeSlideReact.PropTypes.funcHook to be called before a slide is changed
cellAlignReact.PropTypes.oneOf(['left', 'center', 'right'])When displaying more than one slide, sets which position to anchor the current slide to.Is overridden to left when transitionMode="fade"
cellSpacingReact.PropTypes.numberSpace between slides, as an integer, but reflected as px
draggingReact.PropTypes.boolEnable mouse swipe/dragging.Defaults to true
easingReact.PropTypes.stringAnimation easing function. See valid easings here: D3 Easing Functions
edgeEasingReact.PropTypes.stringAnimation easing function when swipe exceeds edge. See valid easings here: D3 Easing Functions
framePaddingReact.PropTypes.stringUsed to set the margin of the slider frame. Accepts any string dimension value such as "0px 20px" or "500px"
frameOverflowReact.PropTypes.stringUsed to set overflow style property on slider frame. Defaults to hidden
heightModeReact.PropTypes.oneOf(['first', 'current', 'max'])Change the height of the slides based either on the first slide, the current slide, or the maximum height of all slides. Overrides height set by initialSlideHeight
initialSlideHeightReact.PropTypes.numberInitial height of the slides in pixels. Defaults to 100
initialSlideWidthReact.PropTypes.numberInitial width of the slides in pixels
pauseOnHoverReact.PropTypes.boolPause autoPlay when mouse is over carousel. Defaults to true
slideIndexReact.PropTypes.numberManually set the index of the slide to be shown
slidesToShowReact.PropTypes.numberNumber of slides to show at once. Will be cast to an integer when transitionMode="fade"
slidesToScrollReact.PropTypes.oneOfType([ React.PropTypes.number, React.PropTypes.oneOf(['auto'])])Slides to scroll at once. Set to "auto" to always scroll the current number of visible slides. Is overridden to slidesToShow when transitionMode="fade"
slideWidthReact.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number])Manually set slideWidth. If you want hard pixel widths, use a string like slideWidth="20px", and if you prefer a percentage of the container, use a decimal integer like slideWidth={0.8}
speedReact.PropTypes.numberAnimation duration/Transition speed in milliseconds
swipingReact.PropTypes.boolEnable touch swipe/dragging
transitionModeReact.PropTypes.oneOf(['scroll', 'fade'])Set the way slides transition from one to the next. Defaults to scroll
verticalReact.PropTypes.boolEnable the slides to transition vertically
widthReact.PropTypes.stringUsed to hardcode the slider width. Accepts any string dimension value such as "80%" or "500px"
withoutControlsReact.PropTypes.boolUsed to remove all controls at once. Overwrites the render[Top, Right, Bottom, Left]CenterControls(). Defaults to false
wrapAroundReact.PropTypes.boolSets infinite wrapAround mode. Defaults to false
render*Controls

React.PropTypes.func

A set of eight render props for rendering controls in different positions around the carousel.

  • Valid render props for the eight positions are renderTopLeftControls, renderTopCenterControls, renderTopRightControls, renderCenterLeftControls, renderCenterCenterControls, renderCenterRightControls, renderBottomLeftControls, renderBottomCenterControls, and renderBottomRightControls.
<Carousel
  renderTopCenterControls={({ currentSlide }) => (
    <div>Slide: {currentSlide}</div>
  )}
  renderCenterLeftControls={({ previousSlide }) => (
    <button onClick={previousSlide}>Previous</button>
  )}
  renderCenterRightControls={({ nextSlide }) => (
    <button onClick={nextSlide}>Next</button>
  )}
>
  {/* Carousel Content */}
</Carousel>
  • The function returns the props for goToSlide, nextSlide and previousSlide functions in addition to slideCount and currentSlide values. Can also remove all render controls using withoutControls.

You can control the state of the carousel from your parent component as shown below:

import React from 'react';
import Carousel from 'nuka-carousel';

export default class extends React.Component {
  state = {
    slideIndex: 0
  };

  render() {
    return (
      <Carousel
        slideIndex={this.state.slideIndex}
        afterSlide={slideIndex => this.setState({ slideIndex })}
      >
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide1" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide2" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide3" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide4" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide5" />
        <img src="http://placehold.it/1000x400/ffffff/c0392b/&text=slide6" />
      </Carousel>
    );
  }
}

Contributing

See the Contribution Docs.

Keywords

FAQs

Package last updated on 07 Oct 2018

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