2019-08-29 18:13:52 +02:00
|
|
|
/*
|
2024-09-09 14:57:16 +01:00
|
|
|
Copyright 2024 New Vector Ltd.
|
|
|
|
|
Copyright 2019 Sorunome
|
2019-08-29 18:13:52 +02:00
|
|
|
|
2025-01-06 11:18:54 +00:00
|
|
|
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-08-29 18:13:52 +02:00
|
|
|
*/
|
2019-05-22 20:41:27 +02:00
|
|
|
|
2025-03-26 20:25:03 +00: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;
|
2025-03-26 20:25:03 +00:00
|
|
|
children: ReactNode;
|
2021-09-15 20:47:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IState {
|
|
|
|
|
visible: boolean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class Spoiler extends React.Component<IProps, IState> {
|
2022-12-16 12:29:59 +00:00
|
|
|
public constructor(props: IProps) {
|
2019-08-29 18:13:52 +02:00
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
2019-05-22 20:41:27 +02:00
|
|
|
visible: false,
|
|
|
|
|
};
|
2019-08-29 18:13:52 +02:00
|
|
|
}
|
2019-05-22 20:41:27 +02:00
|
|
|
|
2021-09-15 20:47:49 +02:00
|
|
|
private toggleVisible = (e: React.MouseEvent): void => {
|
2019-06-11 22:13:47 +02:00
|
|
|
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
|
|
|
|
2023-02-13 17:01:43 +00:00
|
|
|
public render(): React.ReactNode {
|
2019-05-22 20:41:27 +02:00
|
|
|
const reason = this.props.reason ? (
|
2021-07-19 22:43:11 +01:00
|
|
|
<span className="mx_EventTile_spoiler_reason">{"(" + this.props.reason + ")"}</span>
|
2019-05-22 20:41:27 +02:00
|
|
|
) : null;
|
|
|
|
|
return (
|
2023-08-09 18:27:31 +12:00
|
|
|
<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}
|
|
|
|
|
|
2025-03-26 20:25:03 +00:00
|
|
|
<span className="mx_EventTile_spoiler_content">{this.props.children}</span>
|
2023-08-09 18:27:31 +12:00
|
|
|
</button>
|
2019-05-22 20:41:27 +02:00
|
|
|
);
|
|
|
|
|
}
|
2019-08-29 18:13:52 +02:00
|
|
|
}
|