Path: blob/master/src/packages/frontend/app/use-context.ts
1496 views
/*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";910import type { IntlMessage } from "@cocalc/util/i18n/types";11import { COLORS } from "@cocalc/util/theme";1213import { ACTIVITY_BAR_LABELS_DEFAULT } from "@cocalc/frontend/project/page/activity-bar-consts";14import {15FONT_SIZE_ICONS_NARROW,16FONT_SIZE_ICONS_NORMAL,17NAV_HEIGHT_NARROW_PX,18NAV_HEIGHT_PX,19type PageStyle,20} from "./top-nav-consts";2122export interface AppState {23pageWidthPx: number;24pageStyle: PageStyle;25antdComponentSize?: SizeType;26antdTheme?: ThemeConfig;27formatIntl: (msg: IntlMessage | ReactNode | string) => ReactNode | string;28timeAgoAbsolute?: boolean;29setTimeAgoAbsolute?: (boolean) => void;30showActBarLabels?: boolean; // whether to show labels on the vertical fixed bar31}3233export const DEFAULT_CONTEXT = {34pageWidthPx: 1000, // gets updated35pageStyle: calcStyle(false), // gets updated36formatIntl: () => "Loading…",37showActBarLabels: ACTIVITY_BAR_LABELS_DEFAULT,38};3940export const AppContext = createContext<AppState>(DEFAULT_CONTEXT);4142export default function useAppContext() {43return useContext(AppContext);44}4546export function calcStyle(isNarrow: boolean): PageStyle {47const fontSizeIcons: string = isNarrow48? FONT_SIZE_ICONS_NARROW49: FONT_SIZE_ICONS_NORMAL;50const topPaddingIcons: string = isNarrow ? "2px" : "5px";51const sidePaddingIcons: string = isNarrow ? "7px" : "14px";5253const height = isNarrow ? NAV_HEIGHT_NARROW_PX : NAV_HEIGHT_PX;5455const topBarStyle = {56height: `${height}px`,57background: "#fafafa",58} as const;5960const fileUseStyle = {61background: "white",62border: `2px solid ${COLORS.GRAY_DDD}`,63borderRadius: "5px",64boxShadow: "0 0 15px #aaa",65fontSize: "10pt",66height: "90%",67margin: 0,68overflowX: "hidden",69overflowY: "auto",70padding: "4px",71position: "fixed",72right: "5vw",73top: `${height}px`,74width: isNarrow ? "90vw" : "50vw",75zIndex: 110,76} as const;7778const projectsNavStyle = isNarrow79? ({80/* this makes it so the projects tabs are on a separate row; otherwise, there is literally no room for them at all... */81width: "100vw",82marginTop: "4px",83height: `${height}px`,84// no flex!85} as const)86: ({87flex: "1 1 auto", // necessary to stretch out to the full width88} as const);8990return {91topBarStyle,92fileUseStyle,93projectsNavStyle,94isNarrow,95sidePaddingIcons,96topPaddingIcons,97fontSizeIcons,98height,99};100}101102103