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/help-icon.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
/*
7
Display a ? "help" icon, which -- when clicked -- shows a help tip
8
*/
9
10
import { Button, Popover } from "antd";
11
import type { TooltipPlacement } from "antd/es/tooltip";
12
import { CSSProperties } from "react";
13
14
import { CSS, React, useState } from "@cocalc/frontend/app-framework";
15
import { COLORS } from "@cocalc/util/theme";
16
import { Icon } from "./icon";
17
18
interface Props {
19
title: string;
20
children: React.ReactNode;
21
maxWidth?: string; // default is 50vw
22
style?: CSSProperties;
23
extra?: string;
24
placement?: TooltipPlacement;
25
}
26
27
export const HelpIcon: React.FC<Props> = ({
28
style,
29
title,
30
children,
31
maxWidth = "50vw",
32
extra = "",
33
placement,
34
}: Props) => {
35
const [open, setOpen] = useState<boolean>(false);
36
37
const textStyle: CSS = {
38
color: COLORS.BS_BLUE_TEXT,
39
cursor: "pointer",
40
...style,
41
} as const;
42
43
return (
44
<Popover
45
placement={placement}
46
content={
47
<div onClick={(e) => e.stopPropagation()} style={{ maxWidth }}>
48
{children}
49
</div>
50
}
51
title={
52
<div onClick={(e) => e.stopPropagation()}>
53
{title}
54
<Button
55
type="text"
56
style={{ float: "right", fontWeight: "bold" }}
57
onClick={(e) => {
58
e.stopPropagation();
59
setOpen(false);
60
}}
61
>
62
<Icon name="times" />
63
</Button>
64
</div>
65
}
66
trigger="click"
67
open={open}
68
onOpenChange={setOpen}
69
>
70
<span style={textStyle}>
71
<Icon style={textStyle} name="question-circle" />
72
{extra ? <> {extra}</> : undefined}
73
</span>
74
</Popover>
75
);
76
};
77
78