Skip to content

Commit aea58ae

Browse files
committed
Add placeholder icon if none available
1 parent 0a5c48a commit aea58ae

File tree

4 files changed

+91
-21
lines changed

4 files changed

+91
-21
lines changed

site/api.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { SvgIcon } from "@material-ui/core"
2+
import { Logo } from "./components/Icons"
3+
14
export interface Project {
25
id: string
3-
icon: string
6+
icon?: string
47
name: string
58
description: string
69
}
@@ -16,7 +19,6 @@ export namespace Project {
1619

1720
const project2: Project = {
1821
id: "test-echo-1",
19-
icon: "https://www.datocms-assets.com/2885/1620155117-brandhcterraformverticalcolorwhite.svg",
2022
name: "Echo Project",
2123
description: "Project built on echo provisioner",
2224
}
Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,86 @@
11
import React from "react"
2-
import { Box, Typography } from "@material-ui/core"
2+
import { Box, makeStyles, SvgIcon, Typography } from "@material-ui/core"
33

44
export interface ProjectIconProps {
55
title: string
6-
icon: string
6+
icon?: string
77
description?: string
88
onClick: () => void
99
}
1010

11-
export const ProjectIcon: React.FC<ProjectIconProps> = ({ title, icon, onClick }) => {
11+
const useStyles = makeStyles((theme) => ({
12+
container: {
13+
boxShadow: theme.shadows[1],
14+
cursor: "pointer",
15+
transition: "box-shadow 250ms ease-in-out",
16+
backgroundColor: "lightgrey",
17+
"&:hover": {
18+
boxShadow: theme.shadows[8],
19+
},
20+
},
21+
}))
22+
23+
const Circle: React.FC = () => {
24+
return (
25+
<Box
26+
css={{
27+
width: "96px",
28+
height: "96px",
29+
borderRadius: "96px",
30+
border: "48px solid white",
31+
}}
32+
/>
33+
)
34+
}
35+
36+
const useStyles2 = makeStyles((theme) => ({
37+
root: {
38+
color: theme.palette.text.secondary,
39+
display: "-webkit-box", // See (1)
40+
marginTop: theme.spacing(0.5),
41+
maxWidth: "110%",
42+
minWidth: 0,
43+
overflow: "hidden", // See (1)
44+
textAlign: "center",
45+
textOverflow: "ellipsis", // See (1)
46+
whiteSpace: "normal", // See (1)
47+
48+
// (1) - These styles, along with clamping make it so that not only
49+
// can text not overflow horizontally, but there can also only be a
50+
// maximum of 2 line breaks. This is standard behaviour on OS files
51+
// (ex: Windows 10 Desktop application) to prevent excessive vertical
52+
// line wraps. This is important in Generic Applications, as we have no
53+
// control over the application name used in the manifest.
54+
["-webkit-line-clamp"]: 2,
55+
["-webkit-box-orient"]: "vertical",
56+
},
57+
}))
58+
59+
export const ProjectName: React.FC = ({ children }) => {
60+
const styles = useStyles2()
61+
62+
return (
63+
<Typography className={styles.root} noWrap variant="body2">
64+
{children}
65+
</Typography>
66+
)
67+
}
68+
69+
export const ProjectIcon: React.FC<ProjectIconProps> = ({ icon, title, onClick }) => {
70+
const styles = useStyles()
71+
72+
let iconComponent
73+
74+
if (typeof icon !== "undefined") {
75+
iconComponent = <img src={icon} width={"128px"} height={"128px"} />
76+
} else {
77+
iconComponent = (
78+
<Box width={"128px"} height={"128px"} style={{ display: "flex", justifyContent: "center", alignItems: "center" }}>
79+
<Circle />
80+
</Box>
81+
)
82+
}
83+
1284
return (
1385
<Box
1486
css={{
@@ -18,12 +90,14 @@ export const ProjectIcon: React.FC<ProjectIconProps> = ({ title, icon, onClick }
1890
flexDirection: "column",
1991
justifyContent: "center",
2092
alignItems: "center",
21-
border: "1px solid red",
93+
border: "1px solid black",
94+
borderRadius: "4px",
2295
}}
96+
className={styles.container}
2397
onClick={onClick}
2498
>
25-
<img src={icon} width={"128px"} height={"128px"} />
26-
<Typography>{title}</Typography>
99+
{iconComponent}
100+
<ProjectName>{title}</ProjectName>
27101
</Box>
28102
)
29103
}

site/pages/workspaces/create/[projectId].tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,11 @@ const CreateProjectPage: React.FC = () => {
3535
},
3636
]
3737

38-
return <FormPage title={"Create Project"} organization={"test-org"} buttons={buttons}></FormPage>
38+
return (
39+
<FormPage title={"Create Project"} organization={"test-org"} buttons={buttons}>
40+
<div>TODO: Dynamic form fields</div>
41+
</FormPage>
42+
)
3943
}
4044

4145
export default CreateProjectPage

site/pages/workspaces/create/index.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const CreateSelectProjectPage: React.FC = () => {
1616
router.back()
1717
}
1818

19-
const next = (projectId: string) => () => {
19+
const select = (projectId: string) => () => {
2020
router.push(`/workspaces/create/${projectId}`)
2121
}
2222

@@ -33,7 +33,7 @@ const CreateSelectProjectPage: React.FC = () => {
3333
body = (
3434
<>
3535
{requestState.payload.map((project) => {
36-
return <ProjectIcon title={project.name} icon={project.icon} onClick={() => alert("clicked")} />
36+
return <ProjectIcon title={project.name} icon={project.icon} onClick={select(project.id)} />
3737
})}
3838
</>
3939
)
@@ -48,16 +48,6 @@ const CreateSelectProjectPage: React.FC = () => {
4848
onClick: cancel,
4949
},
5050
},
51-
{
52-
title: "Next",
53-
props: {
54-
variant: "contained",
55-
color: "primary",
56-
disabled: false,
57-
type: "submit",
58-
onClick: next("test1"),
59-
},
60-
},
6151
]
6252

6353
return (

0 commit comments

Comments
 (0)