From 0f0244224d629dbc8774e1a18756e4e021c1e365 Mon Sep 17 00:00:00 2001 From: Aakansha Doshi Date: Thu, 21 Oct 2021 17:35:28 +0530 Subject: [PATCH] feat: Use dialog component for clear canvas instead of window confirm (#4075) * feat: Use dialog component for clear canvas instead of window confirm * reduce font weight * fix specs * update button name and use action * export clearCanvas from actions --- src/actions/actionCanvas.tsx | 27 ++++--------- src/components/ClearCanvas.scss | 42 +++++++++++++++++++++ src/components/ClearCanvas.tsx | 67 +++++++++++++++++++++++++++++++++ src/components/LayerUI.tsx | 1 + src/locales/en.json | 7 +++- 5 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 src/components/ClearCanvas.scss create mode 100644 src/components/ClearCanvas.tsx diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index 375fabcc..e29a3d84 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -1,14 +1,11 @@ -import { getDefaultAppState } from "../appState"; import { ColorPicker } from "../components/ColorPicker"; -import { trash, zoomIn, zoomOut } from "../components/icons"; +import { zoomIn, zoomOut } from "../components/icons"; import { ToolButton } from "../components/ToolButton"; import { DarkModeToggle } from "../components/DarkModeToggle"; import { THEME, ZOOM_STEP } from "../constants"; import { getCommonBounds, getNonDeletedElements } from "../element"; -import { newElementWith } from "../element/mutateElement"; import { ExcalidrawElement } from "../element/types"; import { t } from "../i18n"; -import { useIsMobile } from "../components/App"; import { CODES, KEYS } from "../keys"; import { getNormalizedZoom, getSelectedElements } from "../scene"; import { centerScrollOn } from "../scene/scroll"; @@ -17,6 +14,9 @@ import { AppState, NormalizedZoomValue } from "../types"; import { getShortcutKey } from "../utils"; import { register } from "./register"; import { Tooltip } from "../components/Tooltip"; +import { newElementWith } from "../element/mutateElement"; +import { getDefaultAppState } from "../appState"; +import ClearCanvas from "../components/ClearCanvas"; export const actionChangeViewBackgroundColor = register({ name: "changeViewBackgroundColor", @@ -47,7 +47,7 @@ export const actionChangeViewBackgroundColor = register({ export const actionClearCanvas = register({ name: "clearCanvas", - perform: (elements, appState: AppState) => { + perform: (elements, appState) => { return { elements: elements.map((element) => newElementWith(element, { isDeleted: true }), @@ -65,21 +65,8 @@ export const actionClearCanvas = register({ commitToHistory: true, }; }, - PanelComponent: ({ updateData }) => ( - { - if (window.confirm(t("alerts.clearReset"))) { - updateData(null); - } - }} - data-testid="clear-canvas-button" - /> - ), + + PanelComponent: ({ updateData }) => , }); export const actionZoomIn = register({ diff --git a/src/components/ClearCanvas.scss b/src/components/ClearCanvas.scss new file mode 100644 index 00000000..3a74761f --- /dev/null +++ b/src/components/ClearCanvas.scss @@ -0,0 +1,42 @@ +@import "../css/variables.module"; + +.excalidraw { + .clear-canvas { + &-buttons { + display: flex; + padding: 0.2rem 0; + justify-content: flex-end; + + .ToolIcon__icon { + min-width: 2.5rem; + width: auto; + font-size: 1rem; + } + + .ToolIcon_type_button { + margin-left: 1.5rem; + padding: 0 0.5rem; + } + } + + &__content { + font-size: 1rem; + } + + &--confirm.ToolIcon_type_button { + background-color: $oc-red-6; + + &:hover { + background-color: $oc-red-8; + } + + .ToolIcon__icon { + color: $oc-white; + } + } + + &--cancel.ToolIcon_type_button { + background-color: $oc-gray-2; + } + } +} diff --git a/src/components/ClearCanvas.tsx b/src/components/ClearCanvas.tsx new file mode 100644 index 00000000..abd22409 --- /dev/null +++ b/src/components/ClearCanvas.tsx @@ -0,0 +1,67 @@ +import { useState } from "react"; +import { t } from "../i18n"; +import { useIsMobile } from "./App"; +import { Dialog } from "./Dialog"; +import { trash } from "./icons"; +import { ToolButton } from "./ToolButton"; + +import "./ClearCanvas.scss"; + +const ClearCanvas = ({ onConfirm }: { onConfirm: () => void }) => { + const [showDialog, setShowDialog] = useState(false); + const toggleDialog = () => { + setShowDialog(!showDialog); + }; + + return ( + <> + + + {showDialog && ( + + <> +

{t("alerts.clearReset")}

+
+ { + onConfirm(); + toggleDialog(); + }} + data-testid="confirm-clear-canvas-button" + className="clear-canvas--confirm" + /> + +
+ +
+ )} + + ); +}; + +export default ClearCanvas; diff --git a/src/components/LayerUI.tsx b/src/components/LayerUI.tsx index f08c7620..ec07e08a 100644 --- a/src/components/LayerUI.tsx +++ b/src/components/LayerUI.tsx @@ -468,6 +468,7 @@ const LayerUI = ({ ); }; + const renderCanvasActions = () => (