2020-05-10 04:26:58 +01:00
|
|
|
import { CX } from '../constants'
|
2020-05-09 03:17:19 +01:00
|
|
|
import Button from './button'
|
|
|
|
|
|
|
|
export default class BackButton extends PureComponent {
|
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
static propTypes = {
|
2020-05-10 04:26:58 +01:00
|
|
|
className: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
2020-05-09 03:17:19 +01:00
|
|
|
iconClassName: PropTypes.string,
|
|
|
|
iconSize: PropTypes.string,
|
|
|
|
}
|
|
|
|
|
|
|
|
historyBack = () => {
|
|
|
|
if (window.history && window.history.length === 1) {
|
|
|
|
this.context.router.history.push('/home')
|
|
|
|
} else {
|
|
|
|
this.context.router.history.goBack()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBackClick = () => {
|
|
|
|
this.historyBack()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2020-05-10 04:26:58 +01:00
|
|
|
className,
|
|
|
|
icon,
|
2020-05-09 03:17:19 +01:00
|
|
|
iconClassName,
|
|
|
|
iconSize,
|
|
|
|
} = this.props
|
2020-05-10 04:26:58 +01:00
|
|
|
|
|
|
|
const classes = CX(className, {
|
|
|
|
alignItemsCenter: 1,
|
|
|
|
bgTransparent: 1,
|
|
|
|
mr5: 1,
|
|
|
|
cursorPointer: 1,
|
|
|
|
outlineNone: 1,
|
|
|
|
default: 1,
|
|
|
|
justifyContentCenter: 1,
|
|
|
|
})
|
|
|
|
|
2020-05-09 03:17:19 +01:00
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
noClasses
|
|
|
|
color='primary'
|
|
|
|
backgroundColor='none'
|
2020-05-10 04:26:58 +01:00
|
|
|
className={classes}
|
|
|
|
icon={icon || 'angle-left'}
|
2020-05-09 03:17:19 +01:00
|
|
|
iconSize={iconSize || '24px'}
|
|
|
|
iconClassName={iconClassName || [_s.mr5, _s.fillPrimary].join(' ')}
|
|
|
|
onClick={this.handleBackClick}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|