Pager
Pager component
Install
npx ui8kit add pagerPulls in: box, button, compose, inline, kit-box, kit-button, kit-text, lucide-icon, utils
Preview
Code
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework svelte --dir src --registry-url https://registry.buildy.tw/svelte --strict-cdnnpx ui8kit add pager<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4
5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked
aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for
page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through
props.
-->
<script lang="ts" module>
import type { Snippet } from "svelte";
export type PagerProps = {
page: number;
pages: number;
summary: string;
previousLabel: string;
nextLabel: string;
numbered?: boolean;
pageLabel?: string;
moreLabel?: string;
pageUrl?: string;
firstUrl?: string;
onpage?: (page: number) => void;
onmore?: () => void;
};
</script>
<script lang="ts">
import Box from "../compose/Box.svelte";
import Button from "../compose/Button.svelte";
import Inline from "../compose/Inline.svelte";
import LucideIcon from "../icons/LucideIcon.svelte";
import { pageWindow, tpl, urlOf } from "../utils";
let {
page,
pages,
summary,
previousLabel,
nextLabel,
numbered = false,
pageLabel,
moreLabel,
pageUrl,
firstUrl,
onpage,
onmore,
}: PagerProps = $props();
const numbers = $derived(pageWindow(page, pages));
</script>
<Box
class={"flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground"}
data-slot="pager"
>
<Inline class="flex flex-wrap items-center gap-4">
<Inline>
{summary}
</Inline>
</Inline>
<Inline class="flex flex-wrap items-center gap-2">
{#if (moreLabel && (page < pages))}
<Button variant="outline" size="sm" type="button" onclick={() => onmore?.()}>
{moreLabel}
</Button>
{/if}
<Button
variant="outline"
size="sm"
layout="icon"
aria-label={previousLabel}
disabled={(page <= 1)}
href={urlOf(((page <= 1) ? undefined : (pageUrl ? ((((page - 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page - 1))) : undefined)))}
onclick={() => onpage?.((page - 1))}
>
<LucideIcon name="chevron-left" size={16} />
</Button>
{#if numbered}
{#each numbers as n, i ((n || tpl("gap{0}", i)))}
{#if (n === null)}
<Inline class="w-8 text-center" data-slot="numbers-row">
{"…"}
</Inline>
{:else if (n === page)}
<Inline
class={"flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background"}
aria-current="page"
data-slot="pager-current"
>
{n}
</Inline>
{:else}
<Button
variant="ghost"
size="sm"
layout="icon"
type={(pageUrl ? undefined : "button")}
aria-label={tpl(pageLabel, n)}
href={urlOf((pageUrl ? (((n === 1) && firstUrl) ? firstUrl : tpl(pageUrl, n)) : undefined))}
onclick={() => onpage?.(n)}
>
{n}
</Button>
{/if}
{/each}
{:else}
<Inline class="min-w-12 text-center font-bold text-foreground">
{page}
{" / "}
{pages}
</Inline>
{/if}
<Button
variant="outline"
size="sm"
layout="icon"
aria-label={nextLabel}
disabled={(page >= pages)}
href={urlOf(((page >= pages) ? undefined : (pageUrl ? ((((page + 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page + 1))) : undefined)))}
onclick={() => onpage?.((page + 1))}
>
<LucideIcon name="chevron-right" size={16} />
</Button>
</Inline>
</Box>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework react --dir src --registry-url https://registry.buildy.tw/react --strict-cdnnpx ui8kit add pager// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4
* 5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked
* aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for
* page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through
* props.
*/
import { Fragment, type ReactNode } from "react";
import { Box, Button, Inline } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { pageWindow, tpl, urlOf } from "../utils";
export type PagerProps = {
page: number;
pages: number;
summary: string;
previousLabel: string;
nextLabel: string;
numbered?: boolean;
pageLabel?: string;
moreLabel?: string;
pageUrl?: string;
firstUrl?: string;
onPage?: (page: number) => void;
onMore?: () => void;
};
export function Pager({
page,
pages,
summary,
previousLabel,
nextLabel,
numbered = false,
pageLabel,
moreLabel,
pageUrl,
firstUrl,
onPage,
onMore,
}: PagerProps) {
const numbers = pageWindow(page, pages);
return (
<Box
className={"flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground"}
data-slot="pager"
>
<Inline className="flex flex-wrap items-center gap-4">
<Inline>
{summary}
</Inline>
</Inline>
<Inline className="flex flex-wrap items-center gap-2">
{(moreLabel && (page < pages)) ? (
<Button variant="outline" size="sm" type="button" onClick={() => onMore?.()}>
{moreLabel}
</Button>
) : null}
<Button
variant="outline"
size="sm"
layout="icon"
aria-label={previousLabel}
disabled={(page <= 1)}
href={urlOf(((page <= 1) ? undefined : (pageUrl ? ((((page - 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page - 1))) : undefined)))}
onClick={() => onPage?.((page - 1))}
>
<LucideIcon name="chevron-left" size={16} />
</Button>
{numbered ? (
<>
{(numbers ?? []).map((n, i) => (
<Fragment key={(n || tpl("gap{0}", i))}>
{(n === null) ? (
<Inline className="w-8 text-center" data-slot="numbers-row">
{"…"}
</Inline>
) : (n === page) ? (
<Inline
className={"flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background"}
aria-current="page"
data-slot="pager-current"
>
{n}
</Inline>
) : (
<Button
variant="ghost"
size="sm"
layout="icon"
type={(pageUrl ? undefined : "button")}
aria-label={tpl(pageLabel, n)}
href={urlOf((pageUrl ? (((n === 1) && firstUrl) ? firstUrl : tpl(pageUrl, n)) : undefined))}
onClick={() => onPage?.(n)}
>
{n}
</Button>
)}
</Fragment>
))}
</>
) : (
<Inline className="min-w-12 text-center font-bold text-foreground">
{page}
{" / "}
{pages}
</Inline>
)}
<Button
variant="outline"
size="sm"
layout="icon"
aria-label={nextLabel}
disabled={(page >= pages)}
href={urlOf(((page >= pages) ? undefined : (pageUrl ? ((((page + 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page + 1))) : undefined)))}
onClick={() => onPage?.((page + 1))}
>
<LucideIcon name="chevron-right" size={16} />
</Button>
</Inline>
</Box>
);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework vue --dir src --registry-url https://registry.buildy.tw/vue --strict-cdnnpx ui8kit add pager<!-- Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT. -->
<!--
The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4
5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked
aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for
page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through
props.
-->
<script lang="ts">
export type PagerProps = {
page: number;
pages: number;
summary: string;
previousLabel: string;
nextLabel: string;
numbered?: boolean;
pageLabel?: string;
moreLabel?: string;
pageUrl?: string;
firstUrl?: string;
};
</script>
<script setup lang="ts">
import { computed } from "vue";
import Box from "../compose/Box.vue";
import Button from "../compose/Button.vue";
import Inline from "../compose/Inline.vue";
import LucideIcon from "../icons/LucideIcon.vue";
import { pageWindow, tpl, urlOf } from "../utils";
const {
page,
pages,
summary,
previousLabel,
nextLabel,
numbered = false,
pageLabel,
moreLabel,
pageUrl,
firstUrl,
} = defineProps<PagerProps>();
const emit = defineEmits<{ page: [page: number], more: [] }>();
const numbers = computed(() => pageWindow(page, pages));
</script>
<template>
<Box
:class="'flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground'"
data-slot="pager"
>
<Inline class="flex flex-wrap items-center gap-4">
<Inline>
{{ summary }}
</Inline>
</Inline>
<Inline class="flex flex-wrap items-center gap-2">
<Button
v-if="(moreLabel && (page < pages))"
variant="outline"
size="sm"
type="button"
@click="() => emit('more')"
>
{{ moreLabel }}
</Button>
<Button
variant="outline"
size="sm"
layout="icon"
:aria-label="previousLabel"
:disabled="(page <= 1)"
:href="urlOf(((page <= 1) ? undefined : (pageUrl ? ((((page - 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page - 1))) : undefined)))"
@click="() => emit('page', (page - 1))"
>
<LucideIcon name="chevron-left" :size="16" />
</Button>
<template v-if="numbered">
<template v-for="(n, i) in numbers" :key="(n || tpl('gap{0}', i))">
<Inline v-if="(n === null)" class="w-8 text-center" data-slot="numbers-row">
{{ "…" }}
</Inline>
<Inline v-else-if="(n === page)"
:class="'flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background'"
aria-current="page"
data-slot="pager-current"
>
{{ n }}
</Inline>
<Button v-else
variant="ghost"
size="sm"
layout="icon"
:type="(pageUrl ? undefined : 'button')"
:aria-label="tpl(pageLabel, n)"
:href="urlOf((pageUrl ? (((n === 1) && firstUrl) ? firstUrl : tpl(pageUrl, n)) : undefined))"
@click="() => emit('page', n)"
>
{{ n }}
</Button>
</template>
</template>
<Inline v-else class="min-w-12 text-center font-bold text-foreground">
{{ page }}
{{ " / " }}
{{ pages }}
</Inline>
<Button
variant="outline"
size="sm"
layout="icon"
:aria-label="nextLabel"
:disabled="(page >= pages)"
:href="urlOf(((page >= pages) ? undefined : (pageUrl ? ((((page + 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page + 1))) : undefined)))"
@click="() => emit('page', (page + 1))"
>
<LucideIcon name="chevron-right" :size="16" />
</Button>
</Inline>
</Box>
</template>
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework solid --dir src --registry-url https://registry.buildy.tw/solid --strict-cdnnpx ui8kit add pager// Code generated by packages/kit-compose/src/organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
/**
* The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4
* 5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked
* aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for
* page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through
* props.
*/
import { For, type JSX } from "solid-js";
import { Box, Button, Inline } from "../compose";
import { LucideIcon } from "../icons/LucideIcon";
import { pageWindow, tpl, urlOf } from "../utils";
export type PagerProps = {
page: number;
pages: number;
summary: string;
previousLabel: string;
nextLabel: string;
numbered?: boolean;
pageLabel?: string;
moreLabel?: string;
pageUrl?: string;
firstUrl?: string;
onPage?: (page: number) => void;
onMore?: () => void;
};
export function Pager({
page,
pages,
summary,
previousLabel,
nextLabel,
numbered = false,
pageLabel,
moreLabel,
pageUrl,
firstUrl,
onPage,
onMore,
}: PagerProps) {
const numbers = pageWindow(page, pages);
return (
<Box
class={"flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground"}
data-slot="pager"
>
<Inline class="flex flex-wrap items-center gap-4">
<Inline>
{summary}
</Inline>
</Inline>
<Inline class="flex flex-wrap items-center gap-2">
{(moreLabel && (page < pages)) ? (
<Button variant="outline" size="sm" type="button" onClick={() => onMore?.()}>
{moreLabel}
</Button>
) : null}
<Button
variant="outline"
size="sm"
layout="icon"
aria-label={previousLabel}
disabled={(page <= 1)}
href={urlOf(((page <= 1) ? undefined : (pageUrl ? ((((page - 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page - 1))) : undefined)))}
onClick={() => onPage?.((page - 1))}
>
<LucideIcon name="chevron-left" size={16} />
</Button>
{numbered ? (
<>
<For each={numbers ?? []}>{(n, iOf) => { const i = iOf(); return (
<>
{(n === null) ? (
<Inline class="w-8 text-center" data-slot="numbers-row">
{"…"}
</Inline>
) : (n === page) ? (
<Inline
class={"flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background"}
aria-current="page"
data-slot="pager-current"
>
{n}
</Inline>
) : (
<Button
variant="ghost"
size="sm"
layout="icon"
type={(pageUrl ? undefined : "button")}
aria-label={tpl(pageLabel, n)}
href={urlOf((pageUrl ? (((n === 1) && firstUrl) ? firstUrl : tpl(pageUrl, n)) : undefined))}
onClick={() => onPage?.(n)}
>
{n}
</Button>
)}
</>
); }}</For>
</>
) : (
<Inline class="min-w-12 text-center font-bold text-foreground">
{page}
{" / "}
{pages}
</Inline>
)}
<Button
variant="outline"
size="sm"
layout="icon"
aria-label={nextLabel}
disabled={(page >= pages)}
href={urlOf(((page >= pages) ? undefined : (pageUrl ? ((((page + 1) === 1) && firstUrl) ? firstUrl : tpl(pageUrl, (page + 1))) : undefined)))}
onClick={() => onPage?.((page + 1))}
>
<LucideIcon name="chevron-right" size={16} />
</Button>
</Inline>
</Box>
);
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework templ --dir src --registry-url https://registry.buildy.tw/templ --strict-cdnnpx ui8kit add pager// Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
// Source: packages/compose-gen/specs/parts/pager.json
package blocks
import (
"github.com/ui8kit/codegen/generated/templ/ui/box"
"github.com/ui8kit/codegen/generated/templ/ui/button"
"github.com/ui8kit/codegen/generated/templ/compose"
"github.com/ui8kit/codegen/generated/templ/icons"
"github.com/ui8kit/codegen/generated/templ/ui/text"
uiutils "github.com/ui8kit/codegen/generated/templ/orgutils"
)
// PagerProps are the props of Pager; the values are the JSON shapes of the TypeScript props.
type PagerProps struct {
Page any `json:"page"`
Pages any `json:"pages"`
Summary any `json:"summary"`
PreviousLabel any `json:"previousLabel"`
NextLabel any `json:"nextLabel"`
Numbered any `json:"numbered"`
PageLabel any `json:"pageLabel"`
MoreLabel any `json:"moreLabel"`
PageUrl any `json:"pageUrl"`
FirstUrl any `json:"firstUrl"`
}
// The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4 5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through props.
templ Pager(p PagerProps) {
{{ vPage := p.Page }}
{{ vPages := p.Pages }}
{{ vSummary := p.Summary }}
{{ vPreviousLabel := p.PreviousLabel }}
{{ vNextLabel := p.NextLabel }}
{{ vNumbered := uiutils.Def(p.Numbered, false) }}
{{ vPageLabel := p.PageLabel }}
{{ vMoreLabel := p.MoreLabel }}
{{ vPageUrl := p.PageUrl }}
{{ vFirstUrl := p.FirstUrl }}
{{ vNumbers := any(uiutils.PageWindow(vPage, vPages)) }}
@compose.Box(compose.BoxProps{BoxProps: box.BoxProps{Class: "flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground", Attrs: uiutils.Attrs("data-slot", "pager")}}) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex flex-wrap items-center gap-4"}}) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{}}) {
{ uiutils.Text(vSummary) }
}
}
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex flex-wrap items-center gap-2"}}) {
if uiutils.T(uiutils.And(vMoreLabel, uiutils.Lt(vPage, vPages))) {
@compose.Button(compose.ButtonProps{Variant: "outline", Size: "sm", ButtonProps: button.ButtonProps{Type: "button"}}) {
{ uiutils.Text(vMoreLabel) }
}
}
@compose.Button(compose.ButtonProps{Variant: "outline", Size: "sm", Layout: "icon", ButtonProps: button.ButtonProps{AriaLabel: uiutils.S(vPreviousLabel), Disabled: uiutils.T(uiutils.Le(vPage, float64(1))), Href: uiutils.URL(uiutils.Cond(uiutils.T(uiutils.Le(vPage, float64(1))), nil, uiutils.Cond(uiutils.T(vPageUrl), uiutils.Cond(uiutils.T(uiutils.And(uiutils.Eq(uiutils.Sub(vPage, float64(1)), float64(1)), vFirstUrl)), vFirstUrl, uiutils.Tpl(vPageUrl, uiutils.Sub(vPage, float64(1)))), nil)), false)}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "chevron-left", Size: 16})
}
if uiutils.T(vNumbered) {
for _, vN := range uiutils.L(vNumbers) {
if uiutils.Eq(vN, nil) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "w-8 text-center", Attrs: uiutils.Attrs("data-slot", "numbers-row")}}) {
{ uiutils.Text("…") }
}
} else if uiutils.Eq(vN, vPage) {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background", Attrs: uiutils.Attrs("aria-current", "page", "data-slot", "pager-current")}}) {
{ uiutils.Text(vN) }
}
} else {
@compose.Button(compose.ButtonProps{Variant: "ghost", Size: "sm", Layout: "icon", ButtonProps: button.ButtonProps{Type: uiutils.S(uiutils.Cond(uiutils.T(vPageUrl), nil, "button")), AriaLabel: uiutils.S(uiutils.Tpl(vPageLabel, vN)), Href: uiutils.URL(uiutils.Cond(uiutils.T(vPageUrl), uiutils.Cond(uiutils.T(uiutils.And(uiutils.Eq(vN, float64(1)), vFirstUrl)), vFirstUrl, uiutils.Tpl(vPageUrl, vN)), nil), false)}}) {
{ uiutils.Text(vN) }
}
}
}
} else {
@compose.Inline(compose.InlineProps{TextProps: text.TextProps{Class: "min-w-12 text-center font-bold text-foreground"}}) {
{ uiutils.Text(vPage) }
{ uiutils.Text(" / ") }
{ uiutils.Text(vPages) }
}
}
@compose.Button(compose.ButtonProps{Variant: "outline", Size: "sm", Layout: "icon", ButtonProps: button.ButtonProps{AriaLabel: uiutils.S(vNextLabel), Disabled: uiutils.T(uiutils.Ge(vPage, vPages)), Href: uiutils.URL(uiutils.Cond(uiutils.T(uiutils.Ge(vPage, vPages)), nil, uiutils.Cond(uiutils.T(vPageUrl), uiutils.Cond(uiutils.T(uiutils.And(uiutils.Eq(uiutils.Add(vPage, float64(1)), float64(1)), vFirstUrl)), vFirstUrl, uiutils.Tpl(vPageUrl, uiutils.Add(vPage, float64(1)))), nil)), false)}}) {
@icons.LucideIcon(icons.LucideIconProps{Name: "chevron-right", Size: 16})
}
}
}
}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework twig --dir src --registry-url https://registry.buildy.tw/twig --strict-cdnnpx ui8kit add pager{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/parts/pager.json
The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4 5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through props.
Props (p): page, pages, summary, previousLabel, nextLabel, numbered, pageLabel, moreLabel, pageUrl, firstUrl. -#}
{%- set v_page = (p.page ?? null) -%}
{%- set v_pages = (p.pages ?? null) -%}
{%- set v_summary = (p.summary ?? null) -%}
{%- set v_previousLabel = (p.previousLabel ?? null) -%}
{%- set v_nextLabel = (p.nextLabel ?? null) -%}
{%- set v_numbered = (p.numbered ?? false) -%}
{%- set v_pageLabel = (p.pageLabel ?? null) -%}
{%- set v_moreLabel = (p.moreLabel ?? null) -%}
{%- set v_pageUrl = (p.pageUrl ?? null) -%}
{%- set v_firstUrl = (p.firstUrl ?? null) -%}
{%- set v_numbers = og_page_window(v_page, v_pages) -%}
{%- set c_11 -%}
{%- set c_2 -%}
{%- set c_1 -%}
{{ og_text(v_summary) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'children': c_1}, with_context = false) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'flex flex-wrap items-center gap-4', 'children': c_2}, with_context = false) }}
{%- set c_10 -%}
{%- if og_t(og_and([v_moreLabel, og_lt(v_page, v_pages)])) %}
{%- set c_3 -%}
{{ og_text(v_moreLabel) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'outline', 'size': 'sm', 'type': 'button', 'children': c_3}, with_context = false) }}
{%- endif %}
{%- set c_4 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'chevron-left', 'size': 16}, with_context = false) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'outline', 'size': 'sm', 'layout': 'icon', 'ariaLabel': og_s(v_previousLabel), 'disabled': og_t(og_le(v_page, 1)), 'href': og_url(og_s((og_t(og_le(v_page, 1)) ? null : (og_t(v_pageUrl) ? (og_t(og_and([og_eq(og_sub(v_page, 1), 1), v_firstUrl])) ? v_firstUrl : og_tpl(v_pageUrl, [og_sub(v_page, 1)])) : null)))), 'children': c_4}, with_context = false) }}
{%- if og_t(v_numbered) %}
{%- for v_n in og_l(v_numbers) %}
{%- set v_i = loop.index0 -%}
{%- if og_t(og_eq(v_n, null)) %}
{%- set c_5 -%}
{{ og_text('…') }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'w-8 text-center', 'attrs': og_attrs(['data-slot', 'numbers-row']), 'children': c_5}, with_context = false) }}
{%- elseif og_t(og_eq(v_n, v_page)) %}
{%- set c_6 -%}
{{ og_text(v_n) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background', 'attrs': og_attrs(['aria-current', 'page', 'data-slot', 'pager-current']), 'children': c_6}, with_context = false) }}
{%- else %}
{%- set c_7 -%}
{{ og_text(v_n) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'ghost', 'size': 'sm', 'layout': 'icon', 'type': og_s((og_t(v_pageUrl) ? null : 'button')), 'ariaLabel': og_s(og_tpl(v_pageLabel, [v_n])), 'href': og_url(og_s((og_t(v_pageUrl) ? (og_t(og_and([og_eq(v_n, 1), v_firstUrl])) ? v_firstUrl : og_tpl(v_pageUrl, [v_n])) : null))), 'children': c_7}, with_context = false) }}
{%- endif %}
{%- endfor %}
{%- else %}
{%- set c_8 -%}
{{ og_text(v_page) }}
{{ og_text(' / ') }}
{{ og_text(v_pages) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'min-w-12 text-center font-bold text-foreground', 'children': c_8}, with_context = false) }}
{%- endif %}
{%- set c_9 -%}
{{ include('icons/LucideIcon.html.twig', {'name': 'chevron-right', 'size': 16}, with_context = false) }}
{%- endset -%}
{{ include('compose/Button.html.twig', {'variant': 'outline', 'size': 'sm', 'layout': 'icon', 'ariaLabel': og_s(v_nextLabel), 'disabled': og_t(og_ge(v_page, v_pages)), 'href': og_url(og_s((og_t(og_ge(v_page, v_pages)) ? null : (og_t(v_pageUrl) ? (og_t(og_and([og_eq(og_add(v_page, 1), 1), v_firstUrl])) ? v_firstUrl : og_tpl(v_pageUrl, [og_add(v_page, 1)])) : null)))), 'children': c_9}, with_context = false) }}
{%- endset -%}
{{ include('compose/Inline.html.twig', {'class': 'flex flex-wrap items-center gap-2', 'children': c_10}, with_context = false) }}
{%- endset -%}
{{ include('compose/Box.html.twig', {'class': 'flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground', 'attrs': og_attrs(['data-slot', 'pager']), 'children': c_11}, with_context = false) }}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework latte --dir src --registry-url https://registry.buildy.tw/latte --strict-cdnnpx ui8kit add pager{* Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/parts/pager.json
The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4 5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through props.
Props (p): page, pages, summary, previousLabel, nextLabel, numbered, pageLabel, moreLabel, pageUrl, firstUrl. *}
{var $v_page = ($p['page'] ?? null)}
{var $v_pages = ($p['pages'] ?? null)}
{var $v_summary = ($p['summary'] ?? null)}
{var $v_previousLabel = ($p['previousLabel'] ?? null)}
{var $v_nextLabel = ($p['nextLabel'] ?? null)}
{var $v_numbered = ($p['numbered'] ?? false)}
{var $v_pageLabel = ($p['pageLabel'] ?? null)}
{var $v_moreLabel = ($p['moreLabel'] ?? null)}
{var $v_pageUrl = ($p['pageUrl'] ?? null)}
{var $v_firstUrl = ($p['firstUrl'] ?? null)}
{var $v_numbers = og_page_window($v_page, $v_pages)}
{capture $c_11}
{capture $c_2}
{capture $c_1}
{=og_text($v_summary)}
{/capture}
{=og_include('compose/Inline.latte', ['children' => (string) $c_1])|noescape}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'flex flex-wrap items-center gap-4', 'children' => (string) $c_2])|noescape}
{capture $c_10}
{if og_t(og_and([$v_moreLabel, og_lt($v_page, $v_pages)]))}
{capture $c_3}
{=og_text($v_moreLabel)}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'outline', 'size' => 'sm', 'type' => 'button', 'children' => (string) $c_3])|noescape}
{/if}
{capture $c_4}
{=og_include('icons/LucideIcon.latte', ['name' => 'chevron-left', 'size' => 16])|noescape}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'outline', 'size' => 'sm', 'layout' => 'icon', 'ariaLabel' => og_s($v_previousLabel), 'disabled' => og_t(og_le($v_page, 1)), 'href' => og_url(og_s((og_t(og_le($v_page, 1)) ? null : (og_t($v_pageUrl) ? (og_t(og_and([og_eq(og_sub($v_page, 1), 1), $v_firstUrl])) ? $v_firstUrl : og_tpl($v_pageUrl, [og_sub($v_page, 1)])) : null)))), 'children' => (string) $c_4])|noescape}
{if og_t($v_numbered)}
{foreach og_l($v_numbers) as $v_n}
{var $v_i = $iterator->counter0}
{if og_t(og_eq($v_n, null))}
{capture $c_5}
{=og_text('…')}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'w-8 text-center', 'attrs' => og_attrs(['data-slot', 'numbers-row']), 'children' => (string) $c_5])|noescape}
{elseif og_t(og_eq($v_n, $v_page))}
{capture $c_6}
{=og_text($v_n)}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background', 'attrs' => og_attrs(['aria-current', 'page', 'data-slot', 'pager-current']), 'children' => (string) $c_6])|noescape}
{else}
{capture $c_7}
{=og_text($v_n)}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'ghost', 'size' => 'sm', 'layout' => 'icon', 'type' => og_s((og_t($v_pageUrl) ? null : 'button')), 'ariaLabel' => og_s(og_tpl($v_pageLabel, [$v_n])), 'href' => og_url(og_s((og_t($v_pageUrl) ? (og_t(og_and([og_eq($v_n, 1), $v_firstUrl])) ? $v_firstUrl : og_tpl($v_pageUrl, [$v_n])) : null))), 'children' => (string) $c_7])|noescape}
{/if}
{/foreach}
{else}
{capture $c_8}
{=og_text($v_page)}
{=og_text(' / ')}
{=og_text($v_pages)}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'min-w-12 text-center font-bold text-foreground', 'children' => (string) $c_8])|noescape}
{/if}
{capture $c_9}
{=og_include('icons/LucideIcon.latte', ['name' => 'chevron-right', 'size' => 16])|noescape}
{/capture}
{=og_include('compose/Button.latte', ['variant' => 'outline', 'size' => 'sm', 'layout' => 'icon', 'ariaLabel' => og_s($v_nextLabel), 'disabled' => og_t(og_ge($v_page, $v_pages)), 'href' => og_url(og_s((og_t(og_ge($v_page, $v_pages)) ? null : (og_t($v_pageUrl) ? (og_t(og_and([og_eq(og_add($v_page, 1), 1), $v_firstUrl])) ? $v_firstUrl : og_tpl($v_pageUrl, [og_add($v_page, 1)])) : null)))), 'children' => (string) $c_9])|noescape}
{/capture}
{=og_include('compose/Inline.latte', ['class' => 'flex flex-wrap items-center gap-2', 'children' => (string) $c_10])|noescape}
{/capture}
{=og_include('compose/Box.latte', ['class' => 'flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground', 'attrs' => og_attrs(['data-slot', 'pager']), 'children' => (string) $c_11])|noescape}
Point the CLI at this runtime once, then add the item:
npx ui8kit init --yes --framework jinja2 --dir src --registry-url https://registry.buildy.tw/jinja2 --strict-cdnnpx ui8kit add pager{#- Code generated by packages/kit-compose/src/server-organisms.ts from packages/compose-gen/specs (compose-gen organism emitters on kit-compose). DO NOT EDIT.
Source: packages/compose-gen/specs/parts/pager.json
The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4 5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through props.
Props (p): page, pages, summary, previousLabel, nextLabel, numbered, pageLabel, moreLabel, pageUrl, firstUrl. -#}
{%- set v_page = og_def(p['page'], none) -%}
{%- set v_pages = og_def(p['pages'], none) -%}
{%- set v_summary = og_def(p['summary'], none) -%}
{%- set v_previousLabel = og_def(p['previousLabel'], none) -%}
{%- set v_nextLabel = og_def(p['nextLabel'], none) -%}
{%- set v_numbered = og_def(p['numbered'], false) -%}
{%- set v_pageLabel = og_def(p['pageLabel'], none) -%}
{%- set v_moreLabel = og_def(p['moreLabel'], none) -%}
{%- set v_pageUrl = og_def(p['pageUrl'], none) -%}
{%- set v_firstUrl = og_def(p['firstUrl'], none) -%}
{%- set v_numbers = og_page_window(v_page, v_pages) -%}
{%- set c_11 -%}
{%- set c_2 -%}
{%- set c_1 -%}
{{ og_text(v_summary) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {}, 'children': c_1}) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex flex-wrap items-center gap-4'}, 'children': c_2}) }}
{%- set c_10 -%}
{%- if og_t(og_and([v_moreLabel, og_lt(v_page, v_pages)])) %}
{%- set c_3 -%}
{{ og_text(v_moreLabel) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'outline', 'Size': 'sm', 'Type': 'button'}, 'children': c_3}) }}
{%- endif %}
{%- set c_4 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'chevron-left', 'Size': 16}}) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'outline', 'Size': 'sm', 'Layout': 'icon', 'AriaLabel': og_s(v_previousLabel), 'Disabled': og_t(og_le(v_page, 1)), 'Href': og_url(og_s((none if og_t(og_le(v_page, 1)) else ((v_firstUrl if og_t(og_and([og_eq(og_sub(v_page, 1), 1), v_firstUrl])) else og_tpl(v_pageUrl, [og_sub(v_page, 1)])) if og_t(v_pageUrl) else none))))}, 'children': c_4}) }}
{%- if og_t(v_numbered) %}
{%- for v_n in og_l(v_numbers) %}
{%- set v_i = loop.index0 -%}
{%- if og_t(og_eq(v_n, none)) %}
{%- set c_5 -%}
{{ og_text('…') }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'w-8 text-center', 'Attrs': og_attrs(['data-slot', 'numbers-row'])}, 'children': c_5}) }}
{%- elif og_t(og_eq(v_n, v_page)) %}
{%- set c_6 -%}
{{ og_text(v_n) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex h-8 min-w-8 items-center justify-center rounded bg-foreground px-2 font-bold text-background', 'Attrs': og_attrs(['aria-current', 'page', 'data-slot', 'pager-current'])}, 'children': c_6}) }}
{%- else %}
{%- set c_7 -%}
{{ og_text(v_n) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'ghost', 'Size': 'sm', 'Layout': 'icon', 'Type': og_s((none if og_t(v_pageUrl) else 'button')), 'AriaLabel': og_s(og_tpl(v_pageLabel, [v_n])), 'Href': og_url(og_s(((v_firstUrl if og_t(og_and([og_eq(v_n, 1), v_firstUrl])) else og_tpl(v_pageUrl, [v_n])) if og_t(v_pageUrl) else none)))}, 'children': c_7}) }}
{%- endif %}
{%- endfor %}
{%- else %}
{%- set c_8 -%}
{{ og_text(v_page) }}
{{ og_text(' / ') }}
{{ og_text(v_pages) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'min-w-12 text-center font-bold text-foreground'}, 'children': c_8}) }}
{%- endif %}
{%- set c_9 -%}
{{ og_include('icons/lucide-icon.html.j2', {'p': {'Name': 'chevron-right', 'Size': 16}}) }}
{%- endset -%}
{{ og_include('compose/button.html.j2', {'p': {'Variant': 'outline', 'Size': 'sm', 'Layout': 'icon', 'AriaLabel': og_s(v_nextLabel), 'Disabled': og_t(og_ge(v_page, v_pages)), 'Href': og_url(og_s((none if og_t(og_ge(v_page, v_pages)) else ((v_firstUrl if og_t(og_and([og_eq(og_add(v_page, 1), 1), v_firstUrl])) else og_tpl(v_pageUrl, [og_add(v_page, 1)])) if og_t(v_pageUrl) else none))))}, 'children': c_9}) }}
{%- endset -%}
{{ og_include('compose/inline.html.j2', {'p': {'Class': 'flex flex-wrap items-center gap-2'}, 'children': c_10}) }}
{%- endset -%}
{{ og_include('compose/box.html.j2', {'p': {'Class': 'flex flex-wrap items-center justify-between gap-4 text-xs font-semibold text-muted-foreground', 'Attrs': og_attrs(['data-slot', 'pager'])}, 'children': c_11}) }}
Props
Names and types come from the xgen specs of the source. Standard HTML attributes (id, role, tabIndex, aria-*) pass through to the root element; the class prop is className in React.
The list footer: a summary line and previous / next page buttons. With `numbered` it shows page numbers (1 … 4 5 6 … 21), with `moreLabel` a "Load more" button. The current page is a plain element marked aria-current="page"; the others are buttons, or links with `pageUrl` (the address of page {0}; `firstUrl` for page 1): a disabled previous / next stays a disabled button, without an address. All text comes in through props.
| Prop | Type | Default | Description |
|---|---|---|---|
| page (required) | number | - | current page, from 1 |
| pages (required) | number | - | number of pages |
| summary (required) | string | - | |
| previousLabel (required) | string | - | |
| nextLabel (required) | string | - | |
| numbered | boolean | false | show page numbers between the arrows |
| pageLabel | string | - | template of the accessible name of a page button, {0} is the number |
| moreLabel | string | - | label of the "Load more" button; no button without it |
| pageUrl | string | - | address of page {0} (/blog/page/{0}/, ?paged={0}, #/posts/{0}); with it every page and previous / next is a link |
| firstUrl | string | - | address of page 1 when it is not pageUrl with 1 (the list's own address) |