From d06784958d73159b5e4abafe5114804662114ed7 Mon Sep 17 00:00:00 2001 From: Ryan Schanzenbacher Date: Thu, 9 Jul 2026 22:15:53 -0400 Subject: move ubersicht modules in tree --- .../lib/components/settings/settings-widgets.jsx | 180 +++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100755 users/ryan/modules/simple-bar/simple-bar-source/lib/components/settings/settings-widgets.jsx (limited to 'users/ryan/modules/simple-bar/simple-bar-source/lib/components/settings/settings-widgets.jsx') diff --git a/users/ryan/modules/simple-bar/simple-bar-source/lib/components/settings/settings-widgets.jsx b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/settings/settings-widgets.jsx new file mode 100755 index 0000000..736e4bb --- /dev/null +++ b/users/ryan/modules/simple-bar/simple-bar-source/lib/components/settings/settings-widgets.jsx @@ -0,0 +1,180 @@ +import * as Uebersicht from "uebersicht"; +import * as Icons from "../icons/icons.jsx"; +import * as Utils from "../../utils"; +import * as Settings from "../../settings"; +import SettingsInner from "./settings-inner.jsx"; + +const { React } = Uebersicht; + +const settingsKeys = { + batteryWidget: "batteryWidgetOptions", + browserTrackWidget: "browserTrackWidgetOptions", + cpuWidget: "cpuWidgetOptions", + cryptoWidget: "cryptoWidgetOptions", + dateWidget: "dateWidgetOptions", + gpuWidget: "gpuWidgetOptions", + memoryWidget: "memoryWidgetOptions", + keyboardWidget: "keyboardWidgetOptions", + micWidget: "micWidgetOptions", + mpdWidget: "mpdWidgetOptions", + musicWidget: "musicWidgetOptions", + netstatsWidget: "netstatsWidgetOptions", + nextMeetingWidget: "nextMeetingWidgetOptions", + notificationsWidget: "notificationsWidgetOptions", + soundWidget: "soundWidgetOptions", + spotifyWidget: "spotifyWidgetOptions", + stockWidget: "stockWidgetOptions", + timeWidget: "timeWidgetOptions", + vpnWidget: "vpnWidgetOptions", + githubWidget: "githubWidgetOptions", + weatherWidget: "weatherWidgetOptions", + wifiWidget: "networkWidgetOptions", + youtubeMusicWidget: "youtubeMusicWidgetOptions", + zoomWidget: "zoomWidgetOptions", + userWidgets: "userWidgets", +}; + +/** + * SettingsWidgets component to render widgets setting category. + * @param {Object} props - Component properties. + * @param {Object} props.newSettings - Object containing current modified settings. + * @param {Function} props.setNewSettings - Function allowing to save newly modified settings. + */ +export default function SettingsWidgets({ newSettings, setNewSettings }) { + const [currentWidget, setCurrentWidget] = React.useState(null); + const currentSetting = Settings.data[currentWidget]; + + /** + * Removes the current widget setting, + */ + const removeCurrentWidget = () => { + setCurrentWidget(null); + }; + + /** + * Prevent checkbox click from propagating to the parent element, + * allowing to avoid triggering the widget selection. + */ + const handleCheckboxClick = (e) => { + e.stopPropagation(); + Utils.clickEffect(e); + }; + + /** + * Updates the current widget based on the clicked element. + * @param {string} widget - The key of the widget to update. + */ + const updateCurrentWidget = (widget) => (e) => { + if (widget === "processWidget") return; + + Utils.clickEffect(e); + const widgetKey = settingsKeys[widget]; + setCurrentWidget(currentWidget === widgetKey ? null : widgetKey); + }; + + return ( +
+ + {!currentWidget ? ( +
+
+ Custom widgets + +
+ {Object.keys(Settings.defaultSettings.widgets).map((subKey) => { + const subSetting = Settings.data[subKey]; + if (!subSetting) return null; + const { label } = subSetting; + const defaultValue = newSettings.widgets[subKey]; + const isProcess = subKey === "processWidget"; + + const classes = Utils.classNames("settings__widgets-item", { + "settings__widgets-item--process": isProcess, + }); + + const onChange = (e) => { + const value = e.target.checked; + + const updatedSettings = { + ...newSettings, + widgets: { ...newSettings.widgets, [subKey]: value }, + }; + setNewSettings(updatedSettings); + }; + + return ( +
+ + {label} + {!isProcess && ( + + )} +
+ ); + })} +
+ ) : ( +
+ +
+ )} +
+ ); +} + +/** + * SettingsWidgets component to render widgets setting category. + * @param {Object} props - Component properties. + * @param {Object} props.currentSetting - Object containing the current setting. + * @param {Function} props.removeCurrentWidget - Function removing the current setting allowing to go back to widget list. + */ +function Breadcrumb({ currentSetting, removeCurrentWidget }) { + if (!currentSetting) { + return ( +
+
Widgets
+
+ ); + } + const { label } = currentSetting; + return ( +
+ + + {">"} {label} + + +
+ ); +} -- cgit v1.3