{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gradient-slider",
  "type": "registry:item",
  "title": "Gradient Slider",
  "description": "A colour slider on a hue or white-balance gradient with a ring knob, a live swatch and an action button.",
  "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/gradient-slider.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/gradient-slider.tsx",
      "content": "import { useEffect, useState, type ReactNode } from 'react';\nimport {\n  Pressable,\n  StyleSheet,\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, {\n  useAnimatedStyle,\n  useSharedValue,\n  withSequence,\n  withSpring,\n  withTiming,\n} 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, timing } from '../../lib/kinetik/motion/motion';\nimport { gradient } from '../../lib/kinetik/tokens/gradient';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { minTouchTarget } from '../../lib/kinetik/tokens/tokens';\n\n/** A colour stop as hue (0–360), saturation and lightness (0–100). */\nexport type HslStop = readonly [hue: number, saturation: number, lightness: number];\n\nexport const GRADIENT_PRESETS = {\n  /** The colour wheel, red through violet and back to red. */\n  hue: [0, 60, 120, 180, 240, 300, 360].map((h) => [h, 85, 58] as const),\n  /** Cool blue through neutral to warm amber, for white balance. */\n  temperature: [\n    [218, 72, 62],\n    [210, 30, 80],\n    [44, 40, 80],\n    [42, 82, 58],\n  ],\n} satisfies Record<string, readonly HslStop[]>;\n\nexport type GradientSliderAction = {\n  icon: ReactNode;\n  /** Accessible name, e.g. \"Reset white balance\". */\n  label: string;\n  onPress: () => void;\n};\n\nexport type GradientSliderProps = {\n  value: number;\n  /** Called with the stepped value and the colour under the knob while dragging. */\n  onValueChange?: (value: number, color: string) => void;\n  onSlidingComplete?: (value: number, color: string) => void;\n  /** Defaults to 0. */\n  min?: number;\n  /** Defaults to 1. */\n  max?: number;\n  /** Snap interval. Defaults to 1/100 of the range. */\n  step?: number;\n  /** A preset name or your own stops, left to right. Defaults to `hue`. */\n  stops?: keyof typeof GRADIENT_PRESETS | readonly HslStop[];\n  /** Accessible name. */\n  label: string;\n  formatValue?: (value: number) => string;\n  /** Show a swatch of the picked colour at the end. Defaults to true without an `action`. */\n  swatch?: boolean;\n  /** A round button at the end, e.g. reset. */\n  action?: GradientSliderAction;\n  disabled?: boolean;\n  /** A tick at both ends. Defaults to true. */\n  haptics?: boolean;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst BAR = 28;\nconst KNOB = 22;\nconst INSET = (BAR - KNOB) / 2;\n\nconst css = ([h, s, l]: readonly number[]) => `hsl(${h}, ${s}%, ${l}%)`;\n\n/** The colour at `t` (0–1) along the stops, as a CSS `hsl()` string. */\nexport function colorAt(stops: readonly HslStop[], t: number): string {\n  if (stops.length === 0) return 'transparent';\n  const x = Math.max(0, Math.min(1, t)) * (stops.length - 1);\n  const i = Math.min(stops.length - 2, Math.floor(x));\n  const a = stops[Math.max(0, i)]!;\n  const b = stops[Math.min(stops.length - 1, i + 1)]!;\n  const f = stops.length === 1 ? 0 : x - i;\n  return css(a.map((v, k) => Math.round((v + (b[k]! - v) * f) * 10) / 10));\n}\n\n/**\n * A slider whose track is the colour range it picks from: the hue wheel, a\n * white-balance blend or your own stops. A ring knob shows the colour under\n * it, and a swatch at the end pops each time the colour lands.\n */\nexport function GradientSlider({\n  value,\n  onValueChange,\n  onSlidingComplete,\n  min = 0,\n  max = 1,\n  step,\n  stops = 'hue',\n  label,\n  formatValue,\n  swatch,\n  action,\n  disabled = false,\n  haptics = true,\n  style,\n}: GradientSliderProps) {\n  const { colors, radius, space, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const list = typeof stops === 'string' ? GRADIENT_PRESETS[stops] : stops;\n  const range = max - min || 1;\n  const stepSize = step ?? range / 100;\n  const decimals = Math.min(6, (String(stepSize).split('.')[1] ?? '').length);\n  const format = formatValue ?? ((v: number) => v.toFixed(decimals));\n  const showSwatch = swatch ?? !action;\n\n  const width = useSharedValue(0);\n  const progress = useSharedValue((value - min) / range);\n  const held = useSharedValue(0);\n  const committed = useSharedValue(value);\n  const dragging = useSharedValue(false);\n  const pop = useSharedValue(1);\n  const [shown, setShown] = useState<number | null>(null);\n  const now = shown ?? value;\n  const color = colorAt(list, (now - min) / range);\n\n  useEffect(() => {\n    if (dragging.get()) return;\n    const p = (Math.min(max, Math.max(min, value)) - min) / range;\n    progress.set(reduced ? p : withSpring(p, spring('smooth')));\n    committed.set(value);\n  }, [value, min, max, range, reduced, progress, committed, dragging]);\n\n  const at = (v: number) => colorAt(list, (v - min) / range);\n  const emit = (v: number) => {\n    setShown(v);\n    onValueChange?.(v, at(v));\n    if (v === min || v === max) haptic('tick');\n  };\n  const complete = (v: number) => {\n    setShown(null);\n    onSlidingComplete?.(v, at(v));\n    if (!reduced) {\n      pop.set(withSequence(withTiming(1.18, timing('quick')), withSpring(1, spring('bouncy'))));\n    }\n  };\n\n  const moveTo = (x: number) => {\n    'worklet';\n    const w = width.get() - BAR;\n    if (w <= 0) return;\n    const p = Math.max(0, Math.min(1, (x - BAR / 2) / w));\n    progress.set(p);\n    const stepped = Math.round((min + p * range) / stepSize) * stepSize;\n    const v = Math.max(min, Math.min(max, Number(stepped.toFixed(decimals))));\n    if (v !== committed.get()) {\n      committed.set(v);\n      scheduleOnRN(emit, v);\n    }\n  };\n\n  const release = () => {\n    'worklet';\n    dragging.set(false);\n    held.set(withSpring(0, spring('smooth', reduced)));\n    progress.set(withSpring((committed.get() - min) / range, spring('snappy', reduced)));\n    scheduleOnRN(complete, committed.get());\n  };\n\n  const pan = Gesture.Pan()\n    .withTestId('gradient-slider')\n    .enabled(!disabled)\n    .activeOffsetX([-4, 4])\n    .failOffsetY([-14, 14])\n    .onBegin(() => {\n      dragging.set(true);\n      held.set(withSpring(1, spring('snappy', reduced)));\n    })\n    .onStart((e) => moveTo(e.x))\n    .onUpdate((e) => moveTo(e.x))\n    .onFinalize(() => release());\n\n  const tap = Gesture.Tap()\n    .withTestId('gradient-slider-tap')\n    .enabled(!disabled)\n    .onEnd((e) => {\n      moveTo(e.x);\n      release();\n    });\n\n  const knob = useAnimatedStyle(() => ({\n    transform: [\n      { translateX: INSET + progress.get() * Math.max(0, width.get() - BAR) },\n      { scale: 1 + held.get() * 0.3 },\n    ],\n  }));\n  const swatchStyle = useAnimatedStyle(() => ({ transform: [{ scale: pop.get() }] }));\n\n  const onAccessibilityAction = (e: AccessibilityActionEvent) => {\n    if (disabled) return;\n    const delta =\n      Math.max(stepSize, range / 20) * (e.nativeEvent.actionName === 'increment' ? 1 : -1);\n    const next = Math.max(min, Math.min(max, committed.get() + delta));\n    const v = Number((Math.round(next / stepSize) * stepSize).toFixed(decimals));\n    committed.set(v);\n    progress.set(withSpring((v - min) / range, spring('snappy', reduced)));\n    onValueChange?.(v, at(v));\n    onSlidingComplete?.(v, at(v));\n  };\n\n  return (\n    <View\n      style={[\n        styles.panel,\n        {\n          backgroundColor: colors.surfaceRaised,\n          borderRadius: radius.lg,\n          paddingLeft: space[3],\n          paddingRight: showSwatch || action ? space[2] : space[3],\n          gap: space[3],\n          opacity: disabled ? 0.45 : 1,\n        },\n        style,\n      ]}\n    >\n      <GestureDetector gesture={Gesture.Race(pan, tap)}>\n        <View\n          collapsable={false}\n          accessible\n          accessibilityRole=\"adjustable\"\n          accessibilityLabel={label}\n          accessibilityValue={{ min, max, now, text: format(now) }}\n          accessibilityState={{ disabled }}\n          accessibilityActions={[{ name: 'increment' }, { name: 'decrement' }]}\n          onAccessibilityAction={onAccessibilityAction}\n          onLayout={(e) => width.set(e.nativeEvent.layout.width)}\n          style={styles.hit}\n        >\n          <View\n            style={[\n              styles.bar,\n              { borderRadius: BAR / 2 },\n              gradient(`linear-gradient(90deg, ${list.map(css).join(', ')})`),\n            ]}\n          />\n          <Animated.View\n            pointerEvents=\"none\"\n            style={[\n              styles.knob,\n              { borderColor: colors.highlight, backgroundColor: color, boxShadow: shadow.sm },\n              knob,\n            ]}\n          />\n        </View>\n      </GestureDetector>\n      {showSwatch ? (\n        <Animated.View\n          aria-hidden\n          style={[styles.swatch, { borderColor: colors.borderStrong }, swatchStyle]}\n        >\n          <View style={[styles.swatchFill, { backgroundColor: color }]} />\n        </Animated.View>\n      ) : null}\n      {action ? <ActionButton action={action} disabled={disabled} /> : null}\n    </View>\n  );\n}\n\nfunction ActionButton({ action, disabled }: { action: GradientSliderAction; disabled: boolean }) {\n  const reduced = useReduceMotion();\n  const press = useSharedValue(0);\n  const style = useAnimatedStyle(() => ({ transform: [{ scale: 1 - press.get() * 0.12 }] }));\n  return (\n    <Pressable\n      accessibilityRole=\"button\"\n      accessibilityLabel={action.label}\n      disabled={disabled}\n      onPress={action.onPress}\n      onPressIn={() => press.set(withSpring(1, spring('snappy', reduced)))}\n      onPressOut={() => press.set(withSpring(0, spring('bouncy', reduced)))}\n      style={styles.action}\n    >\n      <Animated.View style={style}>{action.icon}</Animated.View>\n    </Pressable>\n  );\n}\n\nconst styles = StyleSheet.create({\n  panel: { minHeight: 56, flexDirection: 'row', alignItems: 'center' },\n  hit: { flex: 1, height: minTouchTarget, justifyContent: 'center' },\n  bar: { height: BAR },\n  knob: {\n    position: 'absolute',\n    left: 0,\n    width: KNOB,\n    height: KNOB,\n    borderRadius: KNOB / 2,\n    borderWidth: 2.5,\n  },\n  swatch: {\n    width: 30,\n    height: 30,\n    borderRadius: 15,\n    borderWidth: 2,\n    padding: 3,\n    margin: 7,\n  },\n  swatchFill: { flex: 1, borderRadius: 12 },\n  action: {\n    width: minTouchTarget,\n    height: minTouchTarget,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "input",
    "web": "live",
    "perf": {
      "budget": "The gradient is a static background; the knob moves on the UI thread and its colour updates once per step.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 22,
          "baselineMs": 17,
          "jankyPercent": 1.99,
          "atRest": "idle",
          "memoryMb": 158
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The knob follows the finger without growing and the swatch changes without popping.",
      "screenReader": "Adjustable role with min, max, current value and formatted text. The swatch is decorative; the action button has its own name.",
      "touchTarget": "The track is 44 pt tall; the swatch area and action button are at least 44 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { GradientSlider } from '@/components/kinetik/gradient-slider';\n\n<GradientSlider\n  label=\"Hue\"\n  stops=\"hue\"\n  min={0}\n  max={360}\n  step={1}\n  value={hue}\n  onValueChange={(value, color) => {\n    setHue(value);\n    setTint(color);\n  }}\n/>;\n\n<GradientSlider\n  label=\"Temperature\"\n  stops=\"temperature\"\n  min={2000}\n  max={10000}\n  step={100}\n  value={kelvin}\n  onValueChange={setKelvin}\n  action={{ icon: <TargetIcon />, label: 'Reset white balance', onPress: () => setKelvin(5500) }}\n/>;\n```\n\n## When to use\n\n- Picking a hue, a white balance or any value that is easiest to read as colour.\n- Photo and design editors where the result changes live.\n\n## When not to use\n\n- Exact colours: give people a hex field or a full colour picker as well.\n- Values that are not colours: a coloured track suggests the colour matters.\n\n## Notes\n\n- `stops` takes `hue`, `temperature` or your own `[hue, saturation, lightness]` stops. `colorAt(stops, t)` returns the colour at any point as `hsl()`.\n- The swatch shows when there is no `action`; set `swatch` to show both.\n"
  },
  "docs": "Prefer `npx kinetik-ui add gradient-slider`: it installs dependencies with expo install, so versions match your Expo SDK."
}
