feat: Add shortcut for dark mode (#3543)

* Create and move toggle into an action

* Add shortcut on help dialog
This commit is contained in:
Arun 2021-05-08 15:17:30 +05:30 committed by GitHub
parent 178ee04d82
commit 198800136e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 36 additions and 13 deletions

View File

@ -3,6 +3,7 @@ import { getDefaultAppState } from "../appState";
import { ColorPicker } from "../components/ColorPicker"; import { ColorPicker } from "../components/ColorPicker";
import { resetZoom, trash, zoomIn, zoomOut } from "../components/icons"; import { resetZoom, trash, zoomIn, zoomOut } from "../components/icons";
import { ToolButton } from "../components/ToolButton"; import { ToolButton } from "../components/ToolButton";
import { DarkModeToggle } from "../components/DarkModeToggle";
import { ZOOM_STEP } from "../constants"; import { ZOOM_STEP } from "../constants";
import { getCommonBounds, getNonDeletedElements } from "../element"; import { getCommonBounds, getNonDeletedElements } from "../element";
import { newElementWith } from "../element/mutateElement"; import { newElementWith } from "../element/mutateElement";
@ -260,3 +261,27 @@ export const actionZoomToFit = register({
!event.altKey && !event.altKey &&
!event[KEYS.CTRL_OR_CMD], !event[KEYS.CTRL_OR_CMD],
}); });
export const actionToggleTheme = register({
name: "toggleTheme",
perform: (_, appState, value) => {
return {
appState: {
...appState,
theme: value || (appState.theme === "light" ? "dark" : "light"),
},
commitToHistory: false,
};
},
PanelComponent: ({ appState, updateData }) => (
<div style={{ marginInlineStart: "0.25rem" }}>
<DarkModeToggle
value={appState.theme}
onChange={(theme) => {
updateData(theme);
}}
/>
</div>
),
keyTest: (event) => event.altKey && event.shiftKey && event.code === CODES.D,
});

View File

@ -26,6 +26,7 @@ export {
actionZoomOut, actionZoomOut,
actionResetZoom, actionResetZoom,
actionZoomToFit, actionZoomToFit,
actionToggleTheme,
} from "./actionCanvas"; } from "./actionCanvas";
export { actionFinalize } from "./actionFinalize"; export { actionFinalize } from "./actionFinalize";

View File

@ -98,7 +98,8 @@ export type ActionName =
| "flipHorizontal" | "flipHorizontal"
| "flipVertical" | "flipVertical"
| "viewMode" | "viewMode"
| "exportWithDarkMode"; | "exportWithDarkMode"
| "toggleTheme";
export interface Action { export interface Action {
name: ActionName; name: ActionName;

View File

@ -1,7 +1,6 @@
import React from "react"; import React from "react";
import { ActionManager } from "../actions/manager"; import { ActionManager } from "../actions/manager";
import { AppState } from "../types"; import { AppState } from "../types";
import { DarkModeToggle } from "./DarkModeToggle";
export const BackgroundPickerAndDarkModeToggle = ({ export const BackgroundPickerAndDarkModeToggle = ({
appState, appState,
@ -16,15 +15,6 @@ export const BackgroundPickerAndDarkModeToggle = ({
}) => ( }) => (
<div style={{ display: "flex" }}> <div style={{ display: "flex" }}>
{actionManager.renderAction("changeViewBackgroundColor")} {actionManager.renderAction("changeViewBackgroundColor")}
{showThemeBtn && ( {showThemeBtn && <>{actionManager.renderAction("toggleTheme")}</>}
<div style={{ marginInlineStart: "0.25rem" }}>
<DarkModeToggle
value={appState.theme}
onChange={(theme) => {
setAppState({ theme });
}}
/>
</div>
)}
</div> </div>
); );

View File

@ -231,6 +231,10 @@ export const HelpDialog = ({ onClose }: { onClose?: () => void }) => {
label={t("labels.viewMode")} label={t("labels.viewMode")}
shortcuts={[getShortcutKey("Alt+R")]} shortcuts={[getShortcutKey("Alt+R")]}
/> />
<Shortcut
label={t("labels.toggleTheme")}
shortcuts={[getShortcutKey("Alt+Shift+D")]}
/>
</ShortcutIsland> </ShortcutIsland>
</Column> </Column>
<Column> <Column>

View File

@ -15,6 +15,7 @@ export const CODES = {
QUOTE: "Quote", QUOTE: "Quote",
ZERO: "Digit0", ZERO: "Digit0",
C: "KeyC", C: "KeyC",
D: "KeyD",
G: "KeyG", G: "KeyG",
F: "KeyF", F: "KeyF",
H: "KeyH", H: "KeyH",

View File

@ -96,7 +96,8 @@
"flipVertical": "Flip vertical", "flipVertical": "Flip vertical",
"viewMode": "View mode", "viewMode": "View mode",
"toggleExportColorScheme": "Toggle export color scheme", "toggleExportColorScheme": "Toggle export color scheme",
"share": "Share" "share": "Share",
"toggleTheme": "Toggle theme"
}, },
"buttons": { "buttons": {
"clearReset": "Reset the canvas", "clearReset": "Reset the canvas",