From 2715d4d782831f70b34fa3751123b3d3cf9e5047 Mon Sep 17 00:00:00 2001 From: Simon Kobyda Date: Tue, 22 Aug 2023 14:31:14 +0200 Subject: [PATCH] lib: Show message next to password progress bar --- pkg/lib/cockpit-components-password.jsx | 49 ++++++++++++++++-------- pkg/lib/cockpit-components-password.scss | 3 ++ test/reference | 2 +- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/pkg/lib/cockpit-components-password.jsx b/pkg/lib/cockpit-components-password.jsx index 15cfe30aba65..795d7a2c1c49 100644 --- a/pkg/lib/cockpit-components-password.jsx +++ b/pkg/lib/cockpit-components-password.jsx @@ -30,6 +30,7 @@ import { EyeIcon, EyeSlashIcon, HelpIcon } from '@patternfly/react-icons'; import { FormHelper } from "cockpit-components-form-helper"; import './cockpit-components-password.scss'; +import { Flex, FlexItem } from '@patternfly/react-core'; const _ = cockpit.gettext; @@ -62,7 +63,7 @@ export const PasswordFormFields = ({ }) => { const [password, setPassword] = useState(initial_password || ""); const [passwordConfirm, setConfirmPassword] = useState(""); - const [passwordStrength, setPasswordStrength] = useState(""); + const [passwordStrength, setPasswordStrength] = useState(); const [passwordMessage, setPasswordMessage] = useState(""); const [passwordHidden, setPasswordHidden] = useState(true); const [passwordConfirmHidden, setPasswordConfirmHidden] = useState(true); @@ -81,20 +82,30 @@ export const PasswordFormFields = ({ setPasswordMessage(strength.message); }); } else { - setPasswordStrength(""); + setPasswordStrength(); setPasswordMessage(""); } } let variant; - if (passwordStrength === "") - variant = "default"; - else if (passwordStrength > 66) + let message; + let messageColor; + if (passwordStrength > 66) { variant = "success"; - else if (passwordStrength > 33) + messageColor = "pf-v5-u-success-color-200"; + message = _("Strong password"); + } else if (passwordStrength > 33) { variant = "warning"; - else + messageColor = "pf-v5-u-warning-color-200"; + message = _("Acceptable password"); + } else { variant = "danger"; + messageColor = "pf-v5-u-danger-color-200"; + message = _("Weak password"); + } + + if (!passwordMessage && message) + setPasswordMessage(message); let passwordStrengthValue = Number.isInteger(passwordStrength) ? Number.parseInt(passwordStrength) : -1; if (password !== "" && (passwordStrengthValue >= 0 && passwordStrengthValue < 25)) @@ -129,16 +140,20 @@ export const PasswordFormFields = ({ -
- -
{passwordMessage}
-
+ {passwordStrengthValue >= 0 && + + + + +
{passwordMessage}
+
+
} {error_password && diff --git a/pkg/lib/cockpit-components-password.scss b/pkg/lib/cockpit-components-password.scss index 316e938f64c8..e1d2d449067e 100644 --- a/pkg/lib/cockpit-components-password.scss +++ b/pkg/lib/cockpit-components-password.scss @@ -1,3 +1,6 @@ +@import "global-variables"; +@import "@patternfly/patternfly/utilities/Text/text.scss"; + .ct-password-strength-meter { grid-gap: var(--pf-v5-global--spacer--xs); inline-size: var(--pf-v5-global--spacer--2xl); diff --git a/test/reference b/test/reference index 1a9d33687e9e..45f3107a5d1c 160000 --- a/test/reference +++ b/test/reference @@ -1 +1 @@ -Subproject commit 1a9d33687e9e054ae355716357ec4e436df3e283 +Subproject commit 45f3107a5d1c74dc9d653eda7cb0a68855a12123