UNPKG

@brightlayer-ui/react-native-auth-workflow

Version:

Re-usable workflow components for Authentication and Registration within Eaton applications.

34 lines (33 loc) 1.73 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import React, { useEffect } from 'react'; import { defaultPasswordRequirements } from '../../constants'; import { useTranslation } from 'react-i18next'; import { View } from 'react-native'; import { PasswordRequirementsCheck } from './PasswordRequirementsCheck'; /** * Component to update password requirements. * * @param {PasswordRequirementsProps} props - props of PasswordRequirements component * * @category Component */ export const PasswordRequirements = (props) => { const { t } = useTranslation(); const { passwordText, passwordRequirements = defaultPasswordRequirements(t), style } = props, otherProps = __rest(props, ["passwordText", "passwordRequirements", "style"]); useEffect(() => { // Ensure password requirements are translated if necessary passwordRequirements.forEach((req) => (req.description = t(req.description))); }, [t, passwordRequirements]); return (React.createElement(View, Object.assign({ style: style }, otherProps), passwordRequirements.map((req, ind) => (React.createElement(PasswordRequirementsCheck, { key: `password_requirement_${ind}`, label: req.description, isChecked: new RegExp(req.regex).test(passwordText) }))))); }; export default PasswordRequirements;