2020-09-08 08:48:03 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
2021-06-29 13:11:58 +01:00
|
|
|
import React, { ReactNode } from 'react';
|
2020-09-08 08:48:03 +01:00
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
|
|
import AutoHideScrollbar from "../../structures/AutoHideScrollbar";
|
2021-06-29 13:11:58 +01:00
|
|
|
import { _t } from "../../../languageHandler";
|
2020-09-08 08:48:03 +01:00
|
|
|
import AccessibleButton from "../elements/AccessibleButton";
|
2022-01-05 16:14:44 +01:00
|
|
|
import RightPanelStore from '../../../stores/right-panel/RightPanelStore';
|
2022-01-05 17:25:41 +01:00
|
|
|
import { backLabelForPhase } from '../../../stores/right-panel/RightPanelStorePhases';
|
2020-09-08 08:48:03 +01:00
|
|
|
|
2022-01-05 17:25:41 +01:00
|
|
|
export const CardContext = React.createContext({ isCard: false });
|
2020-09-08 08:48:03 +01:00
|
|
|
interface IProps {
|
|
|
|
|
header?: ReactNode;
|
|
|
|
|
footer?: ReactNode;
|
|
|
|
|
className?: string;
|
|
|
|
|
withoutScrollContainer?: boolean;
|
2020-09-29 10:11:04 +01:00
|
|
|
closeLabel?: string;
|
2020-09-08 08:48:03 +01:00
|
|
|
onClose?(): void;
|
2022-01-05 16:14:44 +01:00
|
|
|
cardState?;
|
2020-09-08 08:48:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface IGroupProps {
|
|
|
|
|
className?: string;
|
|
|
|
|
title: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Group: React.FC<IGroupProps> = ({ className, title, children }) => {
|
|
|
|
|
return <div className={classNames("mx_BaseCard_Group", className)}>
|
2021-07-19 22:43:11 +01:00
|
|
|
<h1>{ title }</h1>
|
|
|
|
|
{ children }
|
2020-09-08 08:48:03 +01:00
|
|
|
</div>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const BaseCard: React.FC<IProps> = ({
|
2020-09-29 10:11:04 +01:00
|
|
|
closeLabel,
|
2020-09-08 08:48:03 +01:00
|
|
|
onClose,
|
|
|
|
|
className,
|
|
|
|
|
header,
|
|
|
|
|
footer,
|
|
|
|
|
withoutScrollContainer,
|
|
|
|
|
children,
|
|
|
|
|
}) => {
|
|
|
|
|
let backButton;
|
2022-01-05 17:25:41 +01:00
|
|
|
const cardHistory = RightPanelStore.instance.roomPhaseHistory;
|
|
|
|
|
if (cardHistory.length > 1) {
|
|
|
|
|
const prevCard = cardHistory[cardHistory.length - 2];
|
2020-09-08 08:48:03 +01:00
|
|
|
const onBackClick = () => {
|
2022-01-05 17:25:41 +01:00
|
|
|
RightPanelStore.instance.popCard();
|
2020-09-08 08:48:03 +01:00
|
|
|
};
|
2022-01-05 17:25:41 +01:00
|
|
|
const label = backLabelForPhase(prevCard.phase) ?? _t("Back");
|
2021-11-11 11:00:18 +00:00
|
|
|
backButton = <AccessibleButton className="mx_BaseCard_back" onClick={onBackClick} title={label} />;
|
2020-09-08 08:48:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let closeButton;
|
|
|
|
|
if (onClose) {
|
2020-09-29 10:11:04 +01:00
|
|
|
closeButton = <AccessibleButton
|
2022-02-08 13:14:52 +01:00
|
|
|
data-test-id='base-card-close-button'
|
2020-09-29 10:11:04 +01:00
|
|
|
className="mx_BaseCard_close"
|
|
|
|
|
onClick={onClose}
|
|
|
|
|
title={closeLabel || _t("Close")}
|
|
|
|
|
/>;
|
2020-09-08 08:48:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!withoutScrollContainer) {
|
|
|
|
|
children = <AutoHideScrollbar>
|
|
|
|
|
{ children }
|
|
|
|
|
</AutoHideScrollbar>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2022-01-05 17:25:41 +01:00
|
|
|
<CardContext.Provider value={{ isCard: true }}>
|
|
|
|
|
<div className={classNames("mx_BaseCard", className)}>
|
|
|
|
|
<div className="mx_BaseCard_header">
|
|
|
|
|
{ backButton }
|
|
|
|
|
{ closeButton }
|
|
|
|
|
{ header }
|
|
|
|
|
</div>
|
|
|
|
|
{ children }
|
|
|
|
|
{ footer && <div className="mx_BaseCard_footer">{ footer }</div> }
|
2020-09-08 08:48:03 +01:00
|
|
|
</div>
|
2022-01-05 17:25:41 +01:00
|
|
|
</CardContext.Provider>
|
2020-09-08 08:48:03 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default BaseCard;
|