npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chipp972/carousel

v1.6.1

Published

Carousel component for multistep screens

Downloads

30

Readme

@chipp972/carousel

Carousel component.

Install

npm i -S @chipp972/carousel

Usage

Setup the carousel in the redux store to be able to control it with redux actions:

import { combineReducers } from 'redux';
import { carouselReducerKey, carouselReducer } from '@chipp972/carousel';
import { otherReducers } from './reducers';

export const rootReducer = combineReducers({
  [carouselReducerKey]: carouselReducer,
  ...otherReducers
});

Use the component in your app by wrapping all the steps you need to display in the carousel:

import React from 'react';
import { Carousel } from '@chipp972/carousel';
import { carouselId } from './constants';
import { StepComponent1, StepComponent2, StepComponent3, StepComponent4 } from './component';

export const Example = () => (
  <Carousel carouselId={carouselId} isScrollToTop isSwipeDisabled>
    <StepComponent1 />
    <StepComponent2 />
    <StepComponent3 />
    <StepComponent4 />
  </Carousel>
);

Here is an example of step:

import React from 'react';
import { carouselId } from '../constants';
import { useCarousel } from '@chipp972/carousel';

export const StepComponent1: React.FC = () => {
  const { currentStepIndex, goPrevStep, goNextStep } = useCarousel(carouselId);
  return (
    <section>
      <div>STEP {currentStepIndex}</div>
      <button onClick={goPrevStep}>go previous step</button>
      <button onClick={goNextStep}>go next step</button>
    </section>
  );
};

Props

| name | type | description | optional | default | | -------------------------- | ------------------------------------------------- | -------------------------------------------------------------------------------------- | -------- | ------- | | carouselId | string | Unique identifier for the carousel in the redux store | false | | | startSlide | number | Index position Swipe should start at | true | 0 | | transitionSpeed | number | Speed of prev and next transitions in milliseconds | true | 300 ms | | isSwipeDisabled | boolean | Stop any touches on this container from scrolling the page | true | false | | isContinuous | boolean | Create an infinite feel with no endpoints | true | false | | isScrollToTop | boolean | Scroll to the top of the carousel on slide change | true | false | | autoSliding | number | Begin with auto slideshow (time in milliseconds between slides) | true | 0 | | widthOfSiblingSlidePreview | number | Width of next and previous slide preview in pixels | true | 0 | | onTransitionStart | (index: number, currentStep: HTMLElement) => void | Runs at slide change | true | | | onTransitionEnd | (index: number, currentStep: HTMLElement) => void | Runs at the end slide transition | true | | | onSwipe | (position: number) => void | invoked while swiping with the percentage (0-1) of the full width that has been swiped | true | |

Usage without Redux

You can use the "raw" version which is just a React wrapper of swipe-js-iso with some additional options.

import React from 'react';
import { RawCarousel, SwipeInstance } from '@chipp972/carousel';

const slideStyle = {
  height: '100vh',
  color: 'white',
  textAlign: 'center',
  fontSize: 50
};

export const Example = () => {
  // You will need a ref to trigger the carousel actions
  const ref = React.useRef<SwipeInstance>(null);

  return (
    <>
      <button onClick={() => ref.current?.slide(0)}>jump to first</button>
      <button onClick={() => ref.current?.prev()}>prev</button>
      <button onClick={() => ref.current?.next()}>next</button>
      <button onClick={() => ref.current?.slide(ref.current?.getNumSlides() - 1)}>jump to last</button>

      <RawCarousel
        ref={ref}
        id="test-raw"
        swipeOptions={{
          widthOfSiblingSlidePreview: 400,
          continuous: false
        }}>
        <div style={{ backgroundColor: 'red', ...slideStyle }}>1</div>
        <div style={{ backgroundColor: 'blue', ...slideStyle }}>2</div>
        <div style={{ backgroundColor: 'green', ...slideStyle }}>3</div>
      </RawCarousel>
    </>
  );
};

Polyfill

You should use a polyfill to enable smoothscrolling on ios devices. For example with smoothscroll-polyfill :

import smoothscroll from 'smoothscroll-polyfill';

smoothscroll.polyfill();

Changelog

1.6.1

  • Use ramda es5 imports

1.6.0

  • Use content-visibility css property to improve performances

1.5.3

  • Remove useless babel config

1.5.2

  • Remove smooth scroll polyfill for ios to not break static site build

1.5.1

  • Fix emotion appearing in build files

1.5.0

  • Add a dependencyList parameter to re-render the carousel on demand
  • fix startSlide being a required parameter (default is 0)

1.4.0

  • Export raw carousel to be used without Redux

1.3.1

  • Fix siblings preview

1.3.0

  • Add polyfill for smooth scrolling on ios devices