2018-10-30 19:15:19 +03:00
|
|
|
/*
|
|
|
|
Copyright 2015, 2016 OpenMarket Ltd
|
|
|
|
Copyright 2017 Vector Creations Ltd
|
|
|
|
Copyright 2017 New Vector Ltd
|
|
|
|
Copyright 2018 New Vector Ltd
|
2019-10-03 11:35:39 +03:00
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2018-10-30 19:15:19 +03: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';
|
|
|
|
import Analytics from '../../../Analytics';
|
2020-07-17 20:16:21 +03:00
|
|
|
import AccessibleTooltipButton from "../elements/AccessibleTooltipButton";
|
2018-10-30 19:15:19 +03:00
|
|
|
|
2020-07-18 14:04:48 +03:00
|
|
|
interface IProps {
|
|
|
|
// Whether this button is highlighted
|
|
|
|
isHighlighted: boolean;
|
|
|
|
// click handler
|
|
|
|
onClick: () => void;
|
|
|
|
// The badge to display above the icon
|
|
|
|
badge: React.ReactNode;
|
|
|
|
// The parameters to track the click event
|
|
|
|
analytics: string[];
|
|
|
|
|
|
|
|
// Button name
|
|
|
|
name: string;
|
|
|
|
// Button title
|
|
|
|
title: string;
|
|
|
|
};
|
|
|
|
|
|
|
|
export default class HeaderButton extends React.Component<IProps> {
|
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
2018-10-30 19:15:19 +03:00
|
|
|
this.onClick = this.onClick.bind(this);
|
|
|
|
}
|
|
|
|
|
2020-07-18 14:04:48 +03:00
|
|
|
onClick(_ev: React.KeyboardEvent) {
|
2018-10-30 19:15:19 +03:00
|
|
|
Analytics.trackEvent(...this.props.analytics);
|
2019-04-10 14:21:07 +03:00
|
|
|
this.props.onClick();
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const classes = classNames({
|
|
|
|
mx_RightPanel_headerButton: true,
|
|
|
|
mx_RightPanel_headerButton_highlight: this.props.isHighlighted,
|
2019-02-12 20:31:47 +03:00
|
|
|
[`mx_RightPanel_${this.props.name}`]: true,
|
2018-10-30 19:15:19 +03:00
|
|
|
});
|
|
|
|
|
2020-07-17 20:16:21 +03:00
|
|
|
return <AccessibleTooltipButton
|
2019-10-03 11:35:39 +03:00
|
|
|
aria-selected={this.props.isHighlighted}
|
|
|
|
role="tab"
|
2018-10-30 19:15:19 +03:00
|
|
|
title={this.props.title}
|
|
|
|
className={classes}
|
2020-07-17 20:16:21 +03:00
|
|
|
onClick={this.onClick}
|
|
|
|
/>;
|
2018-10-30 19:15:19 +03:00
|
|
|
}
|
|
|
|
}
|