From 7af2ad29ff2d52d71ca0330ddbfdf684dbf164ae Mon Sep 17 00:00:00 2001 From: Alex Andreev Date: Mon, 27 Dec 2021 15:48:17 +0300 Subject: [PATCH] Cleaning up Signed-off-by: Alex Andreev --- .../components/switch/switch.module.scss | 14 +++++----- src/renderer/components/switch/switch.tsx | 27 +++++-------------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/renderer/components/switch/switch.module.scss b/src/renderer/components/switch/switch.module.scss index ef15eeceea..874555a7c9 100644 --- a/src/renderer/components/switch/switch.module.scss +++ b/src/renderer/components/switch/switch.module.scss @@ -29,6 +29,11 @@ --track-color-inactive: hsl(80 0% 35%); --track-color-active: hsl(110, 60%, 60%); + --thumb-position: 0%; + --thumb-transition-duration: .25s; + + --hover-highlight-size: 0; + display: flex; align-items: center; gap: 2ch; @@ -39,9 +44,6 @@ font-weight: 500; & > input { - --thumb-position: 0%; - --thumb-transition-duration: .25s; - padding: var(--track-padding); background: var(--track-color-inactive); inline-size: var(--track-size); @@ -62,8 +64,6 @@ transition: background-color .25s ease; &::before { - --highlight-size: 0; - content: ""; cursor: pointer; pointer-events: auto; @@ -71,7 +71,7 @@ inline-size: var(--thumb-size); block-size: var(--thumb-size); background: var(--thumb-color); - box-shadow: 0 0 0 var(--highlight-size) var(--thumb-color-highlight); + box-shadow: 0 0 0 var(--hover-highlight-size) var(--thumb-color-highlight); border-radius: 50%; transform: translateX(var(--thumb-position)); transition: @@ -80,7 +80,7 @@ } &:not(:disabled):hover::before { - --highlight-size: .5rem; + --hover-highlight-size: .5rem; } &:checked { diff --git a/src/renderer/components/switch/switch.tsx b/src/renderer/components/switch/switch.tsx index 926d39d6a2..4a0c11a1c0 100644 --- a/src/renderer/components/switch/switch.tsx +++ b/src/renderer/components/switch/switch.tsx @@ -21,33 +21,18 @@ import styles from "./switch.module.scss"; -import React, { DetailedHTMLProps, InputHTMLAttributes } from "react"; +import React from "react"; import { cssNames } from "../../utils"; -interface Props extends DetailedHTMLProps, HTMLInputElement> { - onClick?: () => void; +interface Props extends React.HTMLProps { + onChange?: (event: React.ChangeEvent) => void; } -export function Switch({ children, onClick, ...settings }: Props) { - const id = `switch-${Date.now()}`; - - const onLabelClick = () => { - if (settings.disabled || !onClick) { - return; - } - - onClick(); - }; - +export function Switch({ children, disabled, ...props }: Props) { return ( -