Skip to content

Commit

Permalink
fix: Only content of Switch label is clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 12, 2024
1 parent 304490d commit 7610cee
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,8 @@ const FlowStatus = () => {
<SettingsSection background>
<Switch
label={statusForm.values.status as Capitalize<string>}
formControlLabelProps={{
sx: {
marginBottom: 0.5,
[`& .${formControlLabelClasses.label}`]: {
fontWeight: FONT_WEIGHT_BOLD,
textTransform: "capitalize",
fontSize: 19,
},
},
name: "service.status",
}}
name={"service.status"}
variant="editorPage"
checked={statusForm.values.status === "online"}
onChange={() =>
statusForm.setFieldValue(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,8 @@ const TextInput: React.FC<{
<Box mb={0.5} display="flex" alignItems="center">
<Switch
label={title}
formControlLabelProps={{
sx: {
marginBottom: 0.5,
[`& .${formControlLabelClasses.label}`]: {
fontWeight: FONT_WEIGHT_BOLD,
textTransform: "capitalize",
fontSize: 19,
},
},
name: switchProps?.name,
}}
name={switchProps?.name}
variant="editorPage"
onChange={switchProps?.onChange}
checked={switchProps?.checked}
/>
Expand Down
29 changes: 22 additions & 7 deletions editor.planx.uk/src/ui/shared/Switch.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,42 @@
import Box from "@mui/material/Box";
import FormControlLabel, { FormControlLabelProps } from "@mui/material/FormControlLabel";
import FormControlLabel, { formControlLabelClasses } from "@mui/material/FormControlLabel";
// eslint-disable-next-line no-restricted-imports
import MuiSwitch, { SwitchProps as MuiSwitchProps } from "@mui/material/Switch";
import React from "react";
import { FONT_WEIGHT_BOLD } from "theme";

interface Props {
checked?: boolean;
onChange: MuiSwitchProps["onChange"];
label: Capitalize<string>
formControlLabelProps?: Partial<FormControlLabelProps>;
name?: string;
variant?: "editorPage" | "editorModal"
}

export const Switch: React.FC<Props> = ({ checked, onChange, label, formControlLabelProps }) => (
export const Switch: React.FC<Props> = ({ checked, onChange, label, name, variant = "editorModal" }) => (
<Box>
<FormControlLabel
control={
<MuiSwitch
checked={checked}
onChange={onChange}
/>
}
sx={{ pointerEvents: "auto"}}
/>
}
name={name}
label={label}
{...formControlLabelProps}
sx={{
pointerEvents: "none",
[`& .${formControlLabelClasses.label}`]: {
pointerEvents: "auto",
display: "contents",
...(variant === "editorPage" && {
fontWeight: FONT_WEIGHT_BOLD,
textTransform: "capitalize",
fontSize: 19,
})
}
}}
/>
</Box>
)
)

0 comments on commit 7610cee

Please sign in to comment.