From ddcd19d5ebc7ca14a960adbca234ac9f85d2bdfa Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Wed, 12 Nov 2025 15:27:10 +0900 Subject: [PATCH] [Refactor] Separate SwitchBox into _atom and wrapper, add secondary label support. --- .../_atoms/_switch_box/_SwitchBox.jsx | 44 +++++++++++++++++++ .../_atoms/_switch_box/_SwitchBox.module.scss | 33 ++++++++++++++ .../_components/switch_box/SwitchBox.jsx | 41 +++-------------- .../switch_box/SwitchBox.module.scss | 34 ++++---------- .../setting_box/device/Device.jsx | 26 +++++------ .../PluginsControlComponent.jsx | 10 ++--- 6 files changed, 106 insertions(+), 82 deletions(-) create mode 100644 src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.jsx create mode 100644 src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.module.scss diff --git a/src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.jsx b/src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.jsx new file mode 100644 index 00000000..042864c1 --- /dev/null +++ b/src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.jsx @@ -0,0 +1,44 @@ +import clsx from "clsx"; +import { useState } from "react"; +import styles from "./_SwitchBox.module.scss"; + +export const _SwitchBox = (props) => { + const [is_hovered, setIsHovered] = useState(false); + const [is_mouse_down, setIsMouseDown] = useState(false); + + const is_pending = (props.variable.state === "pending"); + + const getClassNames = (base_class) => clsx(base_class, { + [styles.is_active]: (props.variable.data === true), + [styles.is_pending]: is_pending, + [styles.is_hovered]: is_hovered, + [styles.is_mouse_down]: is_mouse_down, + }); + + const onMouseEnter = () => setIsHovered(true); + const onMouseLeave = () => setIsHovered(false); + const onMouseDown = () => setIsMouseDown(true); + const onMouseUp = () => setIsMouseDown(false); + + const toggleFunction = () => { + props.toggleFunction(); + }; + + + return ( +
+
+
+ + {is_pending && } +
+
+
+ ); +}; diff --git a/src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.module.scss b/src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.module.scss new file mode 100644 index 00000000..87bf6600 --- /dev/null +++ b/src-ui/views/app/config_page/setting_section/setting_box/_components/_atoms/_switch_box/_SwitchBox.module.scss @@ -0,0 +1,33 @@ +@import "@scss_mixins"; + +.switchbox_container { + display: flex; + justify-content: end; + align-items: center; + height: 2rem; +} + +.switchbox_wrapper { + display: flex; + justify-content: center; + align-items: center; + cursor: pointer; + padding: 2rem; + height: 100%; + flex-shrink: 0; + &.is_pending { + pointer-events: none; + } +} + +.toggle_control { + position: relative; + @include toggle_control_styles; + display: flex; + justify-content: center; + align-items: center; +} + +.loader { + @include loader(2rem, 0.2rem, right, -4rem); +} \ No newline at end of file diff --git a/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.jsx b/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.jsx index 2d77a673..686d3b9b 100644 --- a/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.jsx +++ b/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.jsx @@ -1,44 +1,13 @@ import clsx from "clsx"; import { useState } from "react"; import styles from "./SwitchBox.module.scss"; +import { _SwitchBox } from "../_atoms/_switch_box/_SwitchBox"; export const SwitchBox = (props) => { - const [is_hovered, setIsHovered] = useState(false); - const [is_mouse_down, setIsMouseDown] = useState(false); - - const is_pending = (props.variable.state === "pending"); - - const getClassNames = (base_class) => clsx(base_class, { - [styles.is_active]: (props.variable.data === true), - [styles.is_pending]: is_pending, - [styles.is_hovered]: is_hovered, - [styles.is_mouse_down]: is_mouse_down, - }); - - const onMouseEnter = () => setIsHovered(true); - const onMouseLeave = () => setIsHovered(false); - const onMouseDown = () => setIsMouseDown(true); - const onMouseUp = () => setIsMouseDown(false); - - const toggleFunction = () => { - props.toggleFunction(); - }; - - return ( -
-
-
- - {is_pending && } -
-
+
+ {props.secondary_label &&

{props.secondary_label}

} + <_SwitchBox {...props} />
); -}; +}; \ No newline at end of file diff --git a/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.module.scss b/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.module.scss index 87bf6600..c07a373f 100644 --- a/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.module.scss +++ b/src-ui/views/app/config_page/setting_section/setting_box/_components/switch_box/SwitchBox.module.scss @@ -1,33 +1,17 @@ @import "@scss_mixins"; -.switchbox_container { - display: flex; - justify-content: end; - align-items: center; - height: 2rem; -} - -.switchbox_wrapper { +.container { display: flex; + flex-direction: column; justify-content: center; align-items: center; - cursor: pointer; - padding: 2rem; - height: 100%; - flex-shrink: 0; - &.is_pending { - pointer-events: none; - } + gap: 1rem; } -.toggle_control { - position: relative; - @include toggle_control_styles; - display: flex; - justify-content: center; - align-items: center; -} - -.loader { - @include loader(2rem, 0.2rem, right, -4rem); +.secondary_label { + padding-left: 0.2rem; + padding-right: 0.4rem; + font-size: 1.4rem; + color: var(--dark_500_color); + white-space: nowrap; } \ No newline at end of file diff --git a/src-ui/views/app/config_page/setting_section/setting_box/device/Device.jsx b/src-ui/views/app/config_page/setting_section/setting_box/device/Device.jsx index c40a2f8e..b9408489 100644 --- a/src-ui/views/app/config_page/setting_section/setting_box/device/Device.jsx +++ b/src-ui/views/app/config_page/setting_section/setting_box/device/Device.jsx @@ -81,14 +81,11 @@ const Mic_Container = () => {
- -
-

{t("config_page.device.label_auto_select")}

- -
+ {
- -
-

{t("config_page.device.label_auto_select")}

- -
+

{t("config_page.plugins.no_latest_info")}

- + <_SwitchBox variable={option} toggleFunction={togglePlugin} />
); } else if (plugin_status.is_latest_version_already) { @@ -98,7 +98,7 @@ const DownloadedPluginControl = ({

{latest_version_label}

{t("config_page.plugins.using_latest_version")}

- + <_SwitchBox variable={option} toggleFunction={togglePlugin} />
); } else if (plugin_status.is_latest_version_available) { @@ -107,14 +107,14 @@ const DownloadedPluginControl = ({

{latest_version_label}

{t("config_page.plugins.available_latest_version")}

<_DownloadButton option={option} downloadStartFunction={downloadStartFunction} /> - + <_SwitchBox variable={option} toggleFunction={togglePlugin} />
); } else { return (

{t("config_page.plugins.available_latest_version")}

- + <_SwitchBox variable={option} toggleFunction={togglePlugin} />
); }