PasswordStrength.tsx 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { PasswordStrength } from "@ente/accounts/constants";
  2. import { estimatePasswordStrength } from "@ente/accounts/utils";
  3. import { FlexWrapper } from "@ente/shared/components/Container";
  4. import { Typography } from "@mui/material";
  5. import { t } from "i18next";
  6. import { useMemo } from "react";
  7. export const PasswordStrengthHint = ({
  8. password,
  9. }: {
  10. password: string;
  11. }): JSX.Element => {
  12. const passwordStrength = useMemo(
  13. () => estimatePasswordStrength(password),
  14. [password],
  15. );
  16. return (
  17. <FlexWrapper mt={"8px"} mb={"4px"}>
  18. <Typography
  19. variant="small"
  20. sx={(theme) => ({
  21. color:
  22. passwordStrength === PasswordStrength.WEAK
  23. ? theme.colors.danger.A700
  24. : passwordStrength === PasswordStrength.MODERATE
  25. ? theme.colors.warning.A500
  26. : theme.colors.accent.A500,
  27. })}
  28. textAlign={"left"}
  29. flex={1}
  30. >
  31. {password
  32. ? t("PASSPHRASE_STRENGTH", { context: passwordStrength })
  33. : ""}
  34. </Typography>
  35. </FlexWrapper>
  36. );
  37. };