{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "password-meter",
  "type": "registry:item",
  "title": "Password Meter",
  "description": "A new-password field whose strength meter fills segment by segment while each rule below ticks off.",
  "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"
  ],
  "files": [
    {
      "path": "src/components/kinetik/password-meter.tsx",
      "type": "registry:file",
      "target": "~/components/kinetik/password-meter.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 TextInputProps,\n  type ViewStyle,\n} from 'react-native';\nimport Animated, {\n  interpolateColor,\n  useAnimatedStyle,\n  useSharedValue,\n  withSpring,\n  type SharedValue,\n} from 'react-native-reanimated';\n\nimport { useReduceMotion } from '../../lib/kinetik/hooks/use-reduce-motion';\nimport { spring } from '../../lib/kinetik/motion/motion';\nimport { useKinetikTheme } from '../../lib/kinetik/tokens/theme';\nimport { minTouchTarget } from '../../lib/kinetik/tokens/tokens';\n\nexport type PasswordRule = { label: string; test: (password: string) => boolean };\n\nexport const defaultPasswordRules: readonly PasswordRule[] = [\n  { label: 'At least 8 characters', test: (p) => p.length >= 8 },\n  { label: 'Upper and lower case', test: (p) => /[a-z]/.test(p) && /[A-Z]/.test(p) },\n  { label: 'A number', test: (p) => /\\d/.test(p) },\n  { label: 'A symbol', test: (p) => /[^A-Za-z0-9]/.test(p) },\n];\n\n/** Strength from 0 to 4: the share of rules a password meets, scaled to the four segments. */\nexport function passwordStrength(\n  password: string,\n  rules: readonly PasswordRule[] = defaultPasswordRules,\n): number {\n  if (!password || rules.length === 0) return 0;\n  const met = rules.filter((r) => r.test(password)).length;\n  return Math.round((met / rules.length) * 4);\n}\n\nconst WORDS = ['Too short', 'Weak', 'Fair', 'Good', 'Strong'] as const;\n\nexport type PasswordMeterProps = {\n  value: string;\n  onChangeText: (value: string) => void;\n  /** Shown above the field and names it. Defaults to 'Password'. */\n  label?: string;\n  placeholder?: string;\n  /** What a strong password needs. Defaults to length, mixed case, a number and a symbol. */\n  rules?: readonly PasswordRule[];\n  /** List the rules under the meter, each ticking off as it is met. Defaults to true. */\n  showRules?: boolean;\n  /** Passed to the text input, e.g. `onSubmitEditing` or `returnKeyType`. */\n  inputProps?: Omit<TextInputProps, 'value' | 'onChangeText' | 'secureTextEntry' | 'style'>;\n  testID?: string;\n  style?: StyleProp<ViewStyle>;\n};\n\n/**\n * A new-password field with a strength meter. Four segments fill one after\n * another as the password gets stronger, the colour warms from red to green,\n * and each rule below ticks off the moment it is met.\n */\nexport function PasswordMeter({\n  value,\n  onChangeText,\n  label = 'Password',\n  placeholder,\n  rules = defaultPasswordRules,\n  showRules = true,\n  inputProps,\n  testID,\n  style,\n}: PasswordMeterProps) {\n  const { colors, font, space, radius } = useKinetikTheme();\n  const reduced = useReduceMotion();\n  const [visible, setVisible] = useState(false);\n  const [focused, setFocused] = useState(false);\n  const score = passwordStrength(value, rules);\n  const word = value ? WORDS[score] : '';\n\n  const level = useSharedValue(score);\n  const focus = useSharedValue(0);\n  useEffect(() => {\n    level.set(withSpring(score, spring('smooth', reduced)));\n  }, [score, reduced, level]);\n  useEffect(() => {\n    focus.set(withSpring(focused ? 1 : 0, spring('snappy', reduced)));\n  }, [focused, reduced, focus]);\n\n  // Speak the strength when it changes, not on every keystroke.\n  const spoken = useRef('');\n  useEffect(() => {\n    if (!word || word === spoken.current) return;\n    spoken.current = word;\n    AccessibilityInfo.announceForAccessibility(`Password strength: ${word}`);\n  }, [word]);\n\n  const ramp = [colors.danger, colors.danger, colors.warning, colors.azure, colors.success];\n  const field = useAnimatedStyle(() => ({\n    borderColor: interpolateColor(focus.get(), [0, 1], [colors.border, colors.azure]),\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      <Animated.View\n        style={[\n          styles.field,\n          { backgroundColor: colors.surface, borderRadius: radius.md, paddingLeft: space[4] },\n          field,\n        ]}\n      >\n        <TextInput\n          {...inputProps}\n          value={value}\n          onChangeText={onChangeText}\n          secureTextEntry={!visible}\n          placeholder={placeholder}\n          placeholderTextColor={colors.textSubtle}\n          autoCapitalize=\"none\"\n          autoCorrect={false}\n          autoComplete=\"new-password\"\n          textContentType=\"newPassword\"\n          onFocus={(e) => {\n            setFocused(true);\n            inputProps?.onFocus?.(e);\n          }}\n          onBlur={(e) => {\n            setFocused(false);\n            inputProps?.onBlur?.(e);\n          }}\n          accessibilityLabel={label}\n          selectionColor={colors.azure}\n          style={[styles.input, { color: colors.text, fontSize: font.size.md }]}\n        />\n        <Pressable\n          onPress={() => setVisible((v) => !v)}\n          accessibilityRole=\"button\"\n          accessibilityLabel={visible ? 'Hide password' : 'Show password'}\n          style={({ pressed }) => [\n            styles.reveal,\n            { paddingHorizontal: space[4], opacity: pressed ? 0.6 : 1 },\n          ]}\n        >\n          <Text\n            style={{\n              color: colors.azure,\n              fontSize: font.size.sm,\n              fontWeight: font.weight.semibold,\n            }}\n          >\n            {visible ? 'Hide' : 'Show'}\n          </Text>\n        </Pressable>\n      </Animated.View>\n\n      <View style={styles.meterRow}>\n        <View style={[styles.meter, { gap: 4 }]}>\n          {[0, 1, 2, 3].map((i) => (\n            <Segment\n              key={i}\n              index={i}\n              level={level}\n              ramp={ramp}\n              track={colors.track}\n              radius={radius.pill}\n            />\n          ))}\n        </View>\n        <Text\n          accessibilityLiveRegion=\"polite\"\n          style={[\n            styles.word,\n            {\n              color: value ? ramp[score] : colors.textSubtle,\n              fontSize: font.size.xs,\n              fontWeight: font.weight.semibold,\n            },\n          ]}\n        >\n          {word}\n        </Text>\n      </View>\n\n      {showRules ? (\n        <View style={{ gap: 6, marginTop: space[1] }}>\n          {rules.map((rule) => (\n            <Rule key={rule.label} label={rule.label} met={rule.test(value)} reduced={reduced} />\n          ))}\n        </View>\n      ) : null}\n    </View>\n  );\n}\n\nfunction Segment({\n  index,\n  level,\n  ramp,\n  track,\n  radius,\n}: {\n  index: number;\n  level: SharedValue<number>;\n  ramp: string[];\n  track: string;\n  radius: number;\n}) {\n  const fill = useAnimatedStyle(() => {\n    const l = level.get();\n    return {\n      width: `${Math.max(0, Math.min(1, l - index)) * 100}%`,\n      // The whole meter shares one colour, set by the overall strength.\n      backgroundColor: interpolateColor(l, [0, 1, 2, 3, 4], ramp),\n    };\n  });\n  return (\n    <View style={[styles.segment, { backgroundColor: track, borderRadius: radius }]}>\n      <Animated.View style={[styles.segmentFill, { borderRadius: radius }, fill]} />\n    </View>\n  );\n}\n\nfunction Rule({ label, met, reduced }: { label: string; met: boolean; reduced: boolean }) {\n  const { colors, font } = useKinetikTheme();\n  const on = useSharedValue(met ? 1 : 0);\n  useEffect(() => {\n    on.set(withSpring(met ? 1 : 0, spring('bouncy', reduced)));\n  }, [met, reduced, on]);\n\n  const dot = useAnimatedStyle(() => ({\n    backgroundColor: interpolateColor(on.get(), [0, 1], [colors.track, colors.success]),\n    transform: [{ scale: 1 + Math.sin(Math.max(0, Math.min(1, on.get())) * Math.PI) * 0.25 }],\n  }));\n  const tick = useAnimatedStyle(() => ({\n    opacity: on.get(),\n    transform: [{ rotate: '45deg' }, { scale: Math.max(0, on.get()) }],\n  }));\n  const text = useAnimatedStyle(() => ({\n    color: interpolateColor(on.get(), [0, 1], [colors.textMuted, colors.text]),\n  }));\n\n  return (\n    <View\n      accessible\n      accessibilityLabel={`${label}: ${met ? 'met' : 'not met'}`}\n      style={styles.rule}\n    >\n      <Animated.View style={[styles.dot, dot]}>\n        <Animated.View style={[styles.tick, { borderColor: colors.onEmber }, tick]} />\n      </Animated.View>\n      <Animated.Text style={[{ fontSize: font.size.sm }, text]}>{label}</Animated.Text>\n    </View>\n  );\n}\n\nconst styles = StyleSheet.create({\n  field: {\n    flexDirection: 'row',\n    alignItems: 'center',\n    borderWidth: 1.5,\n    minHeight: 52,\n  },\n  input: { flex: 1, paddingVertical: 12 },\n  reveal: { minHeight: minTouchTarget, justifyContent: 'center' },\n  meterRow: { flexDirection: 'row', alignItems: 'center', gap: 12 },\n  meter: { flex: 1, flexDirection: 'row' },\n  segment: { flex: 1, height: 4, overflow: 'hidden' },\n  segmentFill: { height: '100%' },\n  word: { minWidth: 64, textAlign: 'right' },\n  rule: { flexDirection: 'row', alignItems: 'center', gap: 10 },\n  dot: { width: 16, height: 16, borderRadius: 8, alignItems: 'center', justifyContent: 'center' },\n  tick: { width: 4, height: 8, marginTop: -2, borderBottomWidth: 1.5, borderRightWidth: 1.5 },\n});\n"
    }
  ],
  "meta": {
    "version": "1.0.0",
    "kind": "component",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "category": "input",
    "web": "live",
    "perf": {
      "budget": "One shared value for the meter and one per rule, changed on keystrokes only. 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.88,
          "atRest": "idle",
          "memoryMb": 144
        }
      ]
    },
    "a11y": {
      "reducedMotion": "The meter and the rule ticks change at once, without filling or popping.",
      "screenReader": "A secure text field named by its label, a Show password / Hide password button, and each rule read as met or not met. Changes in strength are announced.",
      "touchTarget": "The field is 52 pt tall; the reveal button is at least 44 pt."
    },
    "requires": "React Native New Architecture (Reanimated 4)",
    "guide": "## Usage\n\n```tsx\nimport { PasswordMeter, passwordStrength } from '@/components/kinetik/password-meter';\n\n<PasswordMeter value={password} onChangeText={setPassword} placeholder=\"At least 8 characters\" />;\n\nconst canContinue = passwordStrength(password) >= 3;\n```\n\n`passwordStrength` gives the same 0 to 4 score the meter shows, so a form can require Good or better before it continues.\n\n## When to use\n\n- Creating or changing a password: sign up, reset, account settings.\n- Anywhere a password policy should be visible while typing rather than after a failed submit.\n\n## When not to use\n\n- Signing in. Strength does not matter there; use a plain password field.\n- As your only check. Validate on the server too, and consider a breached-password list.\n\n## Notes\n\n- `rules` replaces the default four rules (length, mixed case, a number, a symbol). The score is the share of rules met, scaled to the four segments.\n- The meter takes one colour for the overall strength, red through amber and blue to green.\n- The field sets `textContentType=\"newPassword\"` and `autoComplete=\"new-password\"`, so password managers offer to generate one. Pass more input props through `inputProps`.\n- A change of strength is announced, but not every keystroke.\n- With reduced motion the meter and ticks change at once.\n"
  },
  "docs": "Prefer `npx kinetik-ui add password-meter`: it installs dependencies with expo install, so versions match your Expo SDK."
}
