Packages

🍩 Lustre Bindings to Oat UI Components

Current section

Files

Jump to
glaze_oat src glaze_oat@pagination.erl
Raw

src/glaze_oat@pagination.erl

-module(glaze_oat@pagination).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glaze_oat/pagination.gleam").
-export([pagination/2, page_link/2, current_page/2, prev/2, next/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(
" Oat documentation: <https://oat.ink/components/pagination/>\n"
"\n"
" Pagination helpers for multi-page lists and tables.\n"
"\n"
" ## Anatomy\n"
"\n"
" A pagination control usually has page links plus previous/next controls, with\n"
" the current page marked using `aria-current=\"page\"`.\n"
"\n"
" ## Recipe\n"
"\n"
" ```gleam\n"
" import glaze_oat/pagination\n"
" import lustre/attribute\n"
" import lustre/element/html\n"
"\n"
" pagination.pagination([], [\n"
" pagination.prev([attribute.href(\"?page=1\")], [html.text(\"Previous\")]),\n"
" pagination.page_link([attribute.href(\"?page=1\")], [html.text(\"1\")]),\n"
" pagination.current_page([attribute.href(\"?page=2\")], [html.text(\"2\")]),\n"
" pagination.page_link([attribute.href(\"?page=3\")], [html.text(\"3\")]),\n"
" pagination.next([attribute.href(\"?page=3\")], [html.text(\"Next\")]),\n"
" ])\n"
" ```\n"
"\n"
" ## References\n"
"\n"
" - MDN `aria-current`:\n"
" <https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current>\n"
).
-file("src/glaze_oat/pagination.gleam", 36).
-spec pagination(
list(lustre@vdom@vattr:attribute(QIO)),
list(lustre@vdom@vnode:element(QIO))
) -> lustre@vdom@vnode:element(QIO).
pagination(Attrs, Children) ->
lustre@element@html:nav(
[lustre@attribute:aria_label(<<"Pagination"/utf8>>) | Attrs],
[glaze_oat@button:group([], Children)]
).
-file("src/glaze_oat/pagination.gleam", 45).
-spec page_link(
list(lustre@vdom@vattr:attribute(QIU)),
list(lustre@vdom@vnode:element(QIU))
) -> lustre@vdom@vnode:element(QIU).
page_link(Attrs, Children) ->
glaze_oat@button:link(
[glaze_oat@button:outline(), glaze_oat@button:small() | Attrs],
Children
).
-file("src/glaze_oat/pagination.gleam", 56).
?DOC(
" Render the active page link.\n"
"\n"
" This marks the link with `aria-current=\"page\"`.\n"
).
-spec current_page(
list(lustre@vdom@vattr:attribute(QJA)),
list(lustre@vdom@vnode:element(QJA))
) -> lustre@vdom@vnode:element(QJA).
current_page(Attrs, Children) ->
glaze_oat@button:link(
[glaze_oat@button:small(),
lustre@attribute:attribute(<<"aria-current"/utf8>>, <<"page"/utf8>>) |
Attrs],
Children
).
-file("src/glaze_oat/pagination.gleam", 66).
-spec prev(
list(lustre@vdom@vattr:attribute(QJG)),
list(lustre@vdom@vnode:element(QJG))
) -> lustre@vdom@vnode:element(QJG).
prev(Attrs, Children) ->
page_link(Attrs, Children).
-file("src/glaze_oat/pagination.gleam", 73).
-spec next(
list(lustre@vdom@vattr:attribute(QJM)),
list(lustre@vdom@vnode:element(QJM))
) -> lustre@vdom@vnode:element(QJM).
next(Attrs, Children) ->
page_link(Attrs, Children).