Skip to content

Commit

Permalink
fix print preview in dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
kwongz committed Jan 13, 2025
1 parent eb50218 commit c63773a
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/selfish-coins-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@evidence-dev/core-components': patch
---

fixes print preview in dark mode
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@
console.debug('[fix-tprotocol-service-worker] Service Worker registered', { registration });
});
const { syncDataThemeAttribute, cycleAppearance } = getThemeStores();
const { syncDataThemeAttribute, cycleAppearance, selectedAppearance, setAppearance } =
getThemeStores();
onMount(() => {
/** @param {KeyboardEvent} e */
Expand All @@ -149,6 +150,32 @@
});
onMount(() => syncDataThemeAttribute(document.querySelector('html')));
//handles printing in dark mode
onMount(() => {
let currentTheme;
//add event listner for print, switch darkmode to light mode
window.addEventListener('beforeprint', () => {
currentTheme = $selectedAppearance;
if ($selectedAppearance === 'dark') {
setAppearance('light');
}
});
//when finished printing return to previous mode
window.addEventListener('afterprint', () => {
if (currentTheme === 'dark') {
setAppearance('dark');
} else if (currentTheme === 'system') {
setAppearance('system');
}
});
return () => {
window.removeEventListener('beforeprint', () => {});
window.removeEventListener('afterprint', () => {});
};
});
</script>
<slot />
Expand Down

0 comments on commit c63773a

Please sign in to comment.