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/next/components/account/config/system/appearance.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2021 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Space } from "antd";67import {8KEEP_EN_LOCALE,9LOCALIZATIONS,10OTHER_SETTINGS_LOCALE_KEY,11} from "@cocalc/util/i18n";12import A from "components/misc/A";13import Loading from "components/share/loading";14import useEditTable from "lib/hooks/edit-table";15import register from "../register";1617const DESC = {18time_ago_absolute: `19You can display timestamps either as absolute points in time or relative to20the current time.`,21dark_mode: `Use Dark mode to reduce eye strain and save power by showing light text on a dark background.`,22extra: "dark reader",23i18n: "Change the user-interface language",24} as const;2526interface Data {27other_settings: {28time_ago_absolute: boolean;29dark_mode: boolean;30dark_mode_brightness: number;31dark_mode_contrast: number;32dark_mode_sepia: number;33dark_mode_grayscale: number;34};35}3637register({38path: "system/appearance",39title: "Appearance",40icon: "calendar-week",41desc: "Configure dark mode and how times are displayed.",42search: DESC,43Component: () => {44const { edited, original, Save, EditBoolean, EditNumber, EditSelect } =45useEditTable<Data>({46accounts: { other_settings: null },47});4849if (original == null || edited == null) {50return <Loading />;51}5253function renderDarkMode() {54if (edited == null || !edited.other_settings.dark_mode) return;5556return (57<div style={{ width: "100%" }}>58<div59style={{60margin: "15px auto",61maxWidth: "700px",62border: "1px solid lightgrey",63padding: "15px",64borderRadius: "5px",65}}66>67<h2 style={{ textAlign: "center" }}>Parameters</h2>68<EditNumber69path="other_settings.dark_mode_brightness"70title="Brightness"71min={20}72max={100}73/>74<EditNumber75path="other_settings.dark_mode_contrast"76title="Contrast"77min={20}78max={100}79/>80<EditNumber81path="other_settings.dark_mode_sepia"82title="Sepia"83min={0}84max={100}85/>86<EditNumber87path="other_settings.dark_mode_grayscale"88title="Grayscale"89min={0}90max={100}91/>92</div>93</div>94);95}9697function renderI18N() {98// derive {locale:name} from LOCALIZATIONS and replace the en with en-keep entry99const langs: { [key: string]: string } = Object.fromEntries(100Object.entries(LOCALIZATIONS).map(([key, val]) => [key, val.name]),101);102langs[KEEP_EN_LOCALE] = langs.en;103delete langs.en;104105return (106<EditSelect107path={`other_settings.${OTHER_SETTINGS_LOCALE_KEY}`}108icon="translation-outlined"109title="Language"110desc={DESC.i18n}111options={langs}112defaultValue={KEEP_EN_LOCALE}113/>114);115}116117return (118<Space direction="vertical" style={{ width: "100%" }}>119<Save />120121{renderI18N()}122123<EditBoolean124path="other_settings.dark_mode"125icon="caret-square-right"126desc={127<div128style={{129color: "rgba(229, 224, 216, 0.65)",130backgroundColor: "rgb(36, 37, 37)",131marginLeft: "-5px",132padding: "5px",133borderRadius: "3px",134}}135>136{DESC.dark_mode} Dark mode is implemented using{" "}137<A138style={{ color: "#e96c4d", fontWeight: 700 }}139href="https://darkreader.org/"140>141DARK READER142</A>143, and currently only applies when you are actually editing files144(e.g., it doesn't change this configuration page).145</div>146}147/>148149{renderDarkMode()}150151<EditBoolean152path="other_settings.time_ago_absolute"153icon="clock"154title="Timestamp Display"155desc={DESC.time_ago_absolute}156label="Display timestamps as absolute points in time"157/>158</Space>159);160},161});162163164