-
-
Notifications
You must be signed in to change notification settings - Fork 18
Workspace top-right controls => react #7555
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andrew-polk
wants to merge
1
commit into
master
Choose a base branch
from
TopRightMenus
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/BloomBrowserUI/react_components/TopBar/workspaceTopRightControls/HelpMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import * as React from "react"; | ||
| import { BloomTooltip } from "../../BloomToolTip"; | ||
| import { ArrowDropDown, HelpOutline } from "@mui/icons-material"; | ||
| import { postJson, useApiString } from "../../../utils/bloomApi"; | ||
| import { TopRightMenuButton, topRightMenuArrowCss } from "./TopRightMenuButton"; | ||
| import { useL10n } from "../../l10nHooks"; | ||
|
|
||
| export const HelpMenu: React.FunctionComponent = () => { | ||
| const helpText = useL10n("?", "HelpMenu.Help Menu"); | ||
|
|
||
| const uiLanguage = useApiString("currentUiLanguage", "en"); | ||
|
|
||
| const showIconOnly = | ||
| helpText === "?" || ["en", "fr", "de", "es"].includes(uiLanguage); | ||
|
|
||
| const onOpen = () => { | ||
| postJson("workspace/topRight/openHelpMenu", {}); | ||
| }; | ||
|
|
||
| const button = ( | ||
| <TopRightMenuButton | ||
| text={showIconOnly ? "" : helpText} | ||
| onClick={onOpen} | ||
| startIcon={showIconOnly ? <HelpOutline /> : undefined} | ||
| endIcon={<ArrowDropDown css={topRightMenuArrowCss} />} | ||
| hasText={!showIconOnly} | ||
| /> | ||
| ); | ||
|
|
||
| if (!showIconOnly) { | ||
| return button; | ||
| } | ||
|
|
||
| return ( | ||
| <BloomTooltip tip={{ l10nKey: "HelpMenu.Help Menu" }}> | ||
| {button} | ||
| </BloomTooltip> | ||
| ); | ||
| }; |
44 changes: 44 additions & 0 deletions
44
src/BloomBrowserUI/react_components/TopBar/workspaceTopRightControls/TopRightMenuButton.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { css } from "@emotion/react"; | ||
| import * as React from "react"; | ||
| import BloomButton from "../../bloomButton"; | ||
|
|
||
| interface TopRightMenuButtonProps { | ||
| text: string; | ||
| onClick: () => void; | ||
| startIcon?: React.ReactNode; | ||
| endIcon?: React.ReactNode; | ||
| hasText?: boolean; | ||
| } | ||
|
|
||
| export const topRightMenuArrowCss = css` | ||
| font-size: 14px !important; | ||
| `; | ||
|
|
||
| export const TopRightMenuButton: React.FunctionComponent< | ||
| TopRightMenuButtonProps | ||
| > = (props) => { | ||
| return ( | ||
| <BloomButton | ||
| l10nKey="" | ||
| alreadyLocalized={true} | ||
| enabled={true} | ||
| onClick={props.onClick} | ||
| startIcon={props.startIcon} | ||
| endIcon={props.endIcon} | ||
| hasText={props.hasText === undefined ? true : props.hasText} | ||
| variant="text" | ||
| css={css` | ||
| font-size: 12px; | ||
| padding-top: 0px; | ||
| padding-bottom: 0px; | ||
| text-transform: none; | ||
| display: inline-flex; | ||
| align-items: center; | ||
| justify-content: end; | ||
| width: 100%; | ||
| `} | ||
| > | ||
| {props.text} | ||
| </BloomButton> | ||
| ); | ||
| }; | ||
20 changes: 20 additions & 0 deletions
20
src/BloomBrowserUI/react_components/TopBar/workspaceTopRightControls/UiLanguageMenu.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import * as React from "react"; | ||
| import { ArrowDropDown } from "@mui/icons-material"; | ||
| import { postJson, useApiString } from "../../../utils/bloomApi"; | ||
| import { TopRightMenuButton, topRightMenuArrowCss } from "./TopRightMenuButton"; | ||
|
|
||
| export const UiLanguageMenu: React.FunctionComponent = () => { | ||
| const label = useApiString("workspace/topRight/uiLanguageLabel", ""); | ||
|
|
||
| const onOpen = () => { | ||
| postJson("workspace/topRight/openLanguageMenu", {}); | ||
| }; | ||
|
|
||
| return ( | ||
| <TopRightMenuButton | ||
| text={label} | ||
| onClick={onOpen} | ||
| endIcon={<ArrowDropDown css={topRightMenuArrowCss} />} | ||
| /> | ||
| ); | ||
| }; |
86 changes: 86 additions & 0 deletions
86
...BrowserUI/react_components/TopBar/workspaceTopRightControls/WorkspaceTopRightControls.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { css } from "@emotion/react"; | ||
| import * as React from "react"; | ||
| import { useState } from "react"; | ||
| import { lightTheme } from "../../../bloomMaterialUITheme"; | ||
| import { createTheme, ThemeProvider } from "@mui/material/styles"; | ||
| import { WireUpForWinforms } from "../../../utils/WireUpWinform"; | ||
| import { CssBaseline } from "@mui/material"; | ||
| import { ZoomControl } from "./ZoomControl"; | ||
| import { UiLanguageMenu } from "./UiLanguageMenu"; | ||
| import { HelpMenu } from "./HelpMenu"; | ||
| import { kTextOnPurple } from "../../../bloomMaterialUITheme"; | ||
| import { useSubscribeToWebSocketForStringMessage } from "../../../utils/WebSocketManager"; | ||
|
|
||
| export const WorkspaceTopRightControls: React.FunctionComponent = () => { | ||
| const lightThemeOverride = React.useMemo( | ||
| () => | ||
| createTheme(lightTheme, { | ||
| components: { | ||
| // kTextOnPurple: The background isn't always purple, | ||
| // but this matches what the original winforms control was doing. | ||
| // Without the override, we get Bloom blue. | ||
| MuiButton: { | ||
| styleOverrides: { | ||
| root: { | ||
| color: kTextOnPurple, | ||
| fontWeight: "normal", | ||
| }, | ||
| text: { | ||
| color: kTextOnPurple, | ||
| fontWeight: "normal", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| [], | ||
| ); | ||
|
|
||
| // Forces a refresh. Currently used for localization changes. | ||
| const [generation, setGeneration] = useState(0); | ||
| useSubscribeToWebSocketForStringMessage("app", "uiLanguageChanged", () => { | ||
| setGeneration((current) => current + 1); | ||
| }); | ||
|
|
||
| return ( | ||
| <ThemeProvider theme={lightThemeOverride}> | ||
| {/* CssBaseline injects MUI's base styles (it sets html/body to the theme typography, | ||
| normalizes margins, etc.). Without it, the browser keeps default fonts and spacing, | ||
| so our theme's font family/size and resets never reach this control. */} | ||
| <CssBaseline /> | ||
| <div | ||
| key={`workspace-top-right-controls-${generation}`} | ||
| css={css` | ||
| display: flex; | ||
| flex-direction: column; | ||
| gap: 1px; | ||
| align-items: end; | ||
| font-size: 12px; | ||
|
|
||
| // kTextOnPurple: see comment above | ||
| color: ${kTextOnPurple}; | ||
| button { | ||
| color: ${kTextOnPurple}; | ||
| } | ||
| `} | ||
| > | ||
| {/* This grid keeps the two menu buttons the same width which keeps the down arrows aligned horizontally */} | ||
| <div | ||
| css={css` | ||
| display: grid; | ||
| grid-template-columns: 1fr; | ||
| grid-auto-rows: auto; | ||
| width: max-content; | ||
| row-gap: 1px; | ||
| `} | ||
| > | ||
| <UiLanguageMenu /> | ||
| <HelpMenu /> | ||
| </div> | ||
| <ZoomControl /> | ||
| </div> | ||
| </ThemeProvider> | ||
| ); | ||
| }; | ||
|
|
||
| WireUpForWinforms(WorkspaceTopRightControls); |
96 changes: 96 additions & 0 deletions
96
src/BloomBrowserUI/react_components/TopBar/workspaceTopRightControls/ZoomControl.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { css } from "@emotion/react"; | ||
| import * as React from "react"; | ||
| import { useEffect, useState } from "react"; | ||
| import BloomButton from "../../bloomButton"; | ||
| import { get, postJson } from "../../../utils/bloomApi"; | ||
| import { useSubscribeToWebSocketForObject } from "../../../utils/WebSocketManager"; | ||
|
|
||
| interface IZoomInfo { | ||
| zoom: number; | ||
| minZoom: number; | ||
| maxZoom: number; | ||
| zoomEnabled: boolean; | ||
| } | ||
|
|
||
| export const ZoomControl: React.FunctionComponent = () => { | ||
| const [zoomInfo, setZoomInfo] = useState<IZoomInfo | undefined>(undefined); | ||
|
|
||
| // Fetch zoom info once on initial load. | ||
| useEffect(() => { | ||
| get("workspace/topRight/zoom", (result) => { | ||
| const zoomInfo = result.data as IZoomInfo; | ||
| setZoomInfo(zoomInfo); | ||
| }); | ||
| }, []); | ||
| // Get subsequent updates via WebSocket. | ||
| useSubscribeToWebSocketForObject( | ||
| "workspaceTopRightControls", | ||
| "zoom", | ||
| setZoomInfo, | ||
| ); | ||
|
|
||
| const clampZoom = (value: number, current: IZoomInfo) => { | ||
| return Math.min(Math.max(value, current.minZoom), current.maxZoom); | ||
| }; | ||
|
|
||
| const applyDelta = (delta: number) => { | ||
| if (!zoomInfo) { | ||
| return; | ||
| } | ||
| const clamped = clampZoom(zoomInfo.zoom + delta, zoomInfo); | ||
| setZoomInfo({ ...zoomInfo, zoom: clamped }); | ||
| postJson("workspace/topRight/zoom", { zoom: clamped }); | ||
| }; | ||
|
|
||
| if (!zoomInfo || !zoomInfo.zoomEnabled) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| css={css` | ||
| display: flex; | ||
| align-items: center; | ||
| gap: 8px; | ||
| `} | ||
| > | ||
| <PlusMinusButton label="–" onClick={() => applyDelta(-10)} /> | ||
|
|
||
| <span | ||
| css={css` | ||
| cursor: default; // Don't want the user to think he can type | ||
| `} | ||
| >{`${zoomInfo.zoom}%`}</span> | ||
|
|
||
| <PlusMinusButton label="+" onClick={() => applyDelta(10)} /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| interface PlusMinusButtonProps { | ||
| label: string; | ||
| onClick: () => void; | ||
| } | ||
|
|
||
| const PlusMinusButton: React.FunctionComponent<PlusMinusButtonProps> = ( | ||
| props, | ||
| ) => { | ||
| return ( | ||
| <BloomButton | ||
| l10nKey="" | ||
| alreadyLocalized={true} | ||
| enabled={true} | ||
| transparent={true} | ||
| hasText={true} | ||
| onClick={props.onClick} | ||
| css={css` | ||
| font-size: 18px; | ||
| border: none; | ||
| background-color: transparent; | ||
| cursor: pointer; | ||
| `} | ||
| > | ||
| {props.label} | ||
| </BloomButton> | ||
| ); | ||
| }; |
4 changes: 4 additions & 0 deletions
4
...rUI/react_components/TopBar/workspaceTopRightControls/workspaceTopRightControls.entry.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { bootstrapReactComponent } from "../../../utils/entryPointBootstrap"; | ||
| import { WorkspaceTopRightControls } from "./WorkspaceTopRightControls"; | ||
|
|
||
| bootstrapReactComponent(WorkspaceTopRightControls); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use
flex-endinstead ofendfor broader compatibility.Line 37 uses
justify-content: end, but the standard flexbox value isflex-end. While modern browsers supportend, usingflex-endensures compatibility with older browsers.🔎 Proposed fix
display: inline-flex; align-items: center; - justify-content: end; + justify-content: flex-end; width: 100%;📝 Committable suggestion
🤖 Prompt for AI Agents