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/app/nav-tab.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Tooltip } from "antd";67import { CSS, React, useActions } from "@cocalc/frontend/app-framework";8import { Icon, IconName } from "@cocalc/frontend/components";9import track from "@cocalc/frontend/user-tracking";10import { COLORS } from "@cocalc/util/theme";11import { TOP_BAR_ELEMENT_CLASS } from "./top-nav-consts";1213const ACTIVE_BG_COLOR = COLORS.TOP_BAR.ACTIVE;1415interface Props {16//close?: boolean;17active_top_tab?: string;18add_inner_style?: CSS;19children?: React.ReactNode;20hide_label?: boolean;21icon?: IconName | JSX.Element;22is_project?: boolean;23label_class?: string;24label?: string | JSX.Element;25name?: string;26on_click?: () => void;27style?: CSS;28tooltip?: string;29}3031export const NavTab: React.FC<Props> = React.memo((props: Props) => {32const {33//close,34active_top_tab,35add_inner_style = {},36children,37hide_label,38icon,39is_project,40label_class,41label,42name,43on_click,44style = {},45tooltip,46} = props;47const page_actions = useActions("page");4849function render_label() {50if (!hide_label && label != null) {51return (52<span53style={{ marginLeft: "5px" }}54className={label_class}55cocalc-test={name}56>57{label}58</span>59);60}61}6263function render_icon() {64if (icon != null) {65if (typeof icon === "string") {66return <Icon name={icon} style={{ fontSize: "20px" }} />;67} else {68return icon;69}70}71}7273function onClick() {74on_click?.();7576if (is_project) {77track("top_nav", {78name: "project",79project_id: name,80});81} else {82track("top_nav", {83name: name ?? label,84});85}8687if (name != null) {88page_actions.set_active_tab(name);89}90}9192const is_active = active_top_tab === name;9394const outer_style: CSS = {95fontSize: "14px",96cursor: "pointer",97float: "left",98flex: "0 0 auto",99display: "flex",100border: "none",101...style,102...(is_active && { backgroundColor: ACTIVE_BG_COLOR }),103};104105const inner_style: CSS = {106padding: "12px",107display: "flex",108flexDirection: "row",109verticalAlign: "middle",110alignItems: "center",111whiteSpace: "nowrap",112...add_inner_style,113};114115function renderInner(): JSX.Element {116const inner = (117<div style={inner_style}>118{render_icon()}119{render_label()}120{children}121</div>122);123if (tooltip != null) {124return (125<Tooltip126title={tooltip}127mouseEnterDelay={1}128mouseLeaveDelay={0}129placement="bottom"130>131{inner}132</Tooltip>133);134} else {135return inner;136}137}138139return (140<div141onClick={onClick}142style={outer_style}143className={TOP_BAR_ELEMENT_CLASS}144>145{renderInner()}146</div>147);148});149150151