Skip to content

Commit 5b822bd

Browse files
authored
feat: add frameUrl support to Media and ProjectCard components (#80)
1 parent 9009e83 commit 5b822bd

4 files changed

Lines changed: 47 additions & 16 deletions

File tree

apps/app/src/components/fragments/project-card/index.tsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,47 @@ import * as muiIcon from "@mui/icons-material";
22
import * as mui from "@mui/material";
33
import { Link as GatsbyLink } from "gatsby";
44

5-
import { styles } from "./styles";
5+
import { styles, useMediaStyles } from "./styles";
66

77
export interface MediaProps {
8+
frameUrl?: string;
89
title: string;
9-
url: string;
1010
}
1111

12-
export const Media = ({ title, url }: MediaProps) => {
12+
export const Media = (props: MediaProps) => {
13+
const { frameUrl, title } = props;
14+
15+
const styles = useMediaStyles(props);
16+
1317
return (
1418
<mui.Box css={styles.media}>
15-
<iframe css={styles.mediaIframe} src={url} title={title} />
19+
{frameUrl ? (
20+
<iframe css={styles.mediaIframe} src={frameUrl} title={title} />
21+
) : (
22+
<muiIcon.Language css={styles.mediaNoFrame} />
23+
)}
1624
</mui.Box>
1725
);
1826
};
1927

2028
export interface ProjectCardProps {
2129
description?: string;
30+
frameUrl?: string;
2231
onCopy?: () => void;
2332
title: string;
2433
url: string;
2534
}
2635

2736
export const ProjectCard = ({
2837
description,
38+
frameUrl,
2939
onCopy,
3040
title,
3141
url,
3242
}: ProjectCardProps) => {
3343
return (
3444
<mui.Card css={styles.root}>
35-
<mui.CardMedia component={Media} title={title} url={url} />
45+
<mui.CardMedia component={Media} frameUrl={frameUrl} title={title} />
3646
<mui.Divider />
3747
<mui.CardContent css={styles.content}>
3848
<mui.Typography gutterBottom variant="h5">

apps/app/src/components/fragments/project-card/styles.ts

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { css } from "@emotion/react";
22
import { type AppTheme } from "@n8v/app/theme";
33
import { ellipsis } from "polished";
44

5+
import type { MediaProps } from ".";
6+
57
export const styles = {
68
actions: () => css({ justifyContent: "end", marginTop: "auto" }),
79

@@ -16,14 +18,32 @@ export const styles = {
1618
...ellipsis("100%", 3),
1719
}),
1820

19-
media: (theme: AppTheme) =>
21+
root: (theme: AppTheme) =>
2022
css({
21-
height: theme.spacing(27),
22-
overflow: "hidden",
23-
pointerEvents: "none",
24-
position: "relative",
23+
display: "flex",
24+
flexDirection: "column",
25+
height: theme.spacing(50),
2526
width: theme.spacing(40),
2627
}),
28+
};
29+
30+
export const useMediaStyles = (props: MediaProps) => ({
31+
media: (theme: AppTheme) =>
32+
css([
33+
{
34+
color: theme.palette.text.secondary,
35+
height: theme.spacing(27),
36+
overflow: "hidden",
37+
pointerEvents: "none",
38+
position: "relative",
39+
width: theme.spacing(40),
40+
},
41+
!props.frameUrl && {
42+
alignItems: "center",
43+
display: "flex",
44+
justifyContent: "center",
45+
},
46+
]),
2747

2848
mediaIframe: () =>
2949
css({
@@ -36,11 +56,9 @@ export const styles = {
3656
width: "500%",
3757
}),
3858

39-
root: (theme: AppTheme) =>
59+
mediaNoFrame: (theme: AppTheme) =>
4060
css({
41-
display: "flex",
42-
flexDirection: "column",
43-
height: theme.spacing(50),
44-
width: theme.spacing(40),
61+
height: theme.spacing(10),
62+
width: theme.spacing(10),
4563
}),
46-
};
64+
});

apps/app/src/components/screens/projects/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { styles } from "./styles";
99

1010
export interface Project {
1111
description?: string;
12+
frameUrl?: string;
1213
title: string;
1314
url: string;
1415
}
@@ -30,6 +31,7 @@ export const ProjectsScreen = ({
3031
{projects.map((project) => (
3132
<ProjectCard
3233
description={project.description}
34+
frameUrl={project.frameUrl}
3335
key={project.url}
3436
onCopy={() => {
3537
onCopy?.(project.url);

apps/app/src/hooks/use-apps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const useProjects = () =>
88
{
99
description:
1010
"A simple counter app compiled to WebAssembly, written in Rust.",
11+
frameUrl: "/apps/counter",
1112
title: "Wasm Counter",
1213
url: "/apps/counter",
1314
},

0 commit comments

Comments
 (0)