gab-social/app/javascript/gabsocial/features/ui/components/column.js

41 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-07-02 08:10:25 +01:00
import React from 'react';
import ColumnHeader from './column_header';
import PropTypes from 'prop-types';
import { isMobile } from '../../../is_mobile';
import ColumnBackButton from '../../../components/column_back_button';
import ColumnBackButtonSlim from '../../../components/column_back_button_slim';
2019-07-02 08:10:25 +01:00
export default class Column extends React.PureComponent {
static propTypes = {
heading: PropTypes.string,
icon: PropTypes.string,
children: PropTypes.node,
active: PropTypes.bool,
hideHeadingOnMobile: PropTypes.bool,
2019-07-19 20:33:42 +01:00
backBtnSlim: PropTypes.bool,
2019-07-02 08:10:25 +01:00
};
render () {
const { heading, icon, children, active, hideHeadingOnMobile, backBtnSlim } = this.props;
2019-07-02 08:10:25 +01:00
const showHeading = heading && (!hideHeadingOnMobile || (hideHeadingOnMobile && !isMobile(window.innerWidth)));
const columnHeaderId = showHeading && heading.replace(/ /g, '-');
const header = showHeading && (
<ColumnHeader icon={icon} active={active} type={heading} columnHeaderId={columnHeaderId} />
);
const backBtn = backBtnSlim ? (<ColumnBackButtonSlim/>) : (<ColumnBackButton/>);
2019-07-02 08:10:25 +01:00
return (
<div role='region' aria-labelledby={columnHeaderId} className='column'>
{header}
{backBtn}
2019-07-02 08:10:25 +01:00
{children}
</div>
);
}
}