2020-02-03 21:52:21 +04:00
|
|
|
import React from "react";
|
|
|
|
import { t } from "../i18n";
|
|
|
|
import { ExcalidrawElement } from "../element/types";
|
2020-02-16 22:54:50 +01:00
|
|
|
import { getSelectedElements } from "../scene";
|
2020-02-03 21:52:21 +04:00
|
|
|
|
2020-03-13 15:32:47 -04:00
|
|
|
import "./HintViewer.scss";
|
2020-03-08 10:20:55 -07:00
|
|
|
import { AppState } from "../types";
|
2020-02-03 21:52:21 +04:00
|
|
|
|
|
|
|
interface Hint {
|
2020-03-08 10:20:55 -07:00
|
|
|
appState: AppState;
|
2020-02-03 21:52:21 +04:00
|
|
|
elements: readonly ExcalidrawElement[];
|
|
|
|
}
|
|
|
|
|
2020-03-08 10:20:55 -07:00
|
|
|
const getHints = ({ appState, elements }: Hint) => {
|
|
|
|
const { elementType, isResizing } = appState;
|
|
|
|
const multiMode = appState.multiElement !== null;
|
2020-02-03 21:52:21 +04:00
|
|
|
if (elementType === "arrow" || elementType === "line") {
|
|
|
|
if (!multiMode) {
|
|
|
|
return t("hints.linearElement");
|
|
|
|
}
|
|
|
|
return t("hints.linearElementMulti");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isResizing) {
|
2020-03-08 10:20:55 -07:00
|
|
|
const selectedElements = getSelectedElements(elements, appState);
|
2020-02-03 21:52:21 +04:00
|
|
|
if (
|
|
|
|
selectedElements.length === 1 &&
|
|
|
|
(selectedElements[0].type === "arrow" ||
|
|
|
|
selectedElements[0].type === "line") &&
|
|
|
|
selectedElements[0].points.length > 2
|
|
|
|
) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return t("hints.resize");
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
2020-03-08 10:20:55 -07:00
|
|
|
export const HintViewer = ({ appState, elements }: Hint) => {
|
2020-02-03 21:52:21 +04:00
|
|
|
const hint = getHints({
|
2020-03-08 10:20:55 -07:00
|
|
|
appState,
|
2020-02-03 21:52:21 +04:00
|
|
|
elements,
|
|
|
|
});
|
|
|
|
if (!hint) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-03-01 14:39:03 -05:00
|
|
|
return (
|
|
|
|
<div className="HintViewer">
|
|
|
|
<span>{hint}</span>
|
|
|
|
</div>
|
|
|
|
);
|
2020-02-03 21:52:21 +04:00
|
|
|
};
|