From 6c551650d09adb07753dafc3a777e95c5ed5997a Mon Sep 17 00:00:00 2001 From: Lewis Crichton Date: Sun, 14 Jan 2024 16:24:40 +0000 Subject: [PATCH] feat: add reset to default button --- src/api/Settings.ts | 2 +- src/components/Icons.tsx | 19 +++++++++ src/components/ThemeSettings/UserCSSModal.tsx | 40 ++++++++++++++----- 3 files changed, 50 insertions(+), 11 deletions(-) diff --git a/src/api/Settings.ts b/src/api/Settings.ts index 887d9d4c4..8a27d1bed 100644 --- a/src/api/Settings.ts +++ b/src/api/Settings.ts @@ -77,7 +77,7 @@ export interface Settings { }; userCssVars: { - [fileName: string]: { + [themeId: string]: { [varName: string]: string; }; }; diff --git a/src/components/Icons.tsx b/src/components/Icons.tsx index 3d7504f8a..4ff2d9fcf 100644 --- a/src/components/Icons.tsx +++ b/src/components/Icons.tsx @@ -326,3 +326,22 @@ export function PasteIcon(props: IconProps) { ); } + +export function ResetIcon(props: IconProps) { + return ( + + + + + ); +} diff --git a/src/components/ThemeSettings/UserCSSModal.tsx b/src/components/ThemeSettings/UserCSSModal.tsx index 100005a90..3ac4738e7 100644 --- a/src/components/ThemeSettings/UserCSSModal.tsx +++ b/src/components/ThemeSettings/UserCSSModal.tsx @@ -6,7 +6,7 @@ import { Settings, useSettings } from "@api/Settings"; import { Flex } from "@components/Flex"; -import { CopyIcon, PasteIcon } from "@components/Icons"; +import { CopyIcon, PasteIcon, ResetIcon } from "@components/Icons"; import { copyWithToast } from "@utils/misc"; import { ModalCloseButton, ModalContent, ModalHeader, ModalProps, ModalRoot } from "@utils/modal"; import { showToast, Text, Toasts, Tooltip } from "@webpack/common"; @@ -73,9 +73,28 @@ function ImportButton({ themeSettings }: { themeSettings: Settings["userCssVars" ; } +function ResetButton({ themeSettings, themeId }: { themeSettings: Settings["userCssVars"]; themeId: string; }) { + return + {({ onMouseLeave, onMouseEnter }) => ( +
{ + delete themeSettings[themeId]; + }}> + +
+ )} +
; +} + export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModalProps) { // @ts-expect-error UseSettings<> can't determine this is a valid key - const themeSettings = useSettings(["userCssVars"], false).userCssVars[theme.id]; + const { userCssVars } = useSettings(["userCssVars"], false); + + const themeVars = userCssVars[theme.id]; const controls: ReactNode[] = []; @@ -86,7 +105,7 @@ export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModal ); break; @@ -97,7 +116,7 @@ export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModal ); break; @@ -108,7 +127,7 @@ export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModal ); break; @@ -119,7 +138,7 @@ export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModal ); break; @@ -132,7 +151,7 @@ export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModal name={name} options={varInfo.options} default={varInfo.default} - themeSettings={themeSettings} + themeSettings={themeVars} /> ); break; @@ -147,7 +166,7 @@ export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModal min={varInfo.min} max={varInfo.max} step={varInfo.step} - themeSettings={themeSettings} + themeSettings={themeVars} /> ); break; @@ -160,8 +179,9 @@ export function UserCSSSettingsModal({ modalProps, theme }: UserCSSSettingsModal Settings for {theme.name} - - + + +