Reputation: 305
I have a custom range slider in react that renders the toggle(range) value dynamically values from API. Further, the value or amount the slider covers needs to be divided into sub-sections, whose widths need to be the sum of the value or amount the slider covers.
For example, If the slider covers 220 value/range, it should be divided into 2 sections (say) with a width of sub-sections equivalent to 120 & 100 respectively. The divided values are received from the API itself. It will look something like this:
I was able to handle the maximum functionality of this, except to divide the slider into sections properly & set the dynamic width of the sections.
I have included the working snippet:
https://codesandbox.io/s/nifty-matsumoto-5nnrv
Some of the CSS might seem a bit messed up due to browser compatibility-issue, but it pretty works to replicate my problem.
Upvotes: 1
Views: 460
Reputation: 402
here is a working solution. Please make sure to refactor, as it is quick and dirty.
calcSlideWidth
function that determindes the correct width of a slide.sliderPopup
percent
to the Statehttps://codesandbox.io/s/competent-http-br6s6?file=/src/SegmentedSlider.js
Upvotes: 1