Id of the range Selector
Handle max change
Handle min change
Is selected
Maximum value
Minimum value
Range value
Ranges
Update range function
import { useRangeCheckboxes } from "@nosto/preact"
import { useState } from "preact/hooks"
import RadioButton from "./elements/RadioButton"
import RangeInput from "./elements/RangeInput"
export default function RangeSelector({ facet }) {
const {
min,
max,
range,
ranges,
updateRange,
handleMinChange,
handleMaxChange,
isSelected,
} = useRangeSelector(facet.id, 100)
return (
<li>
<div>
<ul>
{ranges.map(({ min, max, selected }, index) => {
return (
<li>
<RadioButton
key={index}
value={`${min} - ${max}`}
selected={selected}
onChange={() => updateRange([min, max])}
/>
</li>
)
})}
<div>
<div>
<label htmlFor={`ns-${facet.id}-min`}>
Min.
</label>
<RangeInput
id={`ns-${facet.id}-min`}
min={min}
max={max}
range={range}
value={range[0] ?? min}
onChange={e => handleMinChange(parseFloat(e.currentTarget.value) || min)}
/>
</div>
<div>
<label htmlFor={`ns-${facet.id}-max`}>
Max.
</label>
<RangeInput
id={`ns-${facet.id}-max`}
min={min}
max={max}
range={range}
value={range[1] ?? max}
onChange={e => handleMaxChange(parseFloat(e.currentTarget.value) || max)}
/>
</div>
</div>
</ul>
</div>
</li>
)
}
Get range selector state