-
Notifications
You must be signed in to change notification settings - Fork 314
/
Copy pathpagination.tsx
73 lines (68 loc) · 2.03 KB
/
pagination.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import { A } from "~/ui/i18n-anchor";
import { Show, Suspense, createMemo } from "solid-js";
import { coreEntries } from "solid:collection";
import { useI18n } from "~/i18n/i18n-context";
/**
* temporary until we have proper types inside collections
*/
type ReferenceCollection = (typeof coreEntries)["reference"];
type LearnCollection = (typeof coreEntries)["learn"];
type Pagination = {
collection: ReferenceCollection | LearnCollection;
currentIndex: number;
};
export function Pagination(props: Pagination) {
const previous = createMemo(() => {
if (props.currentIndex > 0) {
return props.collection[props.currentIndex - 1];
} else {
return null;
}
});
const next = createMemo(() => {
if (props.currentIndex < props.collection.length) {
return props.collection[props.currentIndex + 1];
} else {
return null;
}
});
const i18n = useI18n();
return (
<Suspense>
<Show when={i18n.t}>
<nav class="flex justify-between mt-10 pt-6 border-t border-slate-200 dark:border-slate-800">
<Show when={previous()}>
{(entry) => (
<div>
<span class="font-display text-sm font-medium text-slate-900 dark:text-white">
{i18n.t("pagination.previous")}
</span>
<A
class="flex items-center gap-x-1 text-base font-medium text-slate-500 hover:text-blue-600 dark:text-slate-300 dark:hover:text-blue-300 flex-row-reverse no-underline"
href={entry().path}
>
← {entry().title}
</A>
</div>
)}
</Show>
<Show when={next()}>
{(entry) => (
<div>
<span class="font-display text-sm font-medium text-slate-900 dark:text-white">
{i18n.t("pagination.next")}
</span>
<A
class="flex items-center gap-x-1 text-base font-medium text-slate-500 hover:text-blue-700 dark:text-slate-300 dark:hover:text-blue-300 flex-row-reverse no-underline"
href={entry().path}
>
{entry().title} →
</A>
</div>
)}
</Show>
</nav>
</Show>
</Suspense>
);
}