2017-05-04 15:55:52 +03:00
|
|
|
/*
|
2017-05-04 17:02:21 +03:00
|
|
|
Copyright 2017 Vector Creations Ltd
|
2017-05-04 15:55:52 +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 PropTypes from 'prop-types';
|
|
|
|
import AccessibleButton from './AccessibleButton';
|
2020-05-14 05:41:41 +03:00
|
|
|
import dis from '../../../dispatcher/dispatcher';
|
2019-12-20 04:19:56 +03:00
|
|
|
import * as sdk from '../../../index';
|
2017-09-20 19:16:49 +03:00
|
|
|
import Analytics from '../../../Analytics';
|
2017-05-04 15:55:52 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
export default class ActionButton extends React.Component {
|
|
|
|
static propTypes = {
|
2017-05-04 15:55:52 +03:00
|
|
|
size: PropTypes.string,
|
2017-05-05 16:25:18 +03:00
|
|
|
tooltip: PropTypes.bool,
|
|
|
|
action: PropTypes.string.isRequired,
|
2017-05-25 15:54:59 +03:00
|
|
|
mouseOverAction: PropTypes.string,
|
2017-05-05 16:25:18 +03:00
|
|
|
label: PropTypes.string.isRequired,
|
2018-12-10 17:33:35 +03:00
|
|
|
iconPath: PropTypes.string,
|
2018-12-19 14:11:21 +03:00
|
|
|
className: PropTypes.string,
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-05-04 15:55:52 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
static defaultProps = {
|
|
|
|
size: "25",
|
|
|
|
tooltip: false,
|
|
|
|
};
|
2017-05-04 17:38:09 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
state = {
|
|
|
|
showTooltip: false,
|
|
|
|
};
|
2017-05-04 15:55:52 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_onClick = (ev) => {
|
2017-05-04 15:55:52 +03:00
|
|
|
ev.stopPropagation();
|
2017-09-20 19:16:49 +03:00
|
|
|
Analytics.trackEvent('Action Button', 'click', this.props.action);
|
2017-05-05 16:25:18 +03:00
|
|
|
dis.dispatch({action: this.props.action});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-05-04 15:55:52 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_onMouseEnter = () => {
|
2017-05-04 17:38:09 +03:00
|
|
|
if (this.props.tooltip) this.setState({showTooltip: true});
|
2017-05-25 15:54:59 +03:00
|
|
|
if (this.props.mouseOverAction) {
|
|
|
|
dis.dispatch({action: this.props.mouseOverAction});
|
|
|
|
}
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-05-04 17:38:09 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
_onMouseLeave = () => {
|
2017-05-04 17:38:09 +03:00
|
|
|
this.setState({showTooltip: false});
|
2020-08-29 14:14:16 +03:00
|
|
|
};
|
2017-05-04 17:38:09 +03:00
|
|
|
|
2020-08-29 14:14:16 +03:00
|
|
|
render() {
|
2017-05-04 15:55:52 +03:00
|
|
|
const TintableSvg = sdk.getComponent("elements.TintableSvg");
|
|
|
|
|
2017-05-04 17:38:09 +03:00
|
|
|
let tooltip;
|
|
|
|
if (this.state.showTooltip) {
|
2019-02-01 02:36:19 +03:00
|
|
|
const Tooltip = sdk.getComponent("elements.Tooltip");
|
|
|
|
tooltip = <Tooltip className="mx_RoleButton_tooltip" label={this.props.label} />;
|
2017-05-04 17:38:09 +03:00
|
|
|
}
|
|
|
|
|
2018-12-10 17:33:35 +03:00
|
|
|
const icon = this.props.iconPath ?
|
|
|
|
(<TintableSvg src={this.props.iconPath} width={this.props.size} height={this.props.size} />) :
|
|
|
|
undefined;
|
|
|
|
|
2018-12-19 14:11:21 +03:00
|
|
|
const classNames = ["mx_RoleButton"];
|
|
|
|
if (this.props.className) {
|
|
|
|
classNames.push(this.props.className);
|
|
|
|
}
|
|
|
|
|
2017-05-04 15:55:52 +03:00
|
|
|
return (
|
2018-12-19 14:11:21 +03:00
|
|
|
<AccessibleButton className={classNames.join(" ")}
|
2017-05-04 17:38:09 +03:00
|
|
|
onClick={this._onClick}
|
|
|
|
onMouseEnter={this._onMouseEnter}
|
|
|
|
onMouseLeave={this._onMouseLeave}
|
2017-11-17 16:33:39 +03:00
|
|
|
aria-label={this.props.label}
|
2017-05-04 17:38:09 +03:00
|
|
|
>
|
2018-12-10 17:33:35 +03:00
|
|
|
{ icon }
|
2017-10-11 19:56:17 +03:00
|
|
|
{ tooltip }
|
2017-05-04 15:55:52 +03:00
|
|
|
</AccessibleButton>
|
|
|
|
);
|
2020-08-29 14:14:16 +03:00
|
|
|
}
|
|
|
|
}
|