🛠️ Add route transitions.

This commit is contained in:
pheralb 2023-03-19 14:53:18 +00:00
parent a2aee89088
commit 9afab3cf44
3 changed files with 25 additions and 4 deletions

View File

@ -0,0 +1,10 @@
<script lang="ts">
import { fade } from 'svelte/transition';
export let pathname: string = '';
</script>
{#key pathname}
<div in:fade={{ duration: 300 }}>
<slot />
</div>
{/key}

View File

@ -0,0 +1,5 @@
import type { LayoutServerLoad } from './$types';
export const load: LayoutServerLoad = async ({ url: { pathname } }) => {
return { pathname };
};

View File

@ -1,10 +1,13 @@
<script lang="ts"> <script lang="ts">
import type { LayoutServerData } from './$types';
export let data: LayoutServerData;
// Global styles: // Global styles:
import '../app.css'; import '../app.css';
// Get categories: // Get categories:
import svgData from '../data/svgs.json'; import { svgs } from '@/data/svgs';
const categories = svgData const categories = svgs
.map((svg) => svg.category) .map((svg) => svg.category)
.filter((category, index, array) => array.indexOf(category) === index); .filter((category, index, array) => array.indexOf(category) === index);
@ -14,6 +17,7 @@
// Toaster: // Toaster:
import { Toaster } from 'svelte-french-toast'; import { Toaster } from 'svelte-french-toast';
import Transition from '@/components/transition.svelte';
</script> </script>
<main class="min-h-screen bg-dark font-sans text-mini text-white"> <main class="min-h-screen bg-dark font-sans text-mini text-white">
@ -33,7 +37,7 @@
<a <a
href={`/directory/${category.toLowerCase()}`} href={`/directory/${category.toLowerCase()}`}
class="flex w-full items-center rounded-md p-2 transition-all duration-100 hover:bg-neutral-700/40" class="flex w-full items-center rounded-md p-2 transition-all duration-100 hover:bg-neutral-700/40"
>{category}</a data-sveltekit-preload-data>{category}</a
> >
{/each} {/each}
</div> </div>
@ -69,7 +73,9 @@
</div> </div>
</nav> </nav>
<div class="ml-60 py-6"> <div class="ml-60 py-6">
<slot /> <Transition pathname={data.pathname}>
<slot />
</Transition>
<Toaster position="bottom-center" /> <Toaster position="bottom-center" />
</div> </div>
</main> </main>