Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Only content of Switch label is clickable #3936

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
Comment on lines +33 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the reason for creating a variant here - these label styles need to be merged, just passing in a prop would overwrite them.

})
}
}}
/>
</Box>
)
)
Loading