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/frontend/app/fullscreen-button.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 { useIntl } from "react-intl";
7
8
import {
9
CSS,
10
React,
11
useActions,
12
useTypedRedux,
13
} from "@cocalc/frontend/app-framework";
14
import { Icon, Tip } from "@cocalc/frontend/components";
15
import track from "@cocalc/frontend/user-tracking";
16
import { COLORS } from "@cocalc/util/theme";
17
import {
18
NAV_HEIGHT_PX,
19
PageStyle,
20
TOP_BAR_ELEMENT_CLASS,
21
} from "./top-nav-consts";
22
23
const TIP_STYLE_FULLSCREEN: CSS = {
24
position: "fixed",
25
zIndex: 100,
26
right: 0,
27
top: 0,
28
} as const;
29
30
interface Props {
31
pageStyle: PageStyle;
32
}
33
34
export const FullscreenButton: React.FC<Props> = React.memo((props: Props) => {
35
const { pageStyle } = props;
36
const { fontSizeIcons } = pageStyle;
37
38
const intl = useIntl();
39
const fullscreen = useTypedRedux("page", "fullscreen");
40
const page_actions = useActions("page");
41
42
if (fullscreen == "kiosk" || fullscreen == "project") {
43
// no button, since can't get out.
44
return <></>;
45
}
46
47
const icon = fullscreen ? "compress" : "expand";
48
const icon_style: CSS = {
49
fontSize: fontSizeIcons,
50
color: COLORS.GRAY,
51
cursor: "pointer",
52
...(fullscreen
53
? {
54
background: "white",
55
opacity: 0.7,
56
border: "1px solid grey",
57
}
58
: {
59
display: "flex",
60
alignItems: "center",
61
justifyContent: "center",
62
height: `${NAV_HEIGHT_PX}px`,
63
width: `${NAV_HEIGHT_PX}px`,
64
}),
65
};
66
67
const tooltip = intl.formatMessage({
68
id: "app.fullscreen-button.tooltip",
69
defaultMessage: "Fullscreen mode, focused on the current document or page.",
70
});
71
72
return (
73
<Tip
74
style={fullscreen === "default" ? TIP_STYLE_FULLSCREEN : undefined}
75
title={tooltip}
76
placement={"bottomRight"}
77
delayShow={2000}
78
>
79
<Icon
80
className={TOP_BAR_ELEMENT_CLASS}
81
style={icon_style}
82
name={icon}
83
onClick={(_) => {
84
track("top_nav", {
85
name: "fullscreen",
86
enabled: !fullscreen,
87
});
88
page_actions.toggle_fullscreen();
89
}}
90
/>
91
</Tip>
92
);
93
});
94
95