gab-social/app/javascript/gabsocial/components/column_header.js

89 lines
2.2 KiB
JavaScript
Raw Normal View History

2020-02-22 23:26:23 +00:00
import TabBar from './tab_bar'
2020-02-21 00:57:29 +00:00
import Button from './button'
import Heading from './heading'
2020-02-14 00:40:04 +00:00
2020-03-07 04:53:28 +00:00
export default class ColumnHeader extends PureComponent {
2020-02-14 00:40:04 +00:00
static contextTypes = {
router: PropTypes.object,
}
static propTypes = {
title: PropTypes.node,
2020-02-19 23:57:07 +00:00
showBackBtn: PropTypes.bool,
actions: PropTypes.array,
2020-02-22 23:26:23 +00:00
tabs: PropTypes.array,
2020-02-14 00:40:04 +00:00
}
historyBack = () => {
if (window.history && window.history.length === 1) {
2020-03-07 04:53:28 +00:00
this.context.router.history.push('/home')
2020-02-14 00:40:04 +00:00
} else {
this.context.router.history.goBack()
}
}
handleBackClick = () => {
this.historyBack()
}
2020-02-21 00:57:29 +00:00
render() {
2020-03-07 04:53:28 +00:00
const {
title,
showBackBtn,
tabs,
actions
} = this.props
2020-02-14 00:40:04 +00:00
return (
2020-02-19 23:57:07 +00:00
<div className={[_s.default, _s.height100PC, _s.flexRow].join(' ')}>
{
showBackBtn &&
2020-03-07 04:53:28 +00:00
<Button
backgroundColor='none'
className={[_s.alignItemsCenter, _s.paddingLeft0, _s.justifyContentCenter].join(' ')}
icon='back'
iconWidth='20px'
iconHeight='20px'
iconClassName={[_s.marginRight5PX, _s.fillColorPrimary].join(' ')}
onClick={this.handleBackClick}
/>
2020-02-19 23:57:07 +00:00
}
2020-02-21 00:57:29 +00:00
2020-02-22 23:26:23 +00:00
<div className={[_s.default, _s.height100PC, _s.justifyContentCenter, _s.marginRight10PX].join(' ')}>
2020-02-21 00:57:29 +00:00
<Heading size='h1'>
2020-02-14 00:40:04 +00:00
{title}
2020-02-21 00:57:29 +00:00
</Heading>
</div>
2020-02-22 23:26:23 +00:00
{
!!tabs &&
<TabBar tabs={tabs} />
}
2020-02-19 23:57:07 +00:00
{
!!actions &&
<div className={[_s.default, _s.backgroundTransparent, _s.flexRow, _s.alignItemsCenter, _s.justifyContentCenter, _s.marginLeftAuto].join(' ')}>
{
actions.map((action, i) => (
2020-03-07 04:53:28 +00:00
<Button
radiusSmall
backgroundColor='tertiary'
2020-02-19 23:57:07 +00:00
onClick={() => action.onClick()}
key={`column-header-action-btn-${i}`}
2020-03-07 04:53:28 +00:00
className={[_s.marginLeft5PX, _s.paddingHorizontal10PX].join(' ')}
iconClassName={_s.fillColorSecondary}
icon={action.icon}
iconWidth='20px'
iconHeight='20px'
/>
2020-02-19 23:57:07 +00:00
))
}
</div>
}
2020-02-14 00:40:04 +00:00
</div>
)
}
}