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/landing/image.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
// 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 { CSSProperties } from "react";
12
import { MediaURL } 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?: CSSProperties;
26
alt: string;
27
width?: number;
28
height?: number;
29
priority?: boolean;
30
}
31
32
export default function Image(props: Props) {
33
const { src, style, alt, width, height } = props;
34
if (typeof src === "string") {
35
return (
36
<img
37
src={MediaURL(src)}
38
style={{ ...style, maxWidth: "100%" }}
39
alt={alt}
40
width={width}
41
height={height}
42
/>
43
);
44
}
45
46
// if (height != null && width != null) {
47
// return (
48
// <NextImage
49
// src={src.src}
50
// alt={alt}
51
// height={height}
52
// width={width}
53
// priority={priority}
54
// />
55
// );
56
// }
57
58
if (width != null) {
59
return (
60
<img
61
src={src.src}
62
height={height}
63
width={width}
64
alt={alt}
65
style={{ ...style, maxWidth: "100%" }}
66
/>
67
);
68
}
69
return (
70
<div
71
style={{
72
width: "100%",
73
...style,
74
display: "inline-block",
75
}}
76
>
77
<div style={{ position: "relative", width: "100%" }}>
78
<img
79
src={src.src}
80
height={height}
81
width={width}
82
alt={alt}
83
style={{ ...style, maxWidth: "100%" }}
84
/>
85
</div>
86
</div>
87
);
88
}
89
90