Path: blob/master/src/packages/next/components/landing/header.tsx
1450 views
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Button, Layout, Tooltip } from "antd";6import Link from "next/link";7import { join } from "path";89import { Icon } from "@cocalc/frontend/components/icon";10import { IS_MOBILE } from "@cocalc/frontend/feature";11import { SoftwareEnvNames } from "@cocalc/util/consts/software-envs";12import { COLORS } from "@cocalc/util/theme";13import AccountNavTab from "components/account/navtab";14import Analytics from "components/analytics";15import DemoCell from "components/demo-cell";16import LiveDemo from "components/landing/live-demo";17import Logo from "components/logo";18import A from "components/misc/A";19import ChatGPTHelp from "components/openai/chatgpt-help";20import basePath from "lib/base-path";21import { useCustomize } from "lib/customize";22import SubNav, { Page, SubPage } from "./sub-nav";2324const GAP = "3%";2526const SHOW_AI_CHAT: Readonly<string[]> = ["ai"] as const;2728export const LinkStyle: React.CSSProperties = {29color: "white",30marginRight: GAP,31display: "inline-block",32} as const;3334// The style shouldn't change the size of the label, e.g., don't35// use bold. Otherwise, everything moves a little when you select36// an option, which looks weird.37const SelectedStyle: React.CSSProperties = {38...LinkStyle,39color: COLORS.LANDING.TOP_BG,40borderBottom: "5px solid #c7d9f5",41} as const;4243interface Props {44page?: Page;45subPage?: SubPage;46runnableTag?: string; // if on cocalc.com and have jupyter api use this tag for a little runable editable demo Jupyter cell.47softwareEnv?: SoftwareEnvNames;48}4950export default function Header(props: Props) {51const { page, subPage, softwareEnv, runnableTag } = props;52const {53siteName,54termsOfServiceURL,55account,56onCoCalcCom,57openaiEnabled,58jupyterApiEnabled,59enabledPages,60} = useCustomize();6162if (basePath == null) return null;6364function ask() {65if (onCoCalcCom && !IS_MOBILE) {66return (67<span68style={{69float: "right",70width: "150px", // CRITICAL -- this is to prevent flicker -- see https://github.com/sagemathinc/cocalc/issues/650471}}72>73{true || account ? (74<LiveDemo context="header" btnType="primary" />75) : (76<Button77type="primary"78href="/support/new?type=question&subject=&body=&title=Ask%20Us%20Anything!"79>80<Icon name="question-circle" /> Contact81</Button>82)}83</span>84);85}86}8788return (89<>90<Analytics />91<Layout.Header92style={{93minHeight: "64px",94height: "auto",95lineHeight: "32px",96padding: "16px",97textAlign: "center",98}}99>100{ask()}101<A href="/">102{/* WARNING: This mess is all to support using the next/image component for the image via our Image component. It's ugly. */}103<div104style={{105position: "relative",106display: "inline-block",107top: "15px",108height: "40px",109width: "40px",110marginTop: "-30px",111marginRight: "64px",112}}113>114<Logo115type="icon"116style={{117height: "40px",118width: "40px",119position: "absolute",120}}121/>122</div>123</A>124{account && (125<Tooltip title={"Browse all of your projects"}>126<a style={LinkStyle} href={join(basePath, "projects")}>127Your Projects128</a>129</Tooltip>130)}131{enabledPages?.store && (132<A href="/store" style={page === "store" ? SelectedStyle : LinkStyle}>133Store134</A>135)}136{enabledPages?.features && (137<A138href="/features/"139style={page === "features" ? SelectedStyle : LinkStyle}140>141Features142</A>143)}144{/* supportedRoutes?.software && (145<A146href="/software"147style={page == "software" ? SelectedStyle : LinkStyle}148>149Software150</A>151)*/}152{enabledPages?.legal && (153<A154style={LinkStyle}155href={termsOfServiceURL}156title="View the terms of service and other legal documents."157>158Legal159</A>160)}161{enabledPages?.info && (162<A163style={page === "info" ? SelectedStyle : LinkStyle}164href="/info"165title="Documentation and links to resources for learning more about CoCalc"166>167Docs168</A>169)}170{enabledPages?.share && (171<Link172href={"/share/public_paths/page/1"}173style={page === "share" ? SelectedStyle : LinkStyle}174title="View files that people have published."175>176Share177</Link>178)}179{enabledPages?.support && (180<A181style={page === "support" ? SelectedStyle : LinkStyle}182href="/support"183title="Create and view support tickets"184>185Support186</A>187)}188{enabledPages?.news && (189<A190style={page === "news" ? SelectedStyle : LinkStyle}191href="/news"192title={`News about ${siteName}`}193>194News195</A>196)}197{enabledPages?.about.index && (198<A199style={page === "about" ? SelectedStyle : LinkStyle}200href="/about"201title={`About ${siteName}`}202>203About204</A>205)}206{enabledPages?.policies.index && (207<A208style={page === "policies" ? SelectedStyle : LinkStyle}209href="/policies"210title={`Policies of ${siteName}`}211>212Policies213</A>214)}215{account ? (216<AccountNavTab217style={page === "account" ? SelectedStyle : LinkStyle}218/>219) : (220<>221<A222style={page === "sign-up" ? SelectedStyle : LinkStyle}223href="/auth/sign-up"224title={`Sign up for a ${siteName} account.`}225>226Sign Up227</A>228<A229style={page === "sign-in" ? SelectedStyle : LinkStyle}230href="/auth/sign-in"231title={`Sign in to ${siteName} or create an account.`}232>233Sign In234</A>235</>236)}237{enabledPages?.auth.try && (238<A239style={page === "try" ? SelectedStyle : LinkStyle}240href={"/auth/try"}241title={`Try ${siteName} immediately without creating an account.`}242>243Try244</A>245)}{" "}246</Layout.Header>247<SubNav page={page} subPage={subPage} softwareEnv={softwareEnv} />248{openaiEnabled &&249onCoCalcCom &&250page === "features" &&251typeof subPage === "string" &&252SHOW_AI_CHAT.includes(subPage) ? (253<div style={{ width: "700px", maxWidth: "100%", margin: "15px auto" }}>254<ChatGPTHelp255size="large"256prompt={subPage ? `I am using ${subPage}.` : ""}257tag={`features-${subPage}`}258/>259</div>260) : undefined}261{jupyterApiEnabled && onCoCalcCom && runnableTag ? (262<DemoCell tag={runnableTag} />263) : undefined}264</>265);266}267268269