diff options
| author | kj_sh604 | 2026-03-15 16:19:35 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-03-15 16:19:35 -0400 |
| commit | 6ec259a0e71174651bae95d4628138bf6fd68742 (patch) | |
| tree | 5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/excalidraw/components/Stats/CanvasGrid.tsx | |
| parent | 16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff) | |
refactor: packages/
Diffstat (limited to 'packages/excalidraw/components/Stats/CanvasGrid.tsx')
| -rw-r--r-- | packages/excalidraw/components/Stats/CanvasGrid.tsx | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/packages/excalidraw/components/Stats/CanvasGrid.tsx b/packages/excalidraw/components/Stats/CanvasGrid.tsx new file mode 100644 index 0000000..a08f709 --- /dev/null +++ b/packages/excalidraw/components/Stats/CanvasGrid.tsx @@ -0,0 +1,67 @@ +import StatsDragInput from "./DragInput"; +import type Scene from "../../scene/Scene"; +import type { AppState } from "../../types"; +import { getStepSizedValue } from "./utils"; +import { getNormalizedGridStep } from "../../scene"; + +interface PositionProps { + property: "gridStep"; + scene: Scene; + appState: AppState; + setAppState: React.Component<any, AppState>["setState"]; +} + +const STEP_SIZE = 5; + +const CanvasGrid = ({ + property, + scene, + appState, + setAppState, +}: PositionProps) => { + return ( + <StatsDragInput + label="Grid step" + sensitivity={8} + elements={[]} + dragInputCallback={({ + nextValue, + instantChange, + shouldChangeByStepSize, + setInputValue, + }) => { + setAppState((state) => { + let nextGridStep; + + if (nextValue) { + nextGridStep = nextValue; + } else if (instantChange) { + nextGridStep = shouldChangeByStepSize + ? getStepSizedValue( + state.gridStep + STEP_SIZE * Math.sign(instantChange), + STEP_SIZE, + ) + : state.gridStep + instantChange; + } + + if (!nextGridStep) { + setInputValue(state.gridStep); + return null; + } + + nextGridStep = getNormalizedGridStep(nextGridStep); + setInputValue(nextGridStep); + return { + gridStep: nextGridStep, + }; + }); + }} + scene={scene} + value={appState.gridStep} + property={property} + appState={appState} + /> + ); +}; + +export default CanvasGrid; |
