Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add getting theme from cookie #1067

Merged
merged 49 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
a0bdfe3
feat: add getting theme from cookie
Dec 13, 2023
beb14bd
docs: up CHANGELOG.md
Dec 13, 2023
9aa68da
feat: add storage module
Dec 13, 2023
158a0dc
feat: change storage to strategy
Dec 14, 2023
49ede59
chore: change engine type
Dec 14, 2023
53ff96b
chore: improve comment
Dec 14, 2023
46e359f
chore: review fixes
Dec 18, 2023
fc59dde
docs: add ds docs
Jan 10, 2024
9febba7
chore: union imports
Jan 16, 2024
d48e0c5
Merge branch 'v4' of github.com:V4Fire/Client into givanyan99/theme-p…
Jan 16, 2024
bff6fba
Merge branch 'v4' of github.com:V4Fire/Client into givanyan99/theme-p…
Jan 18, 2024
22b9305
feat(core/system-theme-extractor): add system-theme-extractor module
Jan 19, 2024
53a4306
feat(components/super/i-static-page/modules/theme/theme-manager): ref…
Jan 19, 2024
be28398
chore: improve imports
Jan 19, 2024
2894290
Update CHANGELOG.md
Gannicus91 Jan 22, 2024
ae1b0df
Update src/components/super/i-static-page/modules/theme/CHANGELOG.md
Gannicus91 Jan 22, 2024
fd544bd
chore: refactor
Jan 22, 2024
15202d6
Merge remote-tracking branch 'origin/givanyan99/theme-post-process' i…
Jan 22, 2024
145db20
chore: refactor init
Jan 22, 2024
8752116
docs: improve jsdoc
Jan 22, 2024
6854453
chore: refactor theme-manager.ts
Jan 22, 2024
c23a8d6
chore: update jsdoc
Jan 22, 2024
6de843d
chore: add private initSystemTheme
Jan 22, 2024
adc58c0
chore: add getter for default theme
Jan 22, 2024
71d2e9f
chore: add getThemeAlias
Jan 22, 2024
d961e5a
chore: change getter to readonly field
Jan 22, 2024
9fea378
chore: remove ThemeSetterArg
Jan 22, 2024
c9bbcea
chore: improve naming
Jan 22, 2024
76626ea
chore: remove initialValue
Jan 23, 2024
ad32715
docs: up CHANGELOGs
Jan 23, 2024
d91a10f
chore: refactor theme-manager
Jan 23, 2024
a78ed38
docs: up CHANGELOG.md
Jan 23, 2024
6f7918f
chore: fix initThemeModListener
Jan 23, 2024
90067ab
chore: fix getSystemTheme return value
Jan 24, 2024
c6d3d0b
chore: review fixes
Jan 24, 2024
2d6dd4c
chore: up README.md
Jan 24, 2024
a1fd62b
chore: refactor theme init
Jan 26, 2024
64ef822
chore: up CHANGELOG.md
Jan 26, 2024
dba4128
chore: refactor
Jan 29, 2024
ae131d8
chore: fix import
Jan 29, 2024
6b8c7d9
Merge branch 'v4' of github.com:V4Fire/Client into givanyan99/theme-p…
Jan 30, 2024
949160c
docs: improve docs
Jan 30, 2024
541bd12
chore: review fixes
Jan 30, 2024
2af793e
docs: add examples
Jan 30, 2024
872680c
docs: add examples
Jan 30, 2024
d686fa4
docs: improve readability and fix grammar errors
Jan 30, 2024
737484c
docs(ds): fix example link
shining-mind Jan 31, 2024
bd82576
docs(ds): fix example link
shining-mind Jan 31, 2024
a801d3f
Merge branch 'v4' of https://github.com/v4fire/client into givanyan99…
bonkalol Jan 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build/globals.webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ module.exports = {

DETECT_USER_PREFERENCES: s(config.theme.detectUserPreferences()),

POST_PROCESS_THEME: s(config.theme.postProcessor),

DS: runtime.passDesignSystem && pzlr.designSystem ?
s(getDS()) :
null,
Expand Down
2 changes: 2 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ declare const DETECT_USER_PREFERENCES: CanUndef<
}>>
>;

declare const POST_PROCESS_THEME: CanUndef<boolean>;

declare const DS: CanUndef<DesignSystem>;
declare const DS_COMPONENTS_MODS: CanUndef<{
[name: string]: Nullable<Array<string | boolean | number>>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import symbolGenerator from 'core/symbol';
import { syncLocalStorage } from 'core/kv-storage/engines/cookie';

import type iBlock from 'components/super/i-block/i-block';
import type iStaticPage from 'components/super/i-static-page/i-static-page';
Expand Down Expand Up @@ -50,7 +51,13 @@ export default class ThemeManager extends Friend {

let theme = THEME;

if (Object.isDictionary(DETECT_USER_PREFERENCES)) {
if (POST_PROCESS_THEME) {
const themeFromCookie = syncLocalStorage.get('colorTheme');

if (themeFromCookie != null && this.availableThemes.has(themeFromCookie)) {
theme = themeFromCookie;
}
} else if (Object.isDictionary(DETECT_USER_PREFERENCES)) {
const
prefersColorSchemeEnabled = Object.get<boolean>(DETECT_USER_PREFERENCES, 'prefersColorScheme.enabled') ?? false,
darkTheme = Object.get<string>(DETECT_USER_PREFERENCES, 'prefersColorScheme.aliases.dark') ?? 'dark',
Expand Down Expand Up @@ -97,6 +104,7 @@ export default class ThemeManager extends Friend {
const oldValue = this.currentStore;

this.currentStore = value;
syncLocalStorage.set('colorTheme', value);
document.documentElement.setAttribute(this.themeAttribute, value);

void this.component.lfc.execCbAtTheRightTime(() => {
Expand Down