Skip to content

Commit 3abafdf

Browse files
committed
[dashboard] add alert component and display page
1 parent 89fdaf1 commit 3abafdf

File tree

6 files changed

+147
-2
lines changed

6 files changed

+147
-2
lines changed

components/dashboard/src/App.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ const AdminSettings = React.lazy(() => import(/* webpackPrefetch: true */ "./adm
7777
const ProjectsSearch = React.lazy(() => import(/* webpackPrefetch: true */ "./admin/ProjectsSearch"));
7878
const TeamsSearch = React.lazy(() => import(/* webpackPrefetch: true */ "./admin/TeamsSearch"));
7979
const OAuthClientApproval = React.lazy(() => import(/* webpackPrefetch: true */ "./OauthClientApproval"));
80+
const ComponentsDispay = React.lazy(() => import(/* webpackPrefetch: true */ "./components/Dispay"));
8081

8182
function Loading() {
8283
return <></>;
@@ -479,6 +480,9 @@ function App() {
479480
url.pathname = "/";
480481
window.location.replace(url);
481482
return <div></div>;
483+
} else if (window.location.pathname === "/components/display") {
484+
// } else if (window.location.pathname === "/components/display" && process.env.NODE_ENV !== "production") {
485+
toRender = <ComponentsDispay />;
482486
}
483487

484488
return <Suspense fallback={<Loading />}>{toRender}</Suspense>;
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**
2+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import { useState } from "react";
8+
import { ReactComponent as Exclamation } from "../images/exclamation.svg";
9+
import { ReactComponent as Exclamation2 } from "../images/exclamation2.svg";
10+
import { ReactComponent as InfoSvg } from "../images/info.svg";
11+
import { ReactComponent as XSvg } from "../images/x.svg";
12+
13+
export type AlertType =
14+
// Yellow
15+
| "warning"
16+
// Gray alert
17+
| "info"
18+
// Red
19+
| "error"
20+
// Blue
21+
| "message";
22+
23+
export interface AlertProps {
24+
className?: string;
25+
type?: AlertType;
26+
closable?: boolean;
27+
showIcon?: boolean;
28+
icon?: React.ReactNode;
29+
children?: React.ReactNode;
30+
}
31+
32+
interface AlertInfo {
33+
cls: string;
34+
icon: React.ReactNode;
35+
iconColor?: string;
36+
}
37+
38+
const infoMap: Record<AlertType, AlertInfo> = {
39+
warning: {
40+
cls: "bg-yellow-100 dark:bg-yellow-700 text-yellow-600 dark:text-yellow-50",
41+
icon: <Exclamation2 className="w-4 h-4"></Exclamation2>,
42+
iconColor: "text-yellow-400 dark:text-yellow-900",
43+
},
44+
info: {
45+
cls: "bg-gray-100 dark:bg-gray-700 text-gray-500 dark:text-gray-300",
46+
icon: <InfoSvg className="w-4 h-4"></InfoSvg>,
47+
iconColor: "text-gray-400",
48+
},
49+
message: {
50+
cls: "bg-blue-50 dark:bg-blue-700 text-blue-800 dark:text-blue-100",
51+
icon: <InfoSvg className="w-4 h-4"></InfoSvg>,
52+
iconColor: "text-blue-400",
53+
},
54+
error: {
55+
cls: "bg-red-50 dark:bg-red-800 dark:bg-opacity-50 text-red-600 dark:text-red-200",
56+
icon: <Exclamation className="w-4 h-4"></Exclamation>,
57+
iconColor: "text-red-400",
58+
},
59+
};
60+
61+
export default function Alert(props: AlertProps) {
62+
const [visible, setVisible] = useState(true);
63+
if (!visible) {
64+
return null;
65+
}
66+
const type: AlertType = props.type ?? "info";
67+
const info = infoMap[type];
68+
const showIcon = props.showIcon ?? true;
69+
return (
70+
<div className={`flex relative rounded p-4 ${info.cls} ${props.className || ""}`}>
71+
{showIcon && <span className={`mt-1 mr-4 h-4 w-4 ${info.iconColor}`}>{props.icon ?? info.icon}</span>}
72+
<span className="flex-1 text-left">{props.children}</span>
73+
{props.closable && (
74+
<XSvg onClick={() => setVisible(false)} className="mt-1 ml-4 w-3 h-3 cursor-pointer"></XSvg>
75+
)}
76+
</div>
77+
);
78+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Copyright (c) 2021 Gitpod GmbH. All rights reserved.
3+
* Licensed under the GNU Affero General Public License (AGPL).
4+
* See License-AGPL.txt in the project root for license information.
5+
*/
6+
7+
import Alert from "./Alert";
8+
9+
export function Section(props: { title: string; children: React.ReactNode | React.ReactNode[]; darkMode?: boolean }) {
10+
const darkMode = props.darkMode ?? true;
11+
return (
12+
<>
13+
<h3 className="text-yellow-800 mt-4">{props.title}</h3>
14+
<div className={`grid gap-2 ${darkMode ? "grid-cols-2" : "grid-cols-1"}`}>
15+
<div className="space-y-2 p-4 bg-white rounded">{props.children}</div>
16+
{darkMode && <div className="space-y-2 p-4 dark bg-black rounded">{props.children}</div>}
17+
</div>
18+
</>
19+
);
20+
}
21+
22+
export default function Display() {
23+
return (
24+
<div className="bg-gitpod-kumquat pb-20">
25+
<div className="container">
26+
<h1 className="text-yellow-800">Components Display</h1>
27+
<Section title="Alert">
28+
<Alert closable={true} type="error">
29+
error
30+
</Alert>
31+
<Alert closable={true} type="info">
32+
<strong>Info:</strong> Cupidatat minim culpa voluptate incididunt ad consectetur magna fugiat
33+
pariatur. Nisi aliquip nostrud sunt laboris laboris incididunt Lorem officia qui id. Consectetur
34+
qui nulla deserunt excepteur consectetur deserunt qui qui nisi sint eiusmod ad fugiat tempor.
35+
</Alert>
36+
<Alert closable={true} type="warning">
37+
warning
38+
</Alert>
39+
<Alert closable={true} type="message">
40+
message
41+
</Alert>
42+
<Alert showIcon={false} type="warning">
43+
warning without icon shown and closable. Ea consequat in sint in deserunt adipisicing commodo
44+
mollit aliquip est nostrud. Minim exercitation pariatur non cupidatat consectetur pariatur.
45+
Velit deserunt minim id laboris magna fugiat proident laborum velit laboris amet tempor
46+
consequat in. Amet voluptate qui commodo adipisicing cillum sit duis dolore fugiat ipsum
47+
deserunt.
48+
</Alert>
49+
<Alert showIcon={false} closable type="info">
50+
Aute irure esse officia fugiat ullamco. Amet mollit ipsum esse cillum nostrud sit enim ullamco
51+
pariatur eiusmod cillum. Nisi dolor in duis aute eu adipisicing irure sunt cillum in.
52+
</Alert>
53+
</Section>
54+
</div>
55+
</div>
56+
);
57+
}
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading

components/dashboard/src/images/x.svg

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)