Compare commits

...

2 Commits

Author SHA1 Message Date
zsviczian
4c39abf07f languageList moved out of canvasActions and renamed to showLanguageList 2022-11-04 19:57:22 +01:00
zsviczian
02c1236962 Package configuration options 2022-11-04 19:39:12 +01:00
6 changed files with 81 additions and 17 deletions

View File

@ -516,6 +516,7 @@ class App extends React.Component<AppProps, AppState> {
const {
onCollabButtonClick,
renderTopRightUI,
renderMenuLinks,
renderFooter,
renderCustomStats,
} = this.props;
@ -562,6 +563,7 @@ class App extends React.Component<AppProps, AppState> {
langCode={getLanguage().code}
isCollaborating={this.props.isCollaborating}
renderTopRightUI={renderTopRightUI}
renderMenuLinks={renderMenuLinks}
renderCustomFooter={renderFooter}
renderCustomStats={renderCustomStats}
renderCustomSidebar={this.props.renderSidebar}
@ -576,6 +578,7 @@ class App extends React.Component<AppProps, AppState> {
id={this.id}
onImageAction={this.onImageAction}
renderWelcomeScreen={
this.props.hideWelcomeScreen !== true &&
this.state.showWelcomeScreen &&
this.state.activeTool.type === "selection" &&
!this.scene.getElementsIncludingDeleted().length

View File

@ -71,6 +71,7 @@ interface LayerUIProps {
langCode: Language["code"];
isCollaborating: boolean;
renderTopRightUI?: ExcalidrawProps["renderTopRightUI"];
renderMenuLinks?: ExcalidrawProps["renderMenuLinks"];
renderCustomFooter?: ExcalidrawProps["renderFooter"];
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
renderCustomSidebar?: ExcalidrawProps["renderSidebar"];
@ -96,6 +97,7 @@ const LayerUI = ({
showExitZenModeBtn,
isCollaborating,
renderTopRightUI,
renderMenuLinks,
renderCustomFooter,
renderCustomStats,
renderCustomSidebar,
@ -218,7 +220,8 @@ const LayerUI = ({
actionManager.renderAction("loadScene")}
{/* // TODO barnabasmolnar/editor-redesign */}
{/* is this fine here? */}
{appState.fileHandle &&
{UIOptions.canvasActions.saveToActiveFile &&
appState.fileHandle &&
actionManager.renderAction("saveToActiveFile")}
{renderJSONExportDialog()}
{UIOptions.canvasActions.saveAsImage && (
@ -240,8 +243,16 @@ const LayerUI = ({
{actionManager.renderAction("toggleShortcuts", undefined, true)}
{!appState.viewModeEnabled &&
actionManager.renderAction("clearCanvas")}
<Separator />
<MenuLinks />
{typeof renderMenuLinks === "undefined" ? ( //zsviczian
<Separator />
) : (
renderMenuLinks && <Separator />
)}
{typeof renderMenuLinks === "undefined" ? ( //zsviczian
<MenuLinks />
) : (
renderMenuLinks && renderMenuLinks(device.isMobile, appState)
)}
<Separator />
<div
style={{
@ -251,9 +262,11 @@ const LayerUI = ({
}}
>
<div>{actionManager.renderAction("toggleTheme")}</div>
<div style={{ padding: "0 0.625rem" }}>
<LanguageList style={{ width: "100%" }} />
</div>
{UIOptions.showLanguageList !== false && (
<div style={{ padding: "0 0.625rem" }}>
<LanguageList style={{ width: "100%" }} />
</div>
)}
{!appState.viewModeEnabled && (
<div>
<div style={{ fontSize: ".75rem", marginBottom: ".5rem" }}>
@ -484,9 +497,11 @@ const LayerUI = ({
renderCustomFooter={renderCustomFooter}
onImageAction={onImageAction}
renderTopRightUI={renderTopRightUI}
renderMenuLinks={renderMenuLinks}
renderCustomStats={renderCustomStats}
renderSidebars={renderSidebars}
device={device}
UIOptions={UIOptions}
/>
)}

View File

@ -1,5 +1,5 @@
import React from "react";
import { AppState, Device, ExcalidrawProps } from "../types";
import { AppProps, AppState, Device, ExcalidrawProps } from "../types";
import { ActionManager } from "../actions/manager";
import { t } from "../i18n";
import Stack from "./Stack";
@ -45,10 +45,12 @@ type MobileMenuProps = {
isMobile: boolean,
appState: AppState,
) => JSX.Element | null;
renderMenuLinks?: ExcalidrawProps["renderMenuLinks"];
renderCustomStats?: ExcalidrawProps["renderCustomStats"];
renderSidebars: () => JSX.Element | null;
device: Device;
renderWelcomeScreen?: boolean;
UIOptions: AppProps["UIOptions"];
};
export const MobileMenu = ({
@ -66,10 +68,12 @@ export const MobileMenu = ({
renderCustomFooter,
onImageAction,
renderTopRightUI,
renderMenuLinks,
renderCustomStats,
renderSidebars,
device,
renderWelcomeScreen,
UIOptions,
}: MobileMenuProps) => {
const renderToolbar = () => {
return (
@ -111,8 +115,8 @@ export const MobileMenu = ({
/>
</Stack.Row>
</Island>
{renderTopRightUI && renderTopRightUI(true, appState)}
<div className="mobile-misc-tools-container">
{renderTopRightUI && renderTopRightUI(true, appState)}
<PenModeButton
checked={appState.penMode}
onChange={onPenModeToggle}
@ -192,12 +196,14 @@ export const MobileMenu = ({
{!appState.viewModeEnabled && actionManager.renderAction("loadScene")}
{renderJSONExportDialog()}
{renderImageExportDialog()}
<MenuItem
label={t("buttons.exportImage")}
icon={ExportImageIcon}
dataTestId="image-export-button"
onClick={() => setAppState({ openDialog: "imageExport" })}
/>
{UIOptions.canvasActions.saveAsImage && (
<MenuItem
label={t("buttons.exportImage")}
icon={ExportImageIcon}
dataTestId="image-export-button"
onClick={() => setAppState({ openDialog: "imageExport" })}
/>
)}
{onCollabButtonClick && (
<CollabButton
isCollaborating={isCollaborating}
@ -207,8 +213,16 @@ export const MobileMenu = ({
)}
{actionManager.renderAction("toggleShortcuts", undefined, true)}
{!appState.viewModeEnabled && actionManager.renderAction("clearCanvas")}
<Separator />
<MenuLinks />
{typeof renderMenuLinks === "undefined" ? ( //zsviczian
<Separator />
) : (
renderMenuLinks && <Separator />
)}
{typeof renderMenuLinks === "undefined" ? ( //zsviczian
<MenuLinks />
) : (
renderMenuLinks && renderMenuLinks(device.isMobile, appState)
)}
<Separator />
{!appState.viewModeEnabled && (
<div style={{ marginBottom: ".5rem" }}>

View File

@ -392,6 +392,8 @@ No, Excalidraw package doesn't come with collaboration built in, since the imple
| [`onPointerUpdate`](#onPointerUpdate) | Function | | Callback triggered when mouse pointer is updated. |
| [`langCode`](#langCode) | string | `en` | Language code string |
| [`renderTopRightUI`](#renderTopRightUI) | Function | | Function that renders custom UI in top right corner |
| [`hideWelcomeScreen`](#hideWelcomeScreen) | boolean | | This implies if the app should always hide the welcome sreen |
| [`renderMenuLinks`](#renderMenuLinks) | Function | | Function that renders custom list of links (or other custom UI) in the app menu |
| [`renderFooter `](#renderFooter) | Function | | Function that renders custom UI footer |
| [`renderCustomStats`](#renderCustomStats) | Function | | Function that can be used to render custom stats on the stats dialog. |
| [`renderSIdebar`](#renderSIdebar) | Function | | Render function that renders custom sidebar. |
@ -613,6 +615,22 @@ import { defaultLang, languages } from "@excalidraw/excalidraw";
A function returning JSX to render custom UI in the top right corner of the app.
#### `hideWelcomeScreen`
<pre>
boolean
</pre>
Boolean value to override the displaying of the welcome screen elements. If set to true, the welcome screen will never be shown.
#### `renderMenuLinks`
<pre>
((isMobile: boolean, appState: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L79">AppState</a>) => JSX | null)|null
</pre>
A function returning JSX to render custom UI (intended to be a list of custom links) replacing the default list of links in the app menu. If set to null, the list of links will not be displayed. If unset, the default list of links will be displayed.
#### `renderFooter`
<pre>
@ -685,7 +703,7 @@ This prop sets the name of the drawing which will be used when exporting the dra
#### `UIOptions`
This prop can be used to customise UI of Excalidraw. Currently we support customising [`canvasActions`](#canvasActions) and [`dockedSidebarBreakpoint`](dockedSidebarBreakpoint). It accepts the below parameters
This prop can be used to customise UI of Excalidraw. Currently we support customising [`canvasActions`](#canvasActions), [`dockedSidebarBreakpoint`](dockedSidebarBreakpoint), and ['showLanguageList`](showLanguageList). It accepts the below parameters
<pre>
{ canvasActions: <a href="https://github.com/excalidraw/excalidraw/blob/master/src/types.ts#L208"> CanvasActions<a/> }
@ -709,6 +727,10 @@ This prop indicates at what point should we break to a docked, permanent sidebar
![image](https://user-images.githubusercontent.com/11256141/174664866-c698c3fa-197b-43ff-956c-d79852c7b326.png)
### `showLanguageList`
Boolean prop. If set to `true` the `language selector dropdown list` will be hidden in the app menu. If `false` or `undefined` the language dropdown will be rendered.
#### `exportOpts`
The below attributes can be set in `UIOptions.canvasActions.export` to customize the export dialog. If `UIOptions.canvasActions.export` is `false` the export button will not be rendered.

View File

@ -20,6 +20,8 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
isCollaborating = false,
onPointerUpdate,
renderTopRightUI,
hideWelcomeScreen,
renderMenuLinks,
renderFooter,
renderSidebar,
langCode = defaultLang.code,
@ -93,6 +95,8 @@ const ExcalidrawBase = (props: ExcalidrawProps) => {
isCollaborating={isCollaborating}
onPointerUpdate={onPointerUpdate}
renderTopRightUI={renderTopRightUI}
hideWelcomeScreen={hideWelcomeScreen}
renderMenuLinks={renderMenuLinks}
renderFooter={renderFooter}
langCode={langCode}
viewModeEnabled={viewModeEnabled}

View File

@ -284,6 +284,10 @@ export interface ExcalidrawProps {
isMobile: boolean,
appState: AppState,
) => JSX.Element | null;
renderMenuLinks?:
| ((isMobile: boolean, appState: AppState) => JSX.Element | null)
| null;
hideWelcomeScreen?: boolean;
renderFooter?: (isMobile: boolean, appState: AppState) => JSX.Element | null;
langCode?: Language["code"];
viewModeEnabled?: boolean;
@ -299,6 +303,7 @@ export interface ExcalidrawProps {
UIOptions?: {
dockedSidebarBreakpoint?: number;
canvasActions?: CanvasActions;
showLanguageList?: boolean;
};
detectScroll?: boolean;
handleKeyboardGlobally?: boolean;
@ -371,6 +376,7 @@ export type AppProps = Merge<
UIOptions: {
canvasActions: Required<CanvasActions> & { export: ExportOpts };
dockedSidebarBreakpoint?: number;
showLanguageList?: boolean;
};
detectScroll: boolean;
handleKeyboardGlobally: boolean;