{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "range-slider",
  "type": "registry:item",
  "title": "Range Slider",
  "description": "A two-ended slider for a range: the nearer end follows the finger with a value bubble, over an optional histogram.",
  "categories": [
    "input"
  ],
  "dependencies": [
    "react-native-gesture-handler",
    "react-native-reanimated",
    "react-native-worklets"
  ],
  "registryDependencies": [
    "https://kinetik-ui.dev/r/kinetik-tokens.json",
    "https://kinetik-ui.dev/r/kinetik-motion.json",
    "https://kinetik-ui.dev/r/kinetik-haptics.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/range-slider.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/range-slider.tsx",
      "content": "import { useEffect, useState } from 'react';\nimport {\n  StyleSheet,\n  Text,\n  View,\n  type AccessibilityActionEvent,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, { useAnimatedStyle, useSharedValue, withSpring } from 'react-native-reanimated';\nimport { scheduleOnRN } from 'react-native-worklets';\n\nimport { useHaptic } from '../../lib/kinetik/hooks/use-haptic';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { spring } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { minTouchTarget, withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type RangeValue = readonly [number, number];\n\nexport type RangeSliderProps = {\n  value: RangeValue;\n  /** Called as either end changes while dragging. */\n  onValueChange?: (value: [number, number]) => void;\n  /** Called once when the finger lifts. */\n  onSlidingComplete?: (value: [number, number]) => void;\n  /** Defaults to 0. */\n  min?: number;\n  /** Defaults to 100. */\n  max?: number;\n  /** Defaults to 1. */\n  step?: number;\n  /** The closest the two ends may come, in value units. Defaults to one step. */\n  minDistance?: number;\n  /** Names the slider, e.g. \"Price per night\". Shown above the track. */\n  label: string;\n  /** Names the two ends for screen readers. Defaults to Minimum and Maximum. */\n  endLabels?: readonly [string, string];\n  /** Formats values for the readout, the bubble and screen readers. */\n  formatValue?: (value: number) => string;\n  /** Bars drawn behind the track, e.g. how many results fall in each price band. */\n  histogram?: readonly number[];\n  /** Haptic ticks on each step when steps are coarse. Defaults to true. */\n  haptics?: boolean;\n  disabled?: boolean;\n  testID?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst THUMB = 26;\nconst TRACK = 4;\nconst HISTOGRAM_H = 48;\n\n/**\n * A slider with two ends for picking a range. The nearer end follows the\n * finger and swells while held, a bubble carries its value above it, and an\n * optional histogram behind the track lights up the bars inside the range.\n */\nexport function RangeSlider({\n  value,\n  onValueChange,\n  onSlidingComplete,\n  min = 0,\n  max = 100,\n  step = 1,\n  minDistance,\n  label,\n  endLabels = ['Minimum', 'Maximum'],\n  formatValue = (v) => String(v),\n  histogram,\n  haptics = true,\n  disabled = false,\n  testID,\n  style,\n}: RangeSliderProps) {\n  const { colors, font, space, radius, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const range = max - min || 1;\n  const gap = minDistance ?? step;\n  const tickSteps = range / step <= 40;\n\n  const width = useSharedValue(0);\n  const lo = useSharedValue((value[0] - min) / range);\n  const hi = useSharedValue((value[1] - min) / range);\n  const active = useSharedValue(-1);\n  const held = useSharedValue(0);\n  const committed = useSharedValue<[number, number]>([value[0], value[1]]);\n  const [live, setLive] = useState<[number, number] | null>(null);\n  const [activeEnd, setActiveEnd] = useState(-1);\n  const shown = live ?? value;\n\n  useEffect(() => {\n    if (active.get() !== -1) return;\n    committed.set([value[0], value[1]]);\n    const a = (value[0] - min) / range;\n    const b = (value[1] - min) / range;\n    lo.set(reduced ? a : withSpring(a, spring('smooth')));\n    hi.set(reduced ? b : withSpring(b, spring('smooth')));\n  }, [value, min, range, reduced, lo, hi, active, committed]);\n\n  const emit = (next: [number, number]) => {\n    setLive(next);\n    onValueChange?.(next);\n    if (tickSteps) haptic('tick');\n  };\n  const finish = (next: [number, number]) => {\n    setLive(null);\n    setActiveEnd(-1);\n    onSlidingComplete?.(next);\n  };\n\n  const snap = (p: number) => {\n    'worklet';\n    const v = Math.round((min + p * range) / step) * step;\n    return Number(Math.max(min, Math.min(max, v)).toFixed(6));\n  };\n\n  const moveTo = (x: number) => {\n    'worklet';\n    const w = width.get();\n    if (w === 0 || active.get() < 0) return;\n    const p = Math.max(0, Math.min(1, (x - THUMB / 2) / w));\n    const [a, b] = committed.get();\n    const end = active.get();\n    // Each end stops short of the other by the minimum distance.\n    const v = end === 0 ? Math.min(snap(p), b - gap) : Math.max(snap(p), a + gap);\n    // The thumb stops where the value stops: at the other end, less the minimum distance.\n    if (end === 0) lo.set(Math.max(0, Math.min(p, (b - gap - min) / range)));\n    else hi.set(Math.min(1, Math.max(p, (a + gap - min) / range)));\n    const next: [number, number] = end === 0 ? [v, b] : [a, v];\n    if (next[0] !== a || next[1] !== b) {\n      committed.set(next);\n      scheduleOnRN(emit, next);\n    }\n  };\n\n  const pan = Gesture.Pan()\n    .withTestId('range-slider')\n    .enabled(!disabled)\n    .activeOffsetX([-3, 3])\n    .failOffsetY([-14, 14])\n    .onBegin((e) => {\n      const w = width.get();\n      const x = (e.x - THUMB / 2) / Math.max(1, w);\n      // The nearer end takes the drag; when they touch, the one in the direction of travel does.\n      const dLo = Math.abs(x - lo.get());\n      const dHi = Math.abs(x - hi.get());\n      const end = dLo < dHi || (dLo === dHi && x < lo.get()) ? 0 : 1;\n      active.set(end);\n      held.set(withSpring(1, spring('snappy', reduced)));\n      scheduleOnRN(setActiveEnd, end);\n    })\n    .onUpdate((e) => moveTo(e.x))\n    .onFinalize(() => {\n      if (active.get() < 0) return;\n      const [a, b] = committed.get();\n      lo.set(withSpring((a - min) / range, spring('snappy', reduced)));\n      hi.set(withSpring((b - min) / range, spring('snappy', reduced)));\n      active.set(-1);\n      held.set(withSpring(0, spring('smooth', reduced)));\n      scheduleOnRN(finish, [a, b] as [number, number]);\n    });\n\n  const fill = useAnimatedStyle(() => ({\n    left: THUMB / 2 + lo.get() * width.get(),\n    width: Math.max(0, (hi.get() - lo.get()) * width.get()),\n  }));\n  const loThumb = useAnimatedStyle(() => ({\n    transform: [\n      { translateX: lo.get() * width.get() },\n      { scale: 1 + (active.get() === 0 ? held.get() : 0) * 0.18 },\n    ],\n  }));\n  const hiThumb = useAnimatedStyle(() => ({\n    transform: [\n      { translateX: hi.get() * width.get() },\n      { scale: 1 + (active.get() === 1 ? held.get() : 0) * 0.18 },\n    ],\n  }));\n  const bubble = useAnimatedStyle(() => {\n    const end = active.get();\n    const p = end === 1 ? hi.get() : lo.get();\n    return {\n      opacity: end < 0 ? 0 : held.get(),\n      transform: [\n        { translateX: THUMB / 2 + p * width.get() },\n        { translateY: (1 - held.get()) * 8 },\n        { scale: 0.7 + held.get() * 0.3 },\n      ],\n    };\n  });\n\n  const nudge = (end: 0 | 1) => (e: AccessibilityActionEvent) => {\n    if (disabled) return;\n    const delta = Math.max(step, range / 20) * (e.nativeEvent.actionName === 'increment' ? 1 : -1);\n    const [a, b] = [value[0], value[1]];\n    const next: [number, number] =\n      end === 0\n        ? [Math.max(min, Math.min(b - gap, snap((a + delta - min) / range))), b]\n        : [a, Math.min(max, Math.max(a + gap, snap((b + delta - min) / range)))];\n    onValueChange?.(next);\n    onSlidingComplete?.(next);\n  };\n\n  const bars = histogram && histogram.length > 0 ? histogram : null;\n  const peak = bars ? Math.max(1, ...bars) : 1;\n\n  return (\n    <View testID={testID} style={[{ gap: space[2], opacity: disabled ? 0.45 : 1 }, style]}>\n      <View style={styles.header}>\n        <Text\n          style={{ color: colors.text, fontSize: font.size.sm, fontWeight: font.weight.medium }}\n        >\n          {label}\n        </Text>\n        <Text\n          style={{ color: colors.textMuted, fontSize: font.size.sm, fontVariant: ['tabular-nums'] }}\n        >\n          {formatValue(shown[0])} – {formatValue(shown[1])}\n        </Text>\n      </View>\n\n      {bars ? (\n        <View style={[styles.histogram, { paddingHorizontal: THUMB / 2 }]} pointerEvents=\"none\">\n          {bars.map((n, i) => {\n            const at = min + ((i + 0.5) / bars.length) * range;\n            const inside = at >= shown[0] && at <= shown[1];\n            return (\n              <View\n                key={i}\n                style={[\n                  styles.bar,\n                  {\n                    height: Math.max(3, (n / peak) * HISTOGRAM_H),\n                    backgroundColor: inside ? withAlpha(colors.azure, 0.55) : colors.track,\n                    borderTopLeftRadius: radius.xs / 2,\n                    borderTopRightRadius: radius.xs / 2,\n                  },\n                ]}\n              />\n            );\n          })}\n        </View>\n      ) : null}\n\n      <GestureDetector gesture={pan}>\n        <View\n          collapsable={false}\n          testID={testID ? `${testID}-track` : undefined}\n          style={styles.hit}\n          onLayout={(e) => width.set(Math.max(0, e.nativeEvent.layout.width - THUMB))}\n        >\n          <View\n            style={[\n              styles.track,\n              {\n                backgroundColor: colors.track,\n                borderRadius: radius.pill,\n                marginHorizontal: THUMB / 2,\n              },\n            ]}\n          />\n          <Animated.View\n            style={[\n              styles.fill,\n              { backgroundColor: colors.azure, borderRadius: radius.pill },\n              fill,\n            ]}\n          />\n          {([0, 1] as const).map((end) => (\n            <Animated.View\n              key={end}\n              accessible\n              accessibilityRole=\"adjustable\"\n              accessibilityLabel={`${label}, ${endLabels[end]}`}\n              accessibilityValue={{ min, max, now: shown[end], text: formatValue(shown[end]) }}\n              accessibilityState={{ disabled }}\n              accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}\n              onAccessibilityAction={nudge(end)}\n              hitSlop={(minTouchTarget - THUMB) / 2}\n              style={[\n                styles.thumb,\n                {\n                  backgroundColor: colors.highlight,\n                  borderColor: activeEnd === end ? colors.azure : colors.borderStrong,\n                  boxShadow: shadow.sm,\n                },\n                end === 0 ? loThumb : hiThumb,\n              ]}\n            />\n          ))}\n          <Animated.View pointerEvents=\"none\" style={[styles.bubbleBox, bubble]}>\n            <View\n              style={[styles.bubble, { backgroundColor: colors.ember, borderRadius: radius.sm }]}\n            >\n              <Text\n                style={{\n                  color: colors.onEmber,\n                  fontSize: font.size.xs,\n                  fontWeight: font.weight.semibold,\n                  fontVariant: ['tabular-nums'],\n                }}\n              >\n                {activeEnd >= 0 ? formatValue(shown[activeEnd]!) : ''}\n              </Text>\n            </View>\n          </Animated.View>\n        </View>\n      </GestureDetector>\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'baseline' },\n  histogram: {\n    height: HISTOGRAM_H,\n    flexDirection: 'row',\n    alignItems: 'flex-end',\n    gap: 2,\n    marginBottom: -minTouchTarget / 2 + TRACK / 2,\n  },\n  bar: { flex: 1 },\n  hit: { height: minTouchTarget, justifyContent: 'center' },\n  track: { height: TRACK },\n  fill: { position: 'absolute', height: TRACK },\n  thumb: {\n    position: 'absolute',\n    left: 0,\n    width: THUMB,\n    height: THUMB,\n    borderRadius: THUMB / 2,\n    borderWidth: 2,\n  },\n  bubbleBox: {\n    position: 'absolute',\n    left: 0,\n    bottom: minTouchTarget - 4,\n    width: 0,\n    alignItems: 'center',\n  },\n  bubble: { paddingHorizontal: 8, paddingVertical: 4, minWidth: 40, alignItems: 'center' },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "input",
    "web": "live",
    "perf": {
      "budget": "Thumbs and fill move on the UI thread. The readout and histogram re-render once per step while dragging; nothing runs at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-13",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 21,
          "baselineMs": 20,
          "jankyPercent": 2.87,
          "atRest": "idle",
          "memoryMb": 142
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The ends jump to new values set from outside, and the thumbs do not swell; dragging still follows the finger.",
      "screenReader": "Two adjustable elements (\"Price, Minimum\" and \"Price, Maximum\") with increment and decrement actions that never cross.",
      "touchTarget": "The whole 44 pt track takes the drag and the nearer end follows. Each thumb's slop makes it 44 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { RangeSlider } from '@/components/kinetik/range-slider';\n\nconst [price, setPrice] = useState<[number, number]>([120, 380]);\n\n<RangeSlider\n  label=\"Per night\"\n  value={price}\n  onValueChange={setPrice}\n  max={600}\n  step={10}\n  minDistance={50}\n  formatValue={(v) => `$${v}`}\n  histogram={bands}\n/>;\n```\n\n`histogram` takes one number per band across the range, such as how many results fall in each price band. Bars inside the range light up as it changes.\n\n## When to use\n\n- Filtering by a range: price, distance, duration, year built.\n- Ranges where seeing the spread of results helps people choose, with `histogram`.\n\n## When not to use\n\n- A single value. Use Elastic Slider.\n- Ranges people know exactly and want to type. Pair two number fields instead.\n\n## Notes\n\n- Touch anywhere on the track: the nearer end jumps there and follows the finger. When the ends meet, the one in the direction of the drag moves.\n- `minDistance` keeps the ends apart (one `step` by default). Screen reader actions respect it too.\n- `onValueChange` fires on each step while dragging and `onSlidingComplete` once on release, so you can filter live or only when the finger lifts.\n- With reduced motion, values set from outside jump into place and the held end does not swell.\n"
  },
  "docs": "Prefer `npx kinetik-ui add range-slider`: it installs dependencies with expo install, so versions match your Expo SDK."
}
