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

dub-step

v0.0.7

Published

A set of primitives for building step/index based UI widgets controlled by swipe, timers, and/or buttons.

Downloads

117

Readme

Travis npm GitHub Issues Coverage Styled with Prettier README generated by emdaer Twitter GitHub stars

Many existing carousel/swipe solutions in one way or another end up dictating the markup of your UI. They expose many options to allow for extensibility, but this results in a convoluted API that is not flexible. In these cases, your often very specific design must be fit into an existing rigid solution.

dub-step simply manages the state needed to power a carousel, slideshow, photo gallery, or even multi-step forms, allowing you to build the UI how you want. It uses the function as child and "prop getter" patterns, which gives you maximum flexibility with a minimal API.

NOTE: Version v0.0.5 introduced a breaking change. All occurences of index in the dub-step API were renamed to step, for consistency. Please see the release notes for more info.

Table of Contents

Installation

This module is distributed via npm which is bundled with node and should be installed as one of your project's dependencies:

npm install --save dub-step

This package also depends on react and prop-types. Please make sure you have those installed as well.

Usage

NOTE: Glamorous is used for styles in this example, but is not required.

import DubStep from 'dub-step';
import glamorous, { Div, Img } from 'glamorous';

function BasicSlideshow({slides, onChange}) {
  return (
    <DubStep
      cycle
      pauseOnHover
      duration={1500}
      total={slides.length}
    >
      {({
        Next,
        Previous,
        Pause,
        Play,
        StepIndex,
        step
      }) => (
        <section>
          <Div width="350px" overflow="hidden" margin="0 auto">
            <Div
              display="flex"
              transform={`translate3d(${-step * 350}px, 0, 0)`}
              transition="all .3s ease-in-out"
            >
              {slides.map((url, i) => <Img src={url} alt="doge pic" width="100%" height="100%" />)}
            </Div>
          </Div>
          <Div display="flex" justifyContent="center">
            {slides.map((url, i) => (
              <StepIndex
                component={Img}
                step={i}
                key={i}
                src={url}
                width="30px"
                height="30px"
                margin="5px"
                padding="2px"
                border={i === step ? '1px solid darkgray' : 'none'}
                transform={`scale(${i === step ? 1.2 : 1})`}
              />
            ))}
          </Div>
          <Div display="flex" justifyContent="center">
            <Previous>Previous</Previous>
            <Next>Next</Next>
            <Play>Play</Play>
            <Pause>Pause</Pause>
          </Div>
        </section>
      )}
    </DubStep>
  );
}

const DOGE_PICS = [
  'http://doge2048.com/meta/doge-600.png',
  'http://doge2048.com/meta/doge-600.png',
  'http://doge2048.com/meta/doge-600.png',
  'http://doge2048.com/meta/doge-600.png',
  'http://doge2048.com/meta/doge-600.png'
];

function App() {
  return (
    <BasicSlideshow
      slides={DOGE_PICS}
      onChange={currentIndex => console.log(currentIndex)}
    />
  )
}

Builds... simpleslideshow

In the example of above, the step is used in coordination with a css transform/transition to animate the changing slides.

Props

See the API Docs for information on the props exposed by this package.

Control Props

dub-step manages its own state internally and calls your onChange/OnPlay/OnPause etc. handlers with any relevant changes. The controllable state that dub-step manages includes: step and paused. Your child callback function (read more below) can be used to manipulate this state from within the render function and can likely support many of your use cases.

However, if more control is needed, you can pass any of these pieces of state as a prop (as indicated above) and that state becomes controlled. As soon as this.props[controllableStatePropKey] !== undefined, internally, dub-step will determine its state based on your prop's value rather than its own internal state. You will be required to keep the state up to date, but you can also control the state from anywhere, be that state from other components, redux, react-router, or anywhere else.

How To Render

Dub step uses the child callback render function pattern. This is where you render whatever you want to based on the state of dub-step which is passed to the callback as parameters. The function is passed as the child prop of the DubStep component:

<DubStep>
  {({/* parameters here */}) => (/* your render code here*/)}
</DubStep>

The paramters of this function can be split into three categories: State, Components, and Actions.

See the API Docs for a list of these properties.

Examples

These are not yet available on github. But check out the codesandbox until they are! Fork it and build your own examples then tweet me about it!

Edit dub-step Examples 🕺🏽

Here are some of the existing examples: dub-step-examples

Credits

Kent Dodds' work on downshift 🏎 heavily inspired this package. You may even notice some copy pasta in the README 😏.

This package is also inspired by work I rubber-ducked with flip for managing focus in a TV Shelf UI.

Much of the swipe code was lifted from react-slick by akiran a very solid solution for swipe friendly carousels.

There is no lack of carousel libraries out there. I looked at many of them while writting this package. I hope dub-step represents a move towards an unopinionated solution that enables design and development to work together not against each other.

Check out other solutions on npm.

Some of the time spent writting this package was sponsored by Four Kitchens. I ❤️ 4K. Come work with us!

Contributing

If you'd like to make emdaer better, please read our guide to contributing.

These wonderful people have contributed to dub-step in one way or another:

License

dub-step is MIT licensed.