2020-01-12 02:22:03 +04:00
|
|
|
import React from "react";
|
|
|
|
import { Action } from "./types";
|
|
|
|
import { ColorPicker } from "../components/ColorPicker";
|
2020-01-11 20:34:21 -08:00
|
|
|
import { getDefaultAppState } from "../appState";
|
2020-01-15 20:42:02 +05:00
|
|
|
import { trash } from "../components/icons";
|
|
|
|
import { ToolIcon } from "../components/ToolIcon";
|
2020-01-12 02:22:03 +04:00
|
|
|
|
|
|
|
export const actionChangeViewBackgroundColor: Action = {
|
|
|
|
name: "changeViewBackgroundColor",
|
|
|
|
perform: (elements, appState, value) => {
|
|
|
|
return { appState: { ...appState, viewBackgroundColor: value } };
|
|
|
|
},
|
2020-01-15 20:42:02 +05:00
|
|
|
PanelComponent: ({ appState, updateData }) => {
|
|
|
|
return (
|
|
|
|
<div style={{ position: "relative" }}>
|
|
|
|
<ColorPicker
|
|
|
|
type="canvasBackground"
|
|
|
|
color={appState.viewBackgroundColor}
|
|
|
|
onChange={color => updateData(color)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
export const actionClearCanvas: Action = {
|
|
|
|
name: "clearCanvas",
|
2020-01-15 20:42:02 +05:00
|
|
|
perform: () => {
|
2020-01-12 02:22:03 +04:00
|
|
|
return {
|
|
|
|
elements: [],
|
2020-01-11 20:34:21 -08:00
|
|
|
appState: getDefaultAppState()
|
2020-01-12 02:22:03 +04:00
|
|
|
};
|
|
|
|
},
|
|
|
|
PanelComponent: ({ updateData }) => (
|
2020-01-15 20:42:02 +05:00
|
|
|
<ToolIcon
|
2020-01-12 02:22:03 +04:00
|
|
|
type="button"
|
2020-01-15 20:42:02 +05:00
|
|
|
icon={trash}
|
|
|
|
title="Clear the canvas & reset background color"
|
|
|
|
aria-label="Clear the canvas & reset background color"
|
2020-01-12 02:22:03 +04:00
|
|
|
onClick={() => {
|
|
|
|
if (window.confirm("This will clear the whole canvas. Are you sure?")) {
|
|
|
|
updateData(null);
|
|
|
|
}
|
|
|
|
}}
|
2020-01-15 20:42:02 +05:00
|
|
|
/>
|
2020-01-12 02:22:03 +04:00
|
|
|
)
|
|
|
|
};
|