import initMatrix from '../../../client/initMatrix';
import cons from '../../../client/state/cons';
import settings from '../../../client/state/settings';
-import { toggleMarkdown, toggleMembershipEvents, toggleNickAvatarEvents } from '../../../client/action/settings';
+import { toggleSystemTheme, toggleMarkdown, toggleMembershipEvents, toggleNickAvatarEvents } from '../../../client/action/settings';
import logout from '../../../client/action/logout';
import Text from '../../atoms/text/Text';
return (
<div className="settings-content">
<SettingTile
- title="Theme"
- content={(
- <SegmentedControls
- selected={settings.getThemeIndex()}
- segments={[
- { text: 'Light' },
- { text: 'Silver' },
- { text: 'Dark' },
- { text: 'Butter' },
- ]}
- onSelect={(index) => settings.setTheme(index)}
+ title="Follow system theme"
+ options={(
+ <Toggle
+ isActive={settings.useSystemTheme}
+ onToggle={() => { toggleSystemTheme(); updateState({}); }}
/>
)}
+ content={<Text variant="b3">Use light or dark mode based on the system's settings.</Text>}
/>
+ {(() => {
+ if (!settings.useSystemTheme) {
+ return <SettingTile
+ title="Theme"
+ content={(
+ <SegmentedControls
+ selected={settings.getThemeIndex()}
+ segments={[
+ { text: 'Light' },
+ { text: 'Silver' },
+ { text: 'Dark' },
+ { text: 'Butter' },
+ ]}
+ onSelect={(index) => settings.setTheme(index)}
+ />
+ )}
+ />
+ }
+ })()}
<SettingTile
title="Markdown formatting"
options={(
import appDispatcher from '../dispatcher';
import cons from '../state/cons';
+export function toggleSystemTheme() {
+ appDispatcher.dispatch({
+ type: cons.actions.settings.TOGGLE_SYSTEM_THEME,
+ });
+}
+
export function toggleMarkdown() {
appDispatcher.dispatch({
type: cons.actions.settings.TOGGLE_MARKDOWN,
},
},
settings: {
+ TOGGLE_SYSTEM_THEME: 'TOGGLE_SYSTEM_THEME',
TOGGLE_MARKDOWN: 'TOGGLE_MARKDOWN',
TOGGLE_PEOPLE_DRAWER: 'TOGGLE_PEOPLE_DRAWER',
TOGGLE_MEMBERSHIP_EVENT: 'TOGGLE_MEMBERSHIP_EVENT',
ATTACHMENT_CANCELED: 'ATTACHMENT_CANCELED',
},
settings: {
+ SYSTEM_THEME_TOGGLED: 'SYSTEM_THEME_TOGGLED',
MARKDOWN_TOGGLED: 'MARKDOWN_TOGGLED',
PEOPLE_DRAWER_TOGGLED: 'PEOPLE_DRAWER_TOGGLED',
MEMBERSHIP_EVENTS_TOGGLED: 'MEMBERSHIP_EVENTS_TOGGLED',
this.themes = ['', 'silver-theme', 'dark-theme', 'butter-theme'];
this.themeIndex = this.getThemeIndex();
+ this.useSystemTheme = this.getUseSystemTheme();
this.isMarkdown = this.getIsMarkdown();
this.isPeopleDrawer = this.getIsPeopleDrawer();
this.hideMembershipEvents = this.getHideMembershipEvents();
this.themeIndex = themeIndex;
}
+ getUseSystemTheme() {
+ if (typeof this.useSystemTheme === 'boolean') return this.useSystemTheme;
+
+ const settings = getSettings();
+ if (settings === null) return false;
+ if (typeof settings.useSystemTheme === 'undefined') return false;
+ return settings.useSystemTheme;
+ }
+
getIsMarkdown() {
if (typeof this.isMarkdown === 'boolean') return this.isMarkdown;
setter(action) {
const actions = {
+ [cons.actions.settings.TOGGLE_SYSTEM_THEME]: () => {
+ this.useSystemTheme = !this.useSystemTheme;
+ setSettings('useSystemTheme', this.useSystemTheme);
+ const appBody = document.getElementById('appBody');
+
+ if (this.useSystemTheme) {
+ appBody.classList.add('system-theme');
+ this.themes.forEach((themeName) => {
+ if (themeName === '') return;
+ appBody.classList.remove(themeName);
+ });
+ } else {
+ appBody.classList.remove('system-theme');
+ this.setTheme(this.themeIndex);
+ }
+
+ this.emit(cons.events.settings.SYSTEM_THEME_TOGGLED, this.useSystemTheme);
+ },
[cons.actions.settings.TOGGLE_MARKDOWN]: () => {
this.isMarkdown = !this.isMarkdown;
setSettings('isMarkdown', this.isMarkdown);
--bg-surface-extra-low-transparent: hsla(0, 0%, 91%, 0);
}
-.dark-theme,
-.butter-theme {
+@mixin dark-mode() {
/* background color | --bg-[background type]: value */
--bg-surface: hsl(208, 8%, 20%);
--bg-surface-transparent: hsla(208, 8%, 20%, 0);
--font-secondary: 'Inter', 'Roboto', sans-serif;
}
+.dark-theme,
+.butter-theme {
+ @include dark-mode();
+}
+
+@media (prefers-color-scheme: dark) {
+ .system-theme {
+ @include dark-mode();
+ }
+}
+
.butter-theme {
/* background color | --bg-[background type]: value */
--bg-surface: hsl(64, 6%, 14%);