{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "expense-card",
  "type": "registry:item",
  "title": "Expense Card",
  "description": "A spending card with a period menu and horizontal bars on a dashed grid that grow in one by one.",
  "categories": [
    "data"
  ],
  "dependencies": [
    "react-native-reanimated",
    "react-native-worklets"
  ],
  "registryDependencies": [
    "https://kinetik-ui.dev/r/kinetik-tokens.json",
    "https://kinetik-ui.dev/r/kinetik-motion.json"
  ],
  "files": [
    {
      "path": "src/components/kinetik/expense-card.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/expense-card.tsx",
      "content": "import { useEffect, useState, type ReactNode } 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  FadeIn,\n  FadeOut,\n  useAnimatedStyle,\n  useSharedValue,\n  withDelay,\n  withSpring,\n  ZoomIn,\n} from 'react-native-reanimated';\n\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { durations, easings, spring } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { minTouchTarget, withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type ExpenseRow = { label: string; value: number };\n\nexport type ExpenseCardProps<P extends string> = {\n  title?: string;\n  /** Icon before the title. */\n  icon?: ReactNode;\n  /** The rows for the current period. Values of 0 show an empty marker. */\n  rows: readonly ExpenseRow[];\n  /** Periods offered in the menu, e.g. [\"Weekly\", \"Monthly\", \"Yearly\"]. */\n  periods?: readonly P[];\n  period?: P;\n  onPeriodChange?: (period: P) => void;\n  /** Top of the scale. Defaults to the largest value rounded up to a tidy number. */\n  max?: number;\n  /** Formats axis labels and values. Defaults to 2K, 10K style. */\n  formatValue?: (value: number) => string;\n  /** Bar colour. Defaults to the theme azure. */\n  color?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst LABEL = 76;\nconst BAR = 20;\nconst STEPS = 5;\n\nconst compact = (n: number) =>\n  n >= 1000 ? `${Math.round((n / 1000) * 10) / 10}K`.replace('.0K', 'K') : String(Math.round(n));\n\n/** The smallest of 1, 2, 2.5 or 5 times a power of ten that is at least `n`. */\nexport function niceMax(n: number): number {\n  if (n <= 0) return 10;\n  const p = 10 ** Math.floor(Math.log10(n));\n  for (const m of [1, 2, 2.5, 5, 10]) if (m * p >= n) return m * p;\n  return 10 * p;\n}\n\n/**\n * A spending card: a period menu in the header and horizontal bars on a\n * dashed grid. Bars grow in one after another, regrow when the period\n * changes, and an empty category shows a quiet placeholder square.\n */\nexport function ExpenseCard<P extends string>({\n  title = 'Major Expenses',\n  icon,\n  rows,\n  periods,\n  period,\n  onPeriodChange,\n  max,\n  formatValue = compact,\n  color,\n  style,\n}: ExpenseCardProps<P>) {\n  const { colors, radius, space, font, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const [plot, setPlot] = useState(0);\n  const [open, setOpen] = useState(false);\n  const top = max ?? niceMax(Math.max(0, ...rows.map((r) => r.value)));\n  const fill = color ?? colors.azure;\n\n  return (\n    <View\n      style={[\n        styles.card,\n        {\n          backgroundColor: colors.surfaceRaised,\n          borderColor: colors.border,\n          borderRadius: radius.xl,\n          boxShadow: shadow.md,\n        },\n        style,\n      ]}\n    >\n      <View style={[styles.head, { padding: space[5], paddingBottom: space[4], gap: space[3] }]}>\n        {icon}\n        <Text\n          accessibilityRole=\"header\"\n          style={[\n            styles.grow,\n            { color: colors.text, fontSize: font.size.lg, fontWeight: font.weight.medium },\n          ]}\n        >\n          {title}\n        </Text>\n        {periods && period ? (\n          <Pressable\n            accessibilityRole=\"button\"\n            accessibilityLabel={`Period: ${period}`}\n            accessibilityState={{ expanded: open }}\n            onPress={() => setOpen((o) => !o)}\n            style={[\n              styles.select,\n              { borderColor: colors.borderStrong, borderRadius: radius.md, gap: 6 },\n            ]}\n          >\n            <Text style={{ color: colors.text, fontSize: font.size.md }}>{period}</Text>\n            <View\n              style={[\n                styles.caret,\n                { borderColor: colors.text, transform: [{ rotate: open ? '-135deg' : '45deg' }] },\n              ]}\n            />\n          </Pressable>\n        ) : null}\n      </View>\n      <View style={[styles.rule, { backgroundColor: colors.border, marginHorizontal: space[5] }]} />\n\n      <View\n        accessible\n        accessibilityRole=\"summary\"\n        accessibilityLabel={rows.map((r) => `${r.label} ${formatValue(r.value)}`).join(', ')}\n        style={{ padding: space[5], paddingTop: space[4] }}\n      >\n        <View style={styles.chart}>\n          <View style={{ width: LABEL, gap: 12 }}>\n            {rows.map((r) => (\n              <Text\n                key={r.label}\n                numberOfLines={1}\n                style={[styles.label, { color: colors.textSubtle, fontSize: font.size.md }]}\n              >\n                {r.label}\n              </Text>\n            ))}\n          </View>\n          <View\n            style={styles.grow}\n            onLayout={(e: LayoutChangeEvent) => setPlot(e.nativeEvent.layout.width)}\n          >\n            {/* Dashed grid lines at each step of the scale. */}\n            <View pointerEvents=\"none\" style={[StyleSheet.absoluteFill, styles.grid]}>\n              {Array.from({ length: STEPS + 1 }, (_, i) => (\n                <Dashes key={i} color={colors.borderStrong} />\n              ))}\n            </View>\n            <View style={{ gap: 12 }}>\n              {rows.map((r, i) => (\n                <Bar\n                  key={`${r.label}-${period ?? ''}`}\n                  index={i}\n                  value={r.value}\n                  max={top}\n                  width={plot}\n                  color={fill}\n                  empty={withAlpha(colors.text, 0.08)}\n                />\n              ))}\n            </View>\n          </View>\n        </View>\n        <View style={[styles.axis, { marginLeft: LABEL }]}>\n          {Array.from({ length: STEPS + 1 }, (_, i) => (\n            <Text\n              key={i}\n              style={{\n                color: colors.textSubtle,\n                fontSize: font.size.sm,\n                fontVariant: ['tabular-nums'],\n              }}\n            >\n              {formatValue((top / STEPS) * i)}\n            </Text>\n          ))}\n        </View>\n      </View>\n\n      {open && periods && onPeriodChange ? (\n        <Animated.View\n          entering={reduced ? undefined : ZoomIn.duration(durations.base).easing(easings.standard)}\n          exiting={reduced ? undefined : FadeOut.duration(durations.quick)}\n          style={[\n            styles.menu,\n            {\n              top: space[5] + 44,\n              right: space[5],\n              backgroundColor: colors.surfaceRaised,\n              borderColor: colors.border,\n              borderRadius: radius.md,\n              boxShadow: shadow.lg,\n            },\n          ]}\n        >\n          {periods.map((p) => (\n            <Pressable\n              key={p}\n              accessibilityRole=\"menuitem\"\n              accessibilityState={{ selected: p === period }}\n              onPress={() => {\n                setOpen(false);\n                if (p !== period) onPeriodChange(p);\n              }}\n              style={({ pressed }) => [\n                styles.option,\n                {\n                  backgroundColor: pressed || p === period ? colors.surfaceSunken : 'transparent',\n                  borderRadius: radius.sm,\n                },\n              ]}\n            >\n              <Animated.Text\n                entering={reduced ? undefined : FadeIn.duration(durations.base)}\n                style={{\n                  color: colors.text,\n                  fontSize: font.size.md,\n                  fontWeight: p === period ? font.weight.semibold : font.weight.regular,\n                }}\n              >\n                {p}\n              </Animated.Text>\n            </Pressable>\n          ))}\n        </Animated.View>\n      ) : null}\n    </View>\n  );\n}\n\n/** A vertical dashed line drawn as short segments, which renders the same everywhere. */\nfunction Dashes({ color }: { color: string }) {\n  return (\n    <View style={styles.dashes}>\n      {Array.from({ length: 14 }, (_, i) => (\n        <View key={i} style={[styles.dash, { backgroundColor: color }]} />\n      ))}\n    </View>\n  );\n}\n\nfunction Bar({\n  index,\n  value,\n  max,\n  width,\n  color,\n  empty,\n}: {\n  index: number;\n  value: number;\n  max: number;\n  width: number;\n  color: string;\n  empty: string;\n}) {\n  const reduced = useReduceMotion();\n  const grow = useSharedValue(reduced ? 1 : 0);\n  const target = width * Math.min(1, Math.max(0, value / max));\n\n  useEffect(() => {\n    if (width <= 0) return;\n    grow.set(reduced ? 1 : withDelay(index * 90, withSpring(1, spring('smooth'))));\n  }, [width, index, reduced, grow]);\n\n  const style = useAnimatedStyle(() => ({ width: Math.max(0, target * grow.get()) }));\n\n  if (value <= 0) {\n    return <View style={[styles.placeholder, { backgroundColor: empty }]} />;\n  }\n  return (\n    <View style={styles.barSlot}>\n      <Animated.View style={[styles.bar, { backgroundColor: color }, style]} />\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  card: { borderWidth: StyleSheet.hairlineWidth },\n  head: { flexDirection: 'row', alignItems: 'center' },\n  grow: { flex: 1 },\n  select: {\n    flexDirection: 'row',\n    alignItems: 'center',\n    minHeight: minTouchTarget,\n    paddingHorizontal: 14,\n    borderWidth: 1,\n  },\n  caret: { width: 7, height: 7, borderRightWidth: 1.75, borderBottomWidth: 1.75, marginTop: -3 },\n  rule: { height: StyleSheet.hairlineWidth },\n  chart: { flexDirection: 'row' },\n  label: { height: BAR, lineHeight: BAR },\n  grid: { flexDirection: 'row', justifyContent: 'space-between', marginRight: -1 },\n  dashes: { width: 1, justifyContent: 'space-between', paddingVertical: 2 },\n  dash: { width: 1, height: 3 },\n  barSlot: { height: BAR, justifyContent: 'center' },\n  bar: { height: BAR, borderRadius: 5 },\n  placeholder: { width: BAR, height: BAR, borderRadius: 5 },\n  axis: { flexDirection: 'row', justifyContent: 'space-between', marginTop: 10, marginRight: -6 },\n  menu: {\n    position: 'absolute',\n    minWidth: 140,\n    padding: 4,\n    borderWidth: StyleSheet.hairlineWidth,\n  },\n  option: { minHeight: minTouchTarget, justifyContent: 'center', paddingHorizontal: 12 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "data",
    "web": "live",
    "perf": {
      "budget": "Each bar grows once per change with a UI-thread spring; the grid and labels are static views.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-14",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 18,
          "baselineMs": 17,
          "jankyPercent": 6.25,
          "atRest": "idle",
          "memoryMb": 154
        }
      ]
    },
    "a11y": {
      "reducedMotion": "Bars appear at their length and the menu opens without zooming.",
      "screenReader": "The chart reads as one summary (\"Housing 6.2K, Utilities 1.4K, Food 2.1K\"); the period button reports whether its menu is open; options are menu items.",
      "touchTarget": "The period button and menu options are at least 44 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { ExpenseCard } from '@/components/kinetik/expense-card';\n\n<ExpenseCard\n  icon={<ChartIcon />}\n  rows={[\n    { label: 'Housing', value: 6200 },\n    { label: 'Utilities', value: 1400 },\n    { label: 'Food', value: 2150 },\n  ]}\n  periods={['Weekly', 'Monthly', 'Yearly']}\n  period={period}\n  onPeriodChange={setPeriod}\n/>;\n```\n\n## When to use\n\n- A handful of categories compared on one scale, in a dashboard or finance overview.\n\n## When not to use\n\n- Trends over time: use a line or bar chart with a time axis.\n- More than six categories: the card gets long; show the top few and link to the rest.\n\n## Notes\n\n- The scale tops out at the largest value rounded up to a tidy number (`niceMax`), or at `max`.\n- Bars regrow from zero when the period changes. A category of 0 shows a small placeholder square.\n- Values format as 2K, 10K by default; pass `formatValue` for currencies.\n"
  },
  "docs": "Prefer `npx kinetik-ui add expense-card`: it installs dependencies with expo install, so versions match your Expo SDK."
}
