From 07336bb168025b4fb4d048771ac283db2f7bd3a8 Mon Sep 17 00:00:00 2001 From: Oren Me Date: Sat, 22 Feb 2020 21:24:34 +0200 Subject: [PATCH] feat: add reset zoom button (#777) * feat: add reset zoom button Add zoom reset button. Button is shown only when zoom scale is different from 1 * change reset zoom icon * always show zoom reset * fix typo --- src/actions/actionCanvas.tsx | 13 ++++++++++++- src/components/icons.tsx | 13 +++++++++++++ src/index.tsx | 5 +++-- src/locales/en.json | 1 + 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/actions/actionCanvas.tsx b/src/actions/actionCanvas.tsx index 0e9dbf6f..dc7cec93 100644 --- a/src/actions/actionCanvas.tsx +++ b/src/actions/actionCanvas.tsx @@ -2,7 +2,7 @@ import React from "react"; import { Action } from "./types"; import { ColorPicker } from "../components/ColorPicker"; import { getDefaultAppState } from "../appState"; -import { trash, zoomIn, zoomOut } from "../components/icons"; +import { trash, zoomIn, zoomOut, resetZoom } from "../components/icons"; import { ToolButton } from "../components/ToolButton"; import { t } from "../i18n"; import { getNormalizedZoom } from "../scene"; @@ -131,6 +131,17 @@ export const actionResetZoom: Action = { }, }; }, + PanelComponent: ({ updateData }) => ( + { + updateData(null); + }} + /> + ), keyTest: event => (event.code === KEY_CODES.ZERO || event.code === KEY_CODES.NUM_ZERO) && (event[KEYS.META] || event.shiftKey), diff --git a/src/components/icons.tsx b/src/components/icons.tsx index e6ee3bee..7495fb75 100644 --- a/src/components/icons.tsx +++ b/src/components/icons.tsx @@ -79,3 +79,16 @@ export const undo = createIcon( export const redo = createIcon( "M256.455 8c66.269.119 126.437 26.233 170.859 68.685l35.715-35.715C478.149 25.851 504 36.559 504 57.941V192c0 13.255-10.745 24-24 24H345.941c-21.382 0-32.09-25.851-16.971-40.971l41.75-41.75c-30.864-28.899-70.801-44.907-113.23-45.273-92.398-.798-170.283 73.977-169.484 169.442C88.764 348.009 162.184 424 256 424c41.127 0 79.997-14.678 110.629-41.556 4.743-4.161 11.906-3.908 16.368.553l39.662 39.662c4.872 4.872 4.631 12.815-.482 17.433C378.202 479.813 319.926 504 256 504 119.034 504 8.001 392.967 8 256.002 7.999 119.193 119.646 7.755 256.455 8z", ); + +// Icon imported form Storybook +// Storybook is licensed under MIT https://github.com/storybookjs/storybook/blob/next/LICENSE +export const resetZoom = ( + +); diff --git a/src/index.tsx b/src/index.tsx index 58fad8d4..cdea56e9 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -379,8 +379,9 @@ const LayerUI = React.memo( return ( - {actionManager.renderAction("zoomIn")} - {actionManager.renderAction("zoomOut")} + {actionManager.renderAction(actionZoomIn.name)} + {actionManager.renderAction(actionZoomOut.name)} + {actionManager.renderAction(actionResetZoom.name)}
{(appState.zoom * 100).toFixed(0)}%
diff --git a/src/locales/en.json b/src/locales/en.json index c7337427..203c0643 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -57,6 +57,7 @@ "scrollBackToContent": "Scroll back to content", "zoomIn": "Zoom in", "zoomOut": "Zoom out", + "resetZoom": "Reset zoom", "menu": "Menu", "done": "Done", "edit": "Edit"