2018-10-30 17:15:19 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
|
Copyright 2017 New Vector Ltd
|
|
|
|
|
Copyright 2018 New Vector Ltd
|
2019-10-03 09:35:39 +01:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-10-30 17:15:19 +01:00
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
import classNames from 'classnames';
|
2021-10-22 17:23:32 -05:00
|
|
|
|
2018-10-30 17:15:19 +01:00
|
|
|
import Analytics from '../../../Analytics';
|
2020-07-17 18:16:21 +01:00
|
|
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
2021-06-03 08:41:22 +01:00
|
|
|
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
2022-02-28 14:11:14 +00:00
|
|
|
import { ButtonEvent } from "../elements/AccessibleButton";
|
2018-10-30 17:15:19 +01:00
|
|
|
|
2020-07-18 16:34:48 +05:30
|
|
|
interface IProps {
|
|
|
|
|
// Whether this button is highlighted
|
|
|
|
|
isHighlighted: boolean;
|
|
|
|
|
// click handler
|
2022-02-28 14:11:14 +00:00
|
|
|
onClick: (ev: ButtonEvent) => void;
|
2020-07-18 16:34:48 +05:30
|
|
|
// The parameters to track the click event
|
2020-10-13 22:58:21 +01:00
|
|
|
analytics: Parameters<typeof Analytics.trackEvent>;
|
2020-07-18 16:34:48 +05:30
|
|
|
|
|
|
|
|
// Button name
|
|
|
|
|
name: string;
|
|
|
|
|
// Button title
|
|
|
|
|
title: string;
|
2020-07-18 16:41:57 +05:30
|
|
|
}
|
2020-07-18 16:34:48 +05:30
|
|
|
|
2021-05-25 13:53:46 +01:00
|
|
|
// TODO: replace this, the composer buttons and the right panel buttons with a unified representation
|
2021-03-08 20:12:00 -07:00
|
|
|
@replaceableComponent("views.right_panel.HeaderButton")
|
2020-07-18 16:34:48 +05:30
|
|
|
export default class HeaderButton extends React.Component<IProps> {
|
2022-02-28 14:11:14 +00:00
|
|
|
private onClick = (ev: ButtonEvent) => {
|
2018-10-30 17:15:19 +01:00
|
|
|
Analytics.trackEvent(...this.props.analytics);
|
2022-02-28 14:11:14 +00:00
|
|
|
this.props.onClick(ev);
|
2021-05-25 13:53:46 +01:00
|
|
|
};
|
2018-10-30 17:15:19 +01:00
|
|
|
|
2020-07-30 15:58:07 +05:30
|
|
|
public render() {
|
2021-05-25 13:53:46 +01:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-06-29 13:11:58 +01:00
|
|
|
const { isHighlighted, onClick, analytics, name, title, ...props } = this.props;
|
2021-05-25 13:53:46 +01:00
|
|
|
|
2018-10-30 17:15:19 +01:00
|
|
|
const classes = classNames({
|
|
|
|
|
mx_RightPanel_headerButton: true,
|
2021-05-25 13:53:46 +01:00
|
|
|
mx_RightPanel_headerButton_highlight: isHighlighted,
|
|
|
|
|
[`mx_RightPanel_${name}`]: true,
|
2018-10-30 17:15:19 +01:00
|
|
|
});
|
|
|
|
|
|
2020-07-17 18:16:21 +01:00
|
|
|
return <AccessibleTooltipButton
|
2021-05-25 13:53:46 +01:00
|
|
|
{...props}
|
|
|
|
|
aria-selected={isHighlighted}
|
2019-10-03 09:35:39 +01:00
|
|
|
role="tab"
|
2021-05-25 13:53:46 +01:00
|
|
|
title={title}
|
2018-10-30 17:15:19 +01:00
|
|
|
className={classes}
|
2020-07-17 18:16:21 +01:00
|
|
|
onClick={this.onClick}
|
|
|
|
|
/>;
|
2018-10-30 17:15:19 +01:00
|
|
|
}
|
|
|
|
|
}
|