1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-07-06 03:36:46 +00:00
seahub/frontend/src/components/icon-button.js
Michael An e6261c1c3a
Fix download python file bug (#6736)
* fix download py file bug

* download in current tab
2024-09-09 13:55:17 +08:00

71 lines
1.5 KiB
JavaScript

import React from 'react';
import PropTypes from 'prop-types';
import { Tooltip } from 'reactstrap';
import Icon from './icon';
const propTypes = {
id: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
text: PropTypes.string.isRequired,
onClick: PropTypes.func,
href: PropTypes.string
};
class IconButton extends React.Component {
constructor(props) {
super(props);
this.state = {
tooltipOpen: false
};
}
toggle = () => {
this.setState({
tooltipOpen: !this.state.tooltipOpen
});
};
render() {
const btnContent = (
<>
<Icon symbol={this.props.icon} />
<Tooltip
toggle={this.toggle}
delay={{ show: 0, hide: 0 }}
target={this.props.id}
placement='bottom'
isOpen={this.state.tooltipOpen}>
{this.props.text}
</Tooltip>
</>
);
if (this.props.href) {
return (
<div
id={this.props.id}
className='file-toolbar-btn'
aria-label={this.props.text}
onClick={() => window.open(this.props.href, '_parent')}
>
{btnContent}
</div>
);
} else {
return (
<div
id={this.props.id}
className='file-toolbar-btn'
onClick={this.props.onClick}
aria-label={this.props.text}
>
{btnContent}
</div>
);
}
}
}
IconButton.propTypes = propTypes;
export default IconButton;