2021-12-14 19:14:53 +00:00
|
|
|
import { PropsWithChildren, createContext, useContext } from 'react';
|
2022-08-12 03:47:56 +00:00
|
|
|
import clsx from 'clsx';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
2022-08-12 03:47:56 +00:00
|
|
|
import styles from './HeaderContainer.module.css';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
|
|
|
const Context = createContext<null | boolean>(null);
|
2022-09-20 18:14:24 +00:00
|
|
|
Context.displayName = 'PageHeaderContext';
|
2021-12-14 19:14:53 +00:00
|
|
|
|
|
|
|
export function useHeaderContext() {
|
|
|
|
const context = useContext(Context);
|
|
|
|
|
|
|
|
if (context == null) {
|
2021-12-30 15:46:12 +00:00
|
|
|
throw new Error('Should be nested inside a HeaderContainer component');
|
2021-12-14 19:14:53 +00:00
|
|
|
}
|
|
|
|
}
|
2022-08-19 12:31:17 +00:00
|
|
|
interface Props {
|
|
|
|
id?: string;
|
|
|
|
}
|
2021-12-14 19:14:53 +00:00
|
|
|
|
2022-08-19 12:31:17 +00:00
|
|
|
export function HeaderContainer({ id, children }: PropsWithChildren<Props>) {
|
2021-12-14 19:14:53 +00:00
|
|
|
return (
|
|
|
|
<Context.Provider value>
|
2022-08-19 12:31:17 +00:00
|
|
|
<div id={id} className={clsx('row', styles.header)}>
|
2021-12-14 19:14:53 +00:00
|
|
|
<div id="loadingbar-placeholder" />
|
|
|
|
<div className="col-xs-12">
|
2022-08-12 03:47:56 +00:00
|
|
|
<div className={styles.meta}>{children}</div>
|
2021-12-14 19:14:53 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Context.Provider>
|
|
|
|
);
|
|
|
|
}
|