diff --git a/themebuilder/src/components/ThemeEditorToolbar.tsx b/themebuilder/src/components/ThemeEditorToolbar.tsx index 29d049333344..40d55dc52899 100644 --- a/themebuilder/src/components/ThemeEditorToolbar.tsx +++ b/themebuilder/src/components/ThemeEditorToolbar.tsx @@ -3,7 +3,7 @@ import * as auth from "../services/authClient"; import css from "./styling/ThemeEditor.module.scss"; import { AppStateContext } from "../state/appStateContext"; import { BaseThemePicker } from "./BaseThemePicker"; -import { exportTheme } from "../services/fileSystemService"; +import { exportTheme, importThemeFromFileAsync } from "../services/fileSystemService"; import { Button } from "react-common/components/controls/Button"; import { classList } from "react-common/components/util"; import { ThemeManager } from "react-common/components/theming/themeManager"; @@ -21,6 +21,7 @@ export const ThemeEditorToolbar = () => { fgColor: "var(--pxt-neutral-foreground1)", }; const { state } = React.useContext(AppStateContext); + const fileInputRef = React.useRef(null); const { editingTheme } = state; const [saveState, setSaveState] = React.useState(defaultSaveState); @@ -36,6 +37,13 @@ export const ThemeEditorToolbar = () => { exportTheme(editingTheme); } + function handleImportFromFile(event: React.ChangeEvent) { + const file = event.target.files?.[0]; + if (file) { + importThemeFromFileAsync(file); + } + } + async function handleSaveToProfileClicked() { if (!editingTheme) return; @@ -81,6 +89,21 @@ export const ThemeEditorToolbar = () => { borderColor: saveState.fgColor, }} /> + {/* The button triggers a hidden file input to open the file browser */} +