logo polydile dile-components

dile-range

Web Component to create a customizable range input slider.

The dile-range component is essentially an input type="range" element that allows you to add features such as custom styles, labels, messages, error states, and more. This ensures it can be used consistently alongside other form components in the Dile Components catalog.

Installation

npm i @dile/ui

Usage

Import the dile-range component.

import '@dile/ui/components/range/range.js';

Use the component.

<dile-range name="myrange"></dile-range>

Properties

CSS Custom Properties

You can customize it using CSS Custom Properties.

Custom property Description Default
--dile-range-line-color Color of the slider track --dile-primary-color or #7BB93D
--dile-range-line-height Height of the slider track 0.5rem
--dile-range-thumb-color Color of the slider thumb #303030
--dile-range-thumb-border-radius Border radius of the slider thumb 2rem
--dile-range-thumb-height Height of the slider thumb 1.5rem
--dile-range-thumb-width Width of the slider thumb 1.5rem
--dile-range-thumb-margin-top Top margin of the slider thumb to align it with the track -8px

Events

rangeField.addEventListener('input', (e) => {
  console.log('input event named ', e.target.name, ' has value: ', e.target.value);
});

dile-range demos

Regular range

<script type="module">
  import '@dile/ui/components/range/range.js';
</script>
<dile-range name="myrange"></dile-range>

Styled range

<style>
  .styled {
    --dile-range-thumb-color: rgb(243, 133, 55);
    --dile-range-thumb-height: 3rem;
    --dile-range-line-height: 1.5rem;
    --dile-range-thumb-width: 1rem;
    --dile-range-thumb-border-radius: 0.5rem;
    --dile-range-line-color: rgb(157, 122, 151);
    --dile-range-thumb-margin-top: -12px;
  }
</style>
<dile-range class="styled" name="otherrange"></dile-range>

Dile range with label and error status

<dile-range 
  errored 
  hideErrorOnInput 
  message="Satisfaction incorrect" 
  label="Enter your satisfaction grade" 
  name="satisfaction"
></dile-range>