design: redesign pagination
This commit is contained in:
1 parent
ed9796e4af
commit
73f5cd5e77
4 files changed
+76
-30
No files matched your search
@@ -9,42 +9,68 @@
|
||||
ChevronRight,
|
||||
Icon,
|
||||
} from 'svelte-hero-icons'
|
||||
import { backOut } from 'svelte/easing'
|
||||
import { fly } from 'svelte/transition'
|
||||
|
||||
export let page: number = 0
|
||||
export let cursor: { next?: string; back?: string } | undefined = undefined
|
||||
export let hasMore: boolean = true
|
||||
|
||||
const dispatcher = createEventDispatcher<{ change: number; cursor: string }>()
|
||||
</script>
|
||||
|
||||
<div class="flex flex-row w-full gap-4 items-center">
|
||||
<nav
|
||||
aria-label={$t('aria.pagination')}
|
||||
class="flex flex-row w-full gap-4 items-center justify-center"
|
||||
>
|
||||
{#if $$slots.default}
|
||||
<span class="text-sm text-slate-600 dark:text-zinc-400 font-medium">
|
||||
<slot />
|
||||
</span>
|
||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||
{/if}
|
||||
{#if cursor?.back}
|
||||
<Button
|
||||
on:click={() => {
|
||||
if (cursor?.back) dispatcher('cursor', cursor.back)
|
||||
else dispatcher('change', --page)
|
||||
}}
|
||||
disabled={page <= 1}
|
||||
class={$$slots.default ? '' : 'flex-1'}
|
||||
>
|
||||
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
||||
{$t('common.back')}
|
||||
</Button>
|
||||
<Button
|
||||
color="ghost"
|
||||
on:click={() => {
|
||||
if (cursor?.back) dispatcher('cursor', cursor?.back)
|
||||
else dispatcher('change', --page)
|
||||
}}
|
||||
title={$t('common.back')}
|
||||
size="square-md"
|
||||
rounding="pill"
|
||||
class="text-inherit dark:text-inherit"
|
||||
disabled={(!cursor?.back && cursor?.next) || page <= 1}
|
||||
>
|
||||
<Icon src={ChevronLeft} size="24" mini slot="suffix" />
|
||||
</Button>
|
||||
|
||||
{#if page}
|
||||
<div style="display: grid;">
|
||||
{#key page}
|
||||
<div
|
||||
in:fly={{ y: 8, easing: backOut, duration: 400, delay: 100 }}
|
||||
out:fly={{ y: 8, easing: backOut, duration: 400 }}
|
||||
class="text-md font-medium"
|
||||
style="grid-column: 1; grid-row: 1;"
|
||||
>
|
||||
{page}
|
||||
</div>
|
||||
{/key}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<Button
|
||||
color="ghost"
|
||||
on:click={() => {
|
||||
if (cursor?.next) dispatcher('cursor', cursor?.next)
|
||||
else dispatcher('change', ++page)
|
||||
}}
|
||||
class={$$slots.default ? '' : 'flex-1'}
|
||||
title={$t('common.next')}
|
||||
size="square-md"
|
||||
rounding="pill"
|
||||
class="text-inherit dark:text-inherit"
|
||||
disabled={!hasMore}
|
||||
>
|
||||
{$t('common.next')}
|
||||
<Icon src={ChevronRight} size="18" mini slot="suffix" />
|
||||
<Icon src={ChevronRight} size="24" mini slot="suffix" />
|
||||
</Button>
|
||||
</div>
|
||||
</nav>
|
||||
@@ -38,21 +38,27 @@
|
||||
content: boolean
|
||||
): {
|
||||
top: number
|
||||
bottom: number
|
||||
class: string
|
||||
} => {
|
||||
if (panel) {
|
||||
if (top) {
|
||||
if (content) return { top: 80, class: '!pt-20' }
|
||||
else return { top: 64, class: 'top-16 !max-h-[calc(100vh-4rem)]' }
|
||||
} else return { top: 0, class: '!pb-20' }
|
||||
if (content) return { top: 80, class: '!pt-20', bottom: 0 }
|
||||
else
|
||||
return {
|
||||
top: 64,
|
||||
class: 'top-16 !max-h-[calc(100vh-4rem)]',
|
||||
bottom: 0,
|
||||
}
|
||||
} else return { top: 0, class: '!pb-20', bottom: 80 }
|
||||
} else {
|
||||
if (!content) return { top: 0, class: '' }
|
||||
if (!content) return { top: 0, class: '', bottom: 0 }
|
||||
|
||||
if (top) return { top: 96, class: '!pt-24' }
|
||||
else return { top: 0, class: '!pb-24' }
|
||||
if (top) return { top: 96, class: '!pt-24', bottom: 0 }
|
||||
else return { top: 0, class: '!pb-24', bottom: 96 }
|
||||
}
|
||||
|
||||
return { top: 0, class: ' failed-to-calculate' }
|
||||
return { top: 0, class: ' failed-to-calculate', bottom: 0 }
|
||||
}
|
||||
|
||||
export let screenWidth = writable(1000)
|
||||
|
||||
Reference in new issue
Block a user