Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/src/packages/frontend/app/use-context.ts
Views: 821
/*1Just the minimal app context definitions so that this can also be imported by the nextjs app.23This should be renderable server side, e.g., no window references, etc.4*/56import { ThemeConfig } from "antd";7import type { SizeType } from "antd/es/config-provider/SizeContext";8import { createContext, ReactNode, useContext } from "react";9import type { IntlMessage } from "@cocalc/util/i18n/types";10import { COLORS } from "@cocalc/util/theme";1112import {13FONT_SIZE_ICONS_NARROW,14FONT_SIZE_ICONS_NORMAL,15NAV_HEIGHT_NARROW_PX,16NAV_HEIGHT_PX,17type PageStyle,18} from "./top-nav-consts";1920export interface AppState {21pageWidthPx: number;22pageStyle: PageStyle;23antdComponentSize?: SizeType;24antdTheme?: ThemeConfig;25formatIntl: (msg: IntlMessage | ReactNode | string) => ReactNode | string;26timeAgoAbsolute?: boolean;27setTimeAgoAbsolute?: (boolean) => void;28}2930export const DEFAULT_CONTEXT = {31pageWidthPx: 1000, // gets updated32pageStyle: calcStyle(false), // gets updated33formatIntl: () => "Loading…",34};3536export const AppContext = createContext<AppState>(DEFAULT_CONTEXT);3738export default function useAppContext() {39return useContext(AppContext);40}4142export function calcStyle(isNarrow: boolean): PageStyle {43const fontSizeIcons: string = isNarrow44? FONT_SIZE_ICONS_NARROW45: FONT_SIZE_ICONS_NORMAL;46const topPaddingIcons: string = isNarrow ? "2px" : "5px";47const sidePaddingIcons: string = isNarrow ? "7px" : "14px";4849const height = isNarrow ? NAV_HEIGHT_NARROW_PX : NAV_HEIGHT_PX;5051const topBarStyle = {52height: `${height}px`,53} as const;5455const fileUseStyle = {56background: "white",57border: `2px solid ${COLORS.GRAY_DDD}`,58borderRadius: "5px",59boxShadow: "0 0 15px #aaa",60fontSize: "10pt",61height: "90%",62margin: 0,63overflowX: "hidden",64overflowY: "auto",65padding: "4px",66position: "fixed",67right: "5vw",68top: `${height}px`,69width: isNarrow ? "90vw" : "50vw",70zIndex: 110,71} as const;7273const projectsNavStyle = isNarrow74? ({75/* this makes it so the projects tabs are on a separate row; otherwise, there is literally no room for them at all... */76width: "100vw",77marginTop: "4px",78height: `${height}px`,79// no flex!80} as const)81: ({82flex: "1 1 auto", // necessary to stretch out to the full width83} as const);8485return {86topBarStyle,87fileUseStyle,88projectsNavStyle,89isNarrow,90sidePaddingIcons,91topPaddingIcons,92fontSizeIcons,93height,94};95}969798