1.0.6 • Published 4 years ago

@miraidesigns/range v1.0.6

Weekly downloads
-
License
ISC
Repository
github
Last release
4 years ago

Range Sliders

Range sliders allow users to pick between a minimum and maximum value.


HTML

It is very important to set the input's min, max and step attribute for this module to work properly.\ Otherwise when executed the script will set the values below by default.

<div class="mdf-range">
    <input class="mdf-range__input" type="range" min="0" max="100" step="10" aria-label="Slider">
</div>

Sass

// Include default styles without configuration
@forward '@miraidesigns/range/styles';
// Configure appearance
@use '@miraidesigns/range' with (
    $variable: value
);

@include range.styles();

TypeScript

import { MDFRange } from '@miraidesigns/range';

new MDFRange(document.querySelector('.mdf-range'));

Examples

Some basic examples on how the module can be used.

Label

Lead the slider with a label.

<div class="mdf-range">
    <div id="slider-label" class="mdf-range__leading">
        Label
    </div>

    <div class="mdf-range__track">
        <input class="mdf-range__input" type="range" min="0" max="100" step="10" aria-labelledby="slider-label">
    </div>
</div>

Icons

Icons can be leading and trailing, here demonstrated as a volume slider.

<div class="mdf-range">
    <div class="mdf-range__leading">
        <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="icons.svg#volume-mute"></use>
        </svg>
    </div>

    <div class="mdf-range__track">
        <input class="mdf-range__input" type="range" min="0" max="100" step="10" aria-label="Volume slider">
    </div>

    <div class="mdf-range__trailing">
        <svg class="mdf-icon" viewBox="0 0 24 24" aria-hidden="true">
            <use href="icons.svg#volume-up"></use>
        </svg>
    </div>
</div>

Value

Shows the current value trailing the slider.

<div class="mdf-range">
    <div class="mdf-range__track">
        <input class="mdf-range__input" type="range" min="0" max="100" step="10" aria-label="Slider">
    </div>

    <div class="mdf-range__trailing"></div>
</div>
new MDFRange(document.querySelector('.mdf-range'), {
	value: true,
});

Editable

Allows for the editing of the displayed value with an immediate response from the slider.

<div class="mdf-range mdf-range--editable">
    <div id="slider-label" class="mdf-range__leading">
        Editable slider
    </div>

    <div class="mdf-range__track">
        <input class="mdf-range__input" type="range" min="0" max="100" step="10" aria-labelledby="slider-label">
    </div>

    <div class="mdf-range__trailing">
        <input class="mdf-range__value" type="number" aria-label="Slider value">
    </div>
</div>
new MDFRange(document.querySelector('.mdf-range'), {
	editable: true,
});

Ticks

Ticks visualize the slider snapping points.\ You may display numbers underneath the ticks as well.\

// Without numbers
new MDFRange(document.querySelector('.mdf-range'), {
    ticks: true,
});

// With numbers
new MDFRange(document.querySelector('.mdf-range'), {
    ticks: true,
    numbers: true,
});

Implementation

Classes

NameTypeDescription
mdf-rangeParentRange container element
mdf-range--disabledModifierFades out the element and disabled all interaction
mdf-range--editableModifierSetup the range slider for the editable value input
mdf-range__trackParent / ChildRange track, holds the input and ticks elements. Child to .mdf-range
mdf-range__inputChildRange slider input element. Child to .mdf-range__track
mdf-range__leadingChildThe leading element. Can be used for icons or as a label. Child to .mdf-range
mdf-range__trailingParent / ChildThe trailing element. Can be used for icons or show the current value. Child to .mdf-range
mdf-range__ticksParent / ChildContainer element holding the ticks. Created through JavaScript. Child to .mdf-range__trailing
mdf-range__tickChildSingle tick element. Created through JavaScript. Child to .mdf-range__ticks
mdf-range__valueChildValue input element. Offers another way to change the current range value. Child to .mdf-range__trailing

Properties

NameTypeDescription
.inputHTMLInputElementReturns the input element
.leadingHTMLElementReturns the leading element
.trackHTMLElementReturns the track element
.trailingHTMLElementReturns the trailing element
.valueInputHTMLInputElementReturns the editable value input element
.disabledbooleanGet or set the input's disabled state
.valuestringGet or set the input's value
.minstringGet or set the input's min
.maxstringGet or set the input's max
.stepstringGet or set the input's step

Options

NameTypeDefaultDescription
valuebooleanfalseShow the current value trailing the slider
editablebooleanfalseAllow for the editing of the current value through a separate input
ticksbooleanfalseShow ticks underneath the slider visualizing snapping points
numbersbooleanfalseShow value numbers underneath the ticks