PageTransition
Page transitions — off unless you ask for one.
Walkthrough
1. Presets
Five of the seventeen presets, off unless you ask. Change key and the content transitions; here the key is the step, so the buttons drive it.
<script lang="ts"> import { Button, PageTransition, SegmentedButton } from 'omaris'; import type { PageTransitionName } from 'omaris'; let transition = $state<PageTransitionName>('shared-x'); let step = $state(0); const PANELS = ['Overview', 'Orders', 'Customers'];</script><div class="flex w-full max-w-lg flex-col gap-4"> <SegmentedButton label="Preset" bind:value={transition} items={[ { value: 'fade', label: 'fade' }, { value: 'fade-through', label: 'fade-through' }, { value: 'shared-x', label: 'shared-x' }, { value: 'shared-y', label: 'shared-y' }, { value: 'scale', label: 'scale' } ]} /> <div class="h-32 overflow-hidden rounded-shape-lg border border-border"> <PageTransition key={step} {transition} class="h-full"> <div class="flex h-full items-center justify-center bg-surface-container-low"> <span class="text-title-md">{PANELS[step]}</span> </div> </PageTransition> </div> <div class="flex gap-2"> <Button size="xs" variant="outlined" onclick={() => (step = (step + 2) % 3)}>Back</Button> <Button size="xs" variant="outlined" onclick={() => (step = (step + 1) % 3)}>Forward</Button> </div></div> 2. In a layout
In a real app the key is the pathname, so every navigation transitions and nothing else has to change: ``svelte <PageTransition key={page.url.pathname} transition="shared-x"> {@render children()} </PageTransition> ` direction` is worked out from the keys by default; set it by hand, as here, when the layout already knows which way it went.
/orders<script lang="ts"> import { Button, PageTransition } from 'omaris'; let index = $state(0); let direction = $state<'forward' | 'backward'>('forward'); const PAGES = ['/orders', '/orders/4021', '/orders/4021/items']; function go(step: number) { direction = step > 0 ? 'forward' : 'backward'; index = Math.min(PAGES.length - 1, Math.max(0, index + step)); }</script><div class="flex w-full max-w-lg flex-col gap-4"> <div class="h-28 overflow-hidden rounded-shape-lg border border-border"> <PageTransition key={PAGES[index]} transition="shared-x" {direction} class="h-full"> <div class="flex h-full items-center justify-center bg-surface-container-low"> <code class="text-body-md">{PAGES[index]}</code> </div> </PageTransition> </div> <div class="flex gap-2"> <Button size="xs" variant="outlined" disabled={index === 0} onclick={() => go(-1)}>Back</Button> <Button size="xs" variant="outlined" disabled={index === 2} onclick={() => go(1)}> Deeper </Button> </div></div> 3. Native stack
push is the phone's navigation stack. Forward, the new page slides in over the old one, which sits back a third of the way and dims beneath it; Back pops — the page on top slides off and the one beneath comes back up. Give it onback and a drag from the left edge pulls the page aside with the previous one tracking underneath; let go past halfway and it goes.
9:41
<script lang="ts"> import { Button, DeviceMockup, IconButton, List, ListItem, PageTransition, Text, TopAppBar } from 'omaris'; const ORDERS = [ { id: '4021', who: 'Amina Yusuf', total: '$184.00', items: ['Espresso beans', 'Pour-over kit'] }, { id: '4022', who: 'Karwan Ali', total: '$42.50', items: ['Cold brew', 'Oat milk'] }, { id: '4023', who: 'Hevi Salih', total: '$96.20', items: ['Filter papers', 'Kettle'] } ]; /** The route, as a stack of segments: `[]`, `['4021']`, `['4021', 'Cold brew']`. */ let path = $state<string[]>([]); const order = $derived(ORDERS.find((entry) => entry.id === path[0])); const item = $derived(path[1]); function back() { path = path.slice(0, -1); }</script>{#snippet backButton()} <IconButton aria-label="Back" onclick={back}> <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"> <path d="M15 5l-7 7 7 7" stroke-linecap="round" stroke-linejoin="round" /> </svg> </IconButton>{/snippet}{#snippet chevron()} ...{/snippet}<DeviceMockup width={300}> <PageTransition key={path.join('/')} transition="push" onback={back} class="min-h-full"> {#if !order} <div class="flex min-h-full flex-col"> <TopAppBar size="small" title="Orders" variant="surface" /> <List class="px-2"> {#each ORDERS as entry (entry.id)} <ListItem headline={entry.who} supportingText="#{entry.id} · {entry.total}" lines={2} onclick={() => (path = [entry.id])} > {#snippet trailing()}{@render chevron()}{/snippet} </ListItem> {/each} </List> </div> {:else if !item} <div class="flex min-h-full flex-col"> <TopAppBar size="small" title="Order #{order.id}" variant="surface"> {#snippet leading()}{@render backButton()}{/snippet} </TopAppBar> <div class="flex flex-col gap-4 px-4 pt-2 pb-6"> <div class="rounded-shape-lg bg-primary-container p-4 text-primary-container-foreground"> <Text variant="label-md">{order.who}</Text> <Text variant="display-sm" tabular>{order.total}</Text> </div> <List class="-mx-2"> {#each order.items as name (name)} <ListItem headline={name} onclick={() => (path = [order.id, name])}> {#snippet trailing()}{@render chevron()}{/snippet} </ListItem> {/each} </List> </div> </div> {:else} <div class="flex min-h-full flex-col"> <TopAppBar size="small" title={item} variant="surface"> {#snippet leading()}{@render backButton()}{/snippet} </TopAppBar> <div class="flex flex-col gap-3 px-4 pt-2 pb-6"> <div class="aspect-video rounded-shape-lg bg-surface-container-high"></div> <Text variant="body-md" tone="muted"> In order #{order.id} for {order.who}. Swipe from the left edge, or press Back, to pop this page off the stack. </Text> <Button variant="tonal" class="self-start" onclick={() => (path = [])}> Back to orders </Button> </div> </div> {/if} </PageTransition></DeviceMockup> 4. Cover and reveal
cover is a modal: forward, the page rises over the one below, which sits back and dims; Back drops it away again. reveal is the same pair the other way round, and swap lands with a small overshoot.
/orders<script lang="ts"> import { Button, PageTransition, SegmentedButton } from 'omaris'; import type { PageTransitionName } from 'omaris'; let transition = $state<PageTransitionName>('cover'); let index = $state(0); const PAGES = ['/orders', '/orders/new', '/orders/new/confirm']; function go(step: number) { index = Math.min(PAGES.length - 1, Math.max(0, index + step)); }</script><div class="flex w-full max-w-lg flex-col gap-4"> <SegmentedButton label="Pattern" bind:value={transition} items={[ { value: 'cover', label: 'cover' }, { value: 'reveal', label: 'reveal' }, { value: 'slide', label: 'slide' }, { value: 'swap', label: 'swap' } ]} /> <div class="h-28 overflow-hidden rounded-shape-lg border border-border"> <PageTransition key={PAGES[index]} {transition} class="h-full"> <div class="flex h-full items-center justify-center bg-surface-container-low"> <code class="text-body-md">{PAGES[index]}</code> </div> </PageTransition> </div> <div class="flex gap-2"> <Button size="xs" variant="outlined" disabled={index === 0} onclick={() => go(-1)}>Back</Button> <Button size="xs" variant="outlined" disabled={index === 2} onclick={() => go(1)}> Deeper </Button> </div></div> 5. Auto direction
direction defaults to auto, which keeps the keys it has seen as a stack: a key it has never seen plays forward, and one already on the stack plays backward and unwinds it. Click across the tabs, then back to one you have been to. A tab strip would rather set it by hand — right is forward.
<script lang="ts"> import { PageTransition, SegmentedButton, Text } from 'omaris'; const TABS = ['Overview', 'Orders', 'Menu', 'Staff']; let at = $state('Overview'); let played = $state('—');</script><div class="flex w-full max-w-lg flex-col gap-4"> <SegmentedButton label="Section" bind:value={at} items={TABS.map((tab) => ({ value: tab, label: tab }))} /> <div class="h-28 overflow-hidden rounded-shape-lg border border-border"> <PageTransition key={at} transition="shared-x" class="h-full" onstart={(way) => (played = way)}> <div class="flex h-full items-center justify-center bg-surface-container-low"> <span class="text-title-md">{at}</span> </div> </PageTransition> </div> <Text variant="label-sm" tone="muted">Last transition played: {played}</Text></div>