Skip to content

Commit

Permalink
add defaultMode to InitColorSchemeScript
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Oct 17, 2024
1 parent 064fa67 commit 42ad012
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ export const DEFAULT_COLOR_SCHEME_STORAGE_KEY = 'color-scheme';
export const DEFAULT_ATTRIBUTE = 'data-color-scheme';

export interface InitColorSchemeScriptProps {
/**
* The default mode when the storage is empty (user's first visit)
* @default 'system'
*/
defaultMode?: 'system' | 'light' | 'dark';
/**
* The default color scheme to be used on the light mode
* @default 'light'
Expand Down Expand Up @@ -49,6 +54,7 @@ export interface InitColorSchemeScriptProps {

export default function InitColorSchemeScript(options?: InitColorSchemeScriptProps) {
const {
defaultMode = 'system',
defaultLightColorScheme = 'light',
defaultDarkColorScheme = 'dark',
modeStorageKey = DEFAULT_MODE_STORAGE_KEY,
Expand Down Expand Up @@ -93,7 +99,7 @@ export default function InitColorSchemeScript(options?: InitColorSchemeScriptPro
__html: `(function() {
try {
let colorScheme = '';
const mode = localStorage.getItem('${modeStorageKey}') || 'system';
const mode = localStorage.getItem('${modeStorageKey}') || '${defaultMode}';
const dark = localStorage.getItem('${colorSchemeStorageKey}-dark') || '${defaultDarkColorScheme}';
const light = localStorage.getItem('${colorSchemeStorageKey}-light') || '${defaultLightColorScheme}';
if (mode === 'system') {
Expand Down

0 comments on commit 42ad012

Please sign in to comment.