Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/components/account/config/system/appearance.tsx
5537 views
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
};
35
}
36
37
register({
38
path: "system/appearance",
39
title: "Appearance",
40
icon: "calendar-week",
41
desc: "Configure dark mode and how times are displayed.",
42
search: DESC,
43
Component: () => {
44
const { edited, original, Save, EditBoolean, EditNumber, EditSelect } =
45
useEditTable<Data>({
46
accounts: { other_settings: null },
47
});
48
49
if (original == null || edited == null) {
50
return <Loading />;
51
}
52
53
function renderDarkMode() {
54
if (edited == null || !edited.other_settings.dark_mode) return;
55
56
return (
57
<div style={{ width: "100%" }}>
58
<div
59
style={{
60
margin: "15px auto",
61
maxWidth: "700px",
62
border: "1px solid lightgrey",
63
padding: "15px",
64
borderRadius: "5px",
65
}}
66
>
67
<h2 style={{ textAlign: "center" }}>Parameters</h2>
68
<EditNumber
69
path="other_settings.dark_mode_brightness"
70
title="Brightness"
71
min={20}
72
max={100}
73
/>
74
<EditNumber
75
path="other_settings.dark_mode_contrast"
76
title="Contrast"
77
min={20}
78
max={100}
79
/>
80
<EditNumber
81
path="other_settings.dark_mode_sepia"
82
title="Sepia"
83
min={0}
84
max={100}
85
/>
86
</div>
87
</div>
88
);
89
}
90
91
function renderI18N() {
92
// derive {locale:name} from LOCALIZATIONS and replace the en with en-keep entry
93
const langs: { [key: string]: string } = Object.fromEntries(
94
Object.entries(LOCALIZATIONS).map(([key, val]) => [key, val.name]),
95
);
96
langs[KEEP_EN_LOCALE] = langs.en;
97
delete langs.en;
98
99
return (
100
<EditSelect
101
path={`other_settings.${OTHER_SETTINGS_LOCALE_KEY}`}
102
icon="translation-outlined"
103
title="Language"
104
desc={DESC.i18n}
105
options={langs}
106
defaultValue={KEEP_EN_LOCALE}
107
/>
108
);
109
}
110
111
return (
112
<Space direction="vertical" style={{ width: "100%" }}>
113
<Save />
114
115
{renderI18N()}
116
117
<EditBoolean
118
path="other_settings.dark_mode"
119
icon="caret-square-right"
120
desc={
121
<div
122
style={{
123
color: "rgba(229, 224, 216, 0.65)",
124
backgroundColor: "rgb(36, 37, 37)",
125
marginLeft: "-5px",
126
padding: "5px",
127
borderRadius: "3px",
128
}}
129
>
130
{DESC.dark_mode} Dark mode is implemented using{" "}
131
<A
132
style={{ color: "#e96c4d", fontWeight: 700 }}
133
href="https://darkreader.org/"
134
>
135
DARK READER
136
</A>
137
, and currently only applies when you are actually editing files
138
(e.g., it doesn't change this configuration page).
139
</div>
140
}
141
/>
142
143
{renderDarkMode()}
144
145
<EditBoolean
146
path="other_settings.time_ago_absolute"
147
icon="clock"
148
title="Timestamp Display"
149
desc={DESC.time_ago_absolute}
150
label="Display timestamps as absolute points in time"
151
/>
152
</Space>
153
);
154
},
155
});
156
157