Convert GenericElementContextMenu to TS
Signed-off-by: Šimon Brandner <simon.bra.ag@gmail.com>
This commit is contained in:
parent
5baaa6b77e
commit
8e4529d6ce
1 changed files with 16 additions and 20 deletions
|
@ -15,45 +15,41 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PropTypes from 'prop-types';
|
|
||||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||||
|
|
||||||
/*
|
interface IProps {
|
||||||
* This component can be used to display generic HTML content in a contextual
|
element: React.ReactNode;
|
||||||
* 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
|
// Function to be called when the parent window is resized
|
||||||
// This can be used to reposition or close the menu on resize and
|
// This can be used to reposition or close the menu on resize and
|
||||||
// ensure that it is not displayed in a stale position.
|
// ensure that it is not displayed in a stale position.
|
||||||
onResize: PropTypes.func,
|
onResize?: () => void;
|
||||||
};
|
|
||||||
|
|
||||||
constructor(props) {
|
|
||||||
super(props);
|
|
||||||
this.resize = this.resize.bind(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
/**
|
||||||
this.resize = this.resize.bind(this);
|
* 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<IProps> {
|
||||||
|
constructor(props: IProps) {
|
||||||
|
super(props);
|
||||||
|
}
|
||||||
|
|
||||||
|
public componentDidMount(): void {
|
||||||
window.addEventListener("resize", this.resize);
|
window.addEventListener("resize", this.resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
public componentWillUnmount(): void {
|
||||||
window.removeEventListener("resize", this.resize);
|
window.removeEventListener("resize", this.resize);
|
||||||
}
|
}
|
||||||
|
|
||||||
resize() {
|
private resize = (): void => {
|
||||||
if (this.props.onResize) {
|
if (this.props.onResize) {
|
||||||
this.props.onResize();
|
this.props.onResize();
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
render() {
|
public render(): JSX.Element {
|
||||||
return <div>{ this.props.element }</div>;
|
return <div>{ this.props.element }</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue