Add tablet viewport check

This commit is contained in:
ernstmul
2025-02-03 13:38:12 +01:00
parent cb3407a4fb
commit 17fdd09de7
4 changed files with 15 additions and 6 deletions
+6 -1
View File
@@ -77,7 +77,7 @@
<Navbar.Base {...$$props}>
<div slot="left" class="left">
<div class="only-mobile">
<div class="only-mobile-tablet">
<button
class="sideNavToggle"
on:click={() => {
@@ -276,6 +276,11 @@
display: none;
}
}
@media (min-width: 1024px) {
.only-mobile-tablet {
display: none;
}
}
:global(.icons div:first-of-type:not(:has(.progress-card))) {
height: 20px;
+2 -4
View File
@@ -30,7 +30,7 @@
import { Feedback } from '$lib/components/feedback';
import { type ComponentType, onMount } from 'svelte';
import { getSidebarState, updateSidebarState } from '$lib/helpers/sidebar';
import { isSmallViewport } from '$lib/stores/viewport';
import { isSmallViewport, isTabletViewport } from '$lib/stores/viewport';
type $$Props = HTMLElement & {
state?: 'closed' | 'open' | 'icons';
@@ -61,9 +61,7 @@
}
}
onMount(() => {
state = isSmallViewport ? 'closed' : getSidebarState();
});
$: state = $isTabletViewport ? 'closed' : getSidebarState();
$: updateSidebarState(state);
+5
View File
@@ -1,11 +1,16 @@
import { writable } from 'svelte/store';
export const isSmallViewport = writable(false);
export const isTabletViewport = writable(false);
export function updateViewport() {
if (typeof window !== 'undefined') {
isSmallViewport.set(
typeof window !== 'undefined' ? window.matchMedia('(max-width: 768px)').matches : false
);
isTabletViewport.set(
typeof window !== 'undefined' ? window.matchMedia('(max-width: 1024px)').matches : false
);
}
}
+2 -1
View File
@@ -27,6 +27,7 @@
}
onMount(async () => {
updateViewport();
// handle sources
if (isCloud) {
const urlParams = $page.url.searchParams;
@@ -106,7 +107,7 @@
}
</script>
<svelte:window on:resize={updateViewport} />
<svelte:window on:resize={updateViewport} on:load={updateViewport} />
<Root theme={resolveTheme($app.themeInUse)}>
<Notifications />