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. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/landing/image.tsx
Views: 923
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// NOTE -- at this point, I'm completely giving up on next's image
7
// for now. It's always broken and the api keeps changing and it's
8
// too hard to work with.
9
// import NextImage from "next/image";
10
11
import { CSS } from "components/misc";
12
import { MediaURL, SHADOW } from "./util";
13
14
// copied from https://github.com/vercel/next.js/blob/eb871d30915d668dd9ba897d4d04ced207ce2e6d/packages/next/image-types/global.d.ts
15
// since it seems not exported...
16
export interface StaticImageData {
17
src: string;
18
height: number;
19
width: number;
20
blurDataURL?: string;
21
}
22
23
interface Props {
24
src: string | StaticImageData;
25
style?: CSS;
26
alt: string;
27
width?: number;
28
height?: number;
29
priority?: boolean;
30
shadow?: boolean;
31
}
32
33
34
35
export default function Image(props: Props) {
36
const { src, style, alt, width, height, shadow = false } = props;
37
38
const imgStyle: CSS = {
39
...style,
40
...(shadow ? SHADOW : {}),
41
maxWidth: "100%",
42
} as const;
43
44
if (typeof src === "string") {
45
return (
46
<img
47
src={MediaURL(src)}
48
style={imgStyle}
49
alt={alt}
50
width={width}
51
height={height}
52
/>
53
);
54
}
55
56
// if (height != null && width != null) {
57
// return (
58
// <NextImage
59
// src={src.src}
60
// alt={alt}
61
// height={height}
62
// width={width}
63
// priority={priority}
64
// />
65
// );
66
// }
67
68
if (width != null) {
69
return (
70
<img
71
src={src.src}
72
height={height}
73
width={width}
74
alt={alt}
75
style={imgStyle}
76
/>
77
);
78
}
79
return (
80
<div
81
style={{
82
width: "100%",
83
...style,
84
display: "inline-block",
85
}}
86
>
87
<div style={{ position: "relative", width: "100%" }}>
88
<img
89
src={src.src}
90
height={height}
91
width={width}
92
alt={alt}
93
style={imgStyle}
94
/>
95
</div>
96
</div>
97
);
98
}
99
100