From 4e421e6e9ede12d13b3bf1318ee1f29ee841d062 Mon Sep 17 00:00:00 2001 From: Arun Date: Wed, 24 Feb 2021 19:52:17 +0530 Subject: [PATCH] feat: Support exporting with dark mode (#3046) Co-authored-by: Lipis Co-authored-by: dwelle --- src/actions/actionExport.tsx | 29 +++++ src/actions/types.ts | 3 +- src/appState.ts | 2 + src/components/DarkModeToggle.tsx | 17 +-- src/components/ExportDialog.tsx | 5 + src/constants.ts | 3 + src/css/theme.scss | 3 +- src/css/variables.module.scss | 2 + src/data/index.ts | 1 + src/locales/en.json | 3 +- src/packages/utils/package.json | 2 + src/packages/utils/webpack.prod.config.js | 7 +- src/packages/utils/yarn.lock | 115 +++++++++++++++++- src/renderer/renderScene.ts | 5 + src/scene/export.ts | 12 +- src/scene/types.ts | 1 + .../regressionTests.test.tsx.snap | 67 ++++++++++ src/types.ts | 1 + 18 files changed, 264 insertions(+), 14 deletions(-) diff --git a/src/actions/actionExport.tsx b/src/actions/actionExport.tsx index b24c5e3d..cf303f79 100644 --- a/src/actions/actionExport.tsx +++ b/src/actions/actionExport.tsx @@ -5,6 +5,7 @@ import { ProjectName } from "../components/ProjectName"; import { ToolButton } from "../components/ToolButton"; import "../components/ToolIcon.scss"; import { Tooltip } from "../components/Tooltip"; +import { DarkModeToggle, Appearence } from "../components/DarkModeToggle"; import { loadFromJSON, saveAsJSON } from "../data"; import { t } from "../i18n"; import useIsMobile from "../is-mobile"; @@ -204,3 +205,31 @@ export const actionLoadScene = register({ /> ), }); + +export const actionExportWithDarkMode = register({ + name: "exportWithDarkMode", + perform: (_elements, appState, value) => { + return { + appState: { ...appState, exportWithDarkMode: value }, + commitToHistory: false, + }; + }, + PanelComponent: ({ appState, updateData }) => ( +
+ { + updateData(appearance === "dark"); + }} + title={t("labels.toggleExportColorScheme")} + /> +
+ ), +}); diff --git a/src/actions/types.ts b/src/actions/types.ts index 9d90efd8..ae1baefe 100644 --- a/src/actions/types.ts +++ b/src/actions/types.ts @@ -85,7 +85,8 @@ export type ActionName = | "alignHorizontallyCentered" | "distributeHorizontally" | "distributeVertically" - | "viewMode"; + | "viewMode" + | "exportWithDarkMode"; export interface Action { name: ActionName; diff --git a/src/appState.ts b/src/appState.ts index f77e6cff..dc418fbc 100644 --- a/src/appState.ts +++ b/src/appState.ts @@ -40,6 +40,7 @@ export const getDefaultAppState = (): Omit< errorMessage: null, exportBackground: true, exportEmbedScene: false, + exportWithDarkMode: false, fileHandle: null, gridSize: null, height: window.innerHeight, @@ -118,6 +119,7 @@ const APP_STATE_STORAGE_CONF = (< errorMessage: { browser: false, export: false }, exportBackground: { browser: true, export: false }, exportEmbedScene: { browser: true, export: false }, + exportWithDarkMode: { browser: true, export: false }, fileHandle: { browser: false, export: false }, gridSize: { browser: true, export: true }, height: { browser: false, export: false }, diff --git a/src/components/DarkModeToggle.tsx b/src/components/DarkModeToggle.tsx index 2cf7df07..06d02a64 100644 --- a/src/components/DarkModeToggle.tsx +++ b/src/components/DarkModeToggle.tsx @@ -10,13 +10,18 @@ export type Appearence = "light" | "dark"; export const DarkModeToggle = (props: { value: Appearence; onChange: (value: Appearence) => void; + title?: string; }) => { + const title = props.title + ? props.title + : props.value === "dark" + ? t("buttons.lightMode") + : t("buttons.darkMode"); + return (