Packages

🎨 Gleam UI lustre library by @gleam-br

Current section

Files

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

src/gbr@ui@admin@alert.erl

-module(gbr@ui@admin@alert).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\gbr\\ui\\admin\\alert.gleam").
-export([title/2, content/2, open/2, info/1, success/1, warning/1, error/1, at/2, at_link/3, new/2, render/1]).
-export_type([status/0, u_i_alert/0, u_i_alert_render/1]).
-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 admin alert element\n"
"\n"
).
-type status() :: success | warning | error | info.
-opaque u_i_alert() :: {u_i_alert,
gbr@ui@core@el:u_i_el(),
gbr@ui@desc:u_i_desc(),
status(),
boolean()}.
-opaque u_i_alert_render(OOO) :: {u_i_alert_render,
u_i_alert(),
list(lustre@vdom@vnode:element(OOO))}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 77).
?DOC(" Replace alert title\n").
-spec title(u_i_alert(), binary()) -> u_i_alert().
title(In, Title) ->
Info = gbr@ui@desc:title(erlang:element(3, In), Title),
{u_i_alert,
erlang:element(2, In),
Info,
erlang:element(4, In),
erlang:element(5, In)}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 85).
?DOC(" Replace alert content description\n").
-spec content(u_i_alert(), binary()) -> u_i_alert().
content(In, Content) ->
Info = gbr@ui@desc:content(erlang:element(3, In), Content),
{u_i_alert,
erlang:element(2, In),
Info,
erlang:element(4, In),
erlang:element(5, In)}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 93).
?DOC(" Set open alert element.\n").
-spec open(u_i_alert(), boolean()) -> u_i_alert().
open(In, Open) ->
{u_i_alert,
erlang:element(2, In),
erlang:element(3, In),
erlang:element(4, In),
Open}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 99).
?DOC(" Set info behavior to alert\n").
-spec info(u_i_alert()) -> u_i_alert().
info(In) ->
{u_i_alert,
erlang:element(2, In),
erlang:element(3, In),
info,
erlang:element(5, In)}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 105).
?DOC(" Set success behavior to alert\n").
-spec success(u_i_alert()) -> u_i_alert().
success(In) ->
{u_i_alert,
erlang:element(2, In),
erlang:element(3, In),
success,
erlang:element(5, In)}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 111).
?DOC(" Set warning behavior to alert\n").
-spec warning(u_i_alert()) -> u_i_alert().
warning(In) ->
{u_i_alert,
erlang:element(2, In),
erlang:element(3, In),
warning,
erlang:element(5, In)}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 117).
?DOC(" Set error behavior to alert\n").
-spec error(u_i_alert()) -> u_i_alert().
error(In) ->
{u_i_alert,
erlang:element(2, In),
erlang:element(3, In),
error,
erlang:element(5, In)}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 125).
?DOC(
" New alert render element.\n"
"\n"
" - in: Alert info\n"
).
-spec at(u_i_alert(), list(lustre@vdom@vnode:element(OOR))) -> u_i_alert_render(OOR).
at(In, Inner) ->
{u_i_alert_render, In, Inner}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 135).
?DOC(
" New alert render element with footer link\n"
"\n"
" - in: Alert element\n"
" - href: Link href attribute\n"
" - text: Text to show into link\n"
).
-spec at_link(u_i_alert(), binary(), binary()) -> u_i_alert_render(any()).
at_link(In, Href, Text) ->
Inner = begin
_pipe = gbr@ui@link:new(Href),
_pipe@1 = gbr@ui@link:class(
_pipe,
<<"mt-3 inline-block text-sm font-medium text-gray-500 underline dark:text-gray-400"/utf8>>
),
_pipe@2 = gbr@ui@link:at(_pipe@1, [lustre@element@html:text(Text)]),
gbr@ui@link:render(_pipe@2)
end,
at(In, [Inner]).
-file("src\\gbr\\ui\\admin\\alert.gleam", 177).
-spec svg_status(status()) -> fun((gbr@ui@svg@core:svg()) -> gbr@ui@svg@core:svg()).
svg_status(Status) ->
case Status of
info ->
fun gbr@ui@svg@alert:info/1;
success ->
fun gbr@ui@svg@alert:success/1;
warning ->
fun gbr@ui@svg@alert:warning/1;
error ->
fun gbr@ui@svg@alert:error/1
end.
-file("src\\gbr\\ui\\admin\\alert.gleam", 187).
-spec create_el() -> gbr@ui@core@el:u_i_el().
create_el() ->
_pipe = gbr@ui@core@el:new(<<"alert"/utf8>>),
gbr@ui@core@el:class(_pipe, <<"rounded-xl border p-4"/utf8>>).
-file("src\\gbr\\ui\\admin\\alert.gleam", 62).
?DOC(
" New alert super element pass title and description.\n"
"\n"
" - title: Alert title\n"
" - desc: Alert description\n"
).
-spec new(binary(), binary()) -> u_i_alert().
new(Title, Desc) ->
El = create_el(),
Info = begin
_pipe = gbr@ui@desc:new(Title, Desc),
_pipe@1 = gbr@ui@desc:class_content(
_pipe,
<<"text-sm text-gray-500 dark:text-gray-400"/utf8>>
),
gbr@ui@desc:class_title(
_pipe@1,
<<"mb-1 text-sm font-semibold text-gray-800 dark:text-white/90"/utf8>>
)
end,
{u_i_alert, El, Info, info, false}.
-file("src\\gbr\\ui\\admin\\alert.gleam", 192).
-spec classes_el(gbr@ui@core@el:u_i_el(), status()) -> gbr@ui@core@el:u_i_el().
classes_el(El, Status) ->
gbr@ui@core@el:classes(
El,
[{<<"border-blue-light-500 bg-blue-light-50 dark:border-blue-light-500/30 dark:bg-blue-light-500/15"/utf8>>,
Status =:= info},
{<<"border-success-500 bg-success-50 dark:border-success-500/30 dark:bg-success-500/15"/utf8>>,
Status =:= success},
{<<"border-warning-500 bg-warning-50 dark:border-warning-500/30 dark:bg-warning-500/15"/utf8>>,
Status =:= warning},
{<<"border-error-500 bg-error-50 dark:border-error-500/30 dark:bg-error-500/15"/utf8>>,
Status =:= error}]
).
-file("src\\gbr\\ui\\admin\\alert.gleam", 213).
-spec classes_icon(status()) -> lustre@vdom@vattr:attribute(any()).
classes_icon(Status) ->
_pipe = [{<<"text-blue-light-500"/utf8>>, Status =:= info},
{<<"text-success-500"/utf8>>, Status =:= success},
{<<"text-warning-500 dark:text-orange-400"/utf8>>, Status =:= warning},
{<<"text-error-500"/utf8>>, Status =:= error}],
lustre@attribute:classes(_pipe).
-file("src\\gbr\\ui\\admin\\alert.gleam", 151).
?DOC(
" Set attribute el.classes by status\n"
"\n"
" Render super alert element to `lustre/element/html.{div}`.\n"
).
-spec render(u_i_alert_render(OOW)) -> lustre@vdom@vnode:element(OOW).
render(At) ->
{u_i_alert_render, In, Inner} = At,
{u_i_alert, El, Info, Status, Open} = In,
gleam@bool:guard(
not Open,
lustre@element:none(),
fun() ->
Attrs = begin
_pipe = classes_el(El, Status),
gbr@ui@core@el:attrs(_pipe)
end,
lustre@element@html:'div'(
Attrs,
[lustre@element@html:'div'(
[lustre@attribute:class(
<<"flex items-start gap-3"/utf8>>
)],
[lustre@element@html:'div'(
[lustre@attribute:class(<<"-mt-0.5"/utf8>>),
classes_icon(Status)],
[begin
_pipe@1 = gbr@ui@svg:new(24, 24),
_pipe@2 = (svg_status(Status))(_pipe@1),
gbr@ui@svg:render(_pipe@2)
end]
),
begin
_pipe@3 = gbr@ui@desc:at(Info, Inner),
gbr@ui@desc:render(_pipe@3)
end]
)]
)
end
).