{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "morph-select",
  "type": "registry:item",
  "title": "Morph Select",
  "description": "A select whose field stretches open into its list; a highlight glides to your pick as it folds back.",
  "categories": [
    "input"
  ],
  "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/morph-select.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/morph-select.tsx",
      "content": "import { useEffect, useRef, useState } from 'react';\nimport {\n  Modal,\n  Pressable,\n  ScrollView,\n  StyleSheet,\n  Text,\n  View,\n  useWindowDimensions,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\nimport Animated, {\n  interpolate,\n  useAnimatedStyle,\n  useSharedValue,\n  withDelay,\n  withSpring,\n  withTiming,\n  type SharedValue,\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';\n\nexport type MorphSelectOption = {\n  value: string;\n  label: string;\n  /** A second line in the list, e.g. a time zone offset. */\n  description?: string;\n  disabled?: boolean;\n};\n\nexport type MorphSelectProps = {\n  options: readonly MorphSelectOption[];\n  value: string | null;\n  onValueChange: (value: string) => void;\n  /** Shown above the trigger and used as its accessible name. */\n  label: string;\n  /** Shown in the trigger while nothing is chosen. Defaults to \"Choose\". */\n  placeholder?: string;\n  /** Rows shown before the list scrolls. Defaults to 6. */\n  maxVisible?: number;\n  /** A tick on open and on choosing. Defaults to true. */\n  haptics?: boolean;\n  testID?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst TRIGGER = 52;\nconst ROW = 48;\nconst PAD = 6;\nconst MARGIN = 12;\n\ntype Rect = { x: number; y: number; width: number; height: number };\n\n/**\n * A select whose trigger grows into its list. The field stretches open in\n * place, the options slide in under it one after another, and a highlight\n * glides to the one you pick before the list folds back into the field.\n */\nexport function MorphSelect({\n  options,\n  value,\n  onValueChange,\n  label,\n  placeholder = 'Choose',\n  maxVisible = 6,\n  haptics = true,\n  testID,\n  style,\n}: MorphSelectProps) {\n  const { colors, font, radius, space, shadow } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const window = useWindowDimensions();\n  const trigger = useRef<View>(null);\n  const [visible, setVisible] = useState(false);\n  const [anchor, setAnchor] = useState<Rect | null>(null);\n  const t = useSharedValue(0);\n  const index = options.findIndex((o) => o.value === value);\n  const highlight = useSharedValue(Math.max(0, index));\n  const selected = index >= 0 ? options[index] : undefined;\n\n  const rows = Math.min(options.length, maxVisible);\n  const listH = rows * ROW + PAD * 2;\n  const rect = anchor ?? { x: MARGIN, y: 120, width: window.width - MARGIN * 2, height: TRIGGER };\n  const room = window.height - (rect.y + rect.height) - MARGIN;\n  const down = room >= listH || rect.y < window.height / 2;\n  const fullH = rect.height + Math.min(listH, Math.max(ROW * 2, down ? room : rect.y - MARGIN));\n\n  const open = () => {\n    highlight.set(Math.max(0, index));\n    setAnchor(null);\n    setVisible(true);\n    haptic('tick');\n    trigger.current?.measureInWindow((x, y, width, height) => setAnchor({ x, y, width, height }));\n  };\n\n  useEffect(() => {\n    if (!visible || !anchor) return;\n    t.set(0);\n    t.set(reduced ? 1 : withSpring(1, spring('smooth')));\n  }, [visible, anchor, reduced, t]);\n\n  const close = (chosen?: string) => {\n    const done = () => {\n      setVisible(false);\n      if (chosen !== undefined) onValueChange(chosen);\n    };\n    if (reduced) {\n      t.set(0);\n      done();\n      return;\n    }\n    // A chosen row holds its highlight for a beat before the list folds away.\n    const wait = chosen === undefined ? 0 : 140;\n    t.set(\n      withDelay(\n        wait,\n        withTiming(0, { duration: durations.base, easing: easings.exit }, (finished) => {\n          if (finished) scheduleOnRN(done);\n        }),\n      ),\n    );\n  };\n\n  const choose = (i: number) => {\n    const option = options[i];\n    if (!option || option.disabled) return;\n    haptic('tick');\n    highlight.set(reduced ? i : withSpring(i, spring('snappy')));\n    close(option.value);\n  };\n\n  const panel = useAnimatedStyle(() => {\n    const h = interpolate(t.get(), [0, 1], [rect.height, fullH]);\n    return {\n      height: h,\n      top: down ? rect.y : rect.y + rect.height - h,\n      opacity: anchor ? 1 : 0,\n    };\n  });\n  const scrim = useAnimatedStyle(() => ({ opacity: t.get() * 0.6 }));\n  const chevron = useAnimatedStyle(() => ({\n    transform: [{ rotate: `${t.get() * 180}deg` }],\n  }));\n  const pill = useAnimatedStyle(() => ({ transform: [{ translateY: highlight.get() * ROW }] }));\n\n  const shown = selected?.label ?? placeholder;\n  const field = (\n    <View style={[styles.fieldRow, { paddingHorizontal: space[4] }]}>\n      <Text\n        numberOfLines={1}\n        style={[\n          styles.grow,\n          { color: selected ? colors.text : colors.textSubtle, fontSize: font.size.md },\n        ]}\n      >\n        {shown}\n      </Text>\n      <Animated.View style={visible ? chevron : undefined}>\n        <Chevron color={colors.textMuted} />\n      </Animated.View>\n    </View>\n  );\n\n  return (\n    <View testID={testID} style={[{ gap: space[2] }, style]}>\n      <Text style={{ color: colors.text, fontSize: font.size.sm, fontWeight: font.weight.medium }}>\n        {label}\n      </Text>\n      <Pressable\n        ref={trigger}\n        onPress={open}\n        accessibilityRole=\"button\"\n        accessibilityLabel={`${label}, ${shown}`}\n        accessibilityState={{ expanded: visible }}\n        style={({ pressed }) => [\n          styles.trigger,\n          {\n            backgroundColor: pressed ? colors.surfaceSunken : colors.surface,\n            borderColor: colors.borderStrong,\n            borderRadius: radius.md,\n            opacity: visible && anchor ? 0 : 1,\n          },\n        ]}\n      >\n        {field}\n      </Pressable>\n\n      <Modal\n        visible={visible}\n        transparent\n        animationType=\"none\"\n        onRequestClose={() => close()}\n        statusBarTranslucent\n        navigationBarTranslucent\n      >\n        <View style={StyleSheet.absoluteFill} onAccessibilityEscape={() => close()}>\n          <Animated.View\n            style={[StyleSheet.absoluteFill, { backgroundColor: colors.scrim }, scrim]}\n          >\n            <Pressable\n              style={StyleSheet.absoluteFill}\n              onPress={() => close()}\n              accessibilityRole=\"button\"\n              accessibilityLabel=\"Close list\"\n            />\n          </Animated.View>\n          <Animated.View\n            accessibilityRole=\"list\"\n            style={[\n              styles.panel,\n              {\n                left: rect.x,\n                width: rect.width,\n                backgroundColor: colors.surfaceRaised,\n                borderColor: colors.borderStrong,\n                borderRadius: radius.md,\n                boxShadow: shadow.lg,\n                flexDirection: down ? 'column' : 'column-reverse',\n              },\n              panel,\n            ]}\n          >\n            <Pressable\n              onPress={() => close()}\n              accessibilityRole=\"button\"\n              accessibilityLabel={`${label}, ${shown}`}\n              accessibilityState={{ expanded: true }}\n              style={styles.header}\n            >\n              {field}\n            </Pressable>\n            <View style={[styles.divider, { backgroundColor: colors.border }]} />\n            <ScrollView\n              style={styles.grow}\n              contentContainerStyle={{ padding: PAD }}\n              scrollEnabled={options.length > maxVisible}\n              showsVerticalScrollIndicator={false}\n            >\n              <Animated.View\n                pointerEvents=\"none\"\n                style={[\n                  styles.pill,\n                  { top: PAD, left: PAD, right: PAD, backgroundColor: colors.azureSoft },\n                  { borderRadius: radius.sm, opacity: index >= 0 ? 1 : 0 },\n                  pill,\n                ]}\n              />\n              {options.map((option, i) => (\n                <Row\n                  key={option.value}\n                  option={option}\n                  index={i}\n                  selected={i === index}\n                  t={t}\n                  onPress={() => choose(i)}\n                />\n              ))}\n            </ScrollView>\n          </Animated.View>\n        </View>\n      </Modal>\n    </View>\n  );\n}\n\ntype RowProps = {\n  option: MorphSelectOption;\n  index: number;\n  selected: boolean;\n  t: SharedValue<number>;\n  onPress: () => void;\n};\n\nfunction Row({ option, index, selected, t, onPress }: RowProps) {\n  const { colors, font, space } = useKinetikTheme();\n  // Rows arrive one after another as the panel opens.\n  const motion = useAnimatedStyle(() => {\n    const start = Math.min(0.5, 0.15 + index * 0.06);\n    const p = interpolate(t.get(), [start, start + 0.45], [0, 1], 'clamp');\n    return { opacity: p, transform: [{ translateY: (1 - p) * -8 }] };\n  });\n  return (\n    <Animated.View style={motion}>\n      <Pressable\n        onPress={onPress}\n        disabled={option.disabled}\n        accessibilityRole=\"menuitem\"\n        accessibilityLabel={[option.label, option.description].filter(Boolean).join(', ')}\n        accessibilityState={{ selected, disabled: option.disabled }}\n        style={[styles.row, { paddingHorizontal: space[3], opacity: option.disabled ? 0.4 : 1 }]}\n      >\n        <View style={styles.grow}>\n          <Text\n            numberOfLines={1}\n            style={{\n              color: selected ? colors.azure : colors.text,\n              fontSize: font.size.md,\n              fontWeight: selected ? font.weight.semibold : font.weight.regular,\n            }}\n          >\n            {option.label}\n          </Text>\n          {option.description ? (\n            <Text numberOfLines={1} style={{ color: colors.textSubtle, fontSize: font.size.xs }}>\n              {option.description}\n            </Text>\n          ) : null}\n        </View>\n        {selected ? <Tick color={colors.azure} /> : null}\n      </Pressable>\n    </Animated.View>\n  );\n}\n\nfunction Chevron({ color }: { color: string }) {\n  return (\n    <View style={styles.icon}>\n      <View style={[styles.stroke, { backgroundColor: color }, styles.chevronL]} />\n      <View style={[styles.stroke, { backgroundColor: color }, styles.chevronR]} />\n    </View>\n  );\n}\n\nfunction Tick({ color }: { color: string }) {\n  return (\n    <View style={styles.icon}>\n      <View style={[styles.stroke, { backgroundColor: color }, styles.tickShort]} />\n      <View style={[styles.stroke, { backgroundColor: color }, styles.tickLong]} />\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  trigger: { height: TRIGGER, borderWidth: 1, justifyContent: 'center' },\n  header: { height: TRIGGER - 2, justifyContent: 'center' },\n  fieldRow: { flexDirection: 'row', alignItems: 'center', gap: 8, height: TRIGGER - 2 },\n  grow: { flex: 1 },\n  panel: { position: 'absolute', borderWidth: 1, overflow: 'hidden' },\n  divider: { height: StyleSheet.hairlineWidth },\n  pill: { position: 'absolute', height: ROW },\n  row: { height: ROW, flexDirection: 'row', alignItems: 'center', gap: 8 },\n  icon: { width: 16, height: 16, alignItems: 'center', justifyContent: 'center' },\n  stroke: { position: 'absolute', height: 1.8, borderRadius: 1 },\n  chevronL: { width: 7, left: 2.6, top: 8, transform: [{ rotate: '40deg' }] },\n  chevronR: { width: 7, right: 2.6, top: 8, transform: [{ rotate: '-40deg' }] },\n  tickShort: { width: 5.5, left: 2.2, top: 9, transform: [{ rotate: '45deg' }] },\n  tickLong: { width: 10, left: 4.6, top: 7.4, transform: [{ rotate: '-50deg' }] },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "input",
    "web": "live",
    "perf": {
      "budget": "A modal of plain views: the panel height and every row read one shared value, and one more moves the highlight. Nothing runs at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-13",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 29,
          "baselineMs": 18,
          "jankyPercent": 5.6,
          "atRest": "idle",
          "memoryMb": 154,
          "notes": "p99 spikes are the first frame of the modal window opening."
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The list opens and closes at once and the highlight jumps.",
      "screenReader": "A button that reads the label and the current choice and says whether it is expanded; options are menu items with a selected state.",
      "touchTarget": "The field is 52 pt tall and each option 48 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { MorphSelect } from '@/components/kinetik/morph-select';\n\n<MorphSelect\n  label=\"Time zone\"\n  options={[\n    { value: 'lis', label: 'Lisbon', description: 'UTC+0' },\n    { value: 'ist', label: 'Istanbul', description: 'UTC+3' },\n  ]}\n  value={zone}\n  onValueChange={setZone}\n/>;\n```\n\n## When to use\n\n- One choice from a list of about four to twenty options in a form: a country, a time zone, a size.\n- Places where the options need a second line of detail.\n\n## When not to use\n\n- Two to five options people should compare at a glance. Use Choice Cards or a segmented control.\n- Long lists that need search. Use a searchable picker screen.\n\n## Notes\n\n- The trigger is measured and the panel grows out of it in its own modal, so it floats above everything and Back or a tap outside closes it.\n- The panel opens upwards when there is no room below.\n- Past `maxVisible` rows the list scrolls. Disabled options stay visible but cannot be chosen.\n- With reduced motion the list opens and closes at once.\n"
  },
  "docs": "Prefer `npx kinetik-ui add morph-select`: it installs dependencies with expo install, so versions match your Expo SDK."
}
