export function enableTheme()

in src/lib/theme.ts [15:35]


export function enableTheme(newThemeName: string): void {
  const oldThemeName = getTheme();
  localStorage.setItem('theme', newThemeName);

  for (const themeLink of getAllThemes()) {
    // Disable all theme links, except for the desired theme, which we enable
    themeLink.disabled = themeLink.dataset.theme !== newThemeName;
    themeLink['aria-disabled'] = themeLink.dataset.theme !== newThemeName;
  }

  // Add a class to the `body` element that indicates which theme we're using.
  // This allows any custom styling to adapt to the current theme.
  if (document.body.classList.contains(`appTheme-${oldThemeName}`)) {
    document.body.classList.replace(
      `appTheme-${oldThemeName}`,
      `appTheme-${newThemeName}`
    );
  } else {
    document.body.classList.add(`appTheme-${newThemeName}`);
  }
}