import React from "react"; import { AppState } from "../types"; import { ExcalidrawElement } from "../element/types"; import { ActionManager } from "../actions/manager"; import { hasBackground, hasStroke, hasText, getTargetElement } from "../scene"; import { t } from "../i18n"; import { SHAPES } from "../shapes"; import { ToolButton } from "./ToolButton"; import { capitalizeString, setCursorForShape } from "../utils"; import Stack from "./Stack"; import useIsMobile from "../is-mobile"; export function SelectedShapeActions({ appState, elements, renderAction, elementType, }: { appState: AppState; elements: readonly ExcalidrawElement[]; renderAction: ActionManager["renderAction"]; elementType: ExcalidrawElement["type"]; }) { const targetElements = getTargetElement(elements, appState); const isEditing = Boolean(appState.editingElement); const isMobile = useIsMobile(); return (
{renderAction("changeStrokeColor")} {(hasBackground(elementType) || targetElements.some((element) => hasBackground(element.type))) && ( <> {renderAction("changeBackgroundColor")} {renderAction("changeFillStyle")} )} {(hasStroke(elementType) || targetElements.some((element) => hasStroke(element.type))) && ( <> {renderAction("changeStrokeWidth")} {renderAction("changeSloppiness")} )} {(hasText(elementType) || targetElements.some((element) => hasText(element.type))) && ( <> {renderAction("changeFontSize")} {renderAction("changeFontFamily")} )} {renderAction("changeOpacity")}
{t("labels.layers")}
{renderAction("sendToBack")} {renderAction("sendBackward")} {renderAction("bringToFront")} {renderAction("bringForward")}
{!isMobile && !isEditing && targetElements.length > 0 && (
{t("labels.actions")}
{renderAction("duplicateSelection")} {renderAction("deleteSelectedElements")}
)}
); } export function ShapesSwitcher({ elementType, setAppState, setElements, elements, }: { elementType: ExcalidrawElement["type"]; setAppState: any; setElements: any; elements: readonly ExcalidrawElement[]; }) { return ( <> {SHAPES.map(({ value, icon }, index) => { const label = t(`toolBar.${value}`); const shortcut = `${capitalizeString(value)[0]} ${t( "shortcutsDialog.or", )} ${index + 1}`; return ( { setAppState({ elementType: value, multiElement: null, selectedElementIds: {}, }); setCursorForShape(value); setAppState({}); }} > ); })} ); } export function ZoomActions({ renderAction, zoom, }: { renderAction: ActionManager["renderAction"]; zoom: number; }) { return ( {renderAction("zoomIn")} {renderAction("zoomOut")} {renderAction("resetZoom")}
{(zoom * 100).toFixed(0)}%
); }