You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
8 years ago
|
import React from 'react';
|
||
8 years ago
|
import { FormattedMessage } from 'react-intl';
|
||
8 years ago
|
import PropTypes from 'prop-types';
|
||
6 years ago
|
import Icon from 'mastodon/components/icon';
|
||
5 years ago
|
import { createPortal } from 'react-dom';
|
||
8 years ago
|
|
||
8 years ago
|
export default class ColumnBackButton extends React.PureComponent {
|
||
8 years ago
|
|
||
8 years ago
|
static contextTypes = {
|
||
8 years ago
|
router: PropTypes.object,
|
||
8 years ago
|
};
|
||
8 years ago
|
|
||
5 years ago
|
static propTypes = {
|
||
|
multiColumn: PropTypes.bool,
|
||
|
};
|
||
|
|
||
7 years ago
|
handleClick = () => {
|
||
|
if (window.history && window.history.length === 1) {
|
||
|
this.context.router.history.push('/');
|
||
|
} else {
|
||
|
this.context.router.history.goBack();
|
||
7 years ago
|
}
|
||
2 years ago
|
};
|
||
8 years ago
|
|
||
|
render () {
|
||
5 years ago
|
const { multiColumn } = this.props;
|
||
|
|
||
|
const component = (
|
||
7 years ago
|
<button onClick={this.handleClick} className='column-back-button'>
|
||
6 years ago
|
<Icon id='chevron-left' className='column-back-button__icon' fixedWidth />
|
||
8 years ago
|
<FormattedMessage id='column_back_button.label' defaultMessage='Back' />
|
||
7 years ago
|
</button>
|
||
8 years ago
|
);
|
||
5 years ago
|
|
||
|
if (multiColumn) {
|
||
|
return component;
|
||
|
} else {
|
||
5 years ago
|
// The portal container and the component may be rendered to the DOM in
|
||
|
// the same React render pass, so the container might not be available at
|
||
|
// the time `render()` is called.
|
||
|
const container = document.getElementById('tabs-bar__portal');
|
||
|
if (container === null) {
|
||
|
// The container wasn't available, force a re-render so that the
|
||
|
// component can eventually be inserted in the container and not scroll
|
||
|
// with the rest of the area.
|
||
|
this.forceUpdate();
|
||
|
return component;
|
||
|
} else {
|
||
|
return createPortal(component, container);
|
||
|
}
|
||
5 years ago
|
}
|
||
8 years ago
|
}
|
||
|
|
||
8 years ago
|
}
|