From 8e4529d6ce829d3a08bab0be0e51f72ee7cd4fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Tue, 14 Sep 2021 18:58:20 +0200 Subject: [PATCH] Convert GenericElementContextMenu to TS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- ...tMenu.js => GenericElementContextMenu.tsx} | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) rename src/components/views/context_menus/{GenericElementContextMenu.js => GenericElementContextMenu.tsx} (67%) diff --git a/src/components/views/context_menus/GenericElementContextMenu.js b/src/components/views/context_menus/GenericElementContextMenu.tsx similarity index 67% rename from src/components/views/context_menus/GenericElementContextMenu.js rename to src/components/views/context_menus/GenericElementContextMenu.tsx index 87d44ef0d3..a0a8c89b37 100644 --- a/src/components/views/context_menus/GenericElementContextMenu.js +++ b/src/components/views/context_menus/GenericElementContextMenu.tsx @@ -15,45 +15,41 @@ limitations under the License. */ import React from 'react'; -import PropTypes from 'prop-types'; import { replaceableComponent } from "../../../utils/replaceableComponent"; -/* +interface IProps { + element: React.ReactNode; + // Function to be called when the parent window is resized + // This can be used to reposition or close the menu on resize and + // ensure that it is not displayed in a stale position. + onResize?: () => void; +} + +/** * This component can be used to display generic HTML content in a contextual * menu. */ - @replaceableComponent("views.context_menus.GenericElementContextMenu") -export default class GenericElementContextMenu extends React.Component { - static propTypes = { - element: PropTypes.element.isRequired, - // Function to be called when the parent window is resized - // This can be used to reposition or close the menu on resize and - // ensure that it is not displayed in a stale position. - onResize: PropTypes.func, - }; - - constructor(props) { +export default class GenericElementContextMenu extends React.Component { + constructor(props: IProps) { super(props); - this.resize = this.resize.bind(this); } - componentDidMount() { - this.resize = this.resize.bind(this); + public componentDidMount(): void { window.addEventListener("resize", this.resize); } - componentWillUnmount() { + public componentWillUnmount(): void { window.removeEventListener("resize", this.resize); } - resize() { + private resize = (): void => { if (this.props.onResize) { this.props.onResize(); } - } + }; - render() { + public render(): JSX.Element { return
{ this.props.element }
; } }