feat: add hint around canvas panning (#4159)

This commit is contained in:
David Luzar 2021-11-01 13:36:06 +01:00 committed by GitHub
parent dbc7a8599b
commit 3369035f40
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 5 deletions

View file

@ -11,14 +11,16 @@ import {
} from "../element/typeChecks";
import { getShortcutKey } from "../utils";
interface Hint {
interface HintViewerProps {
appState: AppState;
elements: readonly NonDeletedExcalidrawElement[];
isMobile: boolean;
}
const getHints = ({ appState, elements }: Hint) => {
const getHints = ({ appState, elements, isMobile }: HintViewerProps) => {
const { elementType, isResizing, isRotating, lastPointerDownWith } = appState;
const multiMode = appState.multiElement !== null;
if (elementType === "arrow" || elementType === "line") {
if (!multiMode) {
return t("hints.linearElement");
@ -39,6 +41,7 @@ const getHints = ({ appState, elements }: Hint) => {
}
const selectedElements = getSelectedElements(elements, appState);
if (
isResizing &&
lastPointerDownWith === "mouse" &&
@ -74,13 +77,22 @@ const getHints = ({ appState, elements }: Hint) => {
return t("hints.text_editing");
}
if (elementType === "selection" && !selectedElements.length && !isMobile) {
return t("hints.canvasPanning");
}
return null;
};
export const HintViewer = ({ appState, elements }: Hint) => {
export const HintViewer = ({
appState,
elements,
isMobile,
}: HintViewerProps) => {
let hint = getHints({
appState,
elements,
isMobile,
});
if (!hint) {
return null;