Skip to content

Commit 5c0592b

Browse files
committed
feat: template card interaction and navigation
1 parent 3571936 commit 5c0592b

File tree

1 file changed

+25
-23
lines changed

1 file changed

+25
-23
lines changed

site/src/modules/templates/TemplateCard/TemplateCard.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Interpolation, Theme } from "@emotion/react";
22
import ArrowForwardOutlined from "@mui/icons-material/ArrowForwardOutlined";
33
import Button from "@mui/material/Button";
44
import type { FC, HTMLAttributes } from "react";
5-
import { Link as RouterLink } from "react-router-dom";
5+
import { Link as RouterLink, useNavigate } from "react-router-dom";
66
import type { Template } from "api/typesGenerated";
77
import { ExternalAvatar } from "components/Avatar/Avatar";
88
import { AvatarData } from "components/AvatarData/AvatarData";
@@ -16,10 +16,25 @@ export const TemplateCard: FC<TemplateCardProps> = ({
1616
template,
1717
...divProps
1818
}) => {
19+
const navigate = useNavigate();
20+
const templatePageLink = `/templates/${template.name}`;
1921
const hasIcon = template.icon && template.icon !== "";
2022

23+
const handleKeyDown = (e: React.KeyboardEvent) => {
24+
if (e.key === "Enter" && e.currentTarget === e.target) {
25+
navigate(templatePageLink);
26+
}
27+
};
28+
2129
return (
22-
<div css={styles.card} {...divProps}>
30+
<div
31+
css={styles.card}
32+
{...divProps}
33+
role="button"
34+
tabIndex={0}
35+
onClick={() => navigate(templatePageLink)}
36+
onKeyDown={handleKeyDown}
37+
>
2338
<div css={styles.header}>
2439
<div>
2540
<AvatarData
@@ -60,6 +75,9 @@ export const TemplateCard: FC<TemplateCardProps> = ({
6075
startIcon={<ArrowForwardOutlined />}
6176
title={`Create a workspace using the ${template.display_name} template`}
6277
to={`/templates/${template.name}/workspace`}
78+
onClick={(e) => {
79+
e.stopPropagation();
80+
}}
6381
>
6482
Create Workspace
6583
</Button>
@@ -79,6 +97,11 @@ const styles = {
7997
color: "inherit",
8098
display: "flex",
8199
flexDirection: "column",
100+
cursor: "pointer",
101+
"&:hover": {
102+
color: theme.experimental.l2.hover.text,
103+
borderColor: theme.experimental.l2.hover.text,
104+
},
82105
}),
83106

84107
header: {
@@ -95,27 +118,6 @@ const styles = {
95118
height: 32,
96119
},
97120

98-
tags: {
99-
display: "flex",
100-
flexWrap: "wrap",
101-
gap: 8,
102-
justifyContent: "end",
103-
},
104-
105-
tag: (theme) => ({
106-
borderColor: theme.palette.divider,
107-
textDecoration: "none",
108-
cursor: "pointer",
109-
"&: hover": {
110-
borderColor: theme.palette.primary.main,
111-
},
112-
}),
113-
114-
activeTag: (theme) => ({
115-
borderColor: theme.roles.active.outline,
116-
backgroundColor: theme.roles.active.background,
117-
}),
118-
119121
description: (theme) => ({
120122
fontSize: 13,
121123
color: theme.palette.text.secondary,

0 commit comments

Comments
 (0)