CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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