#Accessible HTML-Stepper#
It will provide some label-magic through aria-label, so that the buttons actually have a meaning, even if you can't see them.
Styling is not part of it, so you can use whatever you want. The plugin itself doesn't know anything about responsiveness. It does not depend on any plugins.
TODOs/ Ideas
- Option for limiting the total & minimal Amount
- Provide Web-Component
- Let users pass in a set of elements
- Possibility to load via AMD-Loaders
##Usage##
Minimal HTML-Setup:
<div class="stepper"
data-stepper-label-up="Add {{steps}} bed to {{sum}}."
data-stepper-label-down="Remove {{steps}} bed from {{sum}}.">
<label for="stepper-1-ipt">Amount of booked beds:</label>
<button data-stepper-button="down">-</button>
<input type="text" id="stepper-1-ipt" data-stepper-target />
<button data-stepper-button="up">+</button>
</div>
Initialize the Javascript:
new Stepper( document.querySelectorAll( '.stepper' )[0] )
.init();
Passing options:
<div class="stepper"
data-stepper-steps-up="2"
data-stepper-steps-down="2"
data-stepper-label-up="Add {{steps}} bed to {{sum}}."
data-stepper-label-down="Remove {{steps}} bed from {{sum}}." />
The same is also possible by passing options in javascript.
var stepper = new Stepper( document.querySelectorAll( '.stepper' )[0] );
/* prefix used for data attributes */
stepper.options.prefix = 'stepper';
stepper.options.steps.up = 2;
stepper.options.steps.down = 2;
stepper.options.label.up = "Add {{steps}} bed to {{sum}}.";
stepper.options.label.down = "Remove {{steps}} bed from {{sum}}.";
/* called, when step > 1 */
stepper.pluralize = function( singular ) {
/* this instanceof Stepper === true */
return singular.replace( 'bed', 'beds' );
};
stepper.init();
Pluralisation can also be done through data attributes:
<div class="stepper"
data-stepper-label-up="Add {{steps}} bed to {{sum}}."
data-stepper-label-up-plural="Add {{steps}} beds to {{sum}}."
data-stepper-label-down="Remove {{steps}} bed from {{sum}}."
data-stepper-label-down-plural="Remove {{steps}} beds of {{sum}}." />