Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix print preview in dark mode #3003

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading