{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "split-button",
  "type": "registry:item",
  "title": "Split Button",
  "description": "A primary action with alternatives behind a chevron; a new pick rolls into the label as the button resizes.",
  "categories": [
    "interaction"
  ],
  "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"
  ],
  "files": [
    {
      "path": "src/components/kinetik/split-button.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/split-button.tsx",
      "content": "import { useEffect, useRef, useState } from 'react';\nimport {\n  Modal,\n  Pressable,\n  StyleSheet,\n  Text,\n  View,\n  useWindowDimensions,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\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, withAlpha } from '../../lib/kinetik/tokens/tokens';\n\nexport type SplitButtonOption = {\n  value: string;\n  /** The button's label while this option is chosen, e.g. \"Squash and merge\". */\n  label: string;\n  /** A line under the label in the menu. */\n  description?: string;\n};\n\nexport type SplitButtonProps = {\n  options: readonly SplitButtonOption[];\n  /** The chosen option, which the main half runs. */\n  value: string;\n  onValueChange: (value: string) => void;\n  /** Runs the chosen option. */\n  onPress: (value: string) => void;\n  /** Defaults to `ember`, the theme's strongest ink. */\n  tone?: 'ember' | 'azure';\n  /** Names the menu button. Defaults to 'More options'. */\n  menuLabel?: string;\n  /** A tick when the menu opens and on a new choice. Defaults to true. */\n  haptics?: boolean;\n  disabled?: boolean;\n  testID?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst HEIGHT = 48;\nconst CHEVRON_W = 48;\nconst PAD = 20;\nconst MENU_W = 280;\n\n/**\n * A primary action with close alternatives behind a chevron. Picking one in\n * the menu makes it the button's action: the old label rolls up and away,\n * the new one rolls in, and the button springs to its width.\n */\nexport function SplitButton({\n  options,\n  value,\n  onValueChange,\n  onPress,\n  tone = 'ember',\n  menuLabel = 'More options',\n  haptics = true,\n  disabled = false,\n  testID,\n  style,\n}: SplitButtonProps) {\n  const { colors, font, radius, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const window = useWindowDimensions();\n  const ink = tone === 'azure' ? colors.azure : colors.ember;\n  const onInk = tone === 'azure' ? colors.onAzure : colors.onEmber;\n  const current = options.find((o) => o.value === value) ?? options[0]!;\n\n  // Label widths, measured once off screen, so the button can spring between them.\n  const [widths, setWidths] = useState<Record<string, number>>({});\n  const width = useSharedValue(0);\n  const [roll, setRoll] = useState({ from: current.label, to: current.label, id: 0 });\n  if (roll.to !== current.label) setRoll({ from: roll.to, to: current.label, id: roll.id + 1 });\n  const t = useSharedValue(1);\n\n  useEffect(() => {\n    const w = widths[current.value];\n    if (w === undefined) return;\n    const target = w + PAD * 2;\n    width.set(width.get() === 0 || reduced ? target : withSpring(target, spring('smooth')));\n  }, [widths, current.value, reduced, width]);\n\n  useEffect(() => {\n    if (roll.id === 0) return;\n    t.set(0);\n    t.set(reduced ? 1 : withSpring(1, spring('smooth')));\n  }, [roll.id, reduced, t]);\n\n  // The menu.\n  const anchor = useRef<View>(null);\n  const [menu, setMenu] = useState<{ x: number; y: number; w: number; h: number } | null>(null);\n  const [open, setOpen] = useState(false);\n  const m = useSharedValue(0);\n  const openMenu = () => {\n    setMenu(null);\n    setOpen(true);\n    haptic('tick');\n    anchor.current?.measureInWindow((x, y, w, h) => setMenu({ x, y, w, h }));\n  };\n  useEffect(() => {\n    if (!open || !menu) return;\n    m.set(0);\n    m.set(reduced ? 1 : withSpring(1, spring('smooth')));\n  }, [open, menu, reduced, m]);\n  const closeMenu = (then?: () => void) => {\n    const done = () => {\n      setOpen(false);\n      then?.();\n    };\n    if (reduced) {\n      m.set(0);\n      done();\n      return;\n    }\n    m.set(\n      withTiming(0, { duration: durations.quick, easing: easings.exit }, (finished) => {\n        if (finished) scheduleOnRN(done);\n      }),\n    );\n  };\n\n  const main = useAnimatedStyle(() => (width.get() > 0 ? { width: width.get() } : {}));\n  const outgoing = useAnimatedStyle(() => ({\n    opacity: 1 - t.get(),\n    transform: [{ translateY: -t.get() * 16 }],\n  }));\n  const incoming = useAnimatedStyle(() => ({\n    opacity: t.get(),\n    transform: [{ translateY: (1 - t.get()) * 16 }],\n  }));\n  const chevron = useAnimatedStyle(() => ({\n    transform: [{ translateY: m.get() * 2 - 2 }, { rotate: `${45 + m.get() * 180}deg` }],\n  }));\n  const panel = useAnimatedStyle(() => ({\n    opacity: Math.min(1, m.get() * 2),\n    transform: [{ translateY: (1 - m.get()) * -8 }, { scale: 0.9 + m.get() * 0.1 }],\n  }));\n\n  const label = { color: onInk, fontSize: font.size.md, fontWeight: font.weight.semibold } as const;\n  const menuLeft = menu\n    ? Math.max(12, Math.min(window.width - MENU_W - 12, menu.x + menu.w - MENU_W))\n    : 0;\n\n  return (\n    <View testID={testID} style={[styles.root, style]}>\n      {/* Measures every label so widths are known before they are needed. */}\n      <View\n        style={styles.measure}\n        pointerEvents=\"none\"\n        accessibilityElementsHidden\n        importantForAccessibility=\"no-hide-descendants\"\n      >\n        {options.map((o) => (\n          <Text\n            key={o.value}\n            style={label}\n            onLayout={(e) => {\n              const w = Math.ceil(e.nativeEvent.layout.width);\n              setWidths((prev) => (prev[o.value] === w ? prev : { ...prev, [o.value]: w }));\n            }}\n          >\n            {o.label}\n          </Text>\n        ))}\n      </View>\n\n      <View\n        ref={anchor}\n        collapsable={false}\n        style={[\n          styles.pill,\n          { backgroundColor: ink, borderRadius: radius.pill, opacity: disabled ? 0.45 : 1 },\n        ]}\n      >\n        <Pressable\n          disabled={disabled}\n          onPress={() => onPress(current.value)}\n          accessibilityRole=\"button\"\n          accessibilityLabel={current.label}\n          style={({ pressed }) => [{ opacity: pressed ? 0.75 : 1 }]}\n        >\n          <Animated.View style={[styles.main, main]}>\n            {roll.from !== roll.to ? (\n              <Animated.View key={`o${roll.id}`} style={[styles.layer, outgoing]}>\n                <Text numberOfLines={1} style={label}>\n                  {roll.from}\n                </Text>\n              </Animated.View>\n            ) : null}\n            <Animated.View key={`i${roll.id}`} style={[styles.layer, incoming]}>\n              <Text numberOfLines={1} style={label}>\n                {roll.to}\n              </Text>\n            </Animated.View>\n          </Animated.View>\n        </Pressable>\n        <View style={[styles.divider, { backgroundColor: withAlpha(onInk, 0.25) }]} />\n        <Pressable\n          disabled={disabled}\n          onPress={openMenu}\n          accessibilityRole=\"button\"\n          accessibilityLabel={menuLabel}\n          accessibilityState={{ expanded: open, disabled }}\n          style={({ pressed }) => [styles.more, { opacity: pressed ? 0.75 : 1 }]}\n        >\n          <Animated.View style={[styles.chevron, { borderColor: onInk }, chevron]} />\n        </Pressable>\n      </View>\n\n      <Modal\n        visible={open}\n        transparent\n        animationType=\"none\"\n        onRequestClose={() => closeMenu()}\n        statusBarTranslucent\n        navigationBarTranslucent\n      >\n        <View style={StyleSheet.absoluteFill} onAccessibilityEscape={() => closeMenu()}>\n          <Pressable\n            style={StyleSheet.absoluteFill}\n            onPress={() => closeMenu()}\n            accessibilityRole=\"button\"\n            accessibilityLabel=\"Close menu\"\n          />\n          <Animated.View\n            style={[\n              styles.panel,\n              {\n                left: menuLeft,\n                top: menu ? menu.y + menu.h + 8 : 0,\n                opacity: menu ? undefined : 0,\n                width: MENU_W,\n                backgroundColor: colors.surfaceRaised,\n                borderColor: colors.border,\n                borderRadius: radius.lg,\n                boxShadow: shadow.lg,\n                transformOrigin: 'right top',\n              },\n              panel,\n            ]}\n          >\n            {options.map((o) => {\n              const chosen = o.value === current.value;\n              return (\n                <Pressable\n                  key={o.value}\n                  onPress={() =>\n                    closeMenu(() => {\n                      if (chosen) return;\n                      haptic('tick');\n                      onValueChange(o.value);\n                    })\n                  }\n                  accessibilityRole=\"menuitem\"\n                  accessibilityLabel={o.description ? `${o.label}, ${o.description}` : o.label}\n                  accessibilityState={{ selected: chosen }}\n                  style={({ pressed }) => [\n                    styles.option,\n                    {\n                      borderRadius: radius.md,\n                      backgroundColor: pressed ? colors.surfaceSunken : undefined,\n                    },\n                  ]}\n                >\n                  <View\n                    style={[styles.check, { borderColor: chosen ? colors.azure : 'transparent' }]}\n                  />\n                  <View style={{ flex: 1, gap: 2 }}>\n                    <Text\n                      style={{\n                        color: colors.text,\n                        fontSize: font.size.md,\n                        fontWeight: font.weight.medium,\n                      }}\n                    >\n                      {o.label}\n                    </Text>\n                    {o.description ? (\n                      <Text style={{ color: colors.textMuted, fontSize: font.size.sm }}>\n                        {o.description}\n                      </Text>\n                    ) : null}\n                  </View>\n                </Pressable>\n              );\n            })}\n          </Animated.View>\n        </View>\n      </Modal>\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  root: { alignSelf: 'flex-start' },\n  // Wide enough that no label wraps while it is measured.\n  measure: {\n    position: 'absolute',\n    opacity: 0,\n    top: 0,\n    left: 0,\n    width: 1000,\n    alignItems: 'flex-start',\n  },\n  pill: { flexDirection: 'row', alignItems: 'center', height: HEIGHT, overflow: 'hidden' },\n  main: { height: HEIGHT, minWidth: 80, justifyContent: 'center' },\n  layer: { ...StyleSheet.absoluteFill, alignItems: 'center', justifyContent: 'center' },\n  divider: { width: StyleSheet.hairlineWidth * 2, height: 22 },\n  more: {\n    width: CHEVRON_W,\n    height: Math.max(HEIGHT, minTouchTarget),\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  chevron: { width: 8, height: 8, borderRightWidth: 2, borderBottomWidth: 2 },\n  panel: { position: 'absolute', padding: 6, borderWidth: StyleSheet.hairlineWidth },\n  option: { flexDirection: 'row', alignItems: 'center', gap: 10, padding: 10, minHeight: 52 },\n  // A tick drawn from two borders, shown only beside the chosen option.\n  check: {\n    width: 7,\n    height: 13,\n    marginHorizontal: 4,\n    marginTop: -4,\n    borderBottomWidth: 2,\n    borderRightWidth: 2,\n    transform: [{ rotate: '45deg' }],\n  },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "interaction",
    "web": "live",
    "perf": {
      "budget": "Plain views; labels are measured once. The menu is a modal mounted only while open. Nothing runs at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-13",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 21,
          "baselineMs": 20,
          "jankyPercent": 2.58,
          "atRest": "idle",
          "memoryMb": 140
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The label and width change at once, and the menu appears in place.",
      "screenReader": "Two buttons: the action, named by the current label, and More options with an expanded state. Menu items read their description and mark the current one as selected.",
      "touchTarget": "Both halves are 48 pt tall; the chevron half is 48 pt wide."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { SplitButton } from '@/components/kinetik/split-button';\n\n<SplitButton\n  options={[\n    { value: 'merge', label: 'Merge', description: 'Keep every commit' },\n    { value: 'squash', label: 'Squash and merge', description: 'One commit on main' },\n  ]}\n  value={method}\n  onValueChange={setMethod}\n  onPress={(m) => merge(m)}\n/>;\n```\n\nThe main half runs `onPress` with the chosen value. Picking another option in the menu only changes the choice; people press the button to run it, so a pick in the menu never acts by surprise.\n\n## When to use\n\n- One default action with two to five close variants: publish now or schedule, merge methods, export formats.\n- Actions where people tend to stick with their last choice. Persist `value` to remember it.\n\n## When not to use\n\n- Unrelated actions. Use Pop Menu.\n- Two options of equal weight. Use two buttons.\n\n## Notes\n\n- Every label is measured once, out of sight, so the button springs straight to the right width.\n- The menu opens in a transparent modal under the button's right edge and stays 12 pt inside the window.\n- With reduced motion the label and width change at once.\n"
  },
  "docs": "Prefer `npx kinetik-ui add split-button`: it installs dependencies with expo install, so versions match your Expo SDK."
}
