chore: handle case where theme is undefined
This commit is contained in:
@@ -2,10 +2,10 @@ import { darken, lighten } from 'color2k';
|
|||||||
|
|
||||||
import { tc } from '$lib/utils/functions/trycatch';
|
import { tc } from '$lib/utils/functions/trycatch';
|
||||||
|
|
||||||
export function setTheme(theme: string) {
|
export function setTheme(theme: string = '') {
|
||||||
localStorage.setItem('theme', theme);
|
localStorage.setItem('theme', theme);
|
||||||
|
|
||||||
if (theme.includes('#')) {
|
if (theme?.includes('#')) {
|
||||||
const escapedHex = theme.replace(/"/g, '\\"');
|
const escapedHex = theme.replace(/"/g, '\\"');
|
||||||
document.body.setAttribute('data-theme', escapedHex);
|
document.body.setAttribute('data-theme', escapedHex);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user