Current section
Files
Jump to
Current section
Files
src/glaze_oat@breadcrumb.erl
-module(glaze_oat@breadcrumb).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glaze_oat/breadcrumb.gleam").
-export([breadcrumb/2, separator/2, slash/1, chevron/1, current/2, link/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/breadcrumb/>\n"
"\n"
" The [`breadcrumb`](#breadcrumb) helpers render hierarchical navigation for\n"
" showing where a user is in the app and how to move back up.\n"
"\n"
" ## Anatomy\n"
"\n"
" A breadcrumb is a nav wrapper with list items for each path segment.\n"
" Most apps render linked ancestors followed by a non-linked current page\n"
" item. Separators are presentational and hidden from assistive tech.\n"
"\n"
" ## Recipes\n"
"\n"
" ### Basic breadcrumb\n"
"\n"
" ```gleam\n"
" import glaze_oat/breadcrumb\n"
" import lustre/attribute\n"
" import lustre/element/html\n"
"\n"
" fn nav() {\n"
" breadcrumb.breadcrumb([], [\n"
" breadcrumb.link([attribute.href(\"/\")], [html.text(\"Home\")]),\n"
" breadcrumb.chevron([]),\n"
" breadcrumb.link([attribute.href(\"/docs\")], [html.text(\"Docs\")]),\n"
" breadcrumb.chevron([]),\n"
" breadcrumb.current([], [html.text(\"Breadcrumb\")]),\n"
" ])\n"
" }\n"
" ```\n"
"\n"
" ### Slash separators\n"
"\n"
" ```gleam\n"
" import glaze_oat/breadcrumb\n"
" import lustre/attribute\n"
" import lustre/element/html\n"
"\n"
" fn nav() {\n"
" breadcrumb.breadcrumb([], [\n"
" breadcrumb.link([attribute.href(\"/\")], [html.text(\"Home\")]),\n"
" breadcrumb.slash([]),\n"
" breadcrumb.link([attribute.href(\"/settings\")], [html.text(\"Settings\")]),\n"
" breadcrumb.slash([]),\n"
" breadcrumb.current([], [html.text(\"Profile\")]),\n"
" ])\n"
" }\n"
" ```\n"
"\n"
).
-file("src/glaze_oat/breadcrumb.gleam", 62).
?DOC(
" Render a breadcrumb navigation container.\n"
"\n"
" Produces semantic markup:\n"
"\n"
" - `<nav aria-label=\"breadcrumb\">`\n"
" - inner ordered list `<ol>` containing breadcrumb items\n"
).
-spec breadcrumb(
list(lustre@vdom@vattr:attribute(PSJ)),
list(lustre@vdom@vnode:element(PSJ))
) -> lustre@vdom@vnode:element(PSJ).
breadcrumb(Attrs, Children) ->
lustre@element@html:nav(
[lustre@attribute:aria_label(<<"breadcrumb"/utf8>>)],
[lustre@element@html:ol(
[lustre@attribute:class(<<"unstyled hstack"/utf8>>),
lustre@attribute:style(
<<"font-size"/utf8>>,
<<"var(--text-7)"/utf8>>
) |
Attrs],
Children
)]
).
-file("src/glaze_oat/breadcrumb.gleam", 83).
?DOC(
" Render a presentational breadcrumb separator element.\n"
"\n"
" Use this when you want a custom separator glyph or icon.\n"
" For accessibility, separators are hidden from assistive tech.\n"
).
-spec separator(
list(lustre@vdom@vattr:attribute(PSP)),
lustre@vdom@vnode:element(PSP)
) -> lustre@vdom@vnode:element(PSP).
separator(Attributes, Content) ->
lustre@element@html:li(
[lustre@attribute:role(<<"presentation"/utf8>>),
lustre@attribute:attribute(<<"aria-hidden"/utf8>>, <<"true"/utf8>>) |
Attributes],
[Content]
).
-file("src/glaze_oat/breadcrumb.gleam", 97).
-spec slash(list(lustre@vdom@vattr:attribute(PSU))) -> lustre@vdom@vnode:element(PSU).
slash(Attributes) ->
separator(Attributes, lustre@element@html:text(<<"/"/utf8>>)).
-file("src/glaze_oat/breadcrumb.gleam", 101).
-spec chevron(list(lustre@vdom@vattr:attribute(PSY))) -> lustre@vdom@vnode:element(PSY).
chevron(Attributes) ->
separator(Attributes, lustre@element@html:text(<<">"/utf8>>)).
-file("src/glaze_oat/breadcrumb.gleam", 115).
?DOC(
" Render the current page item in the breadcrumb.\n"
"\n"
" This is marked as the current location with:\n"
"\n"
" - `role=\"link\"`\n"
" - `aria-disabled=\"true\"`\n"
" - `aria-current=\"page\"`\n"
"\n"
" Use this for the last breadcrumb segment.\n"
).
-spec current(
list(lustre@vdom@vattr:attribute(PTC)),
list(lustre@vdom@vnode:element(PTC))
) -> lustre@vdom@vnode:element(PTC).
current(Attributes, Children) ->
lustre@element@html:a(
[lustre@attribute:role(<<"link"/utf8>>),
lustre@attribute:attribute(
<<"aria-disabled"/utf8>>,
<<"true"/utf8>>
),
lustre@attribute:attribute(<<"aria-current"/utf8>>, <<"page"/utf8>>) |
Attributes],
Children
).
-file("src/glaze_oat/breadcrumb.gleam", 135).
?DOC(
" Render a linked breadcrumb item.\n"
"\n"
" This wraps an anchor in a list item so it participates correctly in the\n"
" ordered breadcrumb structure.\n"
).
-spec link(
list(lustre@vdom@vattr:attribute(PTI)),
list(lustre@vdom@vnode:element(PTI))
) -> lustre@vdom@vnode:element(PTI).
link(Attrs, Children) ->
lustre@element@html:li(
[],
[lustre@element@html:a(
[lustre@attribute:class(<<"unstyled"/utf8>>) | Attrs],
Children
)]
).