2019-06-30 12:58:59 +03:00
|
|
|
/*
|
2019-10-03 11:35:39 +03:00
|
|
|
Copyright 2019 Michael Telatynski <7t3chguy@gmail.com>
|
|
|
|
Copyright 2019 The Matrix.org Foundation C.I.C.
|
2019-06-30 12:58:59 +03:00
|
|
|
|
2019-10-03 11:35:39 +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
|
2019-06-30 12:58:59 +03:00
|
|
|
|
2019-10-03 11:35:39 +03:00
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
2019-06-30 12:58:59 +03:00
|
|
|
|
2019-10-03 11:35:39 +03:00
|
|
|
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.
|
|
|
|
*/
|
2019-06-30 12:58:59 +03:00
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import AccessibleButton from "./AccessibleButton";
|
|
|
|
import sdk from "../../../index";
|
|
|
|
|
|
|
|
export default class AccessibleTooltipButton extends React.PureComponent {
|
|
|
|
static propTypes = {
|
|
|
|
...AccessibleButton.propTypes,
|
2019-06-30 13:00:21 +03:00
|
|
|
// The tooltip to render on hover
|
|
|
|
title: PropTypes.string.isRequired,
|
2019-06-30 12:58:59 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
state = {
|
|
|
|
hover: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
onMouseOver = () => {
|
|
|
|
this.setState({
|
|
|
|
hover: true,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
onMouseOut = () => {
|
|
|
|
this.setState({
|
|
|
|
hover: false,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const Tooltip = sdk.getComponent("elements.Tooltip");
|
|
|
|
const AccessibleButton = sdk.getComponent("elements.AccessibleButton");
|
|
|
|
|
2019-06-30 13:00:21 +03:00
|
|
|
const {title, ...props} = this.props;
|
2019-06-30 12:58:59 +03:00
|
|
|
|
|
|
|
const tip = this.state.hover ? <Tooltip
|
|
|
|
className="mx_AccessibleTooltipButton_container"
|
|
|
|
tooltipClassName="mx_AccessibleTooltipButton_tooltip"
|
2019-06-30 13:00:21 +03:00
|
|
|
label={title}
|
2019-06-30 12:58:59 +03:00
|
|
|
/> : <div />;
|
|
|
|
return (
|
2019-10-03 11:35:39 +03:00
|
|
|
<AccessibleButton {...props} onMouseOver={this.onMouseOver} onMouseOut={this.onMouseOut} aria-label={title}>
|
2019-06-30 12:58:59 +03:00
|
|
|
{ tip }
|
|
|
|
</AccessibleButton>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|