-
Notifications
You must be signed in to change notification settings - Fork 894
refactor(site): improve templates empty state #10518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e3a351e
Redirects to template after setup
BrunoQuaresma cae37d5
Refactor template example cards and first create template experience
BrunoQuaresma d8987b9
Minor improvements
BrunoQuaresma bdb43c6
Fix verbiage
BrunoQuaresma 4109264
Fix test
BrunoQuaresma 935b09b
Fix template display name on card
BrunoQuaresma 250f764
Refactor card layout
BrunoQuaresma 817c01f
Merge branch 'main' of https://github.com/coder/coder into bq/improve…
BrunoQuaresma 6acd193
Move readmore to be inline
BrunoQuaresma db54495
Merge branch 'main' of https://github.com/coder/coder into bq/improve…
BrunoQuaresma 7453346
Decrease line height
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
179 changes: 103 additions & 76 deletions
179
site/src/components/TemplateExampleCard/TemplateExampleCard.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,86 +1,113 @@ | ||
import { type Interpolation, type Theme } from "@emotion/react"; | ||
import Button from "@mui/material/Button"; | ||
import Link from "@mui/material/Link"; | ||
import type { TemplateExample } from "api/typesGenerated"; | ||
import { type FC } from "react"; | ||
import { Link } from "react-router-dom"; | ||
import { Pill } from "components/Pill/Pill"; | ||
import { HTMLProps } from "react"; | ||
import { Link as RouterLink } from "react-router-dom"; | ||
|
||
export interface TemplateExampleCardProps { | ||
type TemplateExampleCardProps = { | ||
example: TemplateExample; | ||
className?: string; | ||
} | ||
activeTag?: string; | ||
} & HTMLProps<HTMLDivElement>; | ||
|
||
export const TemplateExampleCard: FC<TemplateExampleCardProps> = ({ | ||
example, | ||
className, | ||
}) => { | ||
export const TemplateExampleCard = (props: TemplateExampleCardProps) => { | ||
const { example, activeTag, ...divProps } = props; | ||
return ( | ||
<Link | ||
to={`/starter-templates/${example.id}`} | ||
css={styles.template} | ||
className={className} | ||
key={example.id} | ||
<div | ||
css={(theme) => ({ | ||
width: "320px", | ||
padding: theme.spacing(3), | ||
borderRadius: 6, | ||
border: `1px solid ${theme.palette.divider}`, | ||
textAlign: "left", | ||
textDecoration: "none", | ||
color: "inherit", | ||
display: "flex", | ||
flexDirection: "column", | ||
})} | ||
{...divProps} | ||
> | ||
<div css={styles.templateIcon}> | ||
<img src={example.icon} alt="" /> | ||
<div | ||
css={{ | ||
flexShrink: 0, | ||
paddingTop: 4, | ||
width: 32, | ||
height: 32, | ||
marginBottom: 16, | ||
}} | ||
> | ||
<img | ||
src={example.icon} | ||
alt="" | ||
css={{ width: "100%", height: "100%", objectFit: "contain" }} | ||
/> | ||
</div> | ||
<div css={styles.templateInfo}> | ||
<span css={styles.templateName}>{example.name}</span> | ||
<span css={styles.templateDescription}>{example.description}</span> | ||
</div> | ||
</Link> | ||
); | ||
}; | ||
|
||
const styles = { | ||
template: (theme) => ({ | ||
border: `1px solid ${theme.palette.divider}`, | ||
borderRadius: theme.shape.borderRadius, | ||
background: theme.palette.background.paper, | ||
textDecoration: "none", | ||
textAlign: "left", | ||
color: "inherit", | ||
display: "flex", | ||
alignItems: "center", | ||
height: "fit-content", | ||
|
||
"&:hover": { | ||
backgroundColor: theme.palette.background.paperLight, | ||
}, | ||
}), | ||
|
||
templateIcon: (theme) => ({ | ||
width: theme.spacing(12), | ||
height: theme.spacing(12), | ||
display: "flex", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
flexShrink: 0, | ||
|
||
"& img": { | ||
height: theme.spacing(4), | ||
}, | ||
}), | ||
<div> | ||
<h4 css={{ fontSize: 14, fontWeight: 600, margin: 0 }}> | ||
{example.name} | ||
</h4> | ||
<span | ||
css={(theme) => ({ | ||
fontSize: 13, | ||
color: theme.palette.text.secondary, | ||
lineHeight: "0.5", | ||
})} | ||
> | ||
{example.description} | ||
</span> | ||
<div css={{ marginTop: 16, display: "flex", flexWrap: "wrap", gap: 8 }}> | ||
{example.tags.map((tag) => { | ||
const isActive = activeTag === tag; | ||
|
||
templateInfo: (theme) => ({ | ||
padding: theme.spacing(2, 2, 2, 0), | ||
display: "flex", | ||
flexDirection: "column", | ||
overflow: "hidden", | ||
}), | ||
|
||
templateName: (theme) => ({ | ||
fontSize: theme.spacing(2), | ||
textOverflow: "ellipsis", | ||
width: "100%", | ||
overflow: "hidden", | ||
whiteSpace: "nowrap", | ||
}), | ||
return ( | ||
<RouterLink key={tag} to={`/starter-templates?tag=${tag}`}> | ||
<Pill | ||
text={tag} | ||
css={(theme) => ({ | ||
borderColor: isActive | ||
? theme.palette.primary.main | ||
: theme.palette.divider, | ||
cursor: "pointer", | ||
backgroundColor: isActive | ||
? theme.palette.primary.dark | ||
: undefined, | ||
"&: hover": { | ||
borderColor: theme.palette.primary.main, | ||
}, | ||
})} | ||
/> | ||
</RouterLink> | ||
); | ||
})} | ||
</div> | ||
</div> | ||
|
||
templateDescription: (theme) => ({ | ||
fontSize: theme.spacing(1.75), | ||
color: theme.palette.text.secondary, | ||
textOverflow: "ellipsis", | ||
width: "100%", | ||
overflow: "hidden", | ||
whiteSpace: "nowrap", | ||
}), | ||
} satisfies Record<string, Interpolation<Theme>>; | ||
<div | ||
css={{ | ||
display: "flex", | ||
gap: 12, | ||
flexDirection: "column", | ||
paddingTop: 32, | ||
marginTop: "auto", | ||
alignItems: "center", | ||
}} | ||
> | ||
<Button | ||
component={RouterLink} | ||
fullWidth | ||
to={`/templates/new?exampleId=${example.id}`} | ||
> | ||
Use template | ||
</Button> | ||
<Link | ||
component={RouterLink} | ||
css={{ fontSize: 13 }} | ||
to={`/starter-templates/${example.id}`} | ||
> | ||
Read more | ||
</Link> | ||
</div> | ||
</div> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.