Files
ThreadNet-Web/apps/web/src/components/views/elements/Spoiler.tsx
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

53 lines
1.4 KiB
TypeScript
Raw Normal View History

/*
2024-09-09 14:57:16 +01:00
Copyright 2024 New Vector Ltd.
Copyright 2019 Sorunome
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
2024-09-09 14:57:16 +01:00
Please see LICENSE files in the repository root for full details.
*/
2019-05-22 20:41:27 +02:00
import React, { type ReactNode } from "react";
2021-10-22 17:23:32 -05:00
2021-09-15 20:47:49 +02:00
interface IProps {
reason?: string;
children: ReactNode;
2021-09-15 20:47:49 +02:00
}
interface IState {
visible: boolean;
}
export default class Spoiler extends React.Component<IProps, IState> {
public constructor(props: IProps) {
super(props);
this.state = {
2019-05-22 20:41:27 +02:00
visible: false,
};
}
2019-05-22 20:41:27 +02:00
2021-09-15 20:47:49 +02:00
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();
}
2019-05-22 20:41:27 +02:00
this.setState({ visible: !this.state.visible });
2021-09-15 20:47:49 +02:00
};
2019-05-22 20:41:27 +02:00
public render(): React.ReactNode {
2019-05-22 20:41:27 +02:00
const reason = this.props.reason ? (
<span className="mx_EventTile_spoiler_reason">{"(" + this.props.reason + ")"}</span>
2019-05-22 20:41:27 +02:00
) : null;
return (
<button
2021-09-15 20:47:49 +02:00
className={"mx_EventTile_spoiler" + (this.state.visible ? " visible" : "")}
onClick={this.toggleVisible}
>
2019-05-22 20:41:27 +02:00
{reason}
&nbsp;
<span className="mx_EventTile_spoiler_content">{this.props.children}</span>
</button>
2019-05-22 20:41:27 +02:00
);
}
}