-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Only content of Switch label is clickable
- Loading branch information
1 parent
304490d
commit 7610cee
Showing
3 changed files
with
26 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
) | ||
) |