www/components/title.tsx

45 lines
1.2 KiB
TypeScript
Raw Normal View History

2021-12-08 03:38:31 +00:00
import Link from 'next/link';
2022-10-05 03:41:59 +00:00
import style from '../styles/title.module.css';
2021-12-08 03:38:31 +00:00
type propsObj = {
name: string,
title?: string,
ancestors?: Array<{ name: string, path: string }>
};
2022-04-28 01:55:18 +00:00
function createPathElements(ancestors: Array<{ name: string, path: string }>) {
let currentPath = '';
2022-05-15 13:56:45 +00:00
return ancestors.map((ancestor, id) => {
2022-04-28 01:55:18 +00:00
currentPath += `/${ancestor.path}`
return (
<>
2022-05-15 13:56:45 +00:00
<Link key={id + 1} href={currentPath}>
2022-04-28 01:55:18 +00:00
<a>{ancestor.name}</a>
</Link>
<> / </>
</>
2021-12-08 03:38:31 +00:00
);
2022-04-28 01:55:18 +00:00
});
};
function Title({ name, title, ancestors }: propsObj) {
const pathElements = ancestors && createPathElements(ancestors) || <></>;
2021-12-08 03:38:31 +00:00
return (
<>
2022-04-30 13:56:18 +00:00
<div className={style.container}>
<h1 className={style.title}>
{title || name}
</h1>
</div>
2022-04-28 01:55:18 +00:00
<div className={`${style.nav} h1`}>
{name
? <><Link href='/'><a>PaulW.XYZ</a></Link> / {pathElements}{name}</>
: <>PaulW.XYZ /</>}
2021-12-08 03:38:31 +00:00
</div>
</>
);
}
export default Title;