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/components/hidden-visible.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
// See https://getbootstrap.com/docs/3.3/css/
7
8
import { CSSProperties, ReactNode } from "react";
9
10
// Antd has a rule that puts an 8px margin on the left of all spans in antd buttons,
11
// which means that when these buttons get hidden they take up 8px of empty space
12
// (since the span is still there). So for now we workaround this with an explicit style
13
// that cancels this out.
14
const STYLE = { marginLeft: 0 } as const;
15
16
interface Props {
17
children?: ReactNode;
18
style?: CSSProperties;
19
}
20
21
// HiddenXS = hide if width < 768px
22
export function HiddenXS({ children, style }: Props) {
23
return (
24
<span style={{ ...STYLE, ...style }} className={"hidden-xs"}>
25
{children}
26
</span>
27
);
28
}
29
30
export function HiddenSM({ children, style }: Props) {
31
return (
32
<span style={{ ...STYLE, ...style }} className={"hidden-sm"}>
33
{children}
34
</span>
35
);
36
}
37
38
export function HiddenXSSM({ children, style }: Props) {
39
return (
40
<span style={{ ...STYLE, ...style }} className={"hidden-xs hidden-sm"}>
41
{children}
42
</span>
43
);
44
}
45
46
// VisibleMDLG = visible on medium or large devices (anything with width > 992px)
47
export function VisibleMDLG({ children, style }: Props) {
48
return (
49
<span
50
style={{ ...STYLE, ...style }}
51
className={"visible-md-inline visible-lg-inline"}
52
>
53
{children}
54
</span>
55
);
56
}
57
58
// VisibleMDLG = visible on medium or large devices (anything with width > 992px)
59
export function VisibleLG({ children, style }: Props) {
60
return (
61
<span style={{ ...STYLE, ...style }} className={"visible-lg-inline"}>
62
{children}
63
</span>
64
);
65
}
66
67
export function VisibleXSSM({ children, style }: Props) {
68
return (
69
<span
70
style={{ ...STYLE, ...style }}
71
className={"visible-xs-inline visible-sm-inline"}
72
>
73
{children}
74
</span>
75
);
76
}
77
78
export function VisibleXS({ children, style }: Props) {
79
return (
80
<span style={{ ...STYLE, ...style }} className={"visible-xs-inline"}>
81
{children}
82
</span>
83
);
84
}
85
86