2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-05-10 04:26:58 +01:00
|
|
|
import { CX } from '../constants'
|
2020-05-09 03:17:19 +01:00
|
|
|
import Button from './button'
|
|
|
|
|
2020-08-18 01:57:35 +01:00
|
|
|
class BackButton extends React.PureComponent {
|
2020-05-09 03:17:19 +01:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
historyBack = () => {
|
2020-06-10 17:02:56 +01:00
|
|
|
if (window.history && window.history.length === 1 || this.props.toHome) {
|
2020-05-09 03:17:19 +01:00
|
|
|
this.context.router.history.push('/home')
|
|
|
|
} else {
|
|
|
|
this.context.router.history.goBack()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBackClick = () => {
|
|
|
|
this.historyBack()
|
2020-12-04 03:27:09 +00:00
|
|
|
if (!!this.props.onClick) this.props.onClick()
|
2020-05-09 03:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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, {
|
2020-08-18 21:43:06 +01:00
|
|
|
aiCenter: 1,
|
2020-05-10 04:26:58 +01:00
|
|
|
bgTransparent: 1,
|
|
|
|
mr5: 1,
|
|
|
|
cursorPointer: 1,
|
|
|
|
outlineNone: 1,
|
2020-08-18 21:49:11 +01:00
|
|
|
d: 1,
|
2020-08-18 21:43:06 +01:00
|
|
|
jcCenter: 1,
|
2020-05-10 04:26:58 +01:00
|
|
|
})
|
|
|
|
|
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'}
|
2020-08-18 21:43:06 +01:00
|
|
|
iconClassName={iconClassName || [_s.mr5, _s.cPrimary].join(' ')}
|
2020-05-09 03:17:19 +01:00
|
|
|
onClick={this.handleBackClick}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 01:57:35 +01:00
|
|
|
|
|
|
|
BackButton.propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
|
|
|
iconClassName: PropTypes.string,
|
|
|
|
iconSize: PropTypes.string,
|
|
|
|
toHome: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BackButton
|