Refactored checks component
This commit is contained in:
1 parent
4db0beecd8
commit
fdac37b595
7 files changed
+92
-31
No files matched your search
@@ -1,6 +1,8 @@
|
|||||||
import "./check.css";
|
import "./check.css";
|
||||||
import React from "react";
|
import PropTypes from "prop-types";
|
||||||
import CheckGrey from "../../assets/Images/Check-icon-grey.png";
|
import CheckGrey from "../../assets/icons/check.svg?react";
|
||||||
|
import { Stack, Typography } from "@mui/material";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `Check` is a functional React component that displays a check icon and a label.
|
* `Check` is a functional React component that displays a check icon and a label.
|
||||||
@@ -8,6 +10,7 @@ import CheckGrey from "../../assets/Images/Check-icon-grey.png";
|
|||||||
* @component
|
* @component
|
||||||
* @param {Object} props - The properties that define the `Check` component.
|
* @param {Object} props - The properties that define the `Check` component.
|
||||||
* @param {string} props.text - The text to be displayed as the label next to the check icon.
|
* @param {string} props.text - The text to be displayed as the label next to the check icon.
|
||||||
|
* @param {'info' | 'error' | 'success'} [props.variant='info'] - The variant of the check component, affecting its styling.
|
||||||
*
|
*
|
||||||
* @example
|
* @example
|
||||||
* // To use this component, import it and use it in your JSX like this:
|
* // To use this component, import it and use it in your JSX like this:
|
||||||
@@ -15,14 +18,30 @@ import CheckGrey from "../../assets/Images/Check-icon-grey.png";
|
|||||||
*
|
*
|
||||||
* @returns {React.Element} The `Check` component with a check icon and a label, defined by the `text` prop.
|
* @returns {React.Element} The `Check` component with a check icon and a label, defined by the `text` prop.
|
||||||
*/
|
*/
|
||||||
const Check = ({ text }) => {
|
const Check = ({ text, variant = "info" }) => {
|
||||||
|
const theme = useTheme();
|
||||||
return (
|
return (
|
||||||
<div className="check">
|
<Stack
|
||||||
<img className="check-icon" src={CheckGrey} alt="un-checked" />
|
direction="row"
|
||||||
<div className="check-h-spacing" />
|
gap={theme.gap.small}
|
||||||
<label className="check-label">{text}</label>
|
className={`check${
|
||||||
</div>
|
variant === "error"
|
||||||
|
? " check-error"
|
||||||
|
: variant === "success"
|
||||||
|
? " check-success"
|
||||||
|
: " check-info"
|
||||||
|
}`}
|
||||||
|
alignItems="center"
|
||||||
|
>
|
||||||
|
<CheckGrey alt="form checks" />
|
||||||
|
<Typography component="span">{text}</Typography>
|
||||||
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Check.propTypes = {
|
||||||
|
text: PropTypes.string.isRequired,
|
||||||
|
variant: PropTypes.oneOf(["info", "error", "success"]),
|
||||||
|
};
|
||||||
|
|
||||||
export default Check;
|
export default Check;
|
||||||
@@ -1,20 +1,17 @@
|
|||||||
.check {
|
.check span.MuiTypography-root {
|
||||||
display: flex;
|
font-size: var(--env-var-font-size-small-plus);
|
||||||
align-items: center;
|
|
||||||
justify-content: start;
|
|
||||||
}
|
|
||||||
|
|
||||||
.check-icon {
|
|
||||||
width: var(--env-var-img-width-1);
|
|
||||||
height: var(--env-var-img-width-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
.check-h-spacing {
|
|
||||||
margin-right: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.check-label {
|
|
||||||
font-size: var(--env-var-font-size-small);
|
|
||||||
font-weight: 600;
|
|
||||||
color: var(--env-var-color-2);
|
color: var(--env-var-color-2);
|
||||||
|
opacity: 0.8;
|
||||||
|
}
|
||||||
|
.check-error span.MuiTypography-root {
|
||||||
|
color: var(--env-var-color-24);
|
||||||
|
}
|
||||||
|
.check-error svg > path {
|
||||||
|
fill: var(--env-var-color-19);
|
||||||
|
}
|
||||||
|
.check-success span.MuiTypography-root {
|
||||||
|
color: var(--env-var-color-17);
|
||||||
|
}
|
||||||
|
.check-success svg > path {
|
||||||
|
fill: var(--env-var-color-23);
|
||||||
}
|
}
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
color: var(--env-var-color-2);
|
color: var(--env-var-color-2);
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
.login-page button {
|
.login-page button:not(.MuiIconButton-root) {
|
||||||
height: 34px;
|
height: 34px;
|
||||||
border-radius: var(--env-var-radius-2);
|
border-radius: var(--env-var-radius-2);
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
color: var(--env-var-color-2);
|
color: var(--env-var-color-2);
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
.register-page button {
|
.register-page button:not(.MuiIconButton-root) {
|
||||||
height: 34px;
|
height: 34px;
|
||||||
border-radius: var(--env-var-radius-2);
|
border-radius: var(--env-var-radius-2);
|
||||||
line-height: 0;
|
line-height: 0;
|
||||||
@@ -26,6 +26,12 @@
|
|||||||
.register-page svg rect {
|
.register-page svg rect {
|
||||||
fill: none;
|
fill: none;
|
||||||
}
|
}
|
||||||
|
.register-page
|
||||||
|
.MuiFormControl-root:has(#register-password-input)
|
||||||
|
+ span.MuiTypography-root {
|
||||||
|
display: none;
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.register-form {
|
.register-form {
|
||||||
margin-top: 102px;
|
margin-top: 102px;
|
||||||
|
|||||||
@@ -199,9 +199,44 @@ const Register = () => {
|
|||||||
error={errors.confirm}
|
error={errors.confirm}
|
||||||
/>
|
/>
|
||||||
<Stack gap={theme.gap.small}>
|
<Stack gap={theme.gap.small}>
|
||||||
<Check text="Must be at least 8 characters" />
|
<Check
|
||||||
<Check text="Must contain one special character" />
|
text="Must be at least 8 characters long"
|
||||||
<Check text="Must contain at least one upper and lower character" />
|
variant={
|
||||||
|
errors?.password === "Password is required"
|
||||||
|
? "error"
|
||||||
|
: form.password === ""
|
||||||
|
? "info"
|
||||||
|
: form.password.length < 8
|
||||||
|
? "error"
|
||||||
|
: "success"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Check
|
||||||
|
text="Must contain one special character and a number"
|
||||||
|
variant={
|
||||||
|
errors?.password === "Password is required"
|
||||||
|
? "error"
|
||||||
|
: form.password === ""
|
||||||
|
? "info"
|
||||||
|
: !/^(?=.*[!@#$%^&*(),.?":{}|])(?=.*\d).+$/.test(
|
||||||
|
form.password
|
||||||
|
)
|
||||||
|
? "error"
|
||||||
|
: "success"
|
||||||
|
}
|
||||||
|
/>
|
||||||
|
<Check
|
||||||
|
text="Must contain at least one upper and lower character"
|
||||||
|
variant={
|
||||||
|
errors?.password === "Password is required"
|
||||||
|
? "error"
|
||||||
|
: form.password === ""
|
||||||
|
? "info"
|
||||||
|
: !/^(?=.*[A-Z])(?=.*[a-z]).+$/.test(form.password)
|
||||||
|
? "error"
|
||||||
|
: "success"
|
||||||
|
}
|
||||||
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 571 B |
@@ -0,0 +1,4 @@
|
|||||||
|
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<path d="M0 10C0 4.47715 4.47715 0 10 0C15.5228 0 20 4.47715 20 10C20 15.5228 15.5228 20 10 20C4.47715 20 0 15.5228 0 10Z" fill="#D0D5DD"/>
|
||||||
|
<path d="M6.25 10L8.75 12.5L13.75 7.5" stroke="white" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 363 B |
Reference in new issue
Block a user