import React from 'react'; import { calculatePasswordStrength } from '../utils/passwordStrength'; interface Props { password: string; } export const PasswordStrengthMeter: React.FC = ({ password }) => { const { score, label, color, feedback } = calculatePasswordStrength(password); // Calculate width percentage based on score (0-4) // 0: 5%, 1: 25%, 2: 50%, 3: 75%, 4: 100% const width = Math.max(5, (score / 4) * 100); // Map color name to Tailwind classes const getColorClass = (c: string) => { switch (c) { case 'red': return 'bg-red-500'; case 'yellow': return 'bg-yellow-500'; case 'green': return 'bg-green-500'; default: return 'bg-gray-300'; } }; const getTextColorClass = (c: string) => { switch (c) { case 'red': return 'text-red-500'; case 'yellow': return 'text-yellow-600'; case 'green': return 'text-green-600'; default: return 'text-gray-500'; } }; if (!password) return null; return (
{label} {feedback.length > 0 && ( {feedback[0]} )}
); };