{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "order-stages",
  "type": "registry:item",
  "title": "Order Stages",
  "description": "An order on its way: a glowing track runs to a knob showing the stage under way, chips for what comes next.",
  "categories": [
    "data"
  ],
  "dependencies": [
    "react-native-reanimated",
    "react-native-svg",
    "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",
    "https://kinetik-ui.dev/r/kinetik-count.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/order-stages.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/order-stages.tsx",
      "content": "import { useEffect, useRef, useState } from 'react';\nimport { StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport Animated, {\n  useAnimatedStyle,\n  useSharedValue,\n  withRepeat,\n  withSequence,\n  withSpring,\n  withTiming,\n} from 'react-native-reanimated';\nimport Svg, { Path } from 'react-native-svg';\n\nimport { useCountUp } from '../../lib/kinetik/hooks/use-count-up';\nimport { useHaptic } from '../../lib/kinetik/hooks/use-haptic';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { easings, spring } from '../../lib/kinetik/motion/motion';\nimport { gradient } from '../../lib/kinetik/tokens/gradient';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\n\nexport type OrderStage = {\n  /** Status shown while this stage is under way, e.g. \"COOKING\". */\n  label: string;\n  /** Picture on the stage's chip. */\n  icon: 'cook' | 'pack' | 'ride' | 'check';\n};\n\nexport type OrderStagesProps = {\n  stages: OrderStage[];\n  /** Index of the stage under way. Changes slide the knob along. */\n  current: number;\n  /** Minutes until it arrives. */\n  minutesLeft: number;\n  /** Order number in the corner, e.g. \"Nº 27\". */\n  order?: string;\n  /** Label after the minutes. Defaults to \"MIN LEFT\". */\n  leftLabel?: string;\n  /** Vibrate when the stage changes. Defaults to true. */\n  haptics?: boolean;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst TRACK_H = 42;\nconst KNOB = 36;\nconst CHIP = 36;\nconst GAP = 3;\nconst SHEEN_W = 90;\n\nconst ICONS: Record<OrderStage['icon'], string> = {\n  cook: 'M5 11h14v6a3 3 0 0 1-3 3H8a3 3 0 0 1-3-3v-6ZM2.5 11h19M9.5 7.5c0-1.6 1-1.6 1-3.2M13.5 7.5c0-1.6 1-1.6 1-3.2',\n  pack: 'M6 8.5h12l1 11.5H5L6 8.5ZM9 8.5V7a3 3 0 0 1 6 0v1.5',\n  ride: 'M5.5 14a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7ZM18.5 14a3.5 3.5 0 1 0 0 7 3.5 3.5 0 0 0 0-7ZM5.5 17.5 9 10h6l3.5 7.5M15 10l-1.2-4H17',\n  check: 'M5 12.5 9.5 17 19 7.5',\n};\n\n/** Where the knob's left edge sits: past the finished stages, before the chips still to come. */\nexport function knobOffset(width: number, count: number, current: number): number {\n  const ahead = Math.max(0, count - 1 - current);\n  return Math.max(0, width - KNOB - 3 - ahead * (CHIP + GAP));\n}\n\nfunction StageIcon({\n  icon,\n  color,\n  size = 16,\n}: {\n  icon: OrderStage['icon'];\n  color: string;\n  size?: number;\n}) {\n  return (\n    <Svg width={size} height={size} viewBox=\"0 0 24 24\">\n      <Path\n        d={ICONS[icon]}\n        fill=\"none\"\n        stroke={color}\n        strokeWidth={2.2}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n      />\n    </Svg>\n  );\n}\n\n/**\n * An order on its way: a glowing track runs up to a knob showing the stage under\n * way, with chips for the stages to come. When the stage changes the knob springs\n * forward and swells, and a sheen keeps moving along the track.\n */\nexport function OrderStages({\n  stages,\n  current,\n  minutesLeft,\n  order,\n  leftLabel = 'MIN LEFT',\n  haptics = true,\n  style,\n}: OrderStagesProps) {\n  const { colors, font } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const [width, setWidth] = useState(0);\n  const at = Math.max(0, Math.min(stages.length - 1, current));\n  const stage = stages[at];\n  const shown = Math.round(useCountUp(minutesLeft, { instant: reduced }));\n  const target = knobOffset(width, stages.length, at);\n\n  const x = useSharedValue(0);\n  const swell = useSharedValue(1);\n  const sheen = useSharedValue(0);\n  const seen = useRef(at);\n\n  useEffect(() => {\n    x.set(reduced ? target : withSpring(target, spring('smooth')));\n  }, [target, reduced, x]);\n\n  useEffect(() => {\n    if (reduced) return;\n    sheen.set(withRepeat(withTiming(1, { duration: 2800, easing: easings.inOut }), -1, false));\n  }, [reduced, sheen]);\n\n  useEffect(() => {\n    if (seen.current === at) return;\n    seen.current = at;\n    if (!reduced) {\n      swell.set(withSequence(withSpring(1.18, spring('snappy')), withSpring(1, spring('bouncy'))));\n    }\n    haptic('tick');\n  }, [at, reduced, swell, haptic]);\n\n  const rail = useAnimatedStyle(() => ({ width: x.get() + KNOB / 2 + 3 }));\n  const knob = useAnimatedStyle(() => ({\n    transform: [{ translateX: x.get() }, { scale: swell.get() }],\n  }));\n  const shine = useAnimatedStyle(() => ({\n    transform: [{ translateX: sheen.get() * (x.get() + SHEEN_W) - SHEEN_W }],\n  }));\n\n  return (\n    <View\n      accessible\n      accessibilityRole=\"progressbar\"\n      accessibilityLabel={`${minutesLeft} minutes left. ${stage?.label ?? ''}${order ? `. ${order}` : ''}`}\n      accessibilityValue={{ min: 0, max: stages.length, now: at + 1 }}\n      style={[styles.card, style]}\n    >\n      <Text\n        style={{\n          color: colors.highlight,\n          fontSize: font.size.xl,\n          fontWeight: font.weight.semibold,\n          fontVariant: ['tabular-nums'],\n        }}\n      >\n        {shown}\n        <Text style={{ fontSize: font.size.xs, fontWeight: font.weight.medium }}> {leftLabel}</Text>\n      </Text>\n\n      <View\n        testID=\"order-stages-track\"\n        style={styles.track}\n        onLayout={(e) => setWidth(e.nativeEvent.layout.width)}\n      >\n        <Animated.View style={[styles.rail, gradient(RAIL), rail]}>\n          {reduced ? null : <Animated.View style={[styles.sheen, gradient(SHEEN), shine]} />}\n        </Animated.View>\n        <View style={styles.chips}>\n          {stages.slice(at + 1).map((s) => (\n            <View key={s.label} style={styles.chip}>\n              <StageIcon icon={s.icon} color={CHIP_INK} size={16} />\n            </View>\n          ))}\n        </View>\n        <Animated.View style={[styles.knob, knob]}>\n          {stage ? <StageIcon icon={stage.icon} color={KNOB_INK} size={20} /> : null}\n        </Animated.View>\n      </View>\n\n      <View style={styles.foot}>\n        <Text style={{ color: GOLD, fontSize: font.size.xs, fontWeight: font.weight.bold }}>\n          {stage?.label}\n        </Text>\n        {order ? (\n          <Text style={{ color: MUTED, fontSize: font.size.xs, fontVariant: ['tabular-nums'] }}>\n            {order}\n          </Text>\n        ) : null}\n      </View>\n    </View>\n  );\n}\n\nconst MUTED = 'hsl(0, 0%, 62%)';\nconst GOLD = 'hsl(46, 96%, 58%)';\nconst KNOB_INK = 'hsl(42, 80%, 10%)';\nconst CHIP_INK = 'hsl(0, 0%, 72%)';\nconst RAIL = 'linear-gradient(90deg, hsl(44, 60%, 14%) 0%, hsl(45, 72%, 30%) 100%)';\nconst SHEEN =\n  'linear-gradient(90deg, hsla(50, 100%, 80%, 0) 0%, hsla(50, 100%, 80%, 0.14) 50%, hsla(50, 100%, 80%, 0) 100%)';\n\nconst styles = StyleSheet.create({\n  card: {\n    width: '100%',\n    maxWidth: 320,\n    alignSelf: 'center',\n    borderRadius: 24,\n    borderWidth: 1,\n    borderColor: 'hsla(0, 0%, 100%, 0.08)',\n    backgroundColor: 'hsl(0, 0%, 5%)',\n    padding: 16,\n    gap: 8,\n  },\n  track: {\n    height: TRACK_H,\n    borderRadius: TRACK_H / 2,\n    backgroundColor: 'hsl(0, 0%, 10%)',\n    justifyContent: 'center',\n  },\n  rail: {\n    position: 'absolute',\n    top: 0,\n    bottom: 0,\n    left: 0,\n    borderRadius: TRACK_H / 2,\n    overflow: 'hidden',\n  },\n  sheen: { position: 'absolute', top: 0, bottom: 0, width: SHEEN_W },\n  chips: {\n    position: 'absolute',\n    right: 3,\n    flexDirection: 'row',\n    gap: GAP,\n  },\n  chip: {\n    width: CHIP,\n    height: CHIP,\n    borderRadius: 18,\n    alignItems: 'center',\n    justifyContent: 'center',\n    backgroundColor: 'hsl(0, 0%, 17%)',\n  },\n  knob: {\n    position: 'absolute',\n    left: 0,\n    width: KNOB,\n    height: KNOB,\n    borderRadius: 18,\n    alignItems: 'center',\n    justifyContent: 'center',\n    backgroundColor: GOLD,\n    boxShadow: '0px 0px 12px hsla(46, 96%, 58%, 0.45)',\n  },\n  foot: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "data",
    "web": "live",
    "perf": {
      "budget": "Knob and track use UI-thread springs on change. A sheen loops along the track as one view, so it animates at rest.",
      "measurements": [
        {
          "device": "Huawei P20 Lite (ANE-LX1), Android 9",
          "kind": "device",
          "date": "2026-11-02",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 19,
          "jankyPercent": 74.69,
          "atRest": "animating",
          "memoryMb": 121
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The knob jumps to its place, does not swell, the sheen stops and the minutes do not count.",
      "screenReader": "One progress bar (\"21 minutes left. COOKING. Nº 27\") with the stage number.",
      "touchTarget": "Not interactive."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { OrderStages } from '@/components/kinetik/order-stages';\n\n<OrderStages\n  stages={[\n    { label: 'COOKING', icon: 'cook' },\n    { label: 'PACKING', icon: 'pack' },\n    { label: 'ON THE WAY', icon: 'ride' },\n    { label: 'DELIVERED', icon: 'check' },\n  ]}\n  current={0}\n  minutesLeft={21}\n  order=\"Nº 27\"\n/>;\n```\n\n## When to use\n\n- Food, parcel and ride tracking with three to five clear stages.\n- A live activity style widget.\n\n## When not to use\n\n- Many stages: the chips run out of room past about five.\n- When there is no time estimate. Use Step Tracker.\n\n## Notes\n\n- Icons are `cook`, `pack`, `ride` and `check`.\n- Finished stages disappear into the track.\n"
  },
  "docs": "Prefer `npx kinetik-ui add order-stages`: it installs dependencies with expo install, so versions match your Expo SDK."
}
