excalidraw/src/actions/actionCanvas.tsx
Christopher Chedeau d45f48e60f
Set shape background to be transparent by default (#330)
Also makes "Clear canvas" reset the entire app state
2020-01-11 20:34:21 -08:00

45 lines
1.1 KiB
TypeScript

import React from "react";
import { Action } from "./types";
import { ColorPicker } from "../components/ColorPicker";
import { getDefaultAppState } from "../appState";
export const actionChangeViewBackgroundColor: Action = {
name: "changeViewBackgroundColor",
perform: (elements, appState, value) => {
return { appState: { ...appState, viewBackgroundColor: value } };
},
PanelComponent: ({ appState, updateData }) => (
<>
<h5>Canvas Background Color</h5>
<ColorPicker
type="canvasBackground"
color={appState.viewBackgroundColor}
onChange={color => updateData(color)}
/>
</>
)
};
export const actionClearCanvas: Action = {
name: "clearCanvas",
perform: (elements, appState, value) => {
return {
elements: [],
appState: getDefaultAppState()
};
},
PanelComponent: ({ updateData }) => (
<button
type="button"
onClick={() => {
if (window.confirm("This will clear the whole canvas. Are you sure?")) {
updateData(null);
}
}}
title="Clear the canvas & reset background color"
>
Clear canvas
</button>
)
};