0.0.2 • Published 6 years ago

hyperapp-slider v0.0.2

Weekly downloads
2
License
ISC
Repository
github
Last release
6 years ago

hyperapp-slider

Slider/range component for Hyperapp.

Installation

npm install --save hyperapp-slider

Usage

import { h, app } from 'hyperapp';
import { Slider } from 'hyperapp-slider';

const state = {
    mySlider: Slider.state({min: 0, max: 100, value: 50, step: 1})
};

const actions = {
    mySlider: Slider.actions
};

const view = (state, actions) => (
    <div>
        <div>Value: {state.mySlider.value}</div>
        <Slider state={state.mySlider} actions={actions.mySlider} />
    </div>
);

app(state, actions, view, document.body);

There is no default styling. You can style based on the classes .slider, .slider__track, slider__fill and .slider__handle. Alternatively, you can passe your own "base" class with baseClass="my-slider" and get .my-slider, .my-slider__track, my-slider__fill and .my-slider__handle.

See example/index.html and example/index.js for a working example.

NOTE: don’t update values owned by hyperapp-slider manually, things will get out of sync.

Configuration

The slider is configured through the Slider.state function. It returns your configured state for the slider, and should be put in your global state object. It accepts the following properties.

PropertyTypeMandatoryDefaultExplanation
minIntYesThe minimum value
maxIntYesThe maximum value
valueIntYesThe initial value
stepInt/StringNo1The value added or subtracted to value per tick. Set to a number for a discrete slider, or 'any' for a continuous slider

Development

  • npm i
  • npm run watch
  • open http://localhost:1234