-
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.
refactor: Universal toggle button (#4115)
- Loading branch information
Showing
6 changed files
with
113 additions
and
88 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
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 |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import Box from "@mui/material/Box"; | ||
import IconButton from "@mui/material/IconButton"; | ||
import Tooltip from "@mui/material/Tooltip"; | ||
import React from "react"; | ||
import ToggleOverlayIcon from "ui/icons/ToggleOverlay"; | ||
|
||
interface ToggleIconButtonProps { | ||
isToggled: boolean; | ||
onToggle: () => void; | ||
icon: React.ReactNode; | ||
tooltip: string; | ||
ariaLabel: string; | ||
} | ||
|
||
const ToggleIconButton: React.FC<ToggleIconButtonProps> = ({ | ||
isToggled, | ||
onToggle, | ||
icon, | ||
tooltip, | ||
ariaLabel, | ||
}) => { | ||
return ( | ||
<Tooltip title={tooltip} placement="right"> | ||
<IconButton | ||
aria-label={ariaLabel} | ||
onClick={onToggle} | ||
size="large" | ||
sx={(theme) => ({ | ||
position: "relative", | ||
background: theme.palette.background.paper, | ||
padding: theme.spacing(1), | ||
color: isToggled | ||
? theme.palette.text.disabled | ||
: theme.palette.text.primary, | ||
|
||
"&:hover": { | ||
background: theme.palette.common.white, | ||
}, | ||
})} | ||
> | ||
{icon} | ||
<Box | ||
sx={{ | ||
position: "absolute", | ||
top: "55%", | ||
left: "48%", | ||
transform: "translate(-50%, -50%)", | ||
opacity: isToggled ? 1 : 0, | ||
transition: "opacity 0.2s ease-in-out", | ||
}} | ||
> | ||
<ToggleOverlayIcon /> | ||
</Box> | ||
</IconButton> | ||
</Tooltip> | ||
); | ||
}; | ||
|
||
export default ToggleIconButton; |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { useTheme } from "@mui/material/styles"; | ||
import SvgIcon, { SvgIconProps } from "@mui/material/SvgIcon"; | ||
import * as React from "react"; | ||
|
||
export default function EditorIcon(props: SvgIconProps) { | ||
const theme = useTheme(); | ||
const inactiveColor = theme.palette.text.disabled; | ||
const overlayColor = theme.palette.background.paper; | ||
|
||
return ( | ||
<SvgIcon {...props} xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> | ||
<polygon | ||
points="0 0 1.45 0 24 22.5 24 24 22.46 24 0 1.52 0 0" | ||
fill={inactiveColor} | ||
/> | ||
<polygon | ||
points="1.45 0 4.48 0 24 19.55 24 22.5 1.45 0" | ||
fill={overlayColor} | ||
/> | ||
</SvgIcon> | ||
); | ||
} |