2020-08-17 15:07:16 -05:00
|
|
|
import React from 'react'
|
2020-08-17 15:59:29 -05:00
|
|
|
import PropTypes from 'prop-types'
|
2020-05-09 23:26:58 -04:00
|
|
|
import { CX } from '../constants'
|
2020-05-08 22:17:19 -04:00
|
|
|
import Button from './button'
|
|
|
|
|
2020-08-17 19:57:35 -05:00
|
|
|
class BackButton extends React.PureComponent {
|
2020-05-08 22:17:19 -04:00
|
|
|
|
|
|
|
static contextTypes = {
|
|
|
|
router: PropTypes.object,
|
|
|
|
}
|
|
|
|
|
|
|
|
historyBack = () => {
|
2020-06-10 12:02:56 -04:00
|
|
|
if (window.history && window.history.length === 1 || this.props.toHome) {
|
2020-05-08 22:17:19 -04:00
|
|
|
this.context.router.history.push('/home')
|
|
|
|
} else {
|
|
|
|
this.context.router.history.goBack()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleBackClick = () => {
|
|
|
|
this.historyBack()
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
2020-05-09 23:26:58 -04:00
|
|
|
className,
|
|
|
|
icon,
|
2020-05-08 22:17:19 -04:00
|
|
|
iconClassName,
|
|
|
|
iconSize,
|
|
|
|
} = this.props
|
2020-05-09 23:26:58 -04:00
|
|
|
|
|
|
|
const classes = CX(className, {
|
2020-08-18 15:43:06 -05:00
|
|
|
aiCenter: 1,
|
2020-05-09 23:26:58 -04:00
|
|
|
bgTransparent: 1,
|
|
|
|
mr5: 1,
|
|
|
|
cursorPointer: 1,
|
|
|
|
outlineNone: 1,
|
2020-08-18 15:49:11 -05:00
|
|
|
d: 1,
|
2020-08-18 15:43:06 -05:00
|
|
|
jcCenter: 1,
|
2020-05-09 23:26:58 -04:00
|
|
|
})
|
|
|
|
|
2020-05-08 22:17:19 -04:00
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
noClasses
|
|
|
|
color='primary'
|
|
|
|
backgroundColor='none'
|
2020-05-09 23:26:58 -04:00
|
|
|
className={classes}
|
|
|
|
icon={icon || 'angle-left'}
|
2020-05-08 22:17:19 -04:00
|
|
|
iconSize={iconSize || '24px'}
|
2020-08-18 15:43:06 -05:00
|
|
|
iconClassName={iconClassName || [_s.mr5, _s.cPrimary].join(' ')}
|
2020-05-08 22:17:19 -04:00
|
|
|
onClick={this.handleBackClick}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-17 19:57:35 -05:00
|
|
|
|
|
|
|
BackButton.propTypes = {
|
|
|
|
className: PropTypes.string,
|
|
|
|
icon: PropTypes.string,
|
|
|
|
iconClassName: PropTypes.string,
|
|
|
|
iconSize: PropTypes.string,
|
|
|
|
toHome: PropTypes.bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default BackButton
|