TeaWeb/shared/js/ui/react-elements/Icon.tsx
2020-04-10 20:57:50 +02:00

35 lines
No EOL
929 B
TypeScript

import * as React from "react";
export interface IconProperties {
icon: string | JQuery<HTMLDivElement>;
}
export class IconRenderer extends React.Component<IconProperties, {}> {
private readonly icon_ref: React.RefObject<HTMLDivElement>;
constructor(props) {
super(props);
if(typeof this.props.icon === "object")
this.icon_ref = React.createRef();
}
render() {
if(!this.props.icon)
return <div className={"icon-container icon-empty"} />;
else if(typeof this.props.icon === "string")
return <div className={"icon " + this.props.icon} />;
return <div ref={this.icon_ref} />;
}
componentDidMount(): void {
if(this.icon_ref)
$(this.icon_ref.current).replaceWith(this.props.icon);
}
componentWillUnmount(): void {
if(this.icon_ref)
$(this.icon_ref.current).empty();
}
}