-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathThemedPageHeader.tsx
71 lines (64 loc) · 2.69 KB
/
ThemedPageHeader.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React from 'react';
import { BodyShort, Detail } from '@navikt/ds-react';
import { Header } from 'components/_common/headers/Header';
import { classNames } from 'utils/classnames';
import { formatDate } from 'utils/datetime';
import { translator } from 'translations';
import { Illustration } from 'components/_common/illustration/Illustration';
import { getContentTagline } from 'components/_common/headers/sharedHeaderUtils';
import { ProductDataMixin } from 'types/component-props/_mixins';
import { ContentProps } from 'types/content-props/_content-common';
import { themedPageHeaderGetTypeClassName } from './themedPageHeaderUtils';
import style from './ThemedPageHeader.module.scss';
type Props = {
contentProps: Pick<
ContentProps,
'type' | 'displayName' | 'modifiedTime' | 'data' | 'language'
> & {
data: Pick<
ProductDataMixin,
'title' | 'illustration' | 'taxonomy' | 'audience' | 'customCategory'
>;
};
showTimeStamp?: boolean;
};
export const ThemedPageHeader = ({ contentProps, showTimeStamp = true }: Props) => {
const { type, displayName, modifiedTime, language, data } = contentProps;
const { title, illustration } = data;
const getDatesLabel = translator('dates', language);
const typeSpecificClassName = themedPageHeaderGetTypeClassName(type);
const subTitle = getContentTagline(contentProps);
const modified =
showTimeStamp &&
`${getDatesLabel('lastChanged')} ${formatDate({
datetime: modifiedTime,
language,
short: true,
year: true,
})}`;
return (
<div className={classNames(style.themedPageHeader, typeSpecificClassName)}>
<Illustration illustration={illustration} className={style.illustration} />
<div className={style.text}>
<Header level={'1'} size={'xlarge'} className={style.header}>
{title || displayName}
</Header>
{(subTitle || modified) && (
<div className={style.taglineWrapper}>
{subTitle && (
<BodyShort size="small" className={style.taglineLabel}>
{subTitle.toUpperCase()}
</BodyShort>
)}
{subTitle && modified && (
<span aria-hidden="true" className={style.divider}>
{'|'}
</span>
)}
{modified && <Detail>{modified}</Detail>}
</div>
)}
</div>
</div>
);
};