feat(forms): standardized label-to-input spacing in forms via new FieldWrapper component

This commit is contained in:
karenvicent committed 2025-07-13 20:23:10 -04:00
1 parent fdaaacc3af
commit 86160a103d
10 files changed
+196 -71

No files matched your search

+3 -4
View File
@@ -4,15 +4,14 @@ const ConfigBox = styled(Stack)(({ theme }) => ({
display: "flex", display: "flex",
flexDirection: "row", flexDirection: "row",
justifyContent: "space-between", justifyContent: "space-between",
gap: theme.spacing(20),
backgroundColor: theme.palette.primary.main, backgroundColor: theme.palette.primary.main,
border: 1, border: 1,
borderStyle: "solid", borderStyle: "solid",
borderColor: theme.palette.primary.lowContrast, borderColor: theme.palette.primary.lowContrast,
borderRadius: theme.spacing(2), borderRadius: theme.spacing(2),
"& > *": { "& > *": {
paddingTop: theme.spacing(12), paddingTop: theme.spacing(15),
paddingBottom: theme.spacing(18), paddingBottom: theme.spacing(15),
}, },
"& > div:first-of-type": { "& > div:first-of-type": {
flex: 0.7, flex: 0.7,
@@ -25,7 +24,7 @@ const ConfigBox = styled(Stack)(({ theme }) => ({
"& > div:last-of-type": { "& > div:last-of-type": {
flex: 1, flex: 1,
paddingRight: theme.spacing(20), paddingRight: theme.spacing(20),
paddingLeft: theme.spacing(18), paddingLeft: theme.spacing(20),
}, },
"& h1, & h2": { "& h1, & h2": {
color: theme.palette.primary.contrastTextSecondary, color: theme.palette.primary.contrastTextSecondary,
@@ -0,0 +1,51 @@
import { Stack, Typography } from "@mui/material";
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react";
const DEFAULT_GAP = 6;
const FieldWrapper = ({
label,
children,
gap,
labelMb,
labelFontWeight = 500,
labelVariant = "h3",
labelSx = {},
sx = {},
}) => {
const theme = useTheme();
return (
<Stack
gap={gap ?? theme.spacing(DEFAULT_GAP)}
sx={sx}
>
{label && (
<Typography
component={labelVariant}
color={theme.palette.primary.contrastTextSecondary}
fontWeight={labelFontWeight}
sx={{
...(labelMb !== undefined && { mb: theme.spacing(labelMb) }),
...labelSx,
}}
>
{label}
</Typography>
)}
{children}
</Stack>
);
};
FieldWrapper.propTypes = {
label: PropTypes.node,
children: PropTypes.node.isRequired,
gap: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.object]),
labelMb: PropTypes.number,
labelFontWeight: PropTypes.number,
labelVariant: PropTypes.string,
labelSx: PropTypes.object,
sx: PropTypes.object,
};
export default FieldWrapper;
+19 -2
View File
@@ -24,7 +24,17 @@ import "./index.css";
* @returns {JSX.Element} - The rendered Radio component. * @returns {JSX.Element} - The rendered Radio component.
*/ */
const Radio = ({ name, checked, value, id, size, title, desc, onChange }) => { const Radio = ({
name,
checked,
value,
id,
size,
title,
desc,
onChange,
labelSpacing,
}) => {
const theme = useTheme(); const theme = useTheme();
return ( return (
@@ -53,7 +63,14 @@ const Radio = ({ name, checked, value, id, size, title, desc, onChange }) => {
onChange={onChange} onChange={onChange}
label={ label={
<> <>
<Typography component="p">{title}</Typography> <Typography
component="p"
mb={
labelSpacing !== undefined ? theme.spacing(labelSpacing) : theme.spacing(2)
}
>
{title}
</Typography>
<Typography <Typography
component="h6" component="h6"
mt={theme.spacing(1)} mt={theme.spacing(1)}
+20 -11
View File
@@ -12,6 +12,7 @@ import { useTheme } from "@emotion/react";
import SearchIcon from "../../../assets/icons/search.svg?react"; import SearchIcon from "../../../assets/icons/search.svg?react";
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import FieldWrapper from "../FieldWrapper";
/** /**
* Search component using Material UI's Autocomplete. * Search component using Material UI's Autocomplete.
@@ -49,7 +50,7 @@ const SearchAdornment = () => {
); );
}; };
//TODO keep search state inside of component //TODO keep search state inside of component.
const Search = ({ const Search = ({
label, label,
id, id,
@@ -68,6 +69,12 @@ const Search = ({
startAdornment, startAdornment,
endAdornment, endAdornment,
onBlur, onBlur,
//FieldWrapper's props
gap,
labelMb,
labelFontWeight,
labelVariant,
labelSx = {},
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
const { t } = useTranslation(); const { t } = useTranslation();
@@ -139,15 +146,17 @@ const Search = ({
getOptionLabel={(option) => option[filteredBy]} getOptionLabel={(option) => option[filteredBy]}
isOptionEqualToValue={(option, value) => option._id === value._id} // Compare by unique identifier isOptionEqualToValue={(option, value) => option._id === value._id} // Compare by unique identifier
renderInput={(params) => ( renderInput={(params) => (
<Stack> <FieldWrapper
<Typography label={label}
component="h3" labelMb={labelMb}
fontSize={"var(--env-var-font-size-medium)"} labelVariant={labelVariant}
color={theme.palette.primary.contrastTextSecondary} labelFontWeight={labelFontWeight}
fontWeight={500} labelSx={labelSx}
> gap={gap}
{label} sx={{
</Typography> ...sx,
}}
>
<TextField <TextField
{...params} {...params}
error={Boolean(error)} error={Boolean(error)}
@@ -175,7 +184,7 @@ const Search = ({
{error} {error}
</Typography> </Typography>
)} )}
</Stack> </FieldWrapper>
)} )}
filterOptions={(options, { inputValue }) => { filterOptions={(options, { inputValue }) => {
if (inputValue.trim() === "" && multiple && isAdorned) { if (inputValue.trim() === "" && multiple && isAdorned) {
+26 -15
View File
@@ -2,6 +2,7 @@ import PropTypes from "prop-types";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { MenuItem, Select as MuiSelect, Stack, Typography } from "@mui/material"; import { MenuItem, Select as MuiSelect, Stack, Typography } from "@mui/material";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown"; import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import FieldWrapper from "../FieldWrapper";
import "./index.css"; import "./index.css";
@@ -50,8 +51,14 @@ const Select = ({
onBlur, onBlur,
sx, sx,
name = "", name = "",
labelControlSpacing = 2, labelControlSpacing = 6,
maxWidth, maxWidth,
//FieldWrapper's props
labelMb,
labelFontWeight,
labelVariant,
labelSx = {},
fieldWrapperSx = {},
}) => { }) => {
const theme = useTheme(); const theme = useTheme();
const itemStyles = { const itemStyles = {
@@ -69,20 +76,17 @@ const Select = ({
}; };
return ( return (
<Stack <FieldWrapper
gap={theme.spacing(labelControlSpacing)} label={label}
className="select-wrapper" labelMb={labelMb}
labelVariant={labelVariant}
labelFontWeight={labelFontWeight}
labelSx={labelSx}
gap={labelControlSpacing}
sx={{
...fieldWrapperSx,
}}
> >
{label && (
<Typography
component="h3"
color={theme.palette.primary.contrastTextSecondary}
fontWeight={500}
fontSize={13}
>
{label}
</Typography>
)}
<MuiSelect <MuiSelect
className="select-component" className="select-component"
value={value} value={value}
@@ -107,6 +111,13 @@ const Select = ({
"& svg path": { "& svg path": {
fill: theme.palette.primary.contrastTextTertiary, fill: theme.palette.primary.contrastTextTertiary,
}, },
"& .MuiSelect-select": {
padding: "0 13px",
minHeight: "34px",
display: "flex",
alignItems: "center",
lineHeight: 1,
},
...sx, ...sx,
}} }}
renderValue={(selected) => { renderValue={(selected) => {
@@ -151,7 +162,7 @@ const Select = ({
</MenuItem> </MenuItem>
))} ))}
</MuiSelect> </MuiSelect>
</Stack> </FieldWrapper>
); );
}; };
@@ -2,6 +2,7 @@ import { Stack, TextField, Typography } from "@mui/material";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import { forwardRef, useState, cloneElement } from "react"; import { forwardRef, useState, cloneElement } from "react";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
import FieldWrapper from "../FieldWrapper";
const getSx = (theme, type, maxWidth) => { const getSx = (theme, type, maxWidth) => {
const sx = { const sx = {
@@ -85,31 +86,43 @@ const TextInput = forwardRef(
marginLeft, marginLeft,
disabled = false, disabled = false,
hidden = false, hidden = false,
//FieldWrapper's props
gap,
labelMb,
labelFontWeight,
labelVariant,
labelSx = {},
sx = {},
}, },
ref ref
) => { ) => {
const [fieldType, setFieldType] = useState(type); const [fieldType, setFieldType] = useState(type);
const theme = useTheme(); const theme = useTheme();
const labelContent = label && (
<>
{label}
{isRequired && <Required />}
{isOptional && <Optional optionalLabel={optionalLabel} />}
</>
);
return ( return (
<Stack <FieldWrapper
flex={flex} label={labelContent}
display={hidden ? "none" : ""} labelMb={labelMb}
marginTop={marginTop} labelVariant={labelVariant}
marginRight={marginRight} labelFontWeight={labelFontWeight}
marginBottom={marginBottom} labelSx={labelSx}
marginLeft={marginLeft} gap={gap}
sx={{
flex,
display: hidden ? "none" : "",
mt: marginTop,
mr: marginRight,
mb: marginBottom,
ml: marginLeft,
...sx,
}}
> >
<Typography
component="h3"
fontSize={"var(--env-var-font-size-medium)"}
color={theme.palette.primary.contrastTextSecondary}
fontWeight={500}
mb={theme.spacing(2)}
>
{label}
{isRequired && <Required />}
{isOptional && <Optional optionalLabel={optionalLabel} />}
</Typography>
<TextField <TextField
id={id} id={id}
name={name} name={name}
@@ -132,7 +145,7 @@ const TextInput = forwardRef(
}} }}
disabled={disabled} disabled={disabled}
/> />
</Stack> </FieldWrapper>
); );
} }
); );
@@ -10,7 +10,18 @@ import { useState, useEffect } from "react";
import { useTheme } from "@mui/material/styles"; import { useTheme } from "@mui/material/styles";
import PropTypes from "prop-types"; import PropTypes from "prop-types";
const NotificationConfig = ({ notifications, setMonitor, setNotifications }) => { const NotificationConfig = ({
notifications,
setMonitor,
setNotifications,
//FieldWrapper's props
gap,
labelMb,
labelFontWeight,
labelVariant,
labelSx = {},
sx = {},
}) => {
// Local state // Local state
const [notificationsSearch, setNotificationsSearch] = useState(""); const [notificationsSearch, setNotificationsSearch] = useState("");
const [selectedNotifications, setSelectedNotifications] = useState([]); const [selectedNotifications, setSelectedNotifications] = useState([]);
@@ -66,6 +77,14 @@ const NotificationConfig = ({ notifications, setMonitor, setNotifications }) =>
handleChange={(value) => { handleChange={(value) => {
handleSearch(value); handleSearch(value);
}} }}
labelMb={labelMb}
labelVariant={labelVariant}
labelFontWeight={labelFontWeight}
labelSx={labelSx}
gap={gap}
sx={{
...sx,
}}
/> />
<Stack <Stack
flex={1} flex={1}
@@ -62,14 +62,15 @@ export const CustomThreshold = ({
const theme = useTheme(); const theme = useTheme();
return ( return (
<Stack <Stack
direction={"row"} direction={{ sm: "column", md: "row" }}
sx={{ spacing={theme.spacing(2)}
width: "50%",
justifyContent: "space-between",
flexWrap: "wrap",
}}
> >
<Box> <Box
sx={{
width: { md: "45%", lg: "25%", xl: "20%" },
}}
justifyContent="flex-start"
>
<Checkbox <Checkbox
id={checkboxId} id={checkboxId}
name={checkboxName} name={checkboxName}
@@ -81,8 +82,10 @@ export const CustomThreshold = ({
<Stack <Stack
direction={"row"} direction={"row"}
sx={{ sx={{
justifyContent: "flex-end", justifyContent: "flex-start",
}} }}
alignItems="center"
spacing={theme.spacing(4)}
> >
<TextInput <TextInput
maxWidth="var(--env-var-width-4)" maxWidth="var(--env-var-width-4)"
@@ -25,6 +25,7 @@ import { HttpAdornment } from "../../../Components/Inputs/TextInput/Adornments";
import { createToast } from "../../../Utils/toastUtils"; import { createToast } from "../../../Utils/toastUtils";
import Select from "../../../Components/Inputs/Select"; import Select from "../../../Components/Inputs/Select";
import { CustomThreshold } from "./Components/CustomThreshold"; import { CustomThreshold } from "./Components/CustomThreshold";
import FieldWrapper from "../../../Components/Inputs/FieldWrapper";
const SELECT_VALUES = [ const SELECT_VALUES = [
{ _id: 0.25, name: "15 seconds" }, { _id: 0.25, name: "15 seconds" },
@@ -283,7 +284,7 @@ const CreateInfrastructureMonitor = () => {
/> />
</Typography> </Typography>
</Stack> </Stack>
<Stack gap={theme.spacing(15)}> <Stack gap={theme.spacing(8)}>
<TextInput <TextInput
type="url" type="url"
id="url" id="url"
@@ -299,8 +300,10 @@ const CreateInfrastructureMonitor = () => {
disabled={!isCreate} disabled={!isCreate}
/> />
{isCreate && ( {isCreate && (
<Box> <FieldWrapper
<Typography component="p">{t("infrastructureProtocol")}</Typography> label={t("infrastructureProtocol")}
labelVariant="p"
>
<ButtonGroup> <ButtonGroup>
<Button <Button
variant="group" variant="group"
@@ -317,7 +320,7 @@ const CreateInfrastructureMonitor = () => {
{t("http")} {t("http")}
</Button> </Button>
</ButtonGroup> </ButtonGroup>
</Box> </FieldWrapper>
)} )}
<TextInput <TextInput
type="text" type="text"
+7 -7
View File
@@ -117,8 +117,8 @@ const SettingsEmail = ({
<Box> <Box>
<Stack gap={theme.spacing(10)}> <Stack gap={theme.spacing(10)}>
<Box> <Box>
<Typography>{t("settingsPage.emailSettings.labelHost")}</Typography>
<TextInput <TextInput
label={t("settingsPage.emailSettings.labelHost")}
name="systemEmailHost" name="systemEmailHost"
placeholder="smtp.gmail.com" placeholder="smtp.gmail.com"
value={systemEmailHost} value={systemEmailHost}
@@ -126,8 +126,8 @@ const SettingsEmail = ({
/> />
</Box> </Box>
<Box> <Box>
<Typography>{t("settingsPage.emailSettings.labelPort")}</Typography>
<TextInput <TextInput
label={t("settingsPage.emailSettings.labelPort")}
name="systemEmailPort" name="systemEmailPort"
placeholder="425" placeholder="425"
type="number" type="number"
@@ -136,8 +136,8 @@ const SettingsEmail = ({
/> />
</Box> </Box>
<Box> <Box>
<Typography>{t("settingsPage.emailSettings.labelUser")}</Typography>
<TextInput <TextInput
label={t("settingsPage.emailSettings.labelUser")}
name="systemEmailUser" name="systemEmailUser"
placeholder={t("settingsPage.emailSettings.placeholderUser")} placeholder={t("settingsPage.emailSettings.placeholderUser")}
value={systemEmailUser} value={systemEmailUser}
@@ -145,8 +145,8 @@ const SettingsEmail = ({
/> />
</Box> </Box>
<Box> <Box>
<Typography>{t("settingsPage.emailSettings.labelAddress")}</Typography>
<TextInput <TextInput
label={t("settingsPage.emailSettings.labelAddress")}
name="systemEmailAddress" name="systemEmailAddress"
placeholder="uptime@bluewavelabs.ca" placeholder="uptime@bluewavelabs.ca"
value={systemEmailAddress} value={systemEmailAddress}
@@ -155,8 +155,8 @@ const SettingsEmail = ({
</Box> </Box>
{(isEmailPasswordSet === false || emailPasswordHasBeenReset === true) && ( {(isEmailPasswordSet === false || emailPasswordHasBeenReset === true) && (
<Box> <Box>
<Typography>{t("settingsPage.emailSettings.labelPassword")}</Typography>
<TextInput <TextInput
label={t("settingsPage.emailSettings.labelPassword")}
name="systemEmailPassword" name="systemEmailPassword"
type="password" type="password"
placeholder="123 456 789 101112" placeholder="123 456 789 101112"
@@ -188,8 +188,8 @@ const SettingsEmail = ({
</Box> </Box>
)} )}
<Box> <Box>
<Typography>{t("settingsPage.emailSettings.labelTLSServername")}</Typography>
<TextInput <TextInput
label={t("settingsPage.emailSettings.labelTLSServername")}
name="systemEmailTLSServername" name="systemEmailTLSServername"
placeholder="bluewavelabs.ca" placeholder="bluewavelabs.ca"
value={systemEmailTLSServername} value={systemEmailTLSServername}
@@ -197,8 +197,8 @@ const SettingsEmail = ({
/> />
</Box> </Box>
<Box> <Box>
<Typography>{t("settingsPage.emailSettings.labelConnectionHost")}</Typography>
<TextInput <TextInput
label={t("settingsPage.emailSettings.labelConnectionHost")}
name="systemEmailConnectionHost" name="systemEmailConnectionHost"
placeholder="bluewavelabs.ca" placeholder="bluewavelabs.ca"
value={systemEmailConnectionHost} value={systemEmailConnectionHost}