Packages

🎨 Gleam UI lustre library by @gleam-br

Current section

Files

Jump to
gbr_ui src gbr@ui@admin@breadcrumb.erl
Raw

src/gbr@ui@admin@breadcrumb.erl

-module(gbr@ui@admin@breadcrumb).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\gbr\\ui\\admin\\breadcrumb.gleam").
-export([parent/3, new/2, render/1]).
-export_type([parent/0, u_i_breadcrumb/0]).
-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(
"\n"
" 🍞 Gleam UI breadcrumb super element.\n"
"\n"
" ### Roadmap\n"
"\n"
" - [ ] Parent -> List(Parent) -> Parent(name, href, icon)\n"
"\n"
).
-type parent() :: {parent, binary(), binary()}.
-opaque u_i_breadcrumb() :: {u_i_breadcrumb,
gbr@ui@core@el:u_i_el(),
binary(),
gleam@option:option(parent())}.
-file("src\\gbr\\ui\\admin\\breadcrumb.gleam", 50).
?DOC(" Set breadcrumb parent\n").
-spec parent(u_i_breadcrumb(), binary(), binary()) -> u_i_breadcrumb().
parent(In, Href, Name) ->
Parent = {some, {parent, Href, Name}},
{u_i_breadcrumb, erlang:element(2, In), erlang:element(3, In), Parent}.
-file("src\\gbr\\ui\\admin\\breadcrumb.gleam", 100).
-spec format(binary()) -> binary().
format(In) ->
_pipe = In,
_pipe@1 = gleam@string:replace(_pipe, <<"-"/utf8>>, <<" "/utf8>>),
gleam@string:capitalise(_pipe@1).
-file("src\\gbr\\ui\\admin\\breadcrumb.gleam", 40).
?DOC(
" New breadcrumb super element with:\n"
"\n"
" - id (id element)\n"
" - current (curent name)\n"
).
-spec new(binary(), binary()) -> u_i_breadcrumb().
new(Id, Current) ->
El = begin
_pipe = gbr@ui@core@el:new(Id),
gbr@ui@core@el:class(
_pipe,
<<"mb-6 flex flex-wrap items-center justify-between gap-3"/utf8>>
)
end,
{u_i_breadcrumb, El, Current, none}.
-file("src\\gbr\\ui\\admin\\breadcrumb.gleam", 82).
-spec render_parent(binary(), gleam@option:option(parent())) -> lustre@vdom@vnode:element(any()).
render_parent(Current, Parent) ->
gleam@bool:guard(
gleam@option:is_none(Parent),
lustre@element:none(),
fun() ->
{Href@1, Name@1} = case Parent of
{some, {parent, Href, Name}} -> {Href, Name};
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gbr/ui/admin/breadcrumb"/utf8>>,
function => <<"render_parent"/utf8>>,
line => 84,
value => _assert_fail,
start => 1756,
'end' => 1802,
pattern_start => 1767,
pattern_end => 1793})
end,
lustre@element@html:a(
[lustre@attribute:href(Href@1),
lustre@attribute:class(
<<"inline-flex items-center gap-1.5 text-sm text-gray-500 dark:text-gray-400"/utf8>>
)],
[begin
_pipe = format(Name@1),
lustre@element@html:text(_pipe)
end,
case Current of
<<""/utf8>> ->
lustre@element:none();
_ ->
_pipe@1 = gbr@ui@svg:new(16, 17),
_pipe@2 = gbr@ui@svg@icons:greater(_pipe@1),
gbr@ui@svg:render(_pipe@2)
end]
)
end
).
-file("src\\gbr\\ui\\admin\\breadcrumb.gleam", 58).
?DOC(" Render breadcrumb super element to `lustre/element/html.{div}`.\n").
-spec render(u_i_breadcrumb()) -> lustre@vdom@vnode:element(any()).
render(In) ->
{u_i_breadcrumb, El, Current, Parent} = In,
Attrs = gbr@ui@core@el:attrs(El),
lustre@element@html:'div'(
Attrs,
[lustre@element@html:h2(
[lustre@attribute:class(
<<"text-xl font-semibold text-gray-800 dark:text-white/90"/utf8>>
)],
[begin
_pipe = format(Current),
lustre@element@html:text(_pipe)
end]
),
lustre@element@html:nav(
[],
[lustre@element@html:ol(
[lustre@attribute:class(
<<"flex items-center gap-1.5"/utf8>>
)],
[lustre@element@html:li(
[],
[render_parent(Current, Parent)]
),
lustre@element@html:li(
[lustre@attribute:class(
<<"text-sm text-gray-800 dark:text-white/90"/utf8>>
)],
[begin
_pipe@1 = format(Current),
lustre@element@html:text(_pipe@1)
end]
)]
)]
)]
).