Primitives
Animated Number Avatar Badge Button Button Group Toggle Toggle Group Checkbox Chip Countdown Divider Fab Grid Icon Image Input Search Input Textarea Label Loader Marquee Masked Input Message Bubble Notification Banner Offline Banner Progress Progress Ring Radio Group Range Slider Rating Separator Skeleton Slider Stack Stepper Switch Text Theme Toggle Ticker Typing IndicatorComposed
Accordion Achievement Badge Action Bar Action Sheet Action Swap Activity Rings Add to Cart Button Address Card Agenda List Alert Amount Keypad Animated Icons App Bar Audio Message Audio Recorder Autocomplete Avatar Group Balance Display Bar List Barcode Before After Biometric Gate Bloom Menu Bottom Sheet Paywall Sheet Side Sheet Breadcrumb Calendar Calendar Strip Card Carousel Cart Item Character Charts Chat Composer Chat List Item Choice Card Circle Reveal Coach Marks Collapsible Collapsible Header Color Picker Combobox Command Palette Comment Thread Confetti Consent Sheet Context Menu Copy Field Country Picker Coupon Input Currency Input Data Table Date Range Picker Day Schedule Dialog Dock Donut Chart Drawer Driver Card Dropdown Menu Drum Picker Emoji Picker Empty State Error State Event Card Expandable Control Fader Feature Gate File Picker Filter Bar Follow Button Form Gauge Glass Glass Cluster Glass Dock Morph Glass Fab Morph Glass Lab Glass Orb Glass Search Morph Glass Sheet Edge Gradient Button Headline New Heatmap Image Cropper Image Viewer Kanban Card Keyboard Avoiding Keyboard Toolbar Leaderboard Level Progress Lightbox Like Button Line Chart List Reorderable List Swipeable Row Location Card Location Search Map Sheet Map View Markdown View Media Controls Media Picker Media Tile Mention Input Meter Bar Mini Player Mood Slider Morphing Modal Multi Select Navigation Rail Notification Item Number Input Onboarding Pager Order Card Order Summary OTP Input Pagination Paper Clip New Parallax Header Pass Card Password Strength Payment Button Payment Card Payment Method Permission Primer Phone Input PIN Pad Polaroid New Poll Popover Post Card Postage Stamp New Price Tag Pricing Table Product Card Product Gallery Profile Header Promo Banner Prompt Input Property Card Pull To Refresh QR Code Quick Actions Quick Replies Rating Summary Reaction Picker Resend Timer Review Card Review Prompt Ride Option Save Button Scan Frame Scroll Spy Tabs Seat Map Section Header Section Index Segmented Control Select Share Button Share Sheet Shutter Button Signature Pad Slide to Confirm Slot Picker Smart Banner Social Login Button Sparkline Splash Screen Split Button Stat Card Stateful Button Status Dot Step Flow Steps Sticker New Stopwatch Stories Progress Stories Viewer Story Ring Streak Counter Streaming Text Success Seal Swipe Deck Tabs Tag Input Tape New Text Reveal Thinking Indicator Time Picker Timeline Timer Ring Tip Selector Toast Toolbar Tooltip Track Row Transaction Row Trip Progress Variant Picker Video Controls Waveform Weather Card Weekday Picker Zoom TransitionScreens
Account Switcher Biometric Setup Delete Account Forgot Password Grow Auth Login Login — Dark Stage Login — Dense Work Login — Editorial Login — Illustrated Login — Minimal Ink Login — Social Login — Video Loop Food Onboarding Onboarding Onboarding Dark Objects Onboarding Editorial Onboarding Illustrated Onboarding Personalize Onboarding Photo Carousel OTP Verification Passkey — Create Password Reset Permission — Notifications Phone Verification Onboarding Quiz Session Devices Signup Sign-up Chat Sign-up Photo Sheet Social Auth Split Auth Verify Identity Welcome AI Chat AI Assistant Channels List Chat Info Chat List Chat Media Chat Thread Create Group Group Info Message Requests New Message Kept Messages Accessibility Activity Log Appearance Authenticator Blocked Accounts Export Your Data Downloads Edit Profile Edit Profile — Rows Emergency Call Empty States Set Error State Send Feedback Device Locator Help Center Home — Bento Home — Dark Home — Editorial Home Feed Invite Friends Language & Region Linked Accounts Not Found (404) Notification Settings Notifications Password Vault Paywall Paywall — Comparison Paywall — Dark Stage Paywall — Editorial Paywall — Photo Paywall — Trial Timeline Privacy Profile Profile — Gamified Profile — Minimal Profile — Photo Hero QR Scanner Report Issue Saved Items Phone Time Search Search — Command Palette Search — Visual Account Health Settings Settings — Dark Device Settings — Search Storage & Data Terms & Privacy Dating Chat Dating Filters Profile Discover Its A Match Into You Matches Profile Detail Profile Editor Courier Matching Delivery History Delivery Support Package Schedule Parcel Tracking Proof Of Delivery Quick Aisle Quick Home Send Package Substitutions Add Payment Address Book Cart Categories Checkout Checkout — Steps Checkout Success Delivery Filters & Sort Flash Sale Gift Cards Loyalty Points Order Cancel Order Detail Orders Pay Later Checkout Payment Methods Product Detail Product Detail — Hero Product Grid Product Reviews Promo Codes Recently Viewed Return Items Search Results Shop Assistant Store Home Tip & Rate Courier Order Tracking Wishlist Write a Review Event Checkin Event Hero Events Discover My Tickets Seat Selection Ticket Checkout Add Card Bank Accounts Dashboard — Bento Bill Pay Budgets Card Details Crypto Portfolio Finance Dashboard Dashboard — Dark Exchange Currency Expense List Invoice Detail Manage Cards Plan Management Savings Goals Send Money Spending Analytics Split Bill Subscriptions Token Detail Token Swap Transactions Wallet Home Wallet Movers Courier Tracking Food Cart Food Home Food Orders Grocery List Recipe Detail Restaurant — Dark Restaurant Detail Activity Rings Fitness Home Habit Quest Habit Tracker Meal Planner Med Store Meditation Player Mood Check-in Nutrition Home Period Tracker Prior Auth Prior Auth Cases Quest Complete Run Tracking Rx Scan Sleep Tracker Telehealth Booking Walk Map Water Tracker Workout Complete Workout Detail Workout Session Applications Apply Company Interview Schedule Job Detail Job Feed Resume Saved Jobs Create Listing Item Chat Listing Detail Make Offer Market Checkout Market Home Market Search My Listings Offers Inbox Seller Profile Audiobook Player Camera Gallery Albums Game Store Mini Player Music Player Photo Editor Photo Gallery Playlist Detail Podcast Player Clips Feed Serene Home Sound Mixer Stories Video Call Video Player Article Reader Course Detail Event Detail Memory Onboarding Icon Lab Leaderboard Lesson Player Match Detail News Editorial News Home Plant Care Prediction Live Prediction Welcome Smart Home Standings Ticket Wallet Topics Follow Weather Detail Add Task Sheet Alarm Clock Calendar Day Calendar Month Doc Scanner File Manager Focus Timer Journal Kanban Board Mail Inbox Mail Thread Note Editor Notes List Reminders Task List Time Blocks Agent Profile Compare Homes Mortgage Calculator Property Detail Rental Application Saved Homes Schedule Tour Search List Search Map Complete Destination Driver Arriving Ev Charging History Home In Trip Matching Options Parking Receipt Safety Schedule Scooter Unlock Booking Confirmed Booking Review Booking Slots My Bookings Pro On The Way Provider Detail Provider List Rate Service Services Home Arc Create Arc Detail Arc Onboarding Avatar Creator Comments Sheet Create Post Explore Grid Followers List Hashtag Feed Mentions Post Detail Post Hero Social Profile Boarding Pass Booking Confirm Car Rental Trip Discover Flight Live Flight Preferences Flight Results Flight Search Hotel Detail Live Transit Trip — Map Day Trip — Rideshare Request Seat Select Travel Home Trip Itinerary Trip OnboardingNothing matches — try another word.
Password Strength
Compact password strength meter for sign-up forms. Four bars light up as the password gets stronger, and common passwords are flagged straight away.
Preview
import * as React from "react";
import { forwardRef } from "react";
import { Text, View, type ViewProps } from "react-native";
import Animated, {
Easing,
useAnimatedStyle,
useSharedValue,
withSequence,
withSpring,
withTiming,
} from "react-native-reanimated";
import { Sheen, cn, ease, spring, timing, useHaptic, useReducedMotion, useTheme } from "@lumioui/core";
const CHAR_CLASSES = [/[a-z]/, /[A-Z]/, /\d/, /[^a-zA-Z\d\s]/];
const SEQS = "abcdefghijklmnopqrstuvwxyz0123456789";
const COMMON = new Set([
"password", "passw0rd", "123456", "1234567", "12345678", "123456789",
"qwerty", "qwerty123", "letmein", "iloveyou", "admin", "welcome",
"abc123", "111111", "dragon", "monkey", "master", "sunshine",
]);
/** True when `s` holds an ascending/descending sequential run of `n`
* (abcd, 4321) — the giveaway pattern checkers penalize hardest. */
function hasSequentialRun(s: string, n: number) {
const lower = s.toLowerCase();
for (let i = 0; i + n <= lower.length; i++) {
const chunk = lower.slice(i, i + n);
if (SEQS.includes(chunk) || SEQS.includes([...chunk].reverse().join(""))) return true;
}
return false;
}
/** True for passwords on the short most-common list — the meter refuses these. */
export function isCommonPassword(password: string): boolean {
return COMMON.has(password.toLowerCase());
}
/**
* Lightweight local score 0–4 — a deterministic heuristic of length,
* character-class spread, and obvious-pattern penalties. Good enough to
* steer the meter; real entropy estimation stays on the server.
*/
export function derivePasswordScore(password: string): number {
if (!password) return 0;
if (isCommonPassword(password)) return 0;
const classes = CHAR_CLASSES.filter((re) => re.test(password)).length;
let score = 0;
if (password.length >= 8) score += 1;
if (password.length >= 12) score += 1;
if (classes >= 3) score += 1;
if (classes >= 4) score += 1;
if (password.length < 8 || /^\d+$/.test(password)) score = Math.min(score, 1);
if (/^(.)\1+$/.test(password) || hasSequentialRun(password, 4)) score = Math.min(score, 2);
return Math.max(0, Math.min(4, score));
}
/** What the password is still missing — the hint row under the meter. */
function deriveHint(password: string, score: number): string {
if (!password) return "";
if (score >= 4) return STRONG_HINT;
if (isCommonPassword(password)) return "That one is on every list. Try a phrase only you would write.";
const tips: string[] = [];
if (password.length < 12) tips.push(password.length < 8 ? "8+ characters" : "12+ characters");
if (!/[a-z]/.test(password) || !/[A-Z]/.test(password)) tips.push("upper & lower case");
if (!/\d/.test(password)) tips.push("a number");
if (!/[^a-zA-Z\d\s]/.test(password)) tips.push("a symbol");
return tips.length ? `Try ${tips.slice(0, 2).join(" · ")}` : "";
}
const DEFAULT_LABELS = ["Too weak", "Weak", "Fair", "Good", "Strong"] as const;
const STRONG_HINT = "Strong. This one would take centuries.";
/** An unlit lamp: the accent at low brightness, so the meter reads as four lights, not a track. */
const LAMP_DIM = 0.15;
/** A lamp switching on grows from this height share (scaleY). */
const LAMP_IGNITE_FROM = 0.6;
/** Flicker kick in points (§5 rule 4: one 4pt kick). */
const FLICKER_KICK = 4;
/** Label travel on a swap — up when the score rises, down when it falls. */
const LABEL_RISE = 4;
export interface PasswordStrengthProps extends Omit<ViewProps, "className"> {
/** Controlled score 0–4. Omit for uncontrolled via `defaultValue`, or
* pass `password` and the score derives itself. */
value?: number;
/** Uncontrolled initial score. */
defaultValue?: number;
/** Fires whenever the effective score changes (derived or set). */
onValueChange?: (score: number) => void;
/** Live password — derives the score with `derivePasswordScore` and
* generates the hint row. Takes precedence over value/defaultValue. */
password?: string;
/** Labels for scores 0–4. Default ["Too weak","Weak","Fair","Good","Strong"]. */
labels?: readonly string[];
/** Show the score label at the right of the meter row. Default true. */
showLabel?: boolean;
/** Custom hint under the meter — overrides the derived suggestion.
* Pass "" to hide the row entirely. */
hint?: string;
/** Extra classes on the outer container. */
className?: string;
/** Unlit lamp classes. Default: the accent at low brightness. */
trackClassName?: string;
}
/** One lamp. On = full accent; switching on ignites (opacity on timing.fast,
* scaleY 0.6→1 on spring.swap); switching off dims on timing.recede. */
function Lamp({ on, refused, trackClassName }: { on: boolean; refused: boolean; trackClassName?: string }) {
const reduce = useReducedMotion();
const lit = useSharedValue(on ? 1 : 0);
const grow = useSharedValue(1);
const first = React.useRef(true);
React.useEffect(() => {
if (first.current) {
first.current = false;
return;
}
if (on) {
lit.value = withTiming(1, { ...timing.fast, easing: Easing.bezier(...ease.out) });
if (!reduce) {
grow.value = LAMP_IGNITE_FROM;
grow.value = withSpring(1, spring.swap);
}
} else {
lit.value = withTiming(0, { ...timing.recede, easing: Easing.bezier(...ease.in) });
}
}, [on, reduce, lit, grow]);
const style = useAnimatedStyle(() => ({ opacity: lit.value, transform: [{ scaleY: grow.value }] }));
return (
<View className="h-2 flex-1 overflow-hidden rounded-full">
<View className={cn("absolute inset-0", trackClassName ?? (refused ? "bg-destructive" : "bg-primary"))} style={trackClassName ? undefined : { opacity: LAMP_DIM }} />
<Animated.View className="absolute inset-0 rounded-full bg-primary" style={style} />
</View>
);
}
/** Text that swaps in place: the old line dims, the new one ignites with
* a little travel in the direction of the change (dir 1 = rising: it
* starts 4pt low and comes up). */
function useSwap<T>(next: T, dir: 1 | -1) {
const reduce = useReducedMotion();
const [shown, setShown] = React.useState(next);
const o = useSharedValue(1);
const y = useSharedValue(0);
const s = useSharedValue(1);
React.useEffect(() => {
if (Object.is(next, shown)) return;
o.value = withTiming(0, { ...timing.recede, easing: Easing.bezier(...ease.in) });
if (!reduce) s.value = withTiming(0.96, timing.recede);
const t = setTimeout(() => {
setShown(next);
o.value = withTiming(1, { ...timing.fast, easing: Easing.bezier(...ease.out) });
if (reduce) return;
y.value = dir * LABEL_RISE;
y.value = withSpring(0, spring.swap);
s.value = withSpring(1, spring.swap);
}, timing.recede.duration);
return () => clearTimeout(t);
}, [next, shown, dir, reduce, o, y, s]);
const style = useAnimatedStyle(() => ({ opacity: o.value, transform: [{ translateY: y.value }, { scale: s.value }] }));
return [shown, style] as const;
}
/**
* PasswordStrength — the compact meter that rides under signup fields.
* Four lamps in the accent: each score crossing switches one on, a drop
* dims the top one. Colour is the "on" state in one hue — no traffic
* light. A common password flickers the row once in destructive with a
* warning haptic. The label swaps in place (rising 4pt as the score
* climbs). Reaching Strong sends one sheen across the lamps and the hint
* becomes the reward line.
* <PasswordStrength password={pw} />
* <PasswordStrength value={score} onValueChange={...} />
* Expo Go compatible.
*/
export const PasswordStrength = forwardRef<React.ElementRef<typeof View>, PasswordStrengthProps>(
function PasswordStrength(
{
value,
defaultValue,
onValueChange,
password,
labels = DEFAULT_LABELS,
showLabel = true,
hint,
className,
trackClassName,
...props
},
ref
) {
const { colors } = useTheme();
const reduce = useReducedMotion();
const haptic = useHaptic();
// A meter is read-only — nothing internal ever mutates `internal`, so
// the uncontrolled path is just defaultValue resolved during render.
const [internal] = React.useState(defaultValue ?? 0);
const score = Math.max(
0,
Math.min(4, password !== undefined ? derivePasswordScore(password) : value ?? internal)
);
const refused = password !== undefined && isCommonPassword(password);
// Direction of the last score change, resolved during render so the
// label knows which way to travel before its swap starts.
const [track, setTrack] = React.useState<{ score: number; dir: 1 | -1 }>({ score, dir: 1 });
if (track.score !== score) setTrack({ score, dir: score > track.score ? 1 : -1 });
const dir = track.dir;
const prevScore = React.useRef(score);
const [sheen, setSheen] = React.useState(0);
React.useEffect(() => {
const was = prevScore.current;
if (was === score) return;
prevScore.current = score;
onValueChange?.(score);
if (score === 4 && was < 4) {
haptic.success();
setSheen((n) => n + 1);
}
}, [score, onValueChange, haptic]);
// "Can't": a common password flickers the lamps once — 4pt kick, a dip
// to 0.6, released on spring.shake — and never loops.
const kick = useSharedValue(0);
const dip = useSharedValue(1);
React.useEffect(() => {
if (!refused) return;
haptic.warning();
dip.value = withSequence(withTiming(0.6, timing.instant), withTiming(1, timing.fast));
if (reduce) return;
kick.value = FLICKER_KICK;
kick.value = withSpring(0, spring.shake);
}, [refused, reduce, haptic, kick, dip]);
const rowStyle = useAnimatedStyle(() => ({ opacity: dip.value, transform: [{ translateX: kick.value }] }));
const label = refused ? "Too common" : (labels[Math.min(score, labels.length - 1)] ?? "");
const hintText = hint ?? deriveHint(password ?? "", score);
const [shownLabel, labelStyle] = useSwap(label, dir);
const [shownHint, hintStyle] = useSwap(hintText, 1);
// One hue: on states read in ink, the refusal in destructive, empty muted.
const tone = refused ? colors.destructive : score === 0 ? colors.mutedForeground : colors.foreground;
return (
<View
ref={ref}
className={cn("w-full gap-2", className)}
accessibilityRole="progressbar"
accessibilityLabel={props.accessibilityLabel ?? `Password strength: ${label}`}
accessibilityValue={{ min: 0, max: 4, now: score }}
{...props}
>
<View className="flex-row items-center gap-2">
<Animated.View
className="flex-1 flex-row gap-1 overflow-hidden rounded-full"
style={rowStyle}
accessibilityElementsHidden
importantForAccessibility="no-hide-descendants"
>
{[0, 1, 2, 3].map((i) => (
<Lamp key={i} on={i < score} refused={refused} trackClassName={trackClassName} />
))}
<Sheen run={sheen} />
</Animated.View>
{showLabel ? (
<Animated.Text
className="min-w-16 text-right text-[13px] font-semibold"
style={[{ color: tone }, labelStyle]}
accessibilityElementsHidden
importantForAccessibility="no"
>
{shownLabel}
</Animated.Text>
) : null}
</View>
{shownHint ? (
<Animated.View style={hintStyle}>
<Text className={cn("text-[13px]", shownHint === STRONG_HINT ? "font-medium text-primary-text" : "text-muted-foreground")}>
{shownHint}
</Text>
</Animated.View>
) : null}
</View>
);
}
);
PasswordStrength.displayName = "PasswordStrength"; import { PasswordStrength } from "@/components/ui/password-strength/password-strength";
export function Example() {
return (
<PasswordStrength />
);
} Installation
Install the dependencies
npx expo install react-native-reanimatedCopy the source from the Code tab into your project
components/ui/password-strength/password-strength.tsxcomponents/ui/password-strength/index.tsUpdate the import paths to match your project setup.
Usage
import { isCommonPassword, derivePasswordScore, PasswordStrength } from "@/components/ui/password-strength/password-strength"; <PasswordStrength /> Also exported: isCommonPassword, derivePasswordScore.
API reference
value number Controlled score 0–4. Omit for uncontrolled via defaultValue, or pass password and the score derives itself.
defaultValue number Uncontrolled initial score.
—onValueChange (score: number) => void Fires whenever the effective score changes (derived or set).
—password string Live password — derives the score with derivePasswordScore and generates the hint row. Takes precedence over value/defaultValue.
labels readonly string[] Labels for scores 0–4. Default ["Too weak","Weak","Fair","Good","Strong"].
DEFAULT_LABELS showLabel boolean Show the score label at the right of the meter row. Default true.
true hint string Custom hint under the meter — overrides the derived suggestion. Pass "" to hide the row entirely.
—className string Extra classes on the outer container.
—trackClassName string Unlit lamp classes. Default: the accent at low brightness.
—