{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "month-calendar",
  "type": "registry:item",
  "title": "Month Calendar",
  "description": "Pick a date or a range: a disc glides between days, months slide in from the side and a swipe turns the page.",
  "categories": [
    "input"
  ],
  "dependencies": [
    "react-native-gesture-handler",
    "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/month-calendar.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/month-calendar.tsx",
      "content": "import { useEffect, useRef, useState, type ReactNode } from 'react';\nimport { Pressable, StyleSheet, Text, View, type StyleProp, type ViewStyle } from 'react-native';\nimport { Gesture, GestureDetector } from 'react-native-gesture-handler';\nimport Animated, {\n  useAnimatedStyle,\n  useSharedValue,\n  withSpring,\n  withTiming,\n} from 'react-native-reanimated';\nimport { scheduleOnRN } from 'react-native-worklets';\n\nimport { useHaptic } from '../../lib/kinetik/hooks/use-haptic';\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 } from '../../lib/kinetik/tokens/tokens';\n\nexport type DateRange = { start: Date | null; end: Date | null };\n\ntype Common = {\n  /** The month shown first. Defaults to the selected date's month, or today's. */\n  initialMonth?: Date;\n  /** Days before this cannot be chosen. */\n  minDate?: Date;\n  /** Days after this cannot be chosen. */\n  maxDate?: Date;\n  /** Days that get a small dot, e.g. days with events. */\n  marked?: readonly Date[];\n  /** 0 for Sunday, 1 for Monday. Defaults to 1. */\n  weekStartsOn?: 0 | 1;\n  /** Twelve month names. Defaults to English. */\n  monthNames?: readonly string[];\n  /** Seven weekday names starting on Sunday. Defaults to English. */\n  dayNames?: readonly string[];\n  onMonthChange?: (month: Date) => void;\n  /** A tick on each choice. Defaults to true. */\n  haptics?: boolean;\n  testID?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nexport type MonthCalendarProps = Common &\n  (\n    | { mode?: 'single'; value: Date | null; onChange: (date: Date) => void }\n    | { mode: 'range'; range: DateRange; onRangeChange: (range: DateRange) => void }\n  );\n\nconst MONTHS = [\n  'January',\n  'February',\n  'March',\n  'April',\n  'May',\n  'June',\n  'July',\n  'August',\n  'September',\n  'October',\n  'November',\n  'December',\n];\nconst DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];\n\nconst CELL = 44;\nconst DISC = 38;\n\nexport const startOfMonth = (d: Date) => new Date(d.getFullYear(), d.getMonth(), 1);\nconst dayKey = (d: Date) => d.getFullYear() * 10000 + d.getMonth() * 100 + d.getDate();\nconst sameDay = (a: Date | null | undefined, b: Date | null | undefined) =>\n  Boolean(a && b && dayKey(a) === dayKey(b));\nconst addMonths = (d: Date, n: number) => new Date(d.getFullYear(), d.getMonth() + n, 1);\n\n/** The 42 days (six weeks) shown for a month, starting on `weekStartsOn`. */\nexport function monthGrid(month: Date, weekStartsOn: 0 | 1 = 1): Date[] {\n  const first = startOfMonth(month);\n  const offset = (first.getDay() - weekStartsOn + 7) % 7;\n  return Array.from(\n    { length: 42 },\n    (_, i) => new Date(first.getFullYear(), first.getMonth(), 1 - offset + i),\n  );\n}\n\n/**\n * A month of days to pick one date or a range. A disc glides from day to day\n * within the month, a new month slides in from the side you are heading to,\n * and a swipe across the grid turns the page. In range mode a soft band\n * joins the two ends, row by row.\n */\nexport function MonthCalendar(props: MonthCalendarProps) {\n  const {\n    initialMonth,\n    minDate,\n    maxDate,\n    marked,\n    weekStartsOn = 1,\n    monthNames = MONTHS,\n    dayNames = DAYS,\n    onMonthChange,\n    haptics = true,\n    testID,\n    style,\n  } = props;\n  const { colors, font, radius } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const range = props.mode === 'range' ? props.range : null;\n  const single = props.mode === 'range' ? null : props.value;\n\n  const [view, setView] = useState(() => ({\n    month: startOfMonth(initialMonth ?? single ?? range?.start ?? new Date()),\n    dir: 0,\n  }));\n  const [width, setWidth] = useState(0);\n  const cw = width / 7;\n  const days = monthGrid(view.month, weekStartsOn);\n  const today = new Date();\n  const markedKeys = new Set((marked ?? []).map(dayKey));\n  const lo = minDate ? dayKey(minDate) : -Infinity;\n  const hi = maxDate ? dayKey(maxDate) : Infinity;\n\n  const turn = (n: number) => {\n    const month = addMonths(view.month, n);\n    haptic('tick');\n    setView({ month, dir: n });\n    onMonthChange?.(month);\n  };\n\n  const pick = (d: Date) => {\n    haptic('tick');\n    if (props.mode !== 'range') {\n      props.onChange(d);\n      return;\n    }\n    const { start, end } = props.range;\n    if (!start || end || dayKey(d) < dayKey(start)) props.onRangeChange({ start: d, end: null });\n    else props.onRangeChange({ start, end: d });\n  };\n\n  // The disc for a single date glides within a month and jumps across months.\n  const at = single\n    ? days.findIndex((d) => sameDay(d, single) && d.getMonth() === view.month.getMonth())\n    : -1;\n  const x = useSharedValue(0);\n  const y = useSharedValue(0);\n  const shown = useSharedValue(0);\n  const placed = useRef<number | null>(null);\n  const monthKey = view.month.getTime();\n  useEffect(() => {\n    if (at < 0 || cw === 0) {\n      shown.set(withTiming(0, { duration: durations.quick }));\n      placed.current = null;\n      return;\n    }\n    const tx = (at % 7) * cw + (cw - DISC) / 2;\n    const ty = Math.floor(at / 7) * CELL + (CELL - DISC) / 2;\n    if (reduced || placed.current !== monthKey) {\n      x.set(tx);\n      y.set(ty);\n      shown.set(reduced ? 1 : withSpring(1, spring('bouncy')));\n    } else {\n      x.set(withSpring(tx, spring('smooth')));\n      y.set(withSpring(ty, spring('smooth')));\n      shown.set(1);\n    }\n    placed.current = monthKey;\n  }, [at, cw, monthKey, reduced, x, y, shown]);\n  const disc = useAnimatedStyle(() => ({\n    opacity: shown.get(),\n    transform: [\n      { translateX: x.get() },\n      { translateY: y.get() },\n      { scale: 0.6 + shown.get() * 0.4 },\n    ],\n  }));\n\n  const swipe = Gesture.Pan()\n    .withTestId('month-calendar')\n    .activeOffsetX([-16, 16])\n    .failOffsetY([-14, 14])\n    .onEnd((e) => {\n      if (Math.abs(e.translationX) < 48 && Math.abs(e.velocityX) < 400) return;\n      scheduleOnRN(turn, e.translationX < 0 ? 1 : -1);\n    });\n\n  const order = Array.from({ length: 7 }, (_, i) => (i + weekStartsOn) % 7);\n  const title = `${monthNames[view.month.getMonth()]} ${view.month.getFullYear()}`;\n\n  return (\n    <View testID={testID} style={style}>\n      <View style={styles.header}>\n        <Text\n          accessibilityRole=\"header\"\n          style={{ color: colors.text, fontSize: font.size.lg, fontWeight: font.weight.semibold }}\n        >\n          {title}\n        </Text>\n        <View style={styles.arrows}>\n          <Arrow dir={-1} label=\"Previous month\" onPress={() => turn(-1)} />\n          <Arrow dir={1} label=\"Next month\" onPress={() => turn(1)} />\n        </View>\n      </View>\n      <View style={styles.week}>\n        {order.map((d) => (\n          <Text\n            key={d}\n            accessibilityElementsHidden\n            importantForAccessibility=\"no\"\n            style={[styles.weekday, { color: colors.textSubtle, fontSize: font.size.xs }]}\n          >\n            {(dayNames[d] ?? '').slice(0, 2)}\n          </Text>\n        ))}\n      </View>\n      <GestureDetector gesture={swipe}>\n        <View\n          collapsable={false}\n          style={styles.gridBox}\n          onLayout={(e) => setWidth(e.nativeEvent.layout.width)}\n        >\n          <Page key={monthKey} dir={view.dir} reduced={reduced}>\n            {range && width > 0 ? (\n              <Band days={days} month={view.month} range={range} cw={cw} radius={radius.pill} />\n            ) : null}\n            {single !== null ? (\n              <Animated.View\n                pointerEvents=\"none\"\n                style={[styles.disc, { backgroundColor: colors.azure }, disc]}\n              />\n            ) : null}\n            <View style={styles.grid}>\n              {days.map((d) => {\n                const k = dayKey(d);\n                const inMonth = d.getMonth() === view.month.getMonth();\n                const disabled = !inMonth || k < lo || k > hi;\n                const end = range !== null && (sameDay(d, range.start) || sameDay(d, range.end));\n                const chosen = (inMonth && sameDay(d, single)) || (inMonth && end);\n                const isToday = sameDay(d, today);\n                const name = `${dayNames[d.getDay()]}, ${monthNames[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`;\n                return (\n                  <Pressable\n                    key={k}\n                    onPress={() => pick(d)}\n                    disabled={disabled}\n                    accessibilityRole=\"button\"\n                    accessibilityLabel={isToday ? `Today, ${name}` : name}\n                    accessibilityState={{ selected: chosen, disabled }}\n                    accessibilityElementsHidden={!inMonth}\n                    importantForAccessibility={inMonth ? 'auto' : 'no-hide-descendants'}\n                    style={styles.cell}\n                  >\n                    <Text\n                      style={{\n                        color: chosen ? colors.onAzure : isToday ? colors.azure : colors.text,\n                        opacity: !inMonth ? 0.28 : disabled ? 0.4 : 1,\n                        fontSize: font.size.md,\n                        fontWeight: chosen || isToday ? font.weight.semibold : font.weight.regular,\n                        fontVariant: ['tabular-nums'],\n                      }}\n                    >\n                      {d.getDate()}\n                    </Text>\n                    {inMonth && markedKeys.has(k) ? (\n                      <View\n                        style={[\n                          styles.mark,\n                          { backgroundColor: chosen ? colors.onAzure : colors.azure },\n                        ]}\n                      />\n                    ) : null}\n                  </Pressable>\n                );\n              })}\n            </View>\n          </Page>\n        </View>\n      </GestureDetector>\n    </View>\n  );\n}\n\n/** A month's grid; a new one slides in from the side being turned to. */\nfunction Page({ dir, reduced, children }: { dir: number; reduced: boolean; children: ReactNode }) {\n  const p = useSharedValue(dir === 0 || reduced ? 1 : 0);\n  useEffect(() => {\n    p.set(withTiming(1, { duration: durations.base, easing: easings.standard }));\n  }, [p]);\n  const motion = useAnimatedStyle(() => ({\n    opacity: p.get(),\n    transform: [{ translateX: (1 - p.get()) * 36 * dir }],\n  }));\n  return <Animated.View style={motion}>{children}</Animated.View>;\n}\n\ntype BandProps = { days: Date[]; month: Date; range: DateRange; cw: number; radius: number };\n\n/** The range drawn row by row: a soft band between the ends and a disc on each end. */\nfunction Band({ days, month, range, cw, radius }: BandProps) {\n  const { colors } = useKinetikTheme();\n  if (!range.start) return null;\n  const a = dayKey(range.start);\n  const b = range.end ? dayKey(range.end) : a;\n  const pieces: ReactNode[] = [];\n  for (let row = 0; row < 6; row++) {\n    const cols: number[] = [];\n    for (let c = 0; c < 7; c++) {\n      const d = days[row * 7 + c]!;\n      const k = dayKey(d);\n      if (d.getMonth() === month.getMonth() && k >= a && k <= b) cols.push(c);\n    }\n    if (cols.length === 0) continue;\n    const first = cols[0]!;\n    const last = cols[cols.length - 1]!;\n    const top = row * CELL + (CELL - DISC) / 2;\n    if (range.end && a !== b) {\n      pieces.push(\n        <View\n          key={`band-${row}`}\n          style={[\n            styles.band,\n            {\n              top,\n              left: first * cw + (cw - DISC) / 2,\n              width: (last - first) * cw + DISC,\n              backgroundColor: colors.azureSoft,\n              borderRadius: radius,\n            },\n          ]}\n        />,\n      );\n    }\n    for (const c of cols) {\n      const k = dayKey(days[row * 7 + c]!);\n      if (k === a || k === b) {\n        pieces.push(\n          <View\n            key={`end-${k}`}\n            style={[\n              styles.band,\n              {\n                top,\n                left: c * cw + (cw - DISC) / 2,\n                width: DISC,\n                backgroundColor: colors.azure,\n                borderRadius: radius,\n              },\n            ]}\n          />,\n        );\n      }\n    }\n  }\n  return <>{pieces}</>;\n}\n\nfunction Arrow({ dir, label, onPress }: { dir: 1 | -1; label: string; onPress: () => void }) {\n  const { colors, radius } = useKinetikTheme();\n  return (\n    <Pressable\n      onPress={onPress}\n      accessibilityRole=\"button\"\n      accessibilityLabel={label}\n      style={({ pressed }) => [\n        styles.arrow,\n        { borderRadius: radius.pill, backgroundColor: pressed ? colors.surfaceSunken : undefined },\n      ]}\n    >\n      <View style={[styles.icon, { transform: [{ scaleX: dir }] }]}>\n        <View style={[styles.stroke, styles.up, { backgroundColor: colors.text }]} />\n        <View style={[styles.stroke, styles.down, { backgroundColor: colors.text }]} />\n      </View>\n    </Pressable>\n  );\n}\n\nconst styles = StyleSheet.create({\n  header: {\n    flexDirection: 'row',\n    alignItems: 'center',\n    justifyContent: 'space-between',\n    paddingLeft: 4,\n    marginBottom: 4,\n  },\n  arrows: { flexDirection: 'row' },\n  arrow: {\n    width: minTouchTarget,\n    height: minTouchTarget,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  icon: { width: 14, height: 14 },\n  stroke: { position: 'absolute', width: 8, height: 1.8, borderRadius: 1, left: 4 },\n  up: { top: 4.2, transform: [{ rotate: '45deg' }] },\n  down: { top: 8.8, transform: [{ rotate: '-45deg' }] },\n  week: { flexDirection: 'row', marginBottom: 2 },\n  weekday: { flex: 1, textAlign: 'center', paddingVertical: 6 },\n  gridBox: { height: CELL * 6, overflow: 'hidden' },\n  grid: { flexDirection: 'row', flexWrap: 'wrap' },\n  cell: { width: `${100 / 7}%`, height: CELL, alignItems: 'center', justifyContent: 'center' },\n  mark: { position: 'absolute', bottom: 6, width: 4, height: 4, borderRadius: 2 },\n  disc: {\n    position: 'absolute',\n    left: 0,\n    top: 0,\n    width: DISC,\n    height: DISC,\n    borderRadius: DISC / 2,\n  },\n  band: { position: 'absolute', height: DISC },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "input",
    "web": "live",
    "perf": {
      "budget": "42 plain day cells; one disc on three shared values, and one value slides each new month in. Nothing runs at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-13",
          "build": "release",
          "frameMs": 18,
          "p90Ms": 22,
          "baselineMs": 18,
          "jankyPercent": 1.85,
          "atRest": "idle",
          "memoryMb": 154
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The disc jumps to the new day and months change in place.",
      "screenReader": "A header with the month, Previous and Next buttons, and a button for every day that reads its full date and selected state.",
      "touchTarget": "Day cells are 44 pt tall and a seventh of the width; the arrows are 44 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { MonthCalendar } from '@/components/kinetik/month-calendar';\n\n// One date\n<MonthCalendar value={date} onChange={setDate} marked={eventDays} />;\n\n// A range\n<MonthCalendar mode=\"range\" range={stay} onRangeChange={setStay} minDate={new Date()} />;\n```\n\n## When to use\n\n- Picking a date where the day of the week matters: a booking, a delivery slot, a meeting.\n- Picking a stay or a period, with `mode=\"range\"`.\n\n## When not to use\n\n- Dates far in the past, such as a birthday. Use wheels or a typed date.\n- A time of day. Use Time Wheel.\n\n## Notes\n\n- The disc glides between days of the same month; arrows or a horizontal swipe turn the page and the new month slides in from that side.\n- In range mode the first tap sets the start, the second the end, and a third starts again. A tap before the start moves the start.\n- `monthNames`, `dayNames` and `weekStartsOn` localise it. Days outside `minDate`/`maxDate` are dimmed and cannot be chosen.\n- Every day is a button that reads its full date for screen readers; the selected days say so.\n"
  },
  "docs": "Prefer `npx kinetik-ui add month-calendar`: it installs dependencies with expo install, so versions match your Expo SDK."
}
