From 96d1519ac5b2c3b1ab92233a00b17c4a0f2d9c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Brandner?= Date: Wed, 15 Sep 2021 20:47:49 +0200 Subject: [PATCH] Convert Spoiler to TS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Brandner --- .../elements/{Spoiler.js => Spoiler.tsx} | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) rename src/components/views/elements/{Spoiler.js => Spoiler.tsx} (82%) diff --git a/src/components/views/elements/Spoiler.js b/src/components/views/elements/Spoiler.tsx similarity index 82% rename from src/components/views/elements/Spoiler.js rename to src/components/views/elements/Spoiler.tsx index 802c6cf841..4779a7d90e 100644 --- a/src/components/views/elements/Spoiler.js +++ b/src/components/views/elements/Spoiler.tsx @@ -17,25 +17,34 @@ import React from 'react'; import { replaceableComponent } from "../../../utils/replaceableComponent"; +interface IProps { + reason?: string; + contentHtml: string; +} + +interface IState { + visible: boolean; +} + @replaceableComponent("views.elements.Spoiler") -export default class Spoiler extends React.Component { - constructor(props) { +export default class Spoiler extends React.Component { + constructor(props: IProps) { super(props); this.state = { visible: false, }; } - toggleVisible(e) { + private toggleVisible = (e: React.MouseEvent): void => { if (!this.state.visible) { // we are un-blurring, we don't want this click to propagate to potential child pills e.preventDefault(); e.stopPropagation(); } this.setState({ visible: !this.state.visible }); - } + }; - render() { + public render(): JSX.Element { const reason = this.props.reason ? ( { "(" + this.props.reason + ")" } ) : null; @@ -43,7 +52,7 @@ export default class Spoiler extends React.Component { // as such, we pass the this.props.contentHtml instead and then set the raw // HTML content. This is secure as the contents have already been parsed previously return ( - + { reason }