element-portable/src/components/views/right_panel/HeaderButton.tsx
Florian Duros 95ee2979c8
Tooltip: improve accessibility of the right panel (#12490)
* Move to `AccessibleButton`

* Update snapshots

* Update playwright snapshots
2024-05-03 08:44:04 +00:00

63 lines
2 KiB
TypeScript

/*
Copyright 2015, 2016 OpenMarket Ltd
Copyright 2017 Vector Creations Ltd
Copyright 2017 New Vector Ltd
Copyright 2018 New Vector Ltd
Copyright 2019 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.
*/
import React, { ReactNode } from "react";
import classNames from "classnames";
import AccessibleButton, { ButtonEvent } from "../elements/AccessibleButton";
interface IProps {
// Whether this button is highlighted
isHighlighted: boolean;
isUnread?: boolean;
// click handler
onClick: (ev: ButtonEvent) => void;
// Button name
name: string;
// Button title
title: string;
children?: ReactNode;
}
// TODO: replace this, the composer buttons and the right panel buttons with a unified representation
export default class HeaderButton extends React.Component<IProps> {
public render(): React.ReactNode {
const { isHighlighted, isUnread = false, onClick, name, title, ...props } = this.props;
const classes = classNames({
"mx_LegacyRoomHeader_button": true,
"mx_LegacyRoomHeader_button--highlight": isHighlighted,
"mx_LegacyRoomHeader_button--unread": isUnread,
[`mx_RightPanel_${name}`]: true,
});
return (
<AccessibleButton
{...props}
aria-current={isHighlighted ? "true" : "false"}
title={title}
placement="bottom"
className={classes}
onClick={onClick}
/>
);
}
}