Skip to content

Commit

Permalink
fix: Apply dark/light mode class to both body and html element when n…
Browse files Browse the repository at this point in the history
…o target element is provided
  • Loading branch information
jperals committed Dec 6, 2024
1 parent 236c167 commit 087095b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ function toggleClass(target: Element, className: string, enabled: boolean) {
}
}

export function applyMode(mode: Mode | null, target: Element = document.body): void {
export function applyMode(mode: Mode | null, target?: Element): void {
if (mode && !hasValue(Mode, mode)) {
console.warn(`Mode "${mode}" is not supported`);
return;
}
toggleClass(target, 'awsui-dark-mode', mode === Mode.Dark);
if (target) {
toggleClass(target, 'awsui-dark-mode', mode === Mode.Dark);
} else {
applyMode(mode, document.body)
applyMode(mode, document.documentElement)
}
}

export function applyDensity(density: Density | null, target: Element = document.body): void {
Expand Down

0 comments on commit 087095b

Please sign in to comment.