{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "streak-card",
  "type": "registry:item",
  "title": "Streak Card",
  "description": "A streak card: the day count pops into a disc as confetti bursts around it, and the week's marks tick in.",
  "categories": [
    "card"
  ],
  "dependencies": [
    "@shopify/react-native-skia",
    "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/streak-card.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/streak-card.tsx",
      "content": "import { Canvas, Group, Path, Skia, type SkPath } from '@shopify/react-native-skia';\nimport { useEffect, useRef, useState } from 'react';\nimport { Pressable, StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport Animated, {\n  useAnimatedStyle,\n  useDerivedValue,\n  useSharedValue,\n  withDelay,\n  withRepeat,\n  withSequence,\n  withSpring,\n  withTiming,\n  type SharedValue,\n} from 'react-native-reanimated';\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 { withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type StreakDayState = 'done' | 'today' | 'missed' | 'upcoming';\n\nexport type StreakDay = {\n  /** Short day name, e.g. \"Th\". */\n  label: string;\n  state: StreakDayState;\n};\n\nexport type StreakCardProps = {\n  /** Days in a row. A new number pops in with a burst of confetti. */\n  count: number;\n  /** Line under the number. Defaults to \"Back on track\". */\n  title?: string;\n  /** The week around today, in order. The row centres on the day marked `today`. */\n  days: readonly StreakDay[];\n  /** Button label. Defaults to \"Continue\". */\n  ctaLabel?: string;\n  onContinue?: () => void;\n  /** Colour of today's mark and a few confetti pieces. Defaults to the theme warning amber. */\n  accent?: string;\n  /** A success tick when the count changes. Defaults to true. */\n  haptics?: boolean;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst STAGE_H = 176;\nconst DISC = 112;\nconst PILL_W = 46;\nconst PILL_GAP = 8;\nconst BURST_MS = 1300;\n\nconst STATE_WORDS: Record<StreakDayState, string> = {\n  done: 'done',\n  today: 'today',\n  missed: 'missed',\n  upcoming: 'upcoming',\n};\n\ntype PieceKind = 'chip' | 'dot' | 'curl' | 'dash';\ntype Piece = {\n  kind: PieceKind;\n  angle: number;\n  /** Share of the stage radius the piece flies out to. */\n  reach: number;\n  turn: number;\n  spin: number;\n  accent: boolean;\n};\n\n/** A small seeded generator, so the confetti lands the same way on every render. */\nfunction seeded(seed: number) {\n  let s = seed;\n  return () => {\n    s = (s * 1664525 + 1013904223) % 4294967296;\n    return s / 4294967296;\n  };\n}\n\nconst KINDS: PieceKind[] = ['chip', 'dot', 'curl', 'dash', 'chip', 'dot'];\nconst PIECES: Piece[] = (() => {\n  const rand = seeded(7);\n  return Array.from({ length: 22 }, (_, i) => ({\n    kind: KINDS[i % KINDS.length]!,\n    angle: (i / 22) * Math.PI * 2 + rand() * 0.4,\n    reach: 0.62 + rand() * 0.38,\n    turn: rand() * 360,\n    spin: (rand() - 0.5) * 540,\n    accent: i % 7 === 3,\n  }));\n})();\n\nfunction shapeFor(kind: PieceKind): SkPath {\n  const b = Skia.PathBuilder.Make();\n  if (kind === 'chip') b.addRRect(Skia.RRectXY(Skia.XYWHRect(-4.5, -3, 9, 6), 1.5, 1.5));\n  else if (kind === 'dot') b.addCircle(0, 0, 2.6);\n  else if (kind === 'dash') b.moveTo(-5, 0).lineTo(5, 0);\n  else\n    return Skia.Path.MakeFromSVGString('M-9 3c2-7 9-7 8-1.5c-1 4-5.5 3-4.5-1c1-4.5 7.5-5 11 0.5')!;\n  return b.detach();\n}\nconst SHAPES: Record<PieceKind, SkPath> = {\n  chip: shapeFor('chip'),\n  dot: shapeFor('dot'),\n  curl: shapeFor('curl'),\n  dash: shapeFor('dash'),\n};\n\n/**\n * A streak card: the day count pops into a soft disc as confetti bursts out\n * and settles around it, and a row of day pills below ticks off the week,\n * with today's mark pulsing in the accent colour.\n */\nexport function StreakCard({\n  count,\n  title = 'Back on track',\n  days,\n  ctaLabel = 'Continue',\n  onContinue,\n  accent,\n  haptics = true,\n  style,\n}: StreakCardProps) {\n  const { colors, radius, space, font, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const tone = accent ?? colors.warning;\n  const [width, setWidth] = useState(0);\n  const [rowWidth, setRowWidth] = useState(0);\n\n  const burst = useSharedValue(reduced ? 1 : 0);\n  const pop = useSharedValue(reduced ? 1 : 0);\n  const ripple = useSharedValue(1);\n  const first = useRef(true);\n\n  useEffect(() => {\n    if (!first.current) haptic('success');\n    first.current = false;\n    if (reduced) {\n      burst.set(1);\n      pop.set(1);\n      return;\n    }\n    burst.set(0);\n    burst.set(withTiming(1, { duration: BURST_MS }));\n    pop.set(0);\n    pop.set(withSpring(1, spring('bouncy')));\n    ripple.set(0);\n    ripple.set(withTiming(1, { duration: 900 }));\n  }, [count, reduced, haptic, burst, pop, ripple]);\n\n  const disc = useAnimatedStyle(() => ({ transform: [{ scale: 0.84 + pop.get() * 0.16 }] }));\n  const number = useAnimatedStyle(() => ({\n    opacity: Math.min(1, pop.get() * 1.6),\n    transform: [{ translateY: (1 - pop.get()) * 22 }],\n  }));\n  const ring = useAnimatedStyle(() => ({\n    opacity: (1 - ripple.get()) * 0.55,\n    transform: [{ scale: 1 + ripple.get() * 0.38 }],\n  }));\n\n  const today = Math.max(\n    0,\n    days.findIndex((d) => d.state === 'today'),\n  );\n  // Centre today's pill in the row.\n  const offset = rowWidth / 2 - (today * (PILL_W + PILL_GAP) + PILL_W / 2);\n  const fade = (deg: number) =>\n    gradient(\n      `linear-gradient(${deg}deg, ${colors.surfaceRaised} 0%, ${withAlpha(colors.surfaceRaised, 0)} 100%)`,\n    );\n\n  return (\n    <View\n      style={[\n        styles.card,\n        {\n          backgroundColor: colors.surfaceRaised,\n          borderColor: colors.border,\n          borderRadius: radius.xl,\n          padding: space[5],\n          boxShadow: shadow.md,\n        },\n        style,\n      ]}\n    >\n      <View style={styles.stage} onLayout={(e) => setWidth(e.nativeEvent.layout.width)}>\n        {width > 0 ? (\n          <Canvas style={StyleSheet.absoluteFill} pointerEvents=\"none\">\n            {PIECES.map((piece, i) => (\n              <Confetti\n                key={i}\n                piece={piece}\n                cx={width / 2}\n                cy={STAGE_H / 2}\n                spread={Math.min(width / 2 - 12, 150)}\n                burst={burst}\n                color={piece.accent ? tone : withAlpha(colors.textSubtle, 0.42)}\n              />\n            ))}\n          </Canvas>\n        ) : null}\n        <Animated.View\n          pointerEvents=\"none\"\n          style={[styles.ripple, { borderColor: withAlpha(colors.textSubtle, 0.5) }, ring]}\n        />\n        <Animated.View\n          accessible\n          accessibilityLabel={`${count} day streak`}\n          style={[\n            styles.halo,\n            { borderColor: colors.border, backgroundColor: colors.surfaceRaised },\n            disc,\n          ]}\n        >\n          <View style={[styles.disc, { backgroundColor: colors.surfaceSunken }]}>\n            <Animated.Text\n              style={[\n                {\n                  color: colors.text,\n                  fontSize: 64,\n                  lineHeight: 72,\n                  fontWeight: font.weight.heavy,\n                  fontVariant: ['tabular-nums'],\n                  letterSpacing: -1,\n                },\n                number,\n              ]}\n            >\n              {count}\n            </Animated.Text>\n          </View>\n        </Animated.View>\n      </View>\n\n      <Text\n        accessibilityRole=\"header\"\n        style={{\n          color: colors.textMuted,\n          fontSize: font.size.xl + 2,\n          fontWeight: font.weight.semibold,\n          letterSpacing: font.tracking.tight,\n          textAlign: 'center',\n          marginTop: space[2],\n        }}\n      >\n        {title}\n      </Text>\n\n      <View\n        accessible\n        accessibilityLabel={`This week: ${days.map((d) => `${d.label} ${STATE_WORDS[d.state]}`).join(', ')}`}\n        onLayout={(e) => setRowWidth(e.nativeEvent.layout.width)}\n        style={[styles.row, { marginTop: space[4] }]}\n      >\n        <View style={[styles.days, { gap: PILL_GAP, transform: [{ translateX: offset }] }]}>\n          {rowWidth > 0 &&\n            days.map((day, i) => (\n              <DayPill\n                key={`${day.label}-${i}`}\n                day={day}\n                order={Math.abs(i - today)}\n                accent={tone}\n              />\n            ))}\n        </View>\n        <View pointerEvents=\"none\" style={[styles.fade, styles.fadeLeft, fade(90)]} />\n        <View pointerEvents=\"none\" style={[styles.fade, styles.fadeRight, fade(270)]} />\n      </View>\n\n      <Pressable\n        accessibilityRole=\"button\"\n        onPress={onContinue}\n        style={({ pressed }) => [\n          styles.cta,\n          {\n            marginTop: space[6],\n            backgroundColor: colors.ember,\n            borderRadius: radius.pill,\n            transform: [{ scale: pressed ? 0.98 : 1 }],\n          },\n        ]}\n      >\n        <Text\n          style={{ color: colors.onEmber, fontSize: font.size.md, fontWeight: font.weight.medium }}\n        >\n          {ctaLabel}\n        </Text>\n      </Pressable>\n    </View>\n  );\n}\n\n/** One confetti piece flying out from the disc and settling where it lands. */\nfunction Confetti({\n  piece,\n  cx,\n  cy,\n  spread,\n  burst,\n  color,\n}: {\n  piece: Piece;\n  cx: number;\n  cy: number;\n  spread: number;\n  burst: SharedValue<number>;\n  color: string;\n}) {\n  const transform = useDerivedValue(() => {\n    const b = burst.get();\n    const e = 1 - (1 - b) ** 3;\n    const reach = DISC / 2 + 6 + (spread - DISC / 2 - 6) * piece.reach;\n    return [\n      { translateX: cx + Math.cos(piece.angle) * reach * e },\n      // A flatter oval than the stage is wide, and a little fall at the end.\n      { translateY: cy + Math.sin(piece.angle) * reach * 0.56 * e + b * b * 6 },\n      { rotate: ((piece.turn + piece.spin * e) * Math.PI) / 180 },\n      { scale: 0.3 + 0.7 * e },\n    ];\n  });\n  const opacity = useDerivedValue(() => Math.min(1, burst.get() * 5));\n  const stroke = piece.kind === 'curl' || piece.kind === 'dash';\n  return (\n    <Group transform={transform} opacity={opacity}>\n      <Path\n        path={SHAPES[piece.kind]}\n        color={color}\n        style={stroke ? 'stroke' : 'fill'}\n        strokeWidth={1.8}\n        strokeCap=\"round\"\n      />\n    </Group>\n  );\n}\n\n/** A day in the week row: its mark pops in, nearest to today first. */\nfunction DayPill({ day, order, accent }: { day: StreakDay; order: number; accent: string }) {\n  const { colors, font } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const enter = useSharedValue(reduced ? 1 : 0);\n  const pulse = useSharedValue(0);\n\n  useEffect(() => {\n    if (reduced) {\n      enter.set(1);\n      return;\n    }\n    enter.set(withDelay(250 + order * 90, withSpring(1, spring('bouncy'))));\n    if (day.state === 'today') {\n      pulse.set(\n        withDelay(\n          700,\n          withRepeat(\n            withSequence(withTiming(1, timing('slow')), withTiming(0, { duration: 0 })),\n            4,\n          ),\n        ),\n      );\n    }\n  }, [order, reduced, day.state, enter, pulse]);\n\n  const mark = useAnimatedStyle(() => ({ transform: [{ scale: enter.get() }] }));\n  const halo = useAnimatedStyle(() => ({\n    opacity: (1 - pulse.get()) * (pulse.get() > 0 ? 0.6 : 0),\n    transform: [{ scale: 1 + pulse.get() * 0.7 }],\n  }));\n\n  const muted = day.state === 'upcoming' || day.state === 'missed';\n  return (\n    <View\n      style={[styles.pill, { backgroundColor: colors.surfaceSunken, borderColor: colors.border }]}\n    >\n      <Text\n        style={{\n          color: muted ? colors.textSubtle : colors.textMuted,\n          fontSize: font.size.sm,\n          fontWeight: font.weight.medium,\n        }}\n      >\n        {day.label}\n      </Text>\n      <View style={styles.markBox}>\n        {day.state === 'today' ? (\n          <Animated.View style={[styles.mark, styles.halo2, { backgroundColor: accent }, halo]} />\n        ) : null}\n        <Animated.View\n          style={[\n            styles.mark,\n            day.state === 'done' && { backgroundColor: colors.text },\n            day.state === 'today' && { backgroundColor: accent },\n            muted && {\n              backgroundColor: colors.surfaceRaised,\n              borderWidth: 1.5,\n              borderColor: colors.borderStrong,\n            },\n            mark,\n          ]}\n        >\n          {day.state === 'done' ? (\n            <View style={[styles.check, { borderColor: colors.surfaceRaised }]} />\n          ) : null}\n          {day.state === 'today' ? (\n            <View style={[styles.core, { backgroundColor: colors.highlight }]} />\n          ) : null}\n          {day.state === 'missed' ? (\n            <View style={[styles.miss, { backgroundColor: colors.textSubtle }]} />\n          ) : null}\n        </Animated.View>\n      </View>\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  card: { borderWidth: StyleSheet.hairlineWidth, overflow: 'hidden' },\n  stage: { height: STAGE_H, alignItems: 'center', justifyContent: 'center' },\n  halo: {\n    width: DISC + 18,\n    height: DISC + 18,\n    borderRadius: (DISC + 18) / 2,\n    borderWidth: 1,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  ripple: {\n    position: 'absolute',\n    width: DISC + 18,\n    height: DISC + 18,\n    borderRadius: (DISC + 18) / 2,\n    borderWidth: 1.5,\n  },\n  disc: {\n    width: DISC,\n    height: DISC,\n    borderRadius: DISC / 2,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  row: { height: 76, overflow: 'hidden' },\n  days: { flexDirection: 'row', position: 'absolute', left: 0, top: 0, bottom: 0 },\n  fade: { position: 'absolute', top: 0, bottom: 0, width: 44 },\n  fadeLeft: { left: 0 },\n  fadeRight: { right: 0 },\n  pill: {\n    width: PILL_W,\n    height: 76,\n    borderRadius: PILL_W / 2,\n    borderWidth: 1,\n    alignItems: 'center',\n    justifyContent: 'space-between',\n    paddingTop: 10,\n    paddingBottom: 8,\n  },\n  markBox: { width: 30, height: 30, alignItems: 'center', justifyContent: 'center' },\n  mark: {\n    width: 30,\n    height: 30,\n    borderRadius: 15,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  halo2: { position: 'absolute' },\n  check: {\n    width: 12,\n    height: 6,\n    borderLeftWidth: 2,\n    borderBottomWidth: 2,\n    marginTop: -3,\n    transform: [{ rotate: '-45deg' }],\n  },\n  core: { width: 11, height: 11, borderRadius: 5.5 },\n  miss: { width: 8, height: 2, borderRadius: 1 },\n  cta: { minHeight: 52, alignItems: 'center', justifyContent: 'center' },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "card",
    "web": "live",
    "perf": {
      "budget": "The confetti is one Skia canvas driven by a single UI-thread timing; it settles after about a second and nothing animates at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 18,
          "p90Ms": 27,
          "baselineMs": 17,
          "jankyPercent": 3.25,
          "atRest": "idle",
          "memoryMb": 168
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The number, confetti and day marks appear in place without the burst or the pulse.",
      "screenReader": "The count reads as one label (\"2 day streak\"), the title as a header and the week as one line (\"This week: We done, Th today, Fr upcoming\").",
      "touchTarget": "The button is 52 pt tall and full width."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { StreakCard } from '@/components/kinetik/streak-card';\n\n<StreakCard\n  count={streak.days}\n  days={[\n    { label: 'Mo', state: 'done' },\n    { label: 'Tu', state: 'missed' },\n    { label: 'We', state: 'done' },\n    { label: 'Th', state: 'today' },\n    { label: 'Fr', state: 'upcoming' },\n  ]}\n  onContinue={close}\n/>;\n```\n\n## When to use\n\n- Celebrating a habit kept, right after the user finishes the day's task.\n\n## When not to use\n\n- Every app open: the burst is a reward and loses meaning if it plays all the time.\n- Long histories: show a calendar instead of a week row.\n\n## Notes\n\n- The confetti and the number replay whenever `count` changes, with a success haptic after the first render.\n- The week row centres on the day marked `today` and fades out at the sides, so pass a few days either side.\n- `accent` colours today's mark and a few confetti pieces; the rest of the confetti stays quiet grey.\n"
  },
  "docs": "Prefer `npx kinetik-ui add streak-card`: it installs dependencies with expo install, so versions match your Expo SDK."
}
