bigbuffet-rw/app/soapbox/components/ui/column/column.tsx

63 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-03-21 11:09:01 -07:00
import React from 'react';
2022-03-22 05:42:26 -07:00
import { useHistory } from 'react-router-dom';
2022-03-21 11:09:01 -07:00
import Helmet from 'soapbox/components/helmet';
import { Card, CardBody, CardHeader, CardTitle } from '../card/card';
2022-03-22 05:42:26 -07:00
interface IColumn {
2022-03-21 11:09:01 -07:00
backHref?: string,
label?: string,
transparent?: boolean,
withHeader?: boolean,
}
const Column: React.FC<IColumn> = React.forwardRef((props, ref: React.ForwardedRef<HTMLDivElement>): JSX.Element => {
2022-03-22 05:42:26 -07:00
const { backHref, children, label, transparent = false, withHeader = true } = props;
const history = useHistory();
const handleBackClick = () => {
if (backHref) {
history.push(backHref);
return;
}
if (history.length === 1) {
history.push('/');
} else {
history.goBack();
}
};
2022-03-21 11:09:01 -07:00
const renderChildren = () => {
if (transparent) {
return <div className='bg-white sm:bg-transparent'>{children}</div>;
}
return (
<Card variant='rounded'>
{withHeader ? (
<CardHeader onBackClick={handleBackClick}>
2022-03-21 11:09:01 -07:00
<CardTitle title={label} />
</CardHeader>
) : null}
<CardBody>
{children}
</CardBody>
</Card>
);
};
return (
<div role='region' ref={ref} aria-label={label} column-type={transparent ? 'transparent' : 'filled'}>
<Helmet><title>{label}</title></Helmet>
{renderChildren()}
</div>
);
});
2022-03-22 05:42:26 -07:00
export default Column;