Range histogram slider
A range slider over a histogram of results: bars inside the range tinted, heights that spring with new data, a rolling "N results" and ★ a tick per bar crossed.
npx @swipeui/cli add range-histogram-sliderWhen to use it
- Price filters in shopping apps that show how many items fall in each price band.
- Filtering by distance, duration or size where the spread of results helps people choose.
- Any two-thumb range where showing the distribution prevents empty results.
When not to use it
- A single value. Use Slider.
- When you don't have counts for the distribution. Use Slider with a range.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add range-histogram-slider- Adds
components/swipeui/ui/range-histogram-slider.tsx,components/swipeui/ui/use-range-histogram.tsand 14 shared helpers. - Installs react-native-reanimated, clsx, tailwind-merge, react-native-worklets, uniwind, expo-haptics, class-variance-authority, react-native-svg, react-native-gesture-handler. In Expo apps it uses
npx expo installso versions match your SDK.
Usage
import { RangeHistogramSlider } from '@/components/swipeui/ui/range-histogram-slider';
<RangeHistogramSlider
label="Price"
data={[2, 5, 9, 14, 18, 16, 12, 9, 6, 4]}
max={240}
defaultValue={[40, 160]}
formatValue={(v) => `€${v}`}
/>;API reference
RangeHistogramSliderProps
| Prop | Type | Default | Description |
|---|---|---|---|
min? | | | Lowest value. |
max? | | | Highest value; must exceed |
step? | | | The step values snap to. |
label? | | | The visible and spoken name. |
formatValue? | | | Writes a value for the readout, the bubble and screen readers. |
momentum? | | | A fling carries the value on and snaps to a step. |
bubble? | | | A bubble with the value over the thumb: while dragging, always, or never. |
showValue? | | | The value beside the label, rolling its digits. |
marks? | | — | Marks on the track; labelled marks can be pressed to set the value. |
limitStrain? | | | Past an end, the thumb strains toward the finger and springs back, with a limit haptic. |
minGap? | | | A range's thumbs stay at least this far apart. |
trackPress? | | | A press on the track jumps there, takes one step toward it, or does nothing. |
fineScrub? | | | ★ Drag away from the track to slow the rate to ½, ¼ and ⅛, with a tick and an announcement per band. |
grow? | | | The thumb grows while held. |
startAdornment? | | — | An icon before the track. |
endAdornment? | | — | An icon after the track. |
size? | | | Track and thumb size. |
elastic? | | | 1.x: rubber-band past the ends, as Elastic slider does. |
disabled? | | | No changes. |
haptics? | | | Haptics: a switch, or per part ( |
motion? | | | Thumb, bubble and fling motion (select, drag and number roles). |
messages? | | | Built-in strings. The results line, for translation. |
className? | | — | Root classes. |
style? | | — | Root style. |
testID? | | — | Root identifier; parts append |
data? | | — | How many results each bar holds, in order from |
bins? | | — | 1.x name for |
bucketSize? | | | How wide each bar is, in values. |
value? | | — | The chosen range (controlled). |
defaultValue? | | | The range it starts with (uncontrolled). |
onValueChange? | | — | Reports each new step. |
onValueCommit? | | — | Reports once when a gesture settles. |
showCount? | | | A rolling "N results" under the bars. |
barTicks? | | | ★ A tick as each thumb crosses a bar's edge (one per bar, not per step). |
barHeight? | | | The bars' height, in points. |
Slider's range props work too: minGap, momentum, fineScrub, trackPress, marks, step.
Composition and behavior
- Bars inside the range turn the primary colour; the rest stay muted. A bar counts when its middle is inside the range.
- The "N results" line under the bars rolls its digits as the range changes.
- ★ A tick plays as each thumb crosses a bar's edge, one per bar instead of one per step.
- New
datasprings each bar to its new height.
Range histogram slider settings
| Prop | Does | Default |
|---|---|---|
| data | Results per bar, from min (1.x bins) | none |
| bucketSize | How wide each bar is, in values | span ÷ bars |
| showCount | A rolling "N results" | true |
| barTicks | ★ A tick per bar crossed | true |
| barHeight | The bars' height (pt) | 56 |
| value / defaultValue | The range | [min, max] |
| Slider props | min, max, step, minGap, formatValue, … | as Slider |
| messages | The results line | English |
Behavior and gestures
- Drag either thumb (Slider 2.0's range: momentum, minimum gap, fine scrubbing, track presses): bars inside the range turn the primary colour and the rest stay muted.
- The "N results" line under the bars rolls its digits as the range changes (`showCount`).
- ★ A tick plays as each thumb crosses a bar's edge, one per bar instead of one per step (`barTicks`).
- New `data` springs each bar to its new height.
Accessibility
- The two thumbs are adjustable (sliders on the web), named "Label, lower value" and "Label, upper value", with increment and decrement.
- The bars are decorative; the result count is real text.
Motion
- Uses the
select,drag,layoutandnumbermotion roles, so it follows your app's feel. Passmotionto tune this one instance. - Bar heights spring on the layout role; the count rolls on the number role; thumbs move as in Slider.
- Reduce Motion: bars and digits change at once; haptics stay.
Performance
- Tinting and counting run once per step on JS; the thumbs track on the UI thread.
Notes for AI
- Pass `data` as one count per bar from `min` (1.x `bins` still works); `bucketSize` sets how wide each bar is.
- The count is the sum of the bars whose middle is inside the range; use your own text with `messages.results`.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.