app: Move docs button component.

Everything is visually unchanged. This just moves the button logic to the app, since it doesn't conceptually belong to the editor component.

It controls things such as docs which has nothing to do with the editor. This way we don't have to pass states as props around when we add more buttons later.
This commit is contained in:
Laurens Valk
2026-03-30 14:24:49 +02:00
parent c3a703f3b3
commit 7e4a9b94d5
6 changed files with 30 additions and 39 deletions
+16 -2
View File
@@ -3,7 +3,8 @@
import 'react-splitter-layout/lib/index.css';
import './app.scss';
import { Classes, Spinner } from '@blueprintjs/core';
import { Button, Classes, Spinner } from '@blueprintjs/core';
import { Manual } from '@blueprintjs/icons';
import React, { useEffect, useState } from 'react';
import SplitterLayout from 'react-splitter-layout';
import { useLocalStorage, useTernaryDarkMode } from 'usehooks-ts';
@@ -71,7 +72,8 @@ const Docs: React.FunctionComponent = () => {
const App: React.FunctionComponent = () => {
const i18n = useI18n();
const { isDarkMode } = useTernaryDarkMode();
const { isSettingShowDocsEnabled } = useSettingIsShowDocsEnabled();
const { isSettingShowDocsEnabled, toggleIsSettingShowDocsEnabled } =
useSettingIsShowDocsEnabled();
const [isDragging, setIsDragging] = useState(false);
const [docsSplit, setDocsSplit] = useLocalStorage('app-docs-split', 30);
@@ -140,6 +142,18 @@ const App: React.FunctionComponent = () => {
>
<Editor />
</React.Suspense>
<Button
className="pb-app-doc-button"
minimal
large
icon={<Manual />}
title={
isSettingShowDocsEnabled
? i18n.translate('docs.hide')
: i18n.translate('docs.show')
}
onClick={toggleIsSettingShowDocsEnabled}
/>
</main>
<aside
className="pb-app-terminal"
+8
View File
@@ -71,6 +71,7 @@
height: 100%;
display: flex;
flex-direction: column;
position: relative;
& .pb-editor {
min-height: 0;
@@ -78,6 +79,13 @@
}
}
.pb-app-doc-button {
position: absolute;
bottom: bp.$pt-grid-size;
right: bp.$pt-grid-size;
z-index: bp.$pt-z-index-overlay;
}
$splitter-background-color: bp.$light-gray2;
$splitter-background-color-hover: bp.$gray4;
$dark-splitter-background-color: bp.$dark-gray5;
+4
View File
@@ -4,5 +4,9 @@
"editor": "Editor",
"terminal": "Terminal",
"documentation": "Documentation"
},
"docs": {
"show": "Show documentation",
"hide": "Hide documentation"
}
}
+1 -24
View File
@@ -16,15 +16,7 @@ import {
Tabs,
Text,
} from '@blueprintjs/core';
import {
Blank,
Clipboard,
Cross,
Duplicate,
Manual,
Redo,
Undo,
} from '@blueprintjs/icons';
import { Blank, Clipboard, Cross, Duplicate, Redo, Undo } from '@blueprintjs/icons';
import classNames from 'classnames';
import * as monaco from 'monaco-editor';
import tomorrowNightEightiesTheme from 'monaco-themes/themes/Tomorrow-Night-Eighties.json';
@@ -37,7 +29,6 @@ import { UUID } from '../fileStorage';
import { useFileStoragePath } from '../fileStorage/hooks';
import { compile } from '../mpy/actions';
import { useSelector } from '../reducers';
import { useSettingIsShowDocsEnabled } from '../settings/hooks';
import { isMacOS } from '../utils/os';
import Welcome from './Welcome';
import { editorActivateFile, editorCloseFile } from './actions';
@@ -387,8 +378,6 @@ const Editor: React.FunctionComponent = () => {
const dispatch = useDispatch();
const [editor, setEditor] = useState<monaco.editor.IStandaloneCodeEditor>();
const { isSettingShowDocsEnabled, toggleIsSettingShowDocsEnabled } =
useSettingIsShowDocsEnabled();
const { isDarkMode } = useTernaryDarkMode();
const i18n = useI18n();
@@ -510,18 +499,6 @@ const Editor: React.FunctionComponent = () => {
<div className="pb-editor-monaco" ref={editorRef} />
</ContextMenu>
</ResizeSensor>
<Button
className="pb-editor-doc-button"
minimal
large
icon={<Manual />}
title={
isSettingShowDocsEnabled
? i18n.translate('docs.hide')
: i18n.translate('docs.show')
}
onClick={toggleIsSettingShowDocsEnabled}
/>
</div>
);
};
-7
View File
@@ -93,13 +93,6 @@
color: bp.$pt-dark-text-color-muted;
}
}
&-doc-button {
position: absolute;
bottom: bp.$pt-grid-size;
right: bp.$pt-grid-size;
z-index: bp.$pt-z-index-overlay;
}
}
.monaco-editor {
+1 -6
View File
@@ -5,16 +5,11 @@
"welcome": "Welcome",
"placeholder": "Write your program here...",
"check": "Check syntax",
"toggleDocs": "Toggle documentation",
"copy": "Copy",
"paste": "Paste",
"selectAll": "Select all",
"undo": "Undo",
"redo": "Redo",
"closeFile": { "tooltip": "Close {fileName}" },
"contextMenu": { "label": "Editor context menu" },
"docs": {
"show": "Show documentation",
"hide": "Hide documentation"
}
"contextMenu": { "label": "Editor context menu" }
}