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
|
|
|
|
|
|
|
import "./HintViewer.css";
|
|
|
|
|
|
|
|
interface Hint {
|
|
|
|
elementType: string;
|
|
|
|
multiMode: boolean;
|
|
|
|
isResizing: boolean;
|
|
|
|
elements: readonly ExcalidrawElement[];
|
|
|
|
}
|
|
|
|
|
|
|
|
const getHints = ({ elementType, multiMode, isResizing, elements }: Hint) => {
|
|
|
|
if (elementType === "arrow" || elementType === "line") {
|
|
|
|
if (!multiMode) {
|
|
|
|
return t("hints.linearElement");
|
|
|
|
}
|
|
|
|
return t("hints.linearElementMulti");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isResizing) {
|
2020-02-16 22:54:50 +01:00
|
|
|
const selectedElements = getSelectedElements(elements);
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const HintViewer = ({
|
|
|
|
elementType,
|
|
|
|
multiMode,
|
|
|
|
isResizing,
|
|
|
|
elements,
|
|
|
|
}: Hint) => {
|
|
|
|
const hint = getHints({
|
|
|
|
elementType,
|
|
|
|
multiMode,
|
|
|
|
isResizing,
|
|
|
|
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
|
|
|
};
|