Merge pull request #1173 from bluewave-labs/fix/fe/field-refactor

Fix/fe/field refactor
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-11-21 17:33:18 -08:00
commit a84916f0b0
2 files changed
+34 -24

No files matched your search

+28 -18
View File
@@ -7,23 +7,31 @@ import Visibility from "@mui/icons-material/Visibility";
import "./index.css"; import "./index.css";
/** /**
* Field component for rendering various types of input fields with customizable properties
*
* @param {Object} props * @param {Object} props
* @param {string} [props.type] - Type of input field (e.g., 'text', 'password'). * @param {string} [props.type='text'] - Type of input field (text, password, url, email, description, number).
* @param {string} props.id - ID of the input field. * @param {string} props.id - Unique identifier for the input field.
* @param {string} props.name - Name of the input field. * @param {string} props.name - Name attribute for the input field.
* @param {string} [props.label] - Label for the input field. * @param {string} [props.label] - Label text displayed above the input field.
* @param {boolean} [props.https] - Indicates if it should display http or https. * @param {boolean} [props.https=true] - For URL type, determines whether to show https:// or http://.
* @param {boolean} [props.isRequired] - Indicates if the field is required, will display a red asterisk. * @param {boolean} [props.isRequired=false] - Displays a red asterisk if the field is required.
* @param {boolean} [props.isOptional] - Indicates if the field is optional, will display optional text. * @param {boolean} [props.isOptional=false] - Displays an optional label next to the field.
* @param {string} [props.optionalLabel] - Optional label for the input field. * @param {string} [props.optionalLabel='(optional)'] - Custom text for optional label.
* @param {string} [props.autoComplete] - Autocomplete value for the input field. * @param {string} [props.autoComplete] - Autocomplete attribute for the input.
* @param {string} [props.placeholder] - Placeholder text for the input field. * @param {string} [props.placeholder] - Placeholder text for the input field.
* @param {string} props.value - Value of the input field. * @param {string} props.value - Current value of the input field.
* @param {function} props.onChange - Function called on input change. * @param {function} props.onChange - Callback function triggered on input value change.
* @param {string} [props.error] - Error message to display for the input field. * @param {function} [props.onBlur] - Callback function triggered when input loses focus.
* @param {boolean} [props.disabled] - Indicates if the input field is disabled. * @param {function} [props.onInput] - Callback function triggered on input event.
* @param {boolean} [props.hidden] - Indicates if the input field is hidden. * @param {string} [props.error] - Error message to display below the input field.
* @param {React.Ref} [ref] - Ref forwarded to the underlying `TextField` component. Allows for direct interactions such as focusing. * @param {boolean} [props.disabled=false] - Disables the input field if true.
* @param {boolean} [props.hidden=false] - Hides the entire input field if true.
* @param {string} [props.className] - Additional CSS class names for the input container.
* @param {boolean} [props.hideErrorText=false] - Hides the error message if true.
* @param {React.Ref} [ref] - Ref forwarded to the underlying TextField component.
*
* @returns {React.ReactElement} Rendered input field component
*/ */
const Field = forwardRef( const Field = forwardRef(
@@ -46,7 +54,8 @@ const Field = forwardRef(
error, error,
disabled, disabled,
hidden, hidden,
className className,
hideErrorText = false,
}, },
ref ref
) => { ) => {
@@ -190,7 +199,7 @@ const Field = forwardRef(
<Typography <Typography
component="span" component="span"
className="input-error" className="input-error"
hidden={className ? true : false} hidden={hideErrorText}
color={theme.palette.error.main} color={theme.palette.error.main}
mt={theme.spacing(2)} mt={theme.spacing(2)}
sx={{ sx={{
@@ -225,7 +234,8 @@ Field.propTypes = {
error: PropTypes.string, error: PropTypes.string,
disabled: PropTypes.bool, disabled: PropTypes.bool,
hidden: PropTypes.bool, hidden: PropTypes.bool,
className: PropTypes.string className: PropTypes.string,
hideErrorText: PropTypes.bool,
}; };
export default Field; export default Field;
@@ -4,7 +4,6 @@ import Checkbox from "../../../../Components/Inputs/Checkbox";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
/** /**
* `CustomThreshold` is a functional React component that displays a * `CustomThreshold` is a functional React component that displays a
* group of CheckBox with a label and its correspondant threshold input field. * group of CheckBox with a label and its correspondant threshold input field.
@@ -32,9 +31,8 @@ export const CustomThreshold = ({
onFieldBlur, onFieldBlur,
alertUnit, alertUnit,
infrastructureMonitor, infrastructureMonitor,
errors errors,
}) => }) => {
{
const theme = useTheme(); const theme = useTheme();
return ( return (
<Stack <Stack
@@ -42,7 +40,7 @@ export const CustomThreshold = ({
sx={{ sx={{
width: "50%", width: "50%",
justifyContent: "space-between", justifyContent: "space-between",
flexWrap: "wrap" flexWrap: "wrap",
}} }}
> >
<Box> <Box>
@@ -68,6 +66,7 @@ export const CustomThreshold = ({
onChange={onFieldChange} onChange={onFieldChange}
error={errors[fieldId]} error={errors[fieldId]}
disabled={!infrastructureMonitor[checkboxId]} disabled={!infrastructureMonitor[checkboxId]}
hideErrorText={true}
></Field> ></Field>
<Typography <Typography
component="p" component="p"
@@ -77,7 +76,8 @@ export const CustomThreshold = ({
</Typography> </Typography>
</Stack> </Stack>
</Stack> </Stack>
)} );
};
CustomThreshold.propTypes = { CustomThreshold.propTypes = {
checkboxId: PropTypes.string.isRequired, checkboxId: PropTypes.string.isRequired,