{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tag-field",
  "type": "registry:item",
  "title": "Tag Field",
  "description": "Typed words that pop into tags while the rest make room; a duplicate makes the existing tag jump instead.",
  "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/tag-field.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/tag-field.tsx",
      "content": "import { useEffect, useRef, useState } from 'react';\nimport {\n  AccessibilityInfo,\n  Pressable,\n  StyleSheet,\n  Text,\n  TextInput,\n  View,\n  type StyleProp,\n  type ViewStyle,\n} from 'react-native';\nimport Animated, {\n  LinearTransition,\n  ZoomIn,\n  ZoomOut,\n  useAnimatedStyle,\n  useSharedValue,\n  withSequence,\n  withSpring,\n  withTiming,\n} from 'react-native-reanimated';\n\nimport { useHaptic } from '../../lib/kinetik/hooks/use-haptic';\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { durations, easings, spring, timing } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { minTouchTarget } from '../../lib/kinetik/tokens/tokens';\n\nexport type TagFieldProps = {\n  value: readonly string[];\n  onChange: (tags: string[]) => void;\n  /** Shown above the field and used as the input's accessible name. */\n  label: string;\n  placeholder?: string;\n  /** Characters that end a tag as they are typed. Return always does. Defaults to [\",\"]. */\n  separators?: readonly string[];\n  /** No more tags can be added past this. */\n  maxTags?: number;\n  /** Return false to refuse a tag; the field shakes. */\n  validate?: (tag: string) => boolean;\n  /** Ticks as tags are added and removed. Defaults to true. */\n  haptics?: boolean;\n  testID?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\nconst TAG_H = 32;\n\n// Predefined animations with duration modifiers only, so they also run on the web.\nconst enter = ZoomIn.duration(durations.base).easing(easings.standard);\nconst leave = ZoomOut.duration(durations.quick).easing(easings.exit);\nconst reflow = LinearTransition.duration(durations.base).easing(easings.standard);\n\n/**\n * Typed words that turn into tags. A tag pops in when Return or a comma ends\n * it, the others make room on a spring, and Backspace in the empty field\n * marks the last tag before removing it. A duplicate makes the existing tag\n * jump instead of adding another.\n */\nexport function TagField({\n  value,\n  onChange,\n  label,\n  placeholder = 'Add a tag',\n  separators = [','],\n  maxTags,\n  validate,\n  haptics = true,\n  testID,\n  style,\n}: TagFieldProps) {\n  const { colors, font, radius, space } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const haptic = useHaptic(haptics);\n  const input = useRef<TextInput>(null);\n  const [draft, setDraft] = useState('');\n  const [armed, setArmed] = useState(false);\n  const [pulse, setPulse] = useState({ tag: '', n: 0 });\n  const [focused, setFocused] = useState(false);\n  const full = maxTags !== undefined && value.length >= maxTags;\n\n  const shake = useSharedValue(0);\n  const ring = useSharedValue(0);\n  useEffect(() => {\n    ring.set(withTiming(focused ? 1 : 0, timing('quick', reduced)));\n  }, [focused, reduced, ring]);\n\n  const refuse = () => {\n    haptic('warning');\n    if (reduced) return;\n    const step = { duration: 45, easing: easings.inOut };\n    shake.set(\n      withSequence(\n        withTiming(-5, step),\n        withTiming(5, step),\n        withTiming(-3, step),\n        withSpring(0, spring('snappy')),\n      ),\n    );\n  };\n\n  const add = (raw: string): boolean => {\n    const tag = raw.trim();\n    if (!tag) return true;\n    const existing = value.find((t) => t.toLowerCase() === tag.toLowerCase());\n    if (existing) {\n      setPulse((p) => ({ tag: existing, n: p.n + 1 }));\n      haptic('tick');\n      return true;\n    }\n    if (full || (validate && !validate(tag))) {\n      refuse();\n      return false;\n    }\n    haptic('tick');\n    onChange([...value, tag]);\n    AccessibilityInfo.announceForAccessibility(`${tag} added`);\n    return true;\n  };\n\n  const remove = (tag: string) => {\n    haptic('tick');\n    setArmed(false);\n    onChange(value.filter((t) => t !== tag));\n    AccessibilityInfo.announceForAccessibility(`${tag} removed`);\n  };\n\n  const type = (text: string) => {\n    setArmed(false);\n    const cut = separators.find((s) => s && text.includes(s));\n    if (!cut) {\n      setDraft(text);\n      return;\n    }\n    const parts = text.split(cut);\n    const rest = parts.pop() ?? '';\n    const ok = parts.every((p) => add(p));\n    setDraft(ok ? rest : text.replace(cut, ''));\n  };\n\n  const shell = useAnimatedStyle(() => ({ transform: [{ translateX: shake.get() }] }));\n  const outline = useAnimatedStyle(() => ({ opacity: ring.get() }));\n  const last = value[value.length - 1];\n\n  return (\n    <View testID={testID} style={[{ gap: space[2] }, style]}>\n      <View style={styles.header}>\n        <Text\n          style={{ color: colors.text, fontSize: font.size.sm, fontWeight: font.weight.medium }}\n        >\n          {label}\n        </Text>\n        {maxTags !== undefined ? (\n          <Text\n            style={{\n              color: full ? colors.warning : colors.textSubtle,\n              fontSize: font.size.xs,\n              fontVariant: ['tabular-nums'],\n            }}\n          >\n            {value.length}/{maxTags}\n          </Text>\n        ) : null}\n      </View>\n      <Animated.View\n        style={[\n          styles.field,\n          {\n            backgroundColor: colors.surface,\n            borderColor: colors.borderStrong,\n            borderRadius: radius.md,\n            padding: space[2],\n          },\n          shell,\n        ]}\n      >\n        <Animated.View\n          pointerEvents=\"none\"\n          style={[styles.ring, { borderColor: colors.azure, borderRadius: radius.md + 1 }, outline]}\n        />\n        {value.map((tag) => (\n          <Animated.View\n            key={tag}\n            entering={reduced ? undefined : enter}\n            exiting={reduced ? undefined : leave}\n            layout={reduced ? undefined : reflow}\n            style={styles.slot}\n          >\n            <Tag\n              tag={tag}\n              armed={armed && tag === last}\n              pulse={pulse.tag === tag ? pulse.n : 0}\n              reduced={reduced}\n              onRemove={() => remove(tag)}\n            />\n          </Animated.View>\n        ))}\n        <Animated.View layout={reduced ? undefined : reflow} style={styles.inputBox}>\n          <TextInput\n            ref={input}\n            value={draft}\n            onChangeText={type}\n            onSubmitEditing={() => {\n              if (add(draft)) setDraft('');\n            }}\n            submitBehavior=\"submit\"\n            onKeyPress={(e) => {\n              if (e.nativeEvent.key !== 'Backspace' || draft.length > 0 || !last) return;\n              if (armed) remove(last);\n              else {\n                haptic('tick');\n                setArmed(true);\n              }\n            }}\n            onFocus={() => setFocused(true)}\n            onBlur={() => {\n              setFocused(false);\n              setArmed(false);\n            }}\n            editable={!full}\n            accessibilityLabel={label}\n            accessibilityHint={\n              value.length > 0 ? `${value.length} tags: ${value.join(', ')}` : undefined\n            }\n            placeholder={full ? `Up to ${maxTags}` : value.length > 0 ? '' : placeholder}\n            placeholderTextColor={colors.textSubtle}\n            selectionColor={colors.azure}\n            cursorColor={colors.azure}\n            returnKeyType=\"done\"\n            autoCapitalize=\"none\"\n            style={[styles.input, { color: colors.text, fontSize: font.size.md }]}\n          />\n        </Animated.View>\n      </Animated.View>\n    </View>\n  );\n}\n\ntype TagProps = {\n  tag: string;\n  armed: boolean;\n  pulse: number;\n  reduced: boolean;\n  onRemove: () => void;\n};\n\nfunction Tag({ tag, armed, pulse, reduced, onRemove }: TagProps) {\n  const { colors, font, radius } = useKinetikTheme();\n  const scale = useSharedValue(1);\n  useEffect(() => {\n    if (pulse === 0 || reduced) return;\n    scale.set(withSequence(withTiming(1.12, { duration: 90 }), withSpring(1, spring('bouncy'))));\n  }, [pulse, reduced, scale]);\n  const motion = useAnimatedStyle(() => ({ transform: [{ scale: scale.get() }] }));\n\n  return (\n    // The row is a full 44 pt tall so the remove button can be; the pill drawn\n    // inside it is 32 pt.\n    <Animated.View style={[styles.tag, motion]}>\n      <View\n        style={[\n          styles.pill,\n          {\n            backgroundColor: armed ? colors.azureSoft : colors.surfaceRaised,\n            borderColor: armed ? colors.azure : colors.border,\n            borderRadius: radius.pill,\n          },\n        ]}\n      />\n      <Text\n        numberOfLines={1}\n        style={[styles.tagText, { color: colors.text, fontSize: font.size.sm }]}\n      >\n        {tag}\n      </Text>\n      <Pressable\n        onPress={onRemove}\n        accessibilityRole=\"button\"\n        accessibilityLabel={`Remove ${tag}`}\n        style={styles.remove}\n      >\n        {({ pressed }) => (\n          <View\n            style={[\n              styles.cross,\n              { backgroundColor: pressed ? colors.track : undefined, borderRadius: radius.pill },\n            ]}\n          >\n            <View style={[styles.bar, { backgroundColor: colors.textMuted }, styles.barA]} />\n            <View style={[styles.bar, { backgroundColor: colors.textMuted }, styles.barB]} />\n          </View>\n        )}\n      </Pressable>\n    </Animated.View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  header: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center' },\n  field: {\n    borderWidth: 1,\n    flexDirection: 'row',\n    flexWrap: 'wrap',\n    alignItems: 'center',\n    gap: 6,\n    minHeight: 52,\n  },\n  ring: { position: 'absolute', top: -1, left: -1, right: -1, bottom: -1, borderWidth: 2 },\n  // Each tag's slot is a full 44 pt tall (so its remove button is), but takes\n  // only the pill's 32 pt of layout; the margins live on the outermost view so\n  // nothing above clips the target.\n  slot: { marginVertical: -(minTouchTarget - TAG_H) / 2 },\n  tag: {\n    height: minTouchTarget,\n    flexDirection: 'row',\n    alignItems: 'center',\n    paddingLeft: 12,\n    maxWidth: 240,\n  },\n  pill: {\n    position: 'absolute',\n    left: 0,\n    right: 0,\n    top: (minTouchTarget - TAG_H) / 2,\n    bottom: (minTouchTarget - TAG_H) / 2,\n    borderWidth: 1,\n  },\n  tagText: { flexShrink: 1 },\n  remove: {\n    width: minTouchTarget,\n    height: minTouchTarget,\n    alignItems: 'center',\n    justifyContent: 'center',\n  },\n  cross: { width: 24, height: 24, alignItems: 'center', justifyContent: 'center' },\n  bar: { position: 'absolute', width: 10, height: 1.6, borderRadius: 1 },\n  barA: { transform: [{ rotate: '45deg' }] },\n  barB: { transform: [{ rotate: '-45deg' }] },\n  inputBox: { flexGrow: 1, minWidth: 96, marginVertical: -(minTouchTarget - TAG_H - 4) / 2 },\n  input: { minHeight: minTouchTarget, paddingVertical: 0, paddingHorizontal: 6 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "input",
    "web": "live",
    "perf": {
      "budget": "Plain views with Reanimated layout transitions, which run only when a tag is added or removed. Nothing runs at rest.",
      "measurements": [
        {
          "device": "Pixel 9 emulator, API 35",
          "kind": "emulator",
          "date": "2026-10-13",
          "build": "release",
          "frameMs": 17,
          "p90Ms": 23,
          "baselineMs": 18,
          "jankyPercent": 4.76,
          "atRest": "idle",
          "memoryMb": 137,
          "notes": "p99 spikes are the keyboard opening and closing."
        }
      ]
    },
    "a11y": {
      "reducedMotion": "Tags appear and disappear at once and the rest move without a spring.",
      "screenReader": "A text field named by its label whose hint lists the tags; each tag has a Remove button. Changes are announced.",
      "touchTarget": "Each remove button is 44 by 44 pt; the field is at least 52 pt tall."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { TagField } from '@/components/kinetik/tag-field';\n\n<TagField label=\"Topics\" value={tags} onChange={setTags} maxTags={6} />;\n```\n\n## When to use\n\n- Short free-form values people add several of: topics, skills, email recipients, labels.\n- Lists where people should see and edit everything they have added in one place.\n\n## When not to use\n\n- Choosing from a known, short list. Use Filter Chips.\n- A single value. Use Float Field.\n\n## Notes\n\n- Return or any of `separators` (a comma by default) ends a tag; pasted text with commas becomes several tags.\n- A duplicate (ignoring case) makes the existing tag jump instead of adding another; `validate` can refuse a tag, which shakes the field.\n- Backspace in the empty field first marks the last tag, then removes it. Additions and removals are announced to screen readers.\n- Each remove button is a full 44 pt square inside the 32 pt pill.\n"
  },
  "docs": "Prefer `npx kinetik-ui add tag-field`: it installs dependencies with expo install, so versions match your Expo SDK."
}
