Path: blob/master/src/packages/next/components/account/config/system/appearance.tsx
5537 views
/*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;33};34}3536register({37path: "system/appearance",38title: "Appearance",39icon: "calendar-week",40desc: "Configure dark mode and how times are displayed.",41search: DESC,42Component: () => {43const { edited, original, Save, EditBoolean, EditNumber, EditSelect } =44useEditTable<Data>({45accounts: { other_settings: null },46});4748if (original == null || edited == null) {49return <Loading />;50}5152function renderDarkMode() {53if (edited == null || !edited.other_settings.dark_mode) return;5455return (56<div style={{ width: "100%" }}>57<div58style={{59margin: "15px auto",60maxWidth: "700px",61border: "1px solid lightgrey",62padding: "15px",63borderRadius: "5px",64}}65>66<h2 style={{ textAlign: "center" }}>Parameters</h2>67<EditNumber68path="other_settings.dark_mode_brightness"69title="Brightness"70min={20}71max={100}72/>73<EditNumber74path="other_settings.dark_mode_contrast"75title="Contrast"76min={20}77max={100}78/>79<EditNumber80path="other_settings.dark_mode_sepia"81title="Sepia"82min={0}83max={100}84/>85</div>86</div>87);88}8990function renderI18N() {91// derive {locale:name} from LOCALIZATIONS and replace the en with en-keep entry92const langs: { [key: string]: string } = Object.fromEntries(93Object.entries(LOCALIZATIONS).map(([key, val]) => [key, val.name]),94);95langs[KEEP_EN_LOCALE] = langs.en;96delete langs.en;9798return (99<EditSelect100path={`other_settings.${OTHER_SETTINGS_LOCALE_KEY}`}101icon="translation-outlined"102title="Language"103desc={DESC.i18n}104options={langs}105defaultValue={KEEP_EN_LOCALE}106/>107);108}109110return (111<Space direction="vertical" style={{ width: "100%" }}>112<Save />113114{renderI18N()}115116<EditBoolean117path="other_settings.dark_mode"118icon="caret-square-right"119desc={120<div121style={{122color: "rgba(229, 224, 216, 0.65)",123backgroundColor: "rgb(36, 37, 37)",124marginLeft: "-5px",125padding: "5px",126borderRadius: "3px",127}}128>129{DESC.dark_mode} Dark mode is implemented using{" "}130<A131style={{ color: "#e96c4d", fontWeight: 700 }}132href="https://darkreader.org/"133>134DARK READER135</A>136, and currently only applies when you are actually editing files137(e.g., it doesn't change this configuration page).138</div>139}140/>141142{renderDarkMode()}143144<EditBoolean145path="other_settings.time_ago_absolute"146icon="clock"147title="Timestamp Display"148desc={DESC.time_ago_absolute}149label="Display timestamps as absolute points in time"150/>151</Space>152);153},154});155156157