Refactored password visibility state and added small css fix
This commit is contained in:
1 parent
1e9bb5501e
commit
99b1130e29
7 files changed
+7
-31
No files matched your search
@@ -36,16 +36,16 @@
|
|||||||
.field .MuiInputBase-root:has(.MuiInputAdornment-root) {
|
.field .MuiInputBase-root:has(.MuiInputAdornment-root) {
|
||||||
padding-right: var(--env-var-spacing-1-minus);
|
padding-right: var(--env-var-spacing-1-minus);
|
||||||
}
|
}
|
||||||
.field .MuiInputBase-root:has(.MuiInputAdornment-root > .MuiButtonBase-root) {
|
.field .MuiInputBase-root:has(.copy.MuiInputAdornment-root > .MuiButtonBase-root) {
|
||||||
padding-right: 0;
|
padding-right: 0;
|
||||||
}
|
}
|
||||||
.field .MuiInputBase-root .MuiInputAdornment-root .MuiButtonBase-root {
|
.field .MuiInputBase-root .copy.MuiInputAdornment-root .MuiButtonBase-root {
|
||||||
padding: 0 var(--env-var-spacing-1-minus);
|
padding: 0 var(--env-var-spacing-1-minus);
|
||||||
font-size: var(--env-var-font-size-medium);
|
font-size: var(--env-var-font-size-medium);
|
||||||
border-radius: 0;
|
border-radius: 0;
|
||||||
height: 34px;
|
height: 34px;
|
||||||
}
|
}
|
||||||
.field .MuiInputBase-root .MuiInputAdornment-root .MuiButtonBase-root svg {
|
.field .MuiInputBase-root .copy.MuiInputAdornment-root .MuiButtonBase-root svg {
|
||||||
width: 20px;
|
width: 20px;
|
||||||
height: 20px;
|
height: 20px;
|
||||||
margin-right: 5px;
|
margin-right: 5px;
|
||||||
|
|||||||
@@ -19,8 +19,6 @@ const Field = ({
|
|||||||
label,
|
label,
|
||||||
isRequired,
|
isRequired,
|
||||||
isOptional,
|
isOptional,
|
||||||
isVisible,
|
|
||||||
setVisibility,
|
|
||||||
hasCopy,
|
hasCopy,
|
||||||
autoComplete,
|
autoComplete,
|
||||||
placeholder,
|
placeholder,
|
||||||
@@ -38,6 +36,8 @@ const Field = ({
|
|||||||
setTimeout(() => setCopy(false), 1000);
|
setTimeout(() => setCopy(false), 1000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [isVisible, setVisible] = useState(false);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack gap={theme.gap.xs} className={`field field-${type}`}>
|
<Stack gap={theme.gap.xs} className={`field field-${type}`}>
|
||||||
{label && (
|
{label && (
|
||||||
@@ -75,7 +75,7 @@ const Field = ({
|
|||||||
<InputAdornment position="end">
|
<InputAdornment position="end">
|
||||||
<IconButton
|
<IconButton
|
||||||
aria-label="toggle password visibility"
|
aria-label="toggle password visibility"
|
||||||
onClick={() => setVisibility((show) => !show)}
|
onClick={() => setVisible((show) => !show)}
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
sx={{
|
sx={{
|
||||||
color: theme.palette.section.borderColor,
|
color: theme.palette.section.borderColor,
|
||||||
@@ -94,7 +94,7 @@ const Field = ({
|
|||||||
</InputAdornment>
|
</InputAdornment>
|
||||||
) : (
|
) : (
|
||||||
hasCopy && (
|
hasCopy && (
|
||||||
<InputAdornment position="end">
|
<InputAdornment className="copy" position="end">
|
||||||
<Button
|
<Button
|
||||||
level="tertiary"
|
level="tertiary"
|
||||||
label={copy ? "Copied" : "Copy"}
|
label={copy ? "Copied" : "Copy"}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ const PasswordPanel = () => {
|
|||||||
confirm: "",
|
confirm: "",
|
||||||
});
|
});
|
||||||
const [errors, setErrors] = useState({});
|
const [errors, setErrors] = useState({});
|
||||||
const [showPassword, setShowPassword] = useState(false); // password visibility
|
|
||||||
|
|
||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
const { value, id } = event.target;
|
const { value, id } = event.target;
|
||||||
@@ -125,8 +124,6 @@ const PasswordPanel = () => {
|
|||||||
id="edit-current-password"
|
id="edit-current-password"
|
||||||
placeholder="Enter your current password"
|
placeholder="Enter your current password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
isVisible={showPassword}
|
|
||||||
setVisibility={setShowPassword}
|
|
||||||
value={localData.password}
|
value={localData.password}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
error={errors[idToName["edit-current-password"]]}
|
error={errors[idToName["edit-current-password"]]}
|
||||||
@@ -141,8 +138,6 @@ const PasswordPanel = () => {
|
|||||||
id="edit-new-password"
|
id="edit-new-password"
|
||||||
placeholder="Enter your new password"
|
placeholder="Enter your new password"
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
isVisible={showPassword}
|
|
||||||
setVisibility={setShowPassword}
|
|
||||||
value={localData.newPassword}
|
value={localData.newPassword}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
error={errors[idToName["edit-new-password"]]}
|
error={errors[idToName["edit-new-password"]]}
|
||||||
@@ -157,8 +152,6 @@ const PasswordPanel = () => {
|
|||||||
id="edit-confirm-password"
|
id="edit-confirm-password"
|
||||||
placeholder="Reenter your new password"
|
placeholder="Reenter your new password"
|
||||||
autoComplete="new-password"
|
autoComplete="new-password"
|
||||||
isVisible={showPassword}
|
|
||||||
setVisibility={setShowPassword}
|
|
||||||
value={localData.confirm}
|
value={localData.confirm}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
error={errors[idToName["edit-confirm-password"]]}
|
error={errors[idToName["edit-confirm-password"]]}
|
||||||
|
|||||||
@@ -507,8 +507,6 @@ const Demo = () => {
|
|||||||
type="password"
|
type="password"
|
||||||
label="Password"
|
label="Password"
|
||||||
isRequired={true}
|
isRequired={true}
|
||||||
isVisible={visibility}
|
|
||||||
setVisibility={setVisibility}
|
|
||||||
placeholder="Create a password"
|
placeholder="Create a password"
|
||||||
/>
|
/>
|
||||||
<Field
|
<Field
|
||||||
|
|||||||
@@ -110,8 +110,6 @@ const Login = () => {
|
|||||||
navigate("/register");
|
navigate("/register");
|
||||||
};
|
};
|
||||||
|
|
||||||
const [visibility, setVisibility] = useState(false);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="login-page">
|
<div className="login-page">
|
||||||
<BackgroundPattern></BackgroundPattern>
|
<BackgroundPattern></BackgroundPattern>
|
||||||
@@ -142,8 +140,6 @@ const Login = () => {
|
|||||||
type="password"
|
type="password"
|
||||||
id="login-password-input"
|
id="login-password-input"
|
||||||
label="Password"
|
label="Password"
|
||||||
isVisible={visibility}
|
|
||||||
setVisibility={setVisibility}
|
|
||||||
placeholder="Enter your password"
|
placeholder="Enter your password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
onChange={handleInput}
|
onChange={handleInput}
|
||||||
|
|||||||
@@ -117,7 +117,6 @@ const Register = () => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const [visibility, setVisibility] = useState(false);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="register-page">
|
<div className="register-page">
|
||||||
@@ -173,8 +172,6 @@ const Register = () => {
|
|||||||
id="register-password-input"
|
id="register-password-input"
|
||||||
label="Password"
|
label="Password"
|
||||||
isRequired={true}
|
isRequired={true}
|
||||||
isVisible={visibility}
|
|
||||||
setVisibility={setVisibility}
|
|
||||||
placeholder="Create a password"
|
placeholder="Create a password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
error={errors.password}
|
error={errors.password}
|
||||||
@@ -187,8 +184,6 @@ const Register = () => {
|
|||||||
id="register-confirm-input"
|
id="register-confirm-input"
|
||||||
label="Confirm password"
|
label="Confirm password"
|
||||||
isRequired={true}
|
isRequired={true}
|
||||||
isVisible={visibility}
|
|
||||||
setVisibility={setVisibility}
|
|
||||||
placeholder="Confirm your password"
|
placeholder="Confirm your password"
|
||||||
autoComplete="current-password"
|
autoComplete="current-password"
|
||||||
error={errors.confirm}
|
error={errors.confirm}
|
||||||
|
|||||||
@@ -63,8 +63,6 @@ const SetNewPassword = () => {
|
|||||||
}
|
}
|
||||||
}, [form]);
|
}, [form]);
|
||||||
|
|
||||||
const [visibility, setVisibility] = useState(false);
|
|
||||||
|
|
||||||
const { token } = useParams();
|
const { token } = useParams();
|
||||||
return (
|
return (
|
||||||
<div className="set-new-password-page">
|
<div className="set-new-password-page">
|
||||||
@@ -90,8 +88,6 @@ const SetNewPassword = () => {
|
|||||||
id="register-password-input"
|
id="register-password-input"
|
||||||
label="Password"
|
label="Password"
|
||||||
isRequired={true}
|
isRequired={true}
|
||||||
isVisible={visibility}
|
|
||||||
setVisibility={setVisibility}
|
|
||||||
placeholder="••••••••"
|
placeholder="••••••••"
|
||||||
onChange={handleInput}
|
onChange={handleInput}
|
||||||
error={errors.password}
|
error={errors.password}
|
||||||
@@ -102,8 +98,6 @@ const SetNewPassword = () => {
|
|||||||
id="confirm-password-input"
|
id="confirm-password-input"
|
||||||
label="Confirm password"
|
label="Confirm password"
|
||||||
isRequired={true}
|
isRequired={true}
|
||||||
isVisible={visibility}
|
|
||||||
setVisibility={setVisibility}
|
|
||||||
placeholder="••••••••"
|
placeholder="••••••••"
|
||||||
onChange={handleInput}
|
onChange={handleInput}
|
||||||
error={errors.confirm}
|
error={errors.confirm}
|
||||||
|
|||||||
Reference in new issue
Block a user