{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "balance-stack",
  "type": "registry:item",
  "title": "Balance Stack",
  "description": "A dark balance card with payment cards stacked along its edge: tap one to pull it forward as the figure counts.",
  "categories": [
    "card"
  ],
  "dependencies": [
    "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",
    "https://kinetik-ui.dev/r/kinetik-count.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/balance-stack.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/balance-stack.tsx",
      "content": "import { useEffect, useRef, useState } from 'react';\nimport { Pressable, StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport Animated, {\n  Extrapolation,\n  interpolate,\n  useAnimatedStyle,\n  useSharedValue,\n  withDelay,\n  withSequence,\n  withSpring,\n} from 'react-native-reanimated';\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 { spring } 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 BalanceAccount = {\n  id: string;\n  /** The account's balance. The figure counts to it when the card comes to the front. */\n  balance: number;\n  /** Last digits shown after the mask, e.g. \"2048\". */\n  digits: string;\n  /** Wordmark at the end of the card, e.g. \"NOVA\". */\n  network?: string;\n  /** Top and bottom colours of the card. Defaults to an indigo and lilac rotation. */\n  tones?: [string, string];\n  /** Colour of the digits. Defaults to match the rotation. */\n  ink?: string;\n};\n\nexport type BalanceStackProps = {\n  /** One to three accounts. The last one starts at the front. */\n  accounts: BalanceAccount[];\n  label: string;\n  /** Pill beside the label, e.g. \"Earning\". */\n  status?: string;\n  /** Symbol before the figure. Defaults to \"$\". */\n  currency?: string;\n  /** Id of the account at the front, if you control it. */\n  selected?: string;\n  /** Called when a card is tapped. */\n  onSelect?: (id: string) => void;\n  /** Vibrate on tap. Defaults to true. */\n  haptics?: boolean;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst CARD_H = 73;\n/** How much of a card shows above the one in front of it. */\nconst PEEK = 61;\nconst LIFT = 14;\n\nconst TONES: { tones: [string, string]; ink: string }[] = [\n  { tones: ['hsl(244, 76%, 59%)', 'hsl(236, 84%, 67%)'], ink: 'hsl(240, 100%, 97%)' },\n  { tones: ['hsl(258, 90%, 74%)', 'hsl(258, 90%, 84%)'], ink: 'hsl(262, 72%, 36%)' },\n  { tones: ['hsl(190, 76%, 42%)', 'hsl(186, 72%, 56%)'], ink: 'hsl(190, 90%, 12%)' },\n];\n\n/**\n * A dark balance card with payment cards stacked along its bottom edge. Tap the\n * card behind to pull it to the front; the figure counts to that account's\n * balance, its cents dimmed.\n */\nexport function BalanceStack({\n  accounts,\n  label,\n  status,\n  currency = '$',\n  selected,\n  onSelect,\n  haptics = true,\n  style,\n}: BalanceStackProps) {\n  const { colors, font, radius, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const deck = accounts.slice(0, 3);\n  const [own, setOwn] = useState(deck[deck.length - 1]?.id);\n  const frontId = selected ?? own;\n  const front = deck.find((a) => a.id === frontId) ?? deck[deck.length - 1];\n\n  // Cents as a whole number, so the figure can never round to \".100\".\n  const shown = Math.round(useCountUp(front?.balance ?? 0, { instant: reduced }) * 100);\n  const whole = Math.floor(shown / 100).toLocaleString('en-US');\n  const cents = String(shown % 100).padStart(2, '0');\n  const exact = (front?.balance ?? 0).toLocaleString('en-US', {\n    minimumFractionDigits: 2,\n    maximumFractionDigits: 2,\n  });\n\n  const order = deck.filter((a) => a !== front).concat(front ? [front] : []);\n  const pick = (id: string) => {\n    haptic('tap');\n    setOwn(id);\n    onSelect?.(id);\n  };\n\n  return (\n    <View\n      style={[\n        styles.card,\n        gradient(\n          'linear-gradient(180deg, hsl(0, 0%, 28%) 0%, hsl(0, 0%, 11%) 28%, hsl(0, 0%, 9%) 60%, hsl(0, 0%, 19%) 84%, hsl(262, 20%, 25%) 100%)',\n        ),\n        { borderColor: withAlpha(colors.highlight, 0.14) },\n        style,\n      ]}\n    >\n      <View\n        accessible\n        accessibilityLabel={`${label}, ${currency}${exact}${status ? `, ${status}` : ''}`}\n        style={[styles.head, { paddingHorizontal: space[6] + 2, paddingTop: space[6] }]}\n      >\n        <View style={styles.row}>\n          <Text\n            numberOfLines={1}\n            style={[\n              styles.grow,\n              { color: colors.highlight, fontSize: font.size.lg, fontWeight: font.weight.medium },\n            ]}\n          >\n            {label}\n          </Text>\n          {status ? (\n            <View style={[styles.pill, { borderRadius: radius.pill }]}>\n              <Text\n                style={{\n                  color: PILL_INK,\n                  fontSize: font.size.xs + 1,\n                  fontWeight: font.weight.semibold,\n                }}\n              >\n                {status}\n              </Text>\n            </View>\n          ) : null}\n        </View>\n        <Text\n          numberOfLines={1}\n          adjustsFontSizeToFit\n          style={[\n            styles.amount,\n            {\n              color: colors.highlight,\n              fontSize: font.size['4xl'] - 4,\n              fontWeight: font.weight.medium,\n              letterSpacing: font.tracking.tight,\n            },\n          ]}\n        >\n          {currency}\n          {whole}\n          <Text style={{ color: withAlpha(colors.highlight, 0.42) }}>.{cents}</Text>\n        </Text>\n      </View>\n\n      <View style={{ height: CARD_H + (deck.length - 1) * PEEK, marginBottom: space[2] + 2 }}>\n        {deck.map((account, i) => (\n          <StackCard\n            key={account.id}\n            account={account}\n            tone={TONES[i % TONES.length]!}\n            slot={order.indexOf(account)}\n            front={account === front}\n            entry={i}\n            last={deck.length - 1}\n            onPress={() => pick(account.id)}\n          />\n        ))}\n      </View>\n    </View>\n  );\n}\n\nfunction StackCard({\n  account,\n  tone,\n  slot,\n  front,\n  entry,\n  last,\n  onPress,\n}: {\n  account: BalanceAccount;\n  tone: (typeof TONES)[number];\n  slot: number;\n  front: boolean;\n  entry: number;\n  /** Slot of the front card. */\n  last: number;\n  onPress: () => void;\n}) {\n  const { colors, font, radius, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const y = useSharedValue(reduced ? slot * PEEK : slot * PEEK + CARD_H * 2);\n  const lift = useSharedValue(0);\n  const placed = useRef(false);\n\n  useEffect(() => {\n    const to = slot * PEEK;\n    const move = withSpring(to, spring('smooth'));\n    // Cards arrive one after another; later moves start at once.\n    y.set(reduced ? to : placed.current ? move : withDelay(entry * 60, move));\n    placed.current = true;\n  }, [slot, entry, reduced, y]);\n\n  useEffect(() => {\n    if (front && !reduced) {\n      lift.set(withSequence(withSpring(-LIFT, spring('snappy')), withSpring(0, spring('bouncy'))));\n    }\n  }, [front, reduced, lift]);\n\n  // A card behind runs down to the bottom of the stack, so it fills in behind the\n  // rounded corners of the card in front of it.\n  const frontY = last * PEEK;\n  const place = useAnimatedStyle(() => ({\n    height: Math.max(CARD_H, frontY + CARD_H - y.get()),\n    transform: [{ translateY: y.get() + lift.get() }],\n  }));\n  // Its digits stay centred in the part that shows.\n  const row = useAnimatedStyle(() => ({\n    height: interpolate(y.get(), [frontY - PEEK, frontY], [PEEK, CARD_H], Extrapolation.CLAMP),\n  }));\n  const [top, bottom] = account.tones ?? tone.tones;\n  const ink = account.ink ?? tone.ink;\n\n  return (\n    <Animated.View style={[styles.stackCard, { zIndex: slot }, place]}>\n      <Pressable\n        accessibilityRole=\"button\"\n        accessibilityState={{ selected: front }}\n        accessibilityLabel={`${account.network ? `${account.network} card` : 'Card'} ending ${account.digits}`}\n        onPress={onPress}\n        style={[\n          styles.face,\n          {\n            backgroundColor: bottom,\n            borderColor: withAlpha(colors.highlight, 0.28),\n            borderRadius: radius.xl - 2,\n          },\n        ]}\n      >\n        <View\n          pointerEvents=\"none\"\n          style={[styles.tone, gradient(`linear-gradient(180deg, ${top} 0%, ${bottom} 100%)`)]}\n        />\n        <Animated.View style={[styles.content, { paddingHorizontal: space[6] + 2 }, row]}>\n          <Text\n            style={{\n              color: ink,\n              fontSize: font.size.lg,\n              fontWeight: font.weight.medium,\n              fontVariant: ['tabular-nums'],\n            }}\n          >\n            **** {account.digits}\n          </Text>\n          {account.network ? (\n            <Text\n              style={{\n                color: colors.highlight,\n                fontSize: font.size.lg,\n                fontWeight: font.weight.heavy,\n                fontStyle: 'italic',\n                opacity: 0.9,\n              }}\n            >\n              {account.network}\n            </Text>\n          ) : null}\n        </Animated.View>\n      </Pressable>\n    </Animated.View>\n  );\n}\n\nconst PILL_INK = 'hsl(145, 70%, 58%)';\n\nconst styles = StyleSheet.create({\n  card: {\n    width: '100%',\n    maxWidth: 340,\n    alignSelf: 'center',\n    borderRadius: 36,\n    borderWidth: 1,\n    boxShadow: '0px 28px 56px hsla(258, 70%, 58%, 0.34)',\n  },\n  head: { paddingBottom: 26 },\n  row: { flexDirection: 'row', alignItems: 'center', gap: 12 },\n  grow: { flex: 1 },\n  pill: {\n    paddingHorizontal: 14,\n    height: 30,\n    justifyContent: 'center',\n    backgroundColor: 'hsl(150, 40%, 15%)',\n    borderWidth: 1,\n    borderColor: 'hsl(150, 34%, 24%)',\n  },\n  amount: { marginTop: 34, fontVariant: ['tabular-nums'] },\n  stackCard: { position: 'absolute', top: 0, left: 10, right: 10 },\n  face: { flex: 1, borderWidth: 1, overflow: 'hidden' },\n  tone: { position: 'absolute', top: 0, left: 0, right: 0, height: CARD_H },\n  content: {\n    flexDirection: 'row',\n    alignItems: 'center',\n    justifyContent: 'space-between',\n  },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "card",
    "web": "live",
    "perf": {
      "budget": "Cards move on short UI-thread springs; the figure re-renders only while it counts. Nothing animates at rest.",
      "measurements": [
        {
          "device": "Huawei P20 Lite (ANE-LX1), Android 9",
          "kind": "device",
          "date": "2026-11-02",
          "build": "release",
          "frameMs": 32,
          "p90Ms": 42,
          "jankyPercent": 99.65,
          "atRest": "idle",
          "memoryMb": 135
        }
      ]
    },
    "a11y": {
      "reducedMotion": "Cards take their places and the figure changes without moving or counting.",
      "screenReader": "The header reads as one line (\"Savings Vault, €18,904.60, Earning\") and each card as a button (\"NOVA card ending 6190\") with its selected state.",
      "touchTarget": "At least 61 pt of each card stays exposed and tappable."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { BalanceStack } from '@/components/kinetik/balance-stack';\n\n<BalanceStack\n  label=\"Savings Vault\"\n  status=\"Earning\"\n  currency=\"€\"\n  accounts={[\n    { id: 'travel', balance: 6240.18, digits: '2048', network: 'NOVA' },\n    { id: 'daily', balance: 18904.6, digits: '6190', network: 'NOVA' },\n  ]}\n/>;\n```\n\n## When to use\n\n- A home screen or wallet summary for one person with two or three accounts.\n- Switching between accounts where the balance is the thing people came to read.\n\n## When not to use\n\n- More than three accounts: only three fit, so use a list.\n- When every account must be read at once. Only the front one shows its balance.\n\n## Notes\n\n- Pass `selected` and `onSelect` to control which account is at the front.\n- `network` is plain text, so use your own wordmark. Check the rules before showing a real card network's name.\n- The card stays dark in the light theme so the coloured cards keep their contrast.\n"
  },
  "docs": "Prefer `npx kinetik-ui add balance-stack`: it installs dependencies with expo install, so versions match your Expo SDK."
}
