{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "wallet-stack",
  "type": "registry:item",
  "title": "Wallet Stack",
  "description": "Glint Cards tucked in a stitched leather pocket: tap to fan them out, with the balance counting up.",
  "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",
    "https://kinetik-ui.dev/r/glint-card.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/wallet-stack.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/wallet-stack.tsx",
      "content": "import { useEffect, useState } from 'react';\nimport {\n  Pressable,\n  StyleSheet,\n  Text,\n  View,\n  type LayoutChangeEvent,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\nimport Animated, {\n  useAnimatedStyle,\n  useSharedValue,\n  withDelay,\n  withSpring,\n  type SharedValue,\n} from 'react-native-reanimated';\n\nimport { GlintCard } from './glint-card';\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 { palettes, withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type WalletCard = {\n  id: string;\n  /** Name on the card, e.g. \"Kinetik Black\". */\n  name: string;\n  /** Last four digits. */\n  last4?: string;\n  /** A CSS linear-gradient for the card face. Defaults to a theme-coloured one. */\n  background?: string;\n  /** Text colour on the face. Defaults to the theme highlight. */\n  ink?: string;\n};\n\nexport type WalletStackProps = {\n  /** Up to four cards, back to front. */\n  cards: readonly WalletCard[];\n  balance: number;\n  /** Defaults to \"$\". */\n  currency?: string;\n  /** Line above the balance. Defaults to \"Total balance\". */\n  balanceLabel?: string;\n  /** Title above the cards. Defaults to \"Wallet\". */\n  title?: string;\n  /** Called with a card when it is tapped while the wallet is open. */\n  onCardPress?: (card: WalletCard) => void;\n  /** A tick when the wallet opens and closes. Defaults to true. */\n  haptics?: boolean;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst CARD_H = 150;\n/** How much of each card shows above the pocket while closed, and when open. */\nconst PEEK = 30;\nconst SPREAD = 64;\nconst POCKET_H = 190;\n/** Extra lift for the front card when open, so it clears the pocket's lip. */\nconst LIFT = 34;\n\n/**\n * A wallet: cards (Glint Cards, catching the light as you tilt) tucked in a\n * stitched leather pocket. Tap it and the cards slide up and fan out; the\n * balance counts up on the pocket's face. Tap again to tuck them away.\n */\nexport function WalletStack({\n  cards,\n  balance,\n  currency = '$',\n  balanceLabel = 'Total balance',\n  title = 'Wallet',\n  onCardPress,\n  haptics = true,\n  style,\n}: WalletStackProps) {\n  const { radius, space, font, shadow } = useKinetikTheme();\n  // Leather reads dark on either theme, like a real wallet.\n  const colors = palettes.dark;\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const [open, setOpen] = useState(false);\n  const [width, setWidth] = useState(0);\n  const deck = cards.slice(0, 4);\n  const spread = useSharedValue(0);\n  const shown = useCountUp(balance, { instant: reduced, duration: 1100 });\n\n  useEffect(() => {\n    spread.set(reduced ? (open ? 1 : 0) : withSpring(open ? 1 : 0, spring('bouncy')));\n  }, [open, reduced, spread]);\n\n  const toggle = () => {\n    haptic('tap');\n    setOpen((o) => !o);\n  };\n\n  const whole = Math.floor(shown);\n  const cents = Math.round((shown - whole) * 100);\n  const amount = `${currency} ${whole.toLocaleString('en-US')}`;\n  const top = space[10] + 6;\n  // Every card, the front one included, shows a strip above the pocket.\n  const height = top + deck.length * PEEK + POCKET_H + 6;\n\n  // Opening grows the wallet so the fanned cards have room above the pocket.\n  const extra = Math.max(0, deck.length - 1) * (SPREAD - PEEK) + LIFT;\n  const grow = useAnimatedStyle(() => ({ height: height + spread.get() * extra }));\n\n  return (\n    <Animated.View\n      onLayout={(e: LayoutChangeEvent) => setWidth(e.nativeEvent.layout.width)}\n      style={[\n        styles.frame,\n        {\n          backgroundColor: colors.surface,\n          borderColor: colors.borderStrong,\n          borderRadius: radius.xl + 8,\n          // No outer shadow: the frame grows as it opens, and a blurred shadow would redraw every frame.\n        },\n        style,\n        grow,\n      ]}\n    >\n      <Text\n        accessibilityRole=\"header\"\n        style={[\n          styles.title,\n          {\n            color: colors.textSubtle,\n            fontSize: font.size.lg,\n            fontWeight: font.weight.semibold,\n            top: space[3],\n          },\n        ]}\n      >\n        {title}\n      </Text>\n\n      {width > 0 &&\n        deck.map((card, i) => (\n          <Slot\n            key={card.id}\n            card={card}\n            index={i}\n            count={deck.length}\n            top={top}\n            width={width - space[6] * 2}\n            spread={spread}\n            open={open}\n            interactive={open && !!onCardPress}\n            onPress={() => onCardPress?.(card)}\n          />\n        ))}\n\n      <View style={[styles.pocketSlot, { height: POCKET_H }]}>\n        <Pressable\n          accessibilityRole=\"button\"\n          accessibilityLabel={`${title}, ${balanceLabel} ${currency}${balance.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`}\n          accessibilityHint={open ? 'Tucks the cards away' : 'Shows the cards'}\n          accessibilityState={{ expanded: open }}\n          onPress={toggle}\n          style={[\n            styles.pocket,\n            {\n              borderRadius: radius.xl + 4,\n              boxShadow: shadow.lg,\n            },\n            gradient(\n              `linear-gradient(160deg, ${colors.surfaceRaised} 0%, ${colors.surfaceSunken} 45%, ${withAlpha(colors.danger, 0.55)} 100%)`,\n            ),\n          ]}\n        >\n          {/* Stitching around the edge. */}\n          <View\n            pointerEvents=\"none\"\n            style={[\n              styles.stitch,\n              { borderColor: withAlpha(colors.text, 0.28), borderRadius: radius.xl - 2 },\n            ]}\n          />\n          {/* A soft sheen along the top lip. */}\n          <View\n            pointerEvents=\"none\"\n            style={[\n              styles.lip,\n              gradient(\n                `linear-gradient(180deg, ${withAlpha(colors.highlight, 0.14)} 0%, ${withAlpha(colors.highlight, 0)} 100%)`,\n              ),\n            ]}\n          />\n          <Text style={{ color: colors.textMuted, fontSize: font.size.md }}>{balanceLabel}</Text>\n          <Text\n            style={{\n              color: colors.text,\n              fontSize: font.size['3xl'],\n              fontWeight: font.weight.semibold,\n              fontVariant: ['tabular-nums'],\n              marginTop: 4,\n            }}\n          >\n            {amount}\n            <Text style={{ color: colors.textSubtle, fontSize: font.size.xl }}>\n              .{String(cents).padStart(2, '0')}\n            </Text>\n          </Text>\n        </Pressable>\n      </View>\n    </Animated.View>\n  );\n}\n\nfunction Slot({\n  card,\n  index,\n  count,\n  top,\n  width,\n  spread,\n  open,\n  interactive,\n  onPress,\n}: {\n  card: WalletCard;\n  index: number;\n  count: number;\n  top: number;\n  width: number;\n  spread: SharedValue<number>;\n  open: boolean;\n  interactive: boolean;\n  onPress: () => void;\n}) {\n  const { space, font } = useKinetikTheme();\n  const colors = palettes.dark;\n  const reduced = useReduceMotion();\n  const fromFront = count - 1 - index;\n  // Cards settle in one after another when the wallet first appears.\n  const arrive = useSharedValue(reduced ? 1 : 0);\n  useEffect(() => {\n    if (!reduced) arrive.set(withDelay(150 + index * 90, withSpring(1, spring('smooth'))));\n  }, [index, reduced, arrive]);\n\n  const style = useAnimatedStyle(() => {\n    const s = spread.get();\n    // Closed: each card a little higher than the one in front. Open: lifted and fanned.\n    const y = top + index * PEEK + s * (index * (SPREAD - PEEK)) + (1 - arrive.get()) * 80;\n    const tilt = (index - (count - 1) / 2) * s * 3.5;\n    return {\n      opacity: arrive.get(),\n      transform: [\n        { translateY: y },\n        { rotate: `${tilt}deg` },\n        { scale: 1 - fromFront * 0.03 * (1 - s) },\n      ],\n    };\n  });\n\n  const face =\n    card.background ??\n    [\n      `linear-gradient(135deg, ${colors.azure} 0%, ${colors.sky} 100%)`,\n      `linear-gradient(135deg, ${colors.surfaceRaised} 0%, ${colors.textSubtle} 100%)`,\n      `linear-gradient(135deg, ${colors.surfaceSunken} 0%, ${colors.surfaceRaised} 100%)`,\n      `linear-gradient(135deg, ${colors.success} 0%, ${colors.azure} 100%)`,\n    ][index % 4]!;\n  const ink = card.ink ?? colors.highlight;\n\n  return (\n    <Animated.View\n      pointerEvents={interactive ? 'auto' : 'none'}\n      style={[styles.slot, { left: space[6], width, height: CARD_H }, style]}\n    >\n      <Pressable\n        accessibilityRole=\"button\"\n        accessibilityLabel={`${card.name}${card.last4 ? ` ending ${card.last4}` : ''}`}\n        accessibilityElementsHidden={!interactive}\n        importantForAccessibility={interactive ? 'auto' : 'no-hide-descendants'}\n        disabled={!interactive}\n        onPress={onPress}\n        style={styles.fill}\n      >\n        <GlintCard\n          // The light follows the finger: no motion sensors, so opening stays smooth.\n          source=\"touch\"\n          active={open}\n          tiltDegrees={0}\n          intensity={0.55}\n          radius={16}\n          style={[styles.fill, gradient(face), { borderColor: withAlpha(ink, 0.35) }, styles.edge]}\n          contentStyle={[styles.cardContent, { padding: space[4] }]}\n        >\n          <Text\n            numberOfLines={1}\n            style={{\n              flexShrink: 1,\n              color: ink,\n              fontSize: font.size.md,\n              fontWeight: font.weight.heavy,\n              fontStyle: 'italic',\n              letterSpacing: 1,\n            }}\n          >\n            {card.name.toUpperCase()}\n          </Text>\n          {card.last4 ? (\n            <Text\n              style={{\n                color: ink,\n                opacity: 0.8,\n                fontSize: font.size.sm,\n                fontVariant: ['tabular-nums'],\n              }}\n            >\n              •••• {card.last4}\n            </Text>\n          ) : null}\n        </GlintCard>\n      </Pressable>\n    </Animated.View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  frame: { borderWidth: 3, overflow: 'hidden' },\n  title: { position: 'absolute', alignSelf: 'center' },\n  slot: { position: 'absolute', top: 0 },\n  fill: { flex: 1 },\n  edge: { borderWidth: 1.5 },\n  cardContent: {\n    flex: 1,\n    flexDirection: 'row',\n    justifyContent: 'space-between',\n    alignItems: 'flex-start',\n  },\n  pocketSlot: { position: 'absolute', left: 6, right: 6, bottom: 6 },\n  pocket: { flex: 1, alignItems: 'center', justifyContent: 'center', overflow: 'hidden' },\n  stitch: {\n    position: 'absolute',\n    top: 8,\n    left: 8,\n    right: 8,\n    bottom: 8,\n    borderWidth: 1,\n    borderStyle: 'dashed',\n  },\n  lip: { position: 'absolute', top: 0, left: 0, right: 0, height: 26 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "card",
    "web": "live",
    "perf": {
      "budget": "Opening and closing is one UI-thread spring shared by every card. The Glint Cards follow the finger (no motion sensors) while the wallet is open; closed, nothing animates.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 34,
          "p90Ms": 38,
          "baselineMs": 17,
          "jankyPercent": 3.59,
          "atRest": "idle",
          "memoryMb": 173,
          "notes": "Frames are measured while opening and closing: the wallet grows in height (a layout pass per frame) for about 0.6 s per toggle; framestats show ~6 ms of app work, the rest the emulator GPU. Closed or open at rest, nothing animates."
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The wallet opens and closes without springing, the balance shows at once and the cards hold a still reflection (Glint Card).",
      "screenReader": "The pocket is a button reading the title and balance, with a hint to show or tuck the cards; cards are buttons only while the wallet is open.",
      "touchTarget": "The pocket is about 190 pt tall; open cards are full width and 150 pt tall."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { WalletStack } from '@/components/kinetik/wallet-stack';\n\n<WalletStack\n  balance={account.balance}\n  cards={account.cards.map((c) => ({ id: c.id, name: c.product, last4: c.last4 }))}\n  onCardPress={(card) => router.push(`/cards/${card.id}`)}\n/>;\n```\n\n## When to use\n\n- A wallet or accounts overview with two to four cards and one total.\n\n## When not to use\n\n- Many cards: the pocket shows up to four. Use a list or Parallax Carousel.\n- Showing full card numbers: faces show the name and last four digits only.\n\n## Notes\n\n- Each card is a Glint Card: while the wallet is open, the light follows your finger across a card (no motion sensors, so opening stays smooth). Pass your own `background` gradients to match real card designs; no card-network logos are drawn.\n- Cards are only tappable while the wallet is open; tapping the pocket opens and closes it.\n- The balance counts up when it changes; cents show quieter after the whole amount.\n"
  },
  "docs": "Prefer `npx kinetik-ui add wallet-stack`: it installs dependencies with expo install, so versions match your Expo SDK."
}
