From 1d287357ca33f8bdd9933a27dc5ea63a8f29e2f8 Mon Sep 17 00:00:00 2001 From: Ven Date: Sun, 15 Jan 2023 22:26:02 +0100 Subject: Reimplement Discord's Switch to fix performance (#413) --- src/components/Switch.tsx | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/components/Switch.tsx (limited to 'src/components/Switch.tsx') diff --git a/src/components/Switch.tsx b/src/components/Switch.tsx new file mode 100644 index 0000000..a18a7e4 --- /dev/null +++ b/src/components/Switch.tsx @@ -0,0 +1,76 @@ +/* + * Vencord, a modification for Discord's desktop app + * Copyright (c) 2023 Vendicated and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +import "./Switch.css"; + +import { findByPropsLazy } from "@webpack"; + +interface SwitchProps { + checked: boolean; + onChange: (checked: boolean) => void; + disabled?: boolean; +} + +const SWITCH_ON = "var(--status-green-600)"; +const SWITCH_OFF = "var(--primary-dark-400)"; +const SwitchClasses = findByPropsLazy("slider", "input", "container"); + +export function Switch({ checked, onChange, disabled }: SwitchProps) { + return ( +
+
+ + onChange(e.currentTarget.checked)} + /> +
+
+ ); +} -- cgit