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/frontend/components/help-icon.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45/*6Display a ? "help" icon, which -- when clicked -- shows a help tip7*/89import { Button, Popover } from "antd";10import type { TooltipPlacement } from "antd/es/tooltip";11import { CSSProperties } from "react";1213import { CSS, React, useState } from "@cocalc/frontend/app-framework";14import { COLORS } from "@cocalc/util/theme";15import { Icon } from "./icon";1617interface Props {18title: string;19children: React.ReactNode;20maxWidth?: string; // default is 50vw21style?: CSSProperties;22extra?: string;23placement?: TooltipPlacement;24}2526export const HelpIcon: React.FC<Props> = ({27style,28title,29children,30maxWidth = "50vw",31extra = "",32placement,33}: Props) => {34const [open, setOpen] = useState<boolean>(false);3536const textStyle: CSS = {37color: COLORS.BS_BLUE_TEXT,38cursor: "pointer",39...style,40} as const;4142return (43<Popover44placement={placement}45content={46<div onClick={(e) => e.stopPropagation()} style={{ maxWidth }}>47{children}48</div>49}50title={51<div onClick={(e) => e.stopPropagation()}>52{title}53<Button54type="text"55style={{ float: "right", fontWeight: "bold" }}56onClick={(e) => {57e.stopPropagation();58setOpen(false);59}}60>61<Icon name="times" />62</Button>63</div>64}65trigger="click"66open={open}67onOpenChange={setOpen}68>69<span style={textStyle}>70<Icon style={textStyle} name="question-circle" />71{extra ? <> {extra}</> : undefined}72</span>73</Popover>74);75};767778