Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/next/components/app/iframe.tsx
Views: 687
import { Button, Popover } from "antd";1import { Icon } from "@cocalc/frontend/components/icon";2import { CSSProperties, useRef, useState } from "react";3import SiteName from "components/share/site-name";4import A from "components/misc/A";5import { trunc_middle } from "@cocalc/util/misc";67interface Props {8src: string;9appURL?: string;10path?: string;11style?: CSSProperties;12fullscreen?: boolean;13description?: string;14start?: boolean; // if true, immediately load iframe rather than waiting for user to click a button.15}1617export default function IFrame({18src: src0,19appURL,20path,21style,22fullscreen: fullscreen0,23start: start0,24description,25}: Props) {26const [fullscreen, setFullscreen] = useState<boolean>(!!fullscreen0);27const [reload, setReload] = useState<number>(0);28const iframeRef = useRef<any>(null);29const [start, setStart] = useState<boolean>(!!start0);3031const url = new URL("http://example.com" + src0);32url.search += (url.search ? "&" : "") + `reload=${reload}`;33const src = url.pathname + url.search + url.hash;3435return (36<div37style={38fullscreen39? {40position: "fixed",41top: 0,42left: 0,43width: "100vw",44height: "100vh",45zIndex: 1000,46background: "white",47}48: {49padding: "5px 15px",50height: start ? "95vh" : undefined,51border: "1px solid #ddd",52borderRadius: "5px",53boxShadow: "5px 5px 5px #eee",54display: "flex",55flexDirection: "column",56background: "white",57...style,58}59}60>61<div>62{start && (63<div style={{ display: "flex" }}>64<Button65title="Reload this"66size="small"67type="text"68onClick={() => {69setReload(reload + 1);70//iframeRef.current?.contentWindow.location.reload();71}}72>73<Icon name={"reload"} />74</Button>75<div76style={{77flex: 1,78textAlign: "center",79paddingTop: "2.5px",80paddingLeft: fullscreen ? "15px" : undefined,81}}82>83{appURL && (84<Popover85title="Open in the App"86content={87<div style={{ maxWidth: "350px" }}>88Open {path} in the <SiteName /> app for more options and89to see your other files...90</div>91}92>93<A href={appURL} external>94<Icon name="external-link" style={{ marginRight: "5px" }} />95{path ? trunc_middle(path, 50) : ""}96</A>97</Popover>98)}99</div>100<Button101size="small"102type="text"103title="Full screen"104onClick={() => {105if (!fullscreen) {106document.documentElement.requestFullscreen();107} else {108if (document.fullscreenElement) {109document.exitFullscreen();110}111}112setFullscreen(!fullscreen);113}}114>115<Icon name={fullscreen ? "compress" : "expand"} />116</Button>117</div>118)}119</div>120{start && <hr style={{ width: "100%" }} />}121{!start ? (122<Button123style={{ margin: "15px auto" }}124size="large"125type="primary"126shape="round"127onClick={() => setStart(true)}128>129<span style={{ marginRight: "10px" }}>130<Icon name={"run"} />{" "}131</span>{" "}132Load {description ?? "Editor"}...133</Button>134) : (135<iframe136ref={iframeRef}137src={src}138width={"100%"}139height={"100%"}140frameBorder="0"141/>142)}143</div>144);145}146147148