CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/logo.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { isEmpty } from "lodash";
7
8
import { unreachable } from "@cocalc/util/misc";
9
import Image from "components/landing/image";
10
import useCustomize from "lib/use-customize";
11
import fullLogo from "public/logo/full.svg";
12
import icon from "public/logo/icon.svg";
13
import rectangular from "public/logo/rectangular.svg";
14
import { CSS } from "./misc";
15
16
interface Props {
17
type: "rectangular" | "icon" | "full";
18
style?: React.CSSProperties;
19
width?: number; // px
20
priority?: boolean;
21
}
22
23
export default function Logo(props: Props) {
24
const { priority, type } = props;
25
const { logoRectangularURL, logoSquareURL, siteName } = useCustomize();
26
27
function config(): { alt: string; src: string; custom: boolean } {
28
switch (type) {
29
case "rectangular":
30
return {
31
alt: `Rectangular ${siteName} Logo`,
32
src: logoRectangularURL ? logoRectangularURL : rectangular,
33
custom: !!logoRectangularURL,
34
};
35
case "icon":
36
return {
37
alt: "CoCalc Logo Icon",
38
src: logoSquareURL ? logoSquareURL : icon,
39
custom: !!logoSquareURL,
40
};
41
case "full":
42
return {
43
alt: `${siteName} Logo`,
44
src: fullLogo,
45
custom: false,
46
};
47
default:
48
unreachable(type);
49
return { alt: "Logo", src: icon, custom: false };
50
}
51
}
52
53
const { alt, src, custom } = config();
54
55
const style: CSS = {
56
...(isEmpty(props.style) && { maxWidth: "100%" }),
57
...props.style,
58
};
59
60
if (props.width) {
61
style.width = `${props.width}px`;
62
style.maxWidth = `${props.width}px`;
63
}
64
65
if (type === "full" && logoSquareURL && logoRectangularURL) {
66
// we "fake" a full logo it by stacking the square logo on top of the rectangular one in a div
67
return (
68
<div
69
style={{
70
...props.style,
71
textAlign: "center",
72
marginLeft: "auto",
73
marginRight: "auto",
74
}}
75
>
76
<Image
77
alt={alt}
78
src={logoSquareURL}
79
style={{
80
width: "50%",
81
}}
82
/>
83
<div>
84
<Image
85
src={logoRectangularURL}
86
alt={alt}
87
style={{ width: "100%", marginTop: "1rem" }}
88
/>
89
</div>
90
</div>
91
);
92
} else if (custom) {
93
return <Image alt={alt} src={src} style={style} />;
94
} else {
95
return <Image alt={alt} src={src} style={style} priority={priority} />;
96
}
97
}
98
99