diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-10-28 17:12:58 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | 60c49f18389ff625177a57277ef8f292a31097bf (patch) | |
| tree | 76b0f1f1792b57659e54d282f93df70088446e3c /src/utils/helpers/themes.ts | |
| parent | 05f1dfc6896d3affa7c494a1b955f230d836a4b7 (diff) | |
refactor(providers,hooks): rewrite PrismThemeProvider & usePrismTheme
* reuse Theme provider logic
* move DOM mutation from provider to hook
* add a script to init theme before page load
Diffstat (limited to 'src/utils/helpers/themes.ts')
| -rw-r--r-- | src/utils/helpers/themes.ts | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/utils/helpers/themes.ts b/src/utils/helpers/themes.ts index 8ef3a19..66c0652 100644 --- a/src/utils/helpers/themes.ts +++ b/src/utils/helpers/themes.ts @@ -1,3 +1,6 @@ +import type { Theme } from '../../types'; +import { VALID_THEMES } from '../constants'; + /** * Check if the user prefers dark color scheme. * @@ -16,3 +19,7 @@ export const getThemeFromSystem = () => { if (prefersDarkScheme()) return 'dark'; return 'light'; }; + +export const themeValidator = (value: unknown): value is Theme => + typeof value === 'string' && + (VALID_THEMES as readonly string[]).includes(value); |
