|
1 |
| -import { type Interpolation, type Theme } from "@emotion/react"; |
| 1 | +import Button from "@mui/material/Button"; |
| 2 | +import Link from "@mui/material/Link"; |
2 | 3 | import type { TemplateExample } from "api/typesGenerated";
|
| 4 | +import { Pill } from "components/Pill/Pill"; |
3 | 5 | import { type FC } from "react";
|
4 |
| -import { Link } from "react-router-dom"; |
| 6 | +import { Link as RouterLink } from "react-router-dom"; |
5 | 7 |
|
6 | 8 | export interface TemplateExampleCardProps {
|
7 | 9 | example: TemplateExample;
|
8 |
| - className?: string; |
| 10 | + activeTag?: string; |
9 | 11 | }
|
10 | 12 |
|
11 | 13 | export const TemplateExampleCard: FC<TemplateExampleCardProps> = ({
|
12 | 14 | example,
|
13 |
| - className, |
| 15 | + activeTag, |
14 | 16 | }) => {
|
15 | 17 | return (
|
16 |
| - <Link |
17 |
| - to={`/starter-templates/${example.id}`} |
18 |
| - css={styles.template} |
19 |
| - className={className} |
20 |
| - key={example.id} |
| 18 | + <div |
| 19 | + css={(theme) => ({ |
| 20 | + width: "320px", |
| 21 | + padding: theme.spacing(3), |
| 22 | + borderRadius: 6, |
| 23 | + border: `1px solid ${theme.palette.divider}`, |
| 24 | + textAlign: "left", |
| 25 | + textDecoration: "none", |
| 26 | + color: "inherit", |
| 27 | + display: "flex", |
| 28 | + flexDirection: "column", |
| 29 | + })} |
21 | 30 | >
|
22 |
| - <div css={styles.templateIcon}> |
23 |
| - <img src={example.icon} alt="" /> |
| 31 | + <div |
| 32 | + css={{ |
| 33 | + flexShrink: 0, |
| 34 | + paddingTop: 4, |
| 35 | + width: 32, |
| 36 | + height: 32, |
| 37 | + marginBottom: 16, |
| 38 | + }} |
| 39 | + > |
| 40 | + <img |
| 41 | + src={example.icon} |
| 42 | + alt="" |
| 43 | + css={{ width: "100%", height: "100%", objectFit: "contain" }} |
| 44 | + /> |
24 | 45 | </div>
|
25 |
| - <div css={styles.templateInfo}> |
26 |
| - <span css={styles.templateName}>{example.name}</span> |
27 |
| - <span css={styles.templateDescription}>{example.description}</span> |
28 |
| - </div> |
29 |
| - </Link> |
30 |
| - ); |
31 |
| -}; |
32 |
| - |
33 |
| -const styles = { |
34 |
| - template: (theme) => ({ |
35 |
| - border: `1px solid ${theme.palette.divider}`, |
36 |
| - borderRadius: theme.shape.borderRadius, |
37 |
| - background: theme.palette.background.paper, |
38 |
| - textDecoration: "none", |
39 |
| - textAlign: "left", |
40 |
| - color: "inherit", |
41 |
| - display: "flex", |
42 |
| - alignItems: "center", |
43 |
| - height: "fit-content", |
44 |
| - |
45 |
| - "&:hover": { |
46 |
| - backgroundColor: theme.palette.background.paperLight, |
47 |
| - }, |
48 |
| - }), |
49 |
| - |
50 |
| - templateIcon: (theme) => ({ |
51 |
| - width: theme.spacing(12), |
52 |
| - height: theme.spacing(12), |
53 |
| - display: "flex", |
54 |
| - alignItems: "center", |
55 |
| - justifyContent: "center", |
56 |
| - flexShrink: 0, |
57 | 46 |
|
58 |
| - "& img": { |
59 |
| - height: theme.spacing(4), |
60 |
| - }, |
61 |
| - }), |
| 47 | + <div> |
| 48 | + <h4 css={{ fontSize: 14, fontWeight: 600, margin: 0 }}> |
| 49 | + {example.name} |
| 50 | + </h4> |
| 51 | + <span |
| 52 | + css={(theme) => ({ |
| 53 | + fontSize: 13, |
| 54 | + color: theme.palette.text.secondary, |
| 55 | + lineHeight: "0.5", |
| 56 | + })} |
| 57 | + > |
| 58 | + {example.description} |
| 59 | + </span> |
| 60 | + <div css={{ marginTop: 16, display: "flex", flexWrap: "wrap", gap: 8 }}> |
| 61 | + {example.tags.map((tag) => { |
| 62 | + const isActive = activeTag === tag; |
62 | 63 |
|
63 |
| - templateInfo: (theme) => ({ |
64 |
| - padding: theme.spacing(2, 2, 2, 0), |
65 |
| - display: "flex", |
66 |
| - flexDirection: "column", |
67 |
| - overflow: "hidden", |
68 |
| - }), |
69 |
| - |
70 |
| - templateName: (theme) => ({ |
71 |
| - fontSize: theme.spacing(2), |
72 |
| - textOverflow: "ellipsis", |
73 |
| - width: "100%", |
74 |
| - overflow: "hidden", |
75 |
| - whiteSpace: "nowrap", |
76 |
| - }), |
| 64 | + return ( |
| 65 | + <RouterLink key={tag} to={`/starter-templates?tag=${tag}`}> |
| 66 | + <Pill |
| 67 | + text={tag} |
| 68 | + css={(theme) => ({ |
| 69 | + borderColor: isActive |
| 70 | + ? theme.palette.primary.main |
| 71 | + : theme.palette.divider, |
| 72 | + cursor: "pointer", |
| 73 | + backgroundColor: isActive |
| 74 | + ? theme.palette.primary.dark |
| 75 | + : undefined, |
| 76 | + "&: hover": { |
| 77 | + borderColor: theme.palette.primary.main, |
| 78 | + }, |
| 79 | + })} |
| 80 | + /> |
| 81 | + </RouterLink> |
| 82 | + ); |
| 83 | + })} |
| 84 | + </div> |
| 85 | + </div> |
77 | 86 |
|
78 |
| - templateDescription: (theme) => ({ |
79 |
| - fontSize: theme.spacing(1.75), |
80 |
| - color: theme.palette.text.secondary, |
81 |
| - textOverflow: "ellipsis", |
82 |
| - width: "100%", |
83 |
| - overflow: "hidden", |
84 |
| - whiteSpace: "nowrap", |
85 |
| - }), |
86 |
| -} satisfies Record<string, Interpolation<Theme>>; |
| 87 | + <div |
| 88 | + css={{ |
| 89 | + display: "flex", |
| 90 | + gap: 12, |
| 91 | + flexDirection: "column", |
| 92 | + paddingTop: 32, |
| 93 | + marginTop: "auto", |
| 94 | + alignItems: "center", |
| 95 | + }} |
| 96 | + > |
| 97 | + <Button |
| 98 | + component={RouterLink} |
| 99 | + fullWidth |
| 100 | + to={`/templates/new?exampleId=${example.id}`} |
| 101 | + > |
| 102 | + Use template |
| 103 | + </Button> |
| 104 | + <Link |
| 105 | + component={RouterLink} |
| 106 | + css={{ fontSize: 13 }} |
| 107 | + to={`/starter-templates/${example.id}`} |
| 108 | + > |
| 109 | + Read more |
| 110 | + </Link> |
| 111 | + </div> |
| 112 | + </div> |
| 113 | + ); |
| 114 | +}; |
0 commit comments