2022-10-28 16:11:08 +00:00
|
|
|
import {makeT} from 'app/client/lib/localization';
|
2022-09-06 01:51:57 +00:00
|
|
|
import {AppModel} from 'app/client/models/AppModel';
|
|
|
|
import * as css from 'app/client/ui/AccountPageCss';
|
|
|
|
import {labeledSquareCheckbox} from 'app/client/ui2018/checkbox';
|
2023-09-21 16:57:58 +00:00
|
|
|
import {prefersDarkModeObs} from 'app/client/ui2018/cssVars';
|
2022-09-06 01:51:57 +00:00
|
|
|
import {select} from 'app/client/ui2018/menus';
|
|
|
|
import {ThemeAppearance} from 'app/common/ThemePrefs';
|
|
|
|
import {Computed, Disposable, dom, makeTestId, styled} from 'grainjs';
|
|
|
|
|
|
|
|
const testId = makeTestId('test-theme-config-');
|
2022-10-28 16:11:08 +00:00
|
|
|
const t = makeT('ThemeConfig');
|
2022-09-06 01:51:57 +00:00
|
|
|
|
|
|
|
export class ThemeConfig extends Disposable {
|
|
|
|
private _themePrefs = this._appModel.themePrefs;
|
|
|
|
|
|
|
|
private _syncWithOS = Computed.create(this, this._themePrefs, (_use, prefs) => {
|
|
|
|
return prefs.syncWithOS;
|
|
|
|
}).onWrite((value) => this._updateSyncWithOS(value));
|
|
|
|
|
2023-09-21 16:57:58 +00:00
|
|
|
private _appearance = Computed.create(this,
|
|
|
|
this._themePrefs,
|
|
|
|
this._syncWithOS,
|
|
|
|
prefersDarkModeObs(),
|
|
|
|
(_use, prefs, syncWithOS, prefersDarkMode) => {
|
|
|
|
if (syncWithOS) {
|
|
|
|
return prefersDarkMode ? 'dark' : 'light';
|
|
|
|
} else {
|
|
|
|
return prefs.appearance;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.onWrite((value) => this._updateAppearance(value));
|
|
|
|
|
2022-09-06 01:51:57 +00:00
|
|
|
constructor(private _appModel: AppModel) {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
public buildDom() {
|
|
|
|
return dom('div',
|
2023-09-21 16:57:58 +00:00
|
|
|
css.subHeader(t("Appearance ")),
|
2022-09-06 01:51:57 +00:00
|
|
|
css.dataRow(
|
|
|
|
cssAppearanceSelect(
|
|
|
|
select(
|
|
|
|
this._appearance,
|
|
|
|
[
|
|
|
|
{value: 'light', label: 'Light'},
|
|
|
|
{value: 'dark', label: 'Dark'},
|
|
|
|
],
|
2023-09-21 16:57:58 +00:00
|
|
|
{
|
|
|
|
disabled: this._syncWithOS,
|
|
|
|
},
|
2022-09-06 01:51:57 +00:00
|
|
|
),
|
|
|
|
testId('appearance'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
css.dataRow(
|
|
|
|
labeledSquareCheckbox(
|
|
|
|
this._syncWithOS,
|
2022-12-06 13:57:29 +00:00
|
|
|
t("Switch appearance automatically to match system"),
|
2022-09-06 01:51:57 +00:00
|
|
|
testId('sync-with-os'),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
testId('container'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private _updateAppearance(appearance: ThemeAppearance) {
|
|
|
|
this._themePrefs.set({...this._themePrefs.get(), appearance});
|
|
|
|
}
|
|
|
|
|
|
|
|
private _updateSyncWithOS(syncWithOS: boolean) {
|
|
|
|
this._themePrefs.set({...this._themePrefs.get(), syncWithOS});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const cssAppearanceSelect = styled('div', `
|
|
|
|
width: 120px;
|
|
|
|
`);
|