gab-social/app/javascript/gabsocial/components/column_back_button/index.js

40 lines
953 B
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
import { FormattedMessage } from 'react-intl';
import classNames from 'classnames';
import Icon from '../icon';
import './index.scss';
2019-07-02 08:10:25 +01:00
export default class ColumnBackButton extends PureComponent {
2019-07-02 08:10:25 +01:00
static contextTypes = {
router: PropTypes.object,
};
static propTypes = {
slim: PropTypes.bool,
};
2019-07-02 08:10:25 +01:00
handleClick = () => {
if (window.history && window.history.length === 1) {
2019-07-04 00:29:54 +01:00
this.context.router.history.push('/home'); // homehack
2019-07-02 08:10:25 +01:00
} else {
this.context.router.history.goBack();
}
}
render () {
const { slim } = this.props;
const btnClasses = classNames('column-back-button', {
'column-back-button--slim': slim,
});
2019-07-02 08:10:25 +01:00
return (
<button className={btnClasses} onClick={this.handleClick}>
2019-07-02 08:10:25 +01:00
<Icon id='chevron-left' className='column-back-button__icon' fixedWidth />
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
</button>
);
}
}