Primitives for building step based UI widgets controlled by swipe, timers, and/or buttons.
dub-step provides an API for updating the state of an index or "step".
next
is called.Extends Component
(any)
These props affect how/when the step and associated state is updated.
(number)
: Regardless of swipe direction, the step is iterated. Defaults to
false
.
(function)
: Called after the step has changed and after animationSpeed seconds if present. Defaults to
() => {}
.
(function)
: Called when a swipe/drag is moved. Warning: This gets called
a lot
. Defaults to
() => {}
.
This component is responsible for tracking touch/drag interactions and sets dub-steps swipe state properties respectively.
ReactElement
:
// In this example, GlamorousDogeImg is a glamorous.img. The only required prop here is component. The rest gets passed through for glamorous to for styling purposes (Like css transforms).
// NOTE: Glamorous is only used as an example. Any kind of component can be passed to the component prop.
// If no component is passed, a div will be used.
<Step
component={GlamorousDogeImg}
swipeLeftDistance={swipeLeftDistance}
dragging={dragging}
src={url}
alt="doge pic"
/>
This component is responsible for starting an internal interval that increments the step by the stepInterval value.
ReactElement
:
// Any dub-step component can be customized by passing a `component` prop.
<Play component={MyCustomPlayButton}>Play</Play>
This component is responsible for setting the current step of dub-step.
(object)
Name | Description |
---|---|
props.component (ReactElement | string)
(default button )
|
The element to render |
(number)
The step to which dub-step should change.
ReactElement
:
// Remember, any other prop added gets passed through to the component.
<StepIndex
step={index}
onMouseEnter={() => console.log(`About to switch to step ${index}`)}
>
{stepNumber}
</StepIndex>
The state of dub-step and prop getters/actions for changing the state are exposed as a parameter to the render prop.
The paramters of this function can be split into 4 categories: State, Components, Actions.
component
prop which allows you to control your UI,
add internal props, and pass through any additional props you add. Examples include: Step, Next, Previous, Play, Pause.
NOTE: Each component has an alternative and respective "prop getter", if that pattern is preferred. These are functions named get*ControlProps.
Call/spread these on the element you're rendering for a given purpose. For example: <button {...getNextControlProps(otherProps)}))>Next</button>
.
It's advisable to pass all your props to that function rather than applying them on the element yourself to avoid your props being overridden (or overriding the props returned).Type: object
(number)
: state - The current step of dub-step. Controlled.
(boolean)
: state - Is dub-step paused? Controlled.
(boolean)
: state - Is the step component transition animating?
(boolean)
: state - Has the swipe threshold been reached?
(boolean)
: state - Has the step component been initially dragged?
(number)
: state - A number representing the distance the step component has been dragged horizontally.
(number)
: state - A number representing the distance the step component has been dragged vertically.
(boolean)
: state - Has the step component been dragged enough to be moved to the next/previous step?
(number)
: state - A number between 0 and 1 with nearness to 1 representing closeness to being swiped.
(number)
: state - Either 1 or -1. 1 representing right and -1 representing left.
(ReactElement)
: Component - This component is responsible for tracking touch/drag interactions and sets dub-steps swipe state properties respectively.
Alternatively, use
getStepProps
if you prefer the prop getter patern. Returns the props you should apply to an element you render that is expected to have swipe/drag interactions.
(ReactElement)
: Component - This component is responsible for incrementing the step by the stepInterval value.
Alternatively, use
getNextControlProps
if you prefer the prop getter pattern. It returns the props you should apply to a next button element you render.
(ReactElement)
: Component - This component is responsible for decrementing the step by the stepInterval value.
Alternatively, use
getPreviousControlProps
if you prefer the prop getter patern. It returns the props you should apply to a previous/back button element you render.
(ReactElement)
: Component - This component is responsible for starting an internal interval that increments the step by the stepInterval value.
Alternatively, use
getPlayControlProps
if you prefer the prop getter patern. It returns the props you should apply to a play button element you render.
(ReactElement)
: Component - This component is responsible for clearing an internal interval that increments the step by the stepInterval value.
Alternatively, use
getPauseControlProps
if you prefer the prop getter patern. It returns the props you should apply to a pause button element you render.
(ReactElement)
: Component - This component is responsible for setting the current step of dub-step.
NOTE: It takes a step prop representing the step to which dub-step should change.
Alternatively, use
getStepControlProps
if you prefer the prop getter patern. It returns the props you should apply to an element you render that sets the step of dub-step.
(function)
: Action - Increments the step by the stepInterval.
(function)
: Action - Decrements the step by the stepInterval.
(function)
: Action - Starts the dub-step incrementor interval.
(function)
: Action - Pauses dub-step.