Current section
Files
Jump to
Current section
Files
src/gbr@ui@input.erl
-module(gbr@ui@input).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src\\gbr\\ui\\input.gleam").
-export([new/2, text/1, email/1, password/1, class/2, value/2, label/2, note/2, kind/2, at/3, on_click_opt/2, on_click/2, on_change_opt/2, on_change/2, on_paste_opt/2, on_paste/2, on_input_opt/2, on_input/2, on_keypress_opt/2, on_keypress/2, render/1, sr_only/1, checkbox/1, name/2, placeholder/2, required/2, max/2, min/2, size/2]).
-export_type([u_i_input/0, u_i_input_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 input super element.\n"
"\n"
).
-opaque u_i_input() :: {u_i_input,
gbr@ui@core@el:u_i_el(),
binary(),
gleam@option:option(gbr@ui@typo:u_i_typo()),
gleam@option:option(gbr@ui@typo:u_i_typo())}.
-opaque u_i_input_render(PPO) :: {u_i_input_render,
u_i_input(),
list(lustre@vdom@vnode:element(PPO)),
gleam@option:option(PPO),
gleam@option:option(PPO),
gleam@option:option(fun((binary()) -> PPO)),
gleam@option:option(fun((binary()) -> PPO)),
gleam@option:option(fun((binary()) -> PPO))}.
-file("src\\gbr\\ui\\input.gleam", 83).
?DOC(" New input super element.\n").
-spec new(binary(), binary()) -> u_i_input().
new(Id, Kind) ->
El = begin
_pipe = gbr@ui@core@el:new(Id),
gbr@ui@core@el:att(_pipe, [{<<"type_"/utf8>>, Kind}])
end,
{u_i_input, El, <<""/utf8>>, none, none}.
-file("src\\gbr\\ui\\input.gleam", 58).
?DOC(" New input type text super element.\n").
-spec text(binary()) -> u_i_input().
text(Id) ->
new(Id, <<"text"/utf8>>).
-file("src\\gbr\\ui\\input.gleam", 64).
?DOC(" New input type email super element.\n").
-spec email(binary()) -> u_i_input().
email(Id) ->
new(Id, <<"email"/utf8>>).
-file("src\\gbr\\ui\\input.gleam", 70).
?DOC(" New input type password super element.\n").
-spec password(binary()) -> u_i_input().
password(Id) ->
new(Id, <<"password"/utf8>>).
-file("src\\gbr\\ui\\input.gleam", 94).
?DOC(" Set element class\n").
-spec class(u_i_input(), binary()) -> u_i_input().
class(In, Class) ->
El = gbr@ui@core@el:class(erlang:element(2, In), Class),
{u_i_input,
El,
erlang:element(3, In),
erlang:element(4, In),
erlang:element(5, In)}.
-file("src\\gbr\\ui\\input.gleam", 102).
?DOC(" Set input value\n").
-spec value(u_i_input(), binary()) -> u_i_input().
value(In, Value) ->
{u_i_input,
erlang:element(2, In),
Value,
erlang:element(4, In),
erlang:element(5, In)}.
-file("src\\gbr\\ui\\input.gleam", 106).
-spec label(u_i_input(), gbr@ui@typo:u_i_typo()) -> u_i_input().
label(In, Label) ->
{u_i_input,
erlang:element(2, In),
erlang:element(3, In),
{some, Label},
erlang:element(5, In)}.
-file("src\\gbr\\ui\\input.gleam", 110).
-spec note(u_i_input(), gbr@ui@typo:u_i_typo()) -> u_i_input().
note(In, Note) ->
{u_i_input,
erlang:element(2, In),
erlang:element(3, In),
erlang:element(4, In),
{some, Note}}.
-file("src\\gbr\\ui\\input.gleam", 138).
-spec kind(u_i_input(), binary()) -> u_i_input().
kind(In, Kind) ->
El = gbr@ui@core@el:att(erlang:element(2, In), [{<<"type_"/utf8>>, Kind}]),
{u_i_input,
El,
erlang:element(3, In),
erlang:element(4, In),
erlang:element(5, In)}.
-file("src\\gbr\\ui\\input.gleam", 160).
?DOC(" New input render at inner.\n").
-spec at(
u_i_input(),
list(lustre@vdom@vattr:attribute(PPS)),
list(lustre@vdom@vnode:element(PPS))
) -> u_i_input_render(PPS).
at(In, Attrs, Inner) ->
Inner@1 = [lustre@element@html:span(Attrs, Inner)],
{u_i_input_render, In, Inner@1, none, none, none, none, none}.
-file("src\\gbr\\ui\\input.gleam", 204).
-spec on_click_opt(u_i_input_render(PQL), gleam@option:option(PQL)) -> u_i_input_render(PQL).
on_click_opt(In, Onclick) ->
{u_i_input_render,
erlang:element(2, In),
erlang:element(3, In),
Onclick,
erlang:element(5, In),
erlang:element(6, In),
erlang:element(7, In),
erlang:element(8, In)}.
-file("src\\gbr\\ui\\input.gleam", 176).
?DOC(" Set input render event onclick.\n").
-spec on_click(u_i_input_render(PPW), PPW) -> u_i_input_render(PPW).
on_click(In, Onclick) ->
on_click_opt(In, {some, Onclick}).
-file("src\\gbr\\ui\\input.gleam", 208).
-spec on_change_opt(
u_i_input_render(PQP),
gleam@option:option(fun((binary()) -> PQP))
) -> u_i_input_render(PQP).
on_change_opt(In, Onchange) ->
{u_i_input_render,
erlang:element(2, In),
erlang:element(3, In),
erlang:element(4, In),
erlang:element(5, In),
erlang:element(6, In),
Onchange,
erlang:element(8, In)}.
-file("src\\gbr\\ui\\input.gleam", 182).
?DOC(" Set input render event onchange.\n").
-spec on_change(u_i_input_render(PPZ), fun((binary()) -> PPZ)) -> u_i_input_render(PPZ).
on_change(In, Onchange) ->
on_change_opt(In, {some, Onchange}).
-file("src\\gbr\\ui\\input.gleam", 215).
-spec on_paste_opt(u_i_input_render(PQT), gleam@option:option(PQT)) -> u_i_input_render(PQT).
on_paste_opt(In, Onpaste) ->
{u_i_input_render,
erlang:element(2, In),
erlang:element(3, In),
erlang:element(4, In),
Onpaste,
erlang:element(6, In),
erlang:element(7, In),
erlang:element(8, In)}.
-file("src\\gbr\\ui\\input.gleam", 188).
?DOC(" Set input render event onclick.\n").
-spec on_paste(u_i_input_render(PQC), PQC) -> u_i_input_render(PQC).
on_paste(In, Onpaste) ->
on_paste_opt(In, {some, Onpaste}).
-file("src\\gbr\\ui\\input.gleam", 219).
-spec on_input_opt(
u_i_input_render(PQX),
gleam@option:option(fun((binary()) -> PQX))
) -> u_i_input_render(PQX).
on_input_opt(In, Oninput) ->
{u_i_input_render,
erlang:element(2, In),
erlang:element(3, In),
erlang:element(4, In),
erlang:element(5, In),
Oninput,
erlang:element(7, In),
erlang:element(8, In)}.
-file("src\\gbr\\ui\\input.gleam", 194).
?DOC(" Set input render event onclick.\n").
-spec on_input(u_i_input_render(PQF), fun((binary()) -> PQF)) -> u_i_input_render(PQF).
on_input(In, Oninput) ->
on_input_opt(In, {some, Oninput}).
-file("src\\gbr\\ui\\input.gleam", 226).
-spec on_keypress_opt(
u_i_input_render(PRB),
gleam@option:option(fun((binary()) -> PRB))
) -> u_i_input_render(PRB).
on_keypress_opt(In, Onkeypress) ->
{u_i_input_render,
erlang:element(2, In),
erlang:element(3, In),
erlang:element(4, In),
erlang:element(5, In),
erlang:element(6, In),
erlang:element(7, In),
Onkeypress}.
-file("src\\gbr\\ui\\input.gleam", 200).
?DOC(" Set input render event onclick.\n").
-spec on_keypress(u_i_input_render(PQI), fun((binary()) -> PQI)) -> u_i_input_render(PQI).
on_keypress(In, Onkeypress) ->
on_keypress_opt(In, {some, Onkeypress}).
-file("src\\gbr\\ui\\input.gleam", 235).
?DOC(" Render input super element to `lustre/element.{type Element}`.\n").
-spec render(u_i_input_render(PRF)) -> lustre@vdom@vnode:element(PRF).
render(At) ->
{u_i_input_render,
In,
Inner,
Onclick,
Onpaste,
Oninput,
Onchange,
Onkeypress} = At,
{u_i_input, El, _, Label, Note} = In,
Onclick@1 = begin
_pipe = gleam@option:map(Onclick, fun lustre@event:on_click/1),
gleam@option:unwrap(_pipe, lustre@attribute:none())
end,
Oninput@1 = begin
_pipe@1 = gleam@option:map(Oninput, fun lustre@event:on_input/1),
gleam@option:unwrap(_pipe@1, lustre@attribute:none())
end,
Onchange@1 = begin
_pipe@2 = gleam@option:map(Onchange, fun lustre@event:on_change/1),
gleam@option:unwrap(_pipe@2, lustre@attribute:none())
end,
Onkeypress@1 = begin
_pipe@3 = gleam@option:map(Onkeypress, fun lustre@event:on_keypress/1),
gleam@option:unwrap(_pipe@3, lustre@attribute:none())
end,
Onpaste@2 = begin
_pipe@4 = gleam@option:map(
Onpaste,
fun(Onpaste@1) ->
lustre@event:on(
<<"onpaste"/utf8>>,
gleam@dynamic@decode:success(Onpaste@1)
)
end
),
gleam@option:unwrap(_pipe@4, lustre@attribute:none())
end,
Id = gbr@ui@core@el:get_id(El),
Label@2 = case Label of
{some, Label@1} ->
lustre@element@html:label(
[lustre@attribute:for(Id)],
[gbr@ui@typo:render(Label@1)]
);
none ->
lustre@element:none()
end,
Attrs = gbr@ui@core@el:attrs(El),
Input = lustre@element@html:input(
[Onclick@1, Oninput@1, Onchange@1, Onpaste@2, Onkeypress@1 | Attrs]
),
Input@1 = case Note of
none ->
lustre@element@html:'div'([], [Input | Inner]);
{some, Note@1} ->
lustre@element@html:'div'(
[lustre@attribute:class(<<"relative"/utf8>>)],
[Input, gbr@ui@typo:render(Note@1) | Inner]
)
end,
lustre@element@html:'div'([], [Label@2, Input@1]).
-file("src\\gbr\\ui\\input.gleam", 287).
-spec attrs(u_i_input(), list({binary(), binary()})) -> u_i_input().
attrs(In, Att) ->
El = gbr@ui@core@el:att(erlang:element(2, In), Att),
{u_i_input,
El,
erlang:element(3, In),
erlang:element(4, In),
erlang:element(5, In)}.
-file("src\\gbr\\ui\\input.gleam", 116).
?DOC(" Append input class sr-only .\n").
-spec sr_only(u_i_input()) -> u_i_input().
sr_only(In) ->
attrs(In, [{<<"class"/utf8>>, <<"sr-only"/utf8>>}]).
-file("src\\gbr\\ui\\input.gleam", 76).
?DOC(" New input type checkbox super element.\n").
-spec checkbox(binary()) -> u_i_input().
checkbox(Id) ->
_pipe = new(Id, <<"checkbox"/utf8>>),
sr_only(_pipe).
-file("src\\gbr\\ui\\input.gleam", 122).
?DOC(" Set input name.\n").
-spec name(u_i_input(), binary()) -> u_i_input().
name(In, Name) ->
attrs(In, [{<<"name"/utf8>>, Name}]).
-file("src\\gbr\\ui\\input.gleam", 128).
?DOC(" Set input placeholder.\n").
-spec placeholder(u_i_input(), binary()) -> u_i_input().
placeholder(In, Value) ->
attrs(In, [{<<"placeholder"/utf8>>, Value}]).
-file("src\\gbr\\ui\\input.gleam", 134).
?DOC(" Set input required.\n").
-spec required(u_i_input(), binary()) -> u_i_input().
required(In, Value) ->
attrs(In, [{<<"required"/utf8>>, Value}]).
-file("src\\gbr\\ui\\input.gleam", 293).
-spec length(u_i_input(), binary(), integer()) -> u_i_input().
length(In, Name, Value) ->
El = gbr@ui@core@el:att(
erlang:element(2, In),
[{Name, erlang:integer_to_binary(Value)}]
),
{u_i_input,
El,
erlang:element(3, In),
erlang:element(4, In),
erlang:element(5, In)}.
-file("src\\gbr\\ui\\input.gleam", 146).
?DOC(" Set input length.\n").
-spec max(u_i_input(), integer()) -> u_i_input().
max(In, Value) ->
length(In, <<"maxlength"/utf8>>, Value).
-file("src\\gbr\\ui\\input.gleam", 150).
-spec min(u_i_input(), integer()) -> u_i_input().
min(In, Value) ->
length(In, <<"minlength"/utf8>>, Value).
-file("src\\gbr\\ui\\input.gleam", 154).
-spec size(u_i_input(), integer()) -> u_i_input().
size(In, Value) ->
length(In, <<"size"/utf8>>, Value).