Files
image-studio/view/BottomControlsIsland.tsx
2026-07-03 17:49:00 +02:00

47 lines
2.0 KiB
TypeScript

import type { AppStore } from "@editor/store";
import type { ViewportState } from "@editor/state";
import type { BrushSettings, ToolId } from "@editor/tools";
import { BrushControls } from "./bottom-controls/BrushControls";
import { PanControls } from "./bottom-controls/PanControls";
import { TransformControls } from "./bottom-controls/TransformControls";
import { ZoomControls } from "./bottom-controls/ZoomControls";
import type { Rect } from "@core/geometry";
import type { TransformTarget } from "@editor/transform";
export type BottomControlsAction = "pan" | "zoom";
export type BottomControlsIslandProps = {
viewport: ViewportState;
visible: boolean;
action: BottomControlsAction;
activeTool: ToolId;
brushSettings: BrushSettings;
transformBounds?: Rect;
transformTarget?: TransformTarget;
dispatch: AppStore["dispatch"];
};
export function BottomControlsIsland({ viewport, visible, action, activeTool, brushSettings, transformBounds, transformTarget, dispatch }: BottomControlsIslandProps) {
const zoomPercent = Math.round(viewport.zoom * 100);
const x = Math.round(viewport.center.x);
const y = Math.round(viewport.center.y);
return (
<div
aria-hidden={!visible}
className={`flex h-10 min-w-48 items-center justify-center gap-2 rounded-full border border-white/10 bg-black/70 px-2 py-1 text-xs text-white shadow-xl backdrop-blur transition-all duration-200 ${
visible ? "pointer-events-auto translate-y-0 opacity-100" : "pointer-events-none translate-y-3 opacity-0"
}`}
>
{activeTool === "brush" || activeTool === "eraser" ? (
<BrushControls tool={activeTool} settings={brushSettings} dispatch={dispatch} />
) : transformBounds && transformTarget ? (
<TransformControls bounds={transformBounds} target={transformTarget} dispatch={dispatch} />
) : action === "pan" ? (
<PanControls x={x} y={y} />
) : (
<ZoomControls zoom={viewport.zoom} zoomPercent={zoomPercent} dispatch={dispatch} />
)}
</div>
);
}