From 04d89c970d67137bf2a187728c9bc60c7081dc43 Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Thu, 18 Aug 2022 16:54:28 +0300 Subject: [PATCH] Use new inside deprecated material switcher Signed-off-by: Alex Andreev --- .../components/switch/form-switcher.tsx | 16 ++--- src/renderer/components/switch/switcher.tsx | 65 +++---------------- 2 files changed, 17 insertions(+), 64 deletions(-) diff --git a/src/renderer/components/switch/form-switcher.tsx b/src/renderer/components/switch/form-switcher.tsx index 8f2a8a231c..4d256ddca8 100644 --- a/src/renderer/components/switch/form-switcher.tsx +++ b/src/renderer/components/switch/form-switcher.tsx @@ -7,6 +7,7 @@ import React from "react"; import type { FormControlLabelProps } from "@material-ui/core/FormControlLabel"; import FormControlLabel from "@material-ui/core/FormControlLabel"; import { makeStyles } from "@material-ui/styles"; +import { Switch } from "./switch"; const useStyles = makeStyles({ root: { @@ -23,15 +24,12 @@ const useStyles = makeStyles({ /** * @deprecated Use instead from "../switch.tsx". */ -export function FormSwitch(props: FormControlLabelProps) { +export function FormSwitch(props: FormControlLabelProps & { children?: React.ReactNode }) { const classes = useStyles(); - return ( - - ); + const ClonedElement = React.cloneElement(props.control, { + children: props.label, + }); + + return ClonedElement; } diff --git a/src/renderer/components/switch/switcher.tsx b/src/renderer/components/switch/switcher.tsx index 21b2cddb22..39f3b7eb13 100644 --- a/src/renderer/components/switch/switcher.tsx +++ b/src/renderer/components/switch/switcher.tsx @@ -4,10 +4,8 @@ */ import React from "react"; -import type { Theme } from "@material-ui/core/styles"; -import { createStyles, withStyles } from "@material-ui/core/styles"; import type { SwitchClassKey, SwitchProps } from "@material-ui/core/Switch"; -import Switch from "@material-ui/core/Switch"; +import { Switch } from "./switch"; interface Styles extends Partial> { focusVisible?: string; @@ -15,64 +13,21 @@ interface Styles extends Partial> { export interface SwitcherProps extends SwitchProps { classes: Styles; + children?: React.ReactNode; } /** * @deprecated Use instead from "../switch.tsx". */ -export const Switcher = withStyles((theme: Theme) => - createStyles({ - root: { - width: 40, - height: 24, - padding: 0, - margin: "0 0 0 8px", - }, - switchBase: { - padding: 1, - paddingLeft: 4, - "&$checked": { - transform: "translateX(14px)", - color: "white", - "& + $track": { - backgroundColor: "#52d869", - opacity: 1, - border: "none", - }, - }, - "&$focusVisible $thumb": { - color: "#52d869", - border: "6px solid #fff", - }, - }, - thumb: { - width: 18, - height: 18, - marginTop: 2, - boxShadow: "none", - }, - track: { - borderRadius: 26 / 2, - backgroundColor: "#72767b", - opacity: 1, - transition: theme.transitions.create(["background-color", "border"]), - }, - checked: {}, - focusVisible: {}, - }), -)(({ classes, ...props }: SwitcherProps) => { +export const Switcher = () => (({ disabled, checked, onChange, name, children }: SwitcherProps) => { return ( + disabled={disabled} + checked={checked} + name={name} + onChange={(checked, event) => onChange?.(event, checked)} + > + {children} + ); });