forked from BabylonJS/Documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bucketContent.component.tsx
147 lines (140 loc) · 5.04 KB
/
bucketContent.component.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { FunctionComponent } from "react";
import { IDocumentationPageProps } from "../lib/content.interfaces";
import { Card, CardContent, Theme, Typography } from "@mui/material";
import { createStyles, makeStyles } from "@mui/styles";
import Link from "next/link";
import Image from "next/image";
import { getImageUrl } from "../lib/frontendUtils/frontendTools";
export interface IBucketContentProps {
childPages?: {
[key: string]: IDocumentationPageProps;
};
title?: string;
externalLinks?: { title: string; url: string }[];
}
const useStyles = makeStyles((theme: Theme) =>
createStyles({
h3: {
borderTop: "1px solid",
marginTop: "3.125rem !important",
paddingTop: theme.spacing(2),
},
container: {
display: "flex",
flexWrap: "wrap",
maxWidth: "100%",
},
divRoot: {
padding: 16,
height: 160,
minHeight: 160,
minWidth: 200,
width: "100%",
[theme.breakpoints.up("lg")]: {
width: "50% !important",
},
[theme.breakpoints.up("xl")]: {
width: "33% !important",
},
},
root: {
display: "flex",
height: "100%",
cursor: "pointer",
},
details: {
display: "flex",
flexDirection: "column",
width: "50% !important",
flex: 1,
},
content: {
flex: "1 0 auto",
},
imageContainer: {
minHeight: "100%",
cursor: "pointer",
display: "inline-block",
overflow: "hidden",
position: "relative",
minWidth: "150px !important",
width: "unset !important",
"& img": {
pointerEvents: "none",
position: "absolute",
minWidth: "100%",
minHeight: "100%",
objectFit: "cover",
},
},
}),
);
interface IBucketItem {
title: string;
imageUrl: string;
link: string;
description: string;
}
const SingleBucketItem: FunctionComponent<IBucketItem> = ({ link, title, imageUrl, description }: IBucketItem) => {
const classes = useStyles();
return (
<Link key={link} href={link} className={classes.divRoot}>
<Card className={classes.root}>
<div className={classes.details}>
<CardContent className={classes.content}>
<Typography component="h6" variant="h6">
{title}
</Typography>
<Typography style={{}} variant="subtitle1" color="textSecondary" title={title}>
{description}
</Typography>
</CardContent>
</div>
<div className={classes.imageContainer}>
<Image alt={title} src={imageUrl} fill={true}></Image>
</div>
</Card>
</Link>
);
};
export const BucketContent: FunctionComponent<IBucketContentProps> = ({ childPages, title = "Coming next", externalLinks }) => {
const classes = useStyles();
const bucketItems: IBucketItem[] = Object.keys(childPages || []).map((child) => {
const childData = childPages[child].metadata;
const title = (childData.title || child).replace(/_/g, " ");
const link = "/" + childPages[child].id.join("/");
const imageUrl = getImageUrl(childData.imageUrl);
return { title, link, imageUrl, description: childData.description };
});
return (
<>
{(!!bucketItems.length || (externalLinks && !!externalLinks.length)) && (
<>
<Typography className={classes.h3} component="h3" variant="h3">
{title}
</Typography>
{!!bucketItems.length && (
<div className={classes.container}>
{bucketItems.map((child, idx) => {
return <SingleBucketItem key={idx} {...child} />;
})}
</div>
)}
{externalLinks && (
<ul>
{externalLinks.map(({ url, title }) => {
return (
<li key={url}>
<Link href={url} target={"_blank"} rel={"noopener"}>
{title}
</Link>
</li>
);
})}
</ul>
)}
</>
)}
</>
);
};