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