design: redesign pagination
This commit is contained in:
1 parent
ed9796e4af
commit
73f5cd5e77
4 files changed
+66
-20
No files matched your search
@@ -9,42 +9,68 @@
|
|||||||
ChevronRight,
|
ChevronRight,
|
||||||
Icon,
|
Icon,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
|
import { backOut } from 'svelte/easing'
|
||||||
|
import { fly } from 'svelte/transition'
|
||||||
|
|
||||||
export let page: number = 0
|
export let page: number = 0
|
||||||
export let cursor: { next?: string; back?: string } | undefined = undefined
|
export let cursor: { next?: string; back?: string } | undefined = undefined
|
||||||
|
export let hasMore: boolean = true
|
||||||
|
|
||||||
const dispatcher = createEventDispatcher<{ change: number; cursor: string }>()
|
const dispatcher = createEventDispatcher<{ change: number; cursor: string }>()
|
||||||
</script>
|
</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}
|
{#if $$slots.default}
|
||||||
<span class="text-sm text-slate-600 dark:text-zinc-400 font-medium">
|
<span class="text-sm text-slate-600 dark:text-zinc-400 font-medium">
|
||||||
<slot />
|
<slot />
|
||||||
</span>
|
</span>
|
||||||
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
<hr class="border-slate-200 dark:border-zinc-800 flex-1" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if cursor?.back}
|
|
||||||
<Button
|
<Button
|
||||||
|
color="ghost"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (cursor?.back) dispatcher('cursor', cursor.back)
|
if (cursor?.back) dispatcher('cursor', cursor?.back)
|
||||||
else dispatcher('change', --page)
|
else dispatcher('change', --page)
|
||||||
}}
|
}}
|
||||||
disabled={page <= 1}
|
title={$t('common.back')}
|
||||||
class={$$slots.default ? '' : 'flex-1'}
|
size="square-md"
|
||||||
|
rounding="pill"
|
||||||
|
class="text-inherit dark:text-inherit"
|
||||||
|
disabled={(!cursor?.back && cursor?.next) || page <= 1}
|
||||||
>
|
>
|
||||||
<Icon src={ChevronLeft} size="18" mini slot="prefix" />
|
<Icon src={ChevronLeft} size="24" mini slot="suffix" />
|
||||||
{$t('common.back')}
|
|
||||||
</Button>
|
</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}
|
{/if}
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
color="ghost"
|
||||||
on:click={() => {
|
on:click={() => {
|
||||||
if (cursor?.next) dispatcher('cursor', cursor?.next)
|
if (cursor?.next) dispatcher('cursor', cursor?.next)
|
||||||
else dispatcher('change', ++page)
|
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="24" mini slot="suffix" />
|
||||||
<Icon src={ChevronRight} size="18" mini slot="suffix" />
|
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</nav>
|
||||||
@@ -38,21 +38,27 @@
|
|||||||
content: boolean
|
content: boolean
|
||||||
): {
|
): {
|
||||||
top: number
|
top: number
|
||||||
|
bottom: number
|
||||||
class: string
|
class: string
|
||||||
} => {
|
} => {
|
||||||
if (panel) {
|
if (panel) {
|
||||||
if (top) {
|
if (top) {
|
||||||
if (content) return { top: 80, class: '!pt-20' }
|
if (content) return { top: 80, class: '!pt-20', bottom: 0 }
|
||||||
else return { top: 64, class: 'top-16 !max-h-[calc(100vh-4rem)]' }
|
else
|
||||||
} else return { top: 0, class: '!pb-20' }
|
return {
|
||||||
|
top: 64,
|
||||||
|
class: 'top-16 !max-h-[calc(100vh-4rem)]',
|
||||||
|
bottom: 0,
|
||||||
|
}
|
||||||
|
} else return { top: 0, class: '!pb-20', bottom: 80 }
|
||||||
} else {
|
} else {
|
||||||
if (!content) return { top: 0, class: '' }
|
if (!content) return { top: 0, class: '', bottom: 0 }
|
||||||
|
|
||||||
if (top) return { top: 96, class: '!pt-24' }
|
if (top) return { top: 96, class: '!pt-24', bottom: 0 }
|
||||||
else return { top: 0, class: '!pb-24' }
|
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)
|
export let screenWidth = writable(1000)
|
||||||
|
|||||||
@@ -833,5 +833,11 @@
|
|||||||
"captcha_failed": "Incorrect CAPTCHA answer.",
|
"captcha_failed": "Incorrect CAPTCHA answer.",
|
||||||
"cant_block_local_instance": "You can't block the instance you are actively using.",
|
"cant_block_local_instance": "You can't block the instance you are actively using.",
|
||||||
"invalid_vote_value": "You can't commit voter fraud on Lemmy posts, sorry."
|
"invalid_vote_value": "You can't commit voter fraud on Lemmy posts, sorry."
|
||||||
|
},
|
||||||
|
"aria": {
|
||||||
|
"pagination": {
|
||||||
|
"nav": "Pagination",
|
||||||
|
"current": "Current page"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
<div class="mt-4" />
|
<div class="mt-4" />
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="mt-4 mb-0 sticky z-30 mx-auto max-w-full overflow-hidden"
|
class="mt-4 mb-0 sticky z-30 mx-auto max-w-full"
|
||||||
style="top: max(1.5rem, {$contentPadding.top}px);"
|
style="top: max(1.5rem, {$contentPadding.top}px);"
|
||||||
>
|
>
|
||||||
<Tabs
|
<Tabs
|
||||||
@@ -140,11 +140,19 @@
|
|||||||
<InboxItem {item} />
|
<InboxItem {item} />
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
<div class="ml-auto mt-auto">
|
{/if}
|
||||||
|
{#if !(data.page == 1 && (data?.data?.length ?? 0) == 0)}
|
||||||
|
<div
|
||||||
|
class="sticky z-30 mx-auto max-w-full"
|
||||||
|
style="bottom: max(1.5rem, {$contentPadding.bottom}px);"
|
||||||
|
>
|
||||||
|
<Tabs routes={[]} class="mx-auto">
|
||||||
<Pageination
|
<Pageination
|
||||||
|
hasMore={!(!data.data || (data.data?.length ?? 0) == 0)}
|
||||||
page={data.page}
|
page={data.page}
|
||||||
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
on:change={(p) => searchParam($page.url, 'page', p.detail.toString())}
|
||||||
/>
|
/>
|
||||||
|
</Tabs>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
Reference in new issue
Block a user