From 70b4f633a6fbedb58c8b9134ac64ede854d489de Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 20 Nov 2023 12:27:46 +0100 Subject: refactor(components): replace PageLayout template with Page * split pages in smaller components (it is both easier to maintain and more readable, we avoid the use of fragments in pages directory) * extract breadcrumbs from article tag (the navigation is not related to the page contents) * remove useReadingTime hook * remove layout options except `isHome` --- src/components/templates/page/page-header.tsx | 172 ++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 src/components/templates/page/page-header.tsx (limited to 'src/components/templates/page/page-header.tsx') diff --git a/src/components/templates/page/page-header.tsx b/src/components/templates/page/page-header.tsx new file mode 100644 index 0000000..6effc9e --- /dev/null +++ b/src/components/templates/page/page-header.tsx @@ -0,0 +1,172 @@ +import { + type ForwardRefRenderFunction, + forwardRef, + type ReactNode, +} from 'react'; +import { useIntl } from 'react-intl'; +import type { PageLink } from '../../../types'; +import { getReadingTimeFrom } from '../../../utils/helpers'; +import { Header, Heading, type HeaderProps, Link, Time } from '../../atoms'; +import { MetaList, MetaItem } from '../../molecules'; +import styles from './page.module.scss'; + +export type PageHeaderMetaData = { + author: string; + publicationDate: string; + thematics: PageLink[]; + total: number; + updateDate: string; + website: string; + wordsCount: number; +}; + +export type PageHeaderProps = Omit & { + /** + * The page main title. + */ + heading: ReactNode; + /** + * The page introduction. + */ + intro?: ReactNode; + /** + * The page meta. + */ + meta?: Partial; +}; + +const PageHeaderWithRef: ForwardRefRenderFunction< + HTMLElement, + PageHeaderProps +> = ({ className = '', heading, intro, meta, ...props }, ref) => { + const headerClass = `${styles.header} ${className}`; + const intl = useIntl(); + + return ( +
+
+ + {heading} + + {meta ? ( + + {meta.author ? ( + + ) : null} + {meta.publicationDate ? ( + } + /> + ) : null} + {meta.updateDate && meta.updateDate !== meta.publicationDate ? ( + } + /> + ) : null} + {meta.wordsCount ? ( + + ) : null} + {meta.thematics ? ( + { + return { + id: `thematic-${thematic.id}`, + value: {thematic.name}, + }; + })} + /> + ) : null} + {meta.total ? ( + + ) : null} + {meta.website ? ( + + ) : null} + + ) : null} + {typeof intro === 'string' ? ( + // eslint-disable-next-line react/no-danger -- Intro can contain tags. +
+ ) : ( + intro + )} +
+
+ ); +}; + +export const PageHeader = forwardRef(PageHeaderWithRef); -- cgit v1.2.3