import React from "react"; import { ExcalidrawElement } from "../element/types"; import { ActionManager } from "../actions/manager"; import { hasBackground, hasStroke, hasText } from "../scene"; import { t } from "../i18n"; import { SHAPES } from "../shapes"; import { ToolButton } from "./ToolButton"; import { capitalizeString } from "../utils"; import { CURSOR_TYPE } from "../constants"; import Stack from "./Stack"; export function SelectedShapeActions({ targetElements, renderAction, elementType, }: { targetElements: readonly ExcalidrawElement[]; renderAction: ActionManager["renderAction"]; elementType: ExcalidrawElement["type"]; }) { 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")}
); } 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}`); return ( { setAppState({ elementType: value, multiElement: null, selectedElementIds: {}, }); document.documentElement.style.cursor = value === "text" ? CURSOR_TYPE.TEXT : CURSOR_TYPE.CROSSHAIR; setAppState({}); }} > ); })} ); } export function ZoomActions({ renderAction, zoom, }: { renderAction: ActionManager["renderAction"]; zoom: number; }) { return ( {renderAction("zoomIn")} {renderAction("zoomOut")} {renderAction("resetZoom")}
{(zoom * 100).toFixed(0)}%
); }