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(PQL)),
list(lustre@vdom@vnode:element(PQL))
) -> lustre@vdom@vnode:element(PQL).
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(PQR)),
list(lustre@vdom@vnode:element(PQR))
) -> lustre@vdom@vnode:element(PQR).
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(PQX)),
list(lustre@vdom@vnode:element(PQX))
) -> lustre@vdom@vnode:element(PQX).
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(PRD)),
list(lustre@vdom@vnode:element(PRD))
) -> lustre@vdom@vnode:element(PRD).
prev(Attrs, Children) ->
page_link(Attrs, Children).
-file("src/glaze/oat/pagination.gleam", 73).
-spec next(
list(lustre@vdom@vattr:attribute(PRJ)),
list(lustre@vdom@vnode:element(PRJ))
) -> lustre@vdom@vnode:element(PRJ).
next(Attrs, Children) ->
page_link(Attrs, Children).