-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathViewReference.tsx
More file actions
87 lines (80 loc) · 2.11 KB
/
Copy pathViewReference.tsx
File metadata and controls
87 lines (80 loc) · 2.11 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { CardGroup, Hero } from "~/components/blocks";
import type { CardGroupProps } from "~/components/blocks/CardGroup/CardGroup";
import type { ImageProps } from "~/components/primitives";
type ViewReferenceAction = {
href: string;
text: string;
internal?: boolean;
};
type ViewReferenceCard = {
heading: string;
summary?: string | null;
type: string;
details: { href: string; text: string; internal: boolean };
image?: ImageProps;
};
export interface ViewReferenceProps {
id: string;
view?: string;
display?: string;
cards: ViewReferenceCard[];
headingOptional?: string | null;
subheadingOptional?: string | null;
descriptionOptional?: string | null;
action?: ViewReferenceAction;
}
export const ViewReference = ({
id,
view,
display,
cards,
headingOptional,
subheadingOptional,
descriptionOptional,
action,
}: ViewReferenceProps) => {
if (view === "blog" && display === "teaser_featured") {
const featured = cards[0];
const remainingCards = cards.slice(1);
return (
<div id={id}>
<Hero
heading={featured.heading}
image={featured.image}
description={featured.summary ?? ""}
actions={[
{
href: featured.details.href,
text: featured.details.text,
internal: true,
},
]}
/>
{remainingCards.length > 0 && (
<CardGroup
key={id}
heading={headingOptional || ""}
subheading={subheadingOptional || ""}
description={descriptionOptional || ""}
cards={remainingCards as CardGroupProps["cards"]}
action={action as CardGroupProps["action"]}
/>
)}
</div>
);
}
if (view === "blog" && display === "teaser") {
return (
<CardGroup
id={id}
key={id}
heading={headingOptional || ""}
subheading={subheadingOptional || ""}
description={descriptionOptional || ""}
cards={cards as CardGroupProps["cards"]}
action={action as CardGroupProps["action"]}
/>
);
}
return null;
};