Packages

Layout and style that's easy to refactor, all without thinking about CSS.

Current section

Files

Jump to
legos src legos@element.erl
Raw

src/legos@element.erl

-module(legos@element).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/legos/element.gleam").
-export([html/1, html_attribute/1, map/2, map_attribute/2, px/1, shrink/0, fill/0, pct_screen/1, minimum/2, maximum/2, fill_portion/1, pct/1, layout_with/3, layout/2, no_static_style_sheet/0, default_focus/0, focus_style/1, no_hover/0, force_hover/0, text/1, el/2, image/3, below/1, attr_none/0, above/1, on_right/1, on_left/1, in_front/1, behind_content/1, width/1, prose/2, table/3, indexed_table/3, height/1, row/2, column/2, wrapped_row/2, link/3, new_tab_link/3, scale/1, rotate/1, move_up/1, move_down/1, move_right/1, move_left/1, padding/1, padding_xy/2, padding_each/4, center_x/0, center_y/0, align_top/0, align_bottom/0, align_left/0, align_right/0, space_evenly/0, spacing/1, paragraph/2, spacing_xy/2, transition/2, alpha/1, transparent/1, scrollbars/0, scrollbar_y/0, scrollbar_x/0, clip/0, clip_y/0, clip_x/0, pointer/0, cursor/0, classify_device/1, modular/2, mouse_over/1, mouse_down/1, focused/1, hovered/1, vspace/1, hspace/1]).
-export_type([table_column/2, indexed_column/2, internal_table_column/2, cursor/1, device/0, device_class/0, orientation/0, window_size/0, html/1, html_attribute/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.
-type table_column(TDW, TDX) :: {table_column,
legos@internal@model:element(TDX),
legos@internal@model:length(),
fun((TDW) -> legos@internal@model:element(TDX))}.
-type indexed_column(TDY, TDZ) :: {indexed_column,
legos@internal@model:element(TDZ),
legos@internal@model:length(),
fun((integer(), TDY) -> legos@internal@model:element(TDZ))}.
-type internal_table_column(TEA, TEB) :: {internal_indexed_column,
indexed_column(TEA, TEB)} |
{internal_column, table_column(TEA, TEB)}.
-type cursor(TEC) :: {cursor, list(TEC), integer(), integer()}.
-type device() :: {device, device_class(), orientation()}.
-type device_class() :: phone | tablet | desktop | big_desktop.
-type orientation() :: portrait | landscape.
-type window_size() :: {window_size, integer(), integer()}.
-type html(TED) :: any() | {gleam_phantom, TED}.
-type html_attribute(TEE) :: any() | {gleam_phantom, TEE}.
-file("src/legos/element.gleam", 36).
?DOC(" Render a Lustre element with legos\n").
-spec html(
fun((legos@internal@model:layout_context()) -> lustre@vdom@vnode:element(TES))
) -> legos@internal@model:element(TES).
html(A) ->
{unstyled, A}.
-file("src/legos/element.gleam", 41).
?DOC(" Render a Lustre attribute with legos\n").
-spec html_attribute(lustre@vdom@vattr:attribute(TEV)) -> legos@internal@model:attribute(any(), TEV).
html_attribute(A) ->
{attr, A}.
-file("src/legos/element.gleam", 45).
-spec map(legos@internal@model:element(TFA), fun((TFA) -> TFC)) -> legos@internal@model:element(TFC).
map(Element, Transform) ->
legos@internal@model:map(Element, Transform).
-file("src/legos/element.gleam", 49).
-spec map_attribute(
legos@internal@model:attribute(legos@internal@model:aligned(), TFE),
fun((TFE) -> TFG)
) -> legos@internal@model:attribute(legos@internal@model:aligned(), TFG).
map_attribute(Attribute, Transform) ->
legos@internal@model:map_attr(Attribute, Transform).
-file("src/legos/element.gleam", 60).
-spec px(integer()) -> legos@internal@model:length().
px(Pixels) ->
{px, Pixels}.
-file("src/legos/element.gleam", 64).
-spec shrink() -> legos@internal@model:length().
shrink() ->
content.
-file("src/legos/element.gleam", 68).
-spec fill() -> legos@internal@model:length().
fill() ->
{fill, 1}.
-file("src/legos/element.gleam", 73).
?DOC(" Fill a percent of the safe-viewport size\n").
-spec pct_screen(integer()) -> legos@internal@model:length().
pct_screen(Pct) ->
{screen_pct, Pct}.
-file("src/legos/element.gleam", 77).
-spec minimum(legos@internal@model:length(), integer()) -> legos@internal@model:length().
minimum(Length, Min_length) ->
{min, Min_length, Length}.
-file("src/legos/element.gleam", 81).
-spec maximum(legos@internal@model:length(), integer()) -> legos@internal@model:length().
maximum(Length, Max_length) ->
{max, Max_length, Length}.
-file("src/legos/element.gleam", 85).
-spec fill_portion(integer()) -> legos@internal@model:length().
fill_portion(Portion) ->
{fill, Portion}.
-file("src/legos/element.gleam", 89).
-spec pct(integer()) -> legos@internal@model:length().
pct(Portion) ->
{pct, Portion}.
-file("src/legos/element.gleam", 101).
-spec layout_with(
list(legos@internal@model:opt()),
list(legos@internal@model:attribute(legos@internal@model:aligned(), TFO)),
legos@internal@model:element(TFO)
) -> lustre@vdom@vnode:element(TFO).
layout_with(Options, Attributes, Child) ->
legos@internal@model:render_root(
Options,
lists:append(
[[legos@internal@model:html_class(
gleam@string:join(
[<<"ui"/utf8>>, <<"s"/utf8>>, <<"e"/utf8>>],
<<" "/utf8>>
)
)],
legos@internal@model:root_style(),
Attributes]
),
Child
).
-file("src/legos/element.gleam", 94).
-spec layout(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TFI)),
legos@internal@model:element(TFI)
) -> lustre@vdom@vnode:element(TFI).
layout(Attributes, Child) ->
layout_with([], Attributes, Child).
-file("src/legos/element.gleam", 130).
-spec no_static_style_sheet() -> legos@internal@model:opt().
no_static_style_sheet() ->
{render_mode_option, no_static_style_sheet}.
-file("src/legos/element.gleam", 134).
-spec default_focus() -> legos@internal@model:focus_style().
default_focus() ->
{focus_style,
none,
none,
{some, {shadow, {rgba, 0.608, 0.796, 1.0, 1.0}, {0, 0}, 0, 3}}}.
-file("src/legos/element.gleam", 138).
-spec focus_style(legos@internal@model:focus_style()) -> legos@internal@model:opt().
focus_style(Style) ->
{focus_style_option, Style}.
-file("src/legos/element.gleam", 142).
-spec no_hover() -> legos@internal@model:opt().
no_hover() ->
{hover_option, no_hover}.
-file("src/legos/element.gleam", 146).
-spec force_hover() -> legos@internal@model:opt().
force_hover() ->
{hover_option, force_hover}.
-file("src/legos/element.gleam", 153).
-spec text(binary()) -> legos@internal@model:element(any()).
text(Content) ->
{text, Content}.
-file("src/legos/element.gleam", 157).
-spec el(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TFV)),
legos@internal@model:element(TFV)
) -> legos@internal@model:element(TFV).
el(Attributes, Child) ->
legos@internal@model:element(as_el, generic, Attributes, {unkeyed, [Child]}).
-file("src/legos/element.gleam", 584).
?DOC(
" Both a source and a description are required for images.\n"
"\n"
" The description is used for people using screen readers.\n"
"\n"
" Leaving the description blank will cause the image to be ignored by assistive technology. This can make sense for images that are purely decorative and add no additional information.\n"
"\n"
" So, take a moment to describe your image as you would to someone who has a harder time seeing.\n"
).
-spec image(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TIF)),
binary(),
binary()
) -> legos@internal@model:element(TIF).
image(Attributes, Src, Description) ->
Image_attributes = gleam@list:filter(Attributes, fun(A) -> case A of
{width, _} ->
true;
{height, _} ->
true;
_ ->
false
end end),
legos@internal@model:element(
as_el,
generic,
[legos@internal@model:html_class(<<"ic"/utf8>>) | Attributes],
{unkeyed,
[legos@internal@model:element(
as_el,
{node_name, <<"img"/utf8>>},
[{attr, lustre@attribute:src(Src)},
{attr, lustre@attribute:alt(Description)} |
Image_attributes],
{unkeyed, []}
)]}
).
-file("src/legos/element.gleam", 675).
-spec below(legos@internal@model:element(TIT)) -> legos@internal@model:attribute(legos@internal@model:aligned(), TIT).
below(Element) ->
{nearby, below, Element}.
-file("src/legos/element.gleam", 679).
-spec attr_none() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
attr_none() ->
no_attribute.
-file("src/legos/element.gleam", 683).
-spec above(legos@internal@model:element(TIY)) -> legos@internal@model:attribute(legos@internal@model:aligned(), TIY).
above(Element) ->
{nearby, above, Element}.
-file("src/legos/element.gleam", 687).
-spec on_right(legos@internal@model:element(TJB)) -> legos@internal@model:attribute(legos@internal@model:aligned(), TJB).
on_right(Element) ->
{nearby, on_right, Element}.
-file("src/legos/element.gleam", 691).
-spec on_left(legos@internal@model:element(TJE)) -> legos@internal@model:attribute(legos@internal@model:aligned(), TJE).
on_left(Element) ->
{nearby, on_left, Element}.
-file("src/legos/element.gleam", 695).
-spec in_front(legos@internal@model:element(TJH)) -> legos@internal@model:attribute(legos@internal@model:aligned(), TJH).
in_front(Element) ->
{nearby, in_front, Element}.
-file("src/legos/element.gleam", 699).
-spec behind_content(legos@internal@model:element(TJK)) -> legos@internal@model:attribute(legos@internal@model:aligned(), TJK).
behind_content(Element) ->
{nearby, behind, Element}.
-file("src/legos/element.gleam", 704).
-spec width(legos@internal@model:length()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
width(Length) ->
{width, Length}.
-file("src/legos/element.gleam", 348).
-spec prose(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TGY)),
list(legos@internal@model:element(TGY))
) -> legos@internal@model:element(TGY).
prose(Attributes, Children) ->
legos@internal@model:element(
as_text_column,
generic,
lists:append(
[width(
begin
_pipe = fill(),
_pipe@1 = minimum(_pipe, 500),
maximum(_pipe@1, 750)
end
)],
Attributes
),
{unkeyed, Children}
).
-file("src/legos/element.gleam", 445).
-spec table_helper(
list(legos@internal@model:attribute(legos@internal@model:aligned(), THW)),
list(THZ),
list(internal_table_column(THZ, THW))
) -> legos@internal@model:element(THW).
table_helper(Attrs, Data, Columns) ->
{S_x, S_y} = legos@internal@model:get_spacing(Attrs, {0, 0}),
Column_header = fun(Col) -> case Col of
{internal_indexed_column, Col_config} ->
erlang:element(2, Col_config);
{internal_column, Col_config@1} ->
erlang:element(2, Col_config@1)
end end,
Column_width = fun(Col@1) -> case Col@1 of
{internal_indexed_column, Col_config@2} ->
erlang:element(3, Col_config@2);
{internal_column, Col_config@3} ->
erlang:element(3, Col_config@3)
end end,
On_grid = fun(Row_level, Column_level, Elem) ->
legos@internal@model:element(
as_el,
generic,
[{style_class,
legos@internal@flag:grid_position(),
{grid_position, Row_level, Column_level, 1, 1}}],
{unkeyed, [Elem]}
)
end,
Maybe_headers = begin
_pipe = Columns,
_pipe@1 = gleam@list:map(_pipe, Column_header),
(fun(Headers) ->
case gleam@list:all(Headers, fun(A) -> A =:= empty end) of
true ->
none;
false ->
{some,
gleam@list:index_map(
Headers,
fun(Header, Col@2) ->
On_grid(1, Col@2 + 1, Header)
end
)}
end
end)(_pipe@1)
end,
Template = {style_class,
legos@internal@flag:grid_template(),
{grid_template_style,
{px(S_x), px(S_y)},
gleam@list:map(Columns, Column_width),
gleam@list:repeat(content, erlang:length(Data))}},
Add = fun(Cell, Column_config, Cursor) -> case Column_config of
{internal_indexed_column, Col@3} ->
{cursor,
[On_grid(
erlang:element(3, Cursor),
erlang:element(4, Cursor),
(erlang:element(4, Col@3))(
case Maybe_headers =:= none of
true ->
erlang:element(3, Cursor) - 1;
false ->
erlang:element(3, Cursor) - 2
end,
Cell
)
) |
erlang:element(2, Cursor)],
erlang:element(3, Cursor),
erlang:element(4, Cursor) + 1};
{internal_column, Col@4} ->
{cursor,
[On_grid(
erlang:element(3, Cursor),
erlang:element(4, Cursor),
(erlang:element(4, Col@4))(Cell)
) |
erlang:element(2, Cursor)],
erlang:element(3, Cursor),
erlang:element(4, Cursor) + 1}
end end,
Build = fun(Columns@1) ->
fun(Cursor@1, Row_data) ->
New_cursor = gleam@list:fold(
Columns@1,
Cursor@1,
fun(Cursor@2, Column) -> Add(Row_data, Column, Cursor@2) end
),
{cursor,
erlang:element(2, New_cursor),
erlang:element(3, Cursor@1) + 1,
1}
end
end,
Starting_row = case Maybe_headers =:= none of
true ->
1;
false ->
2
end,
Children = gleam@list:fold(
Data,
{cursor, [], Starting_row, 1},
Build(Columns)
),
legos@internal@model:element(
as_grid,
generic,
lists:append([width(fill()), Template], Attrs),
{unkeyed, case Maybe_headers of
none ->
erlang:element(2, Children);
{some, Rendered_headers} ->
lists:append(
Rendered_headers,
lists:reverse(erlang:element(2, Children))
)
end}
).
-file("src/legos/element.gleam", 425).
?DOC(
" Show some tabular data.\n"
"\n"
" Start with a list of records and specify how each column should be rendered.\n"
"\n"
" So, if we have a list of `persons`:\n"
"\n"
" type Person {\n"
" Person(first_name: String, last_name: String)\n"
" }\n"
"\n"
" let persons = [\n"
" Person(\"David\", \"Bowie\"),\n"
" Person(\"Florence\", \"Welch\"),\n"
" ]\n"
"\n"
" We could render it using\n"
"\n"
" table([],\n"
" data: persons,\n"
" columns: [\n"
" Column(\n"
" header: Element.text(\"First Name\"),\n"
" width: fill(),\n"
" view: fn(person) { Element.text(person.first_name) },\n"
" ),\n"
" Column(\n"
" header: Element.text(\"Last Name\"),\n"
" width: fill(),\n"
" view: fn(person) { Element.text(person.last_name) },\n"
" ),\n"
" ]),\n"
"\n"
" **Note:** Sometimes you might not have a list of records directly in your model. In this case it can be really nice to write a function that transforms some part of your model into a list of records before feeding it into `Element.table`.\n"
).
-spec table(
list(legos@internal@model:attribute(legos@internal@model:aligned(), THE)),
list(THH),
list(table_column(THH, THE))
) -> legos@internal@model:element(THE).
table(Attrs, Data, Columns) ->
table_helper(
Attrs,
Data,
gleam@list:map(Columns, fun(Field@0) -> {internal_column, Field@0} end)
).
-file("src/legos/element.gleam", 433).
-spec indexed_table(
list(legos@internal@model:attribute(legos@internal@model:aligned(), THN)),
list(THQ),
list(indexed_column(THQ, THN))
) -> legos@internal@model:element(THN).
indexed_table(Attributes, Data, Columns) ->
table_helper(
Attributes,
Data,
gleam@list:map(
Columns,
fun(Field@0) -> {internal_indexed_column, Field@0} end
)
).
-file("src/legos/element.gleam", 708).
-spec height(legos@internal@model:length()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
height(Length) ->
{height, Length}.
-file("src/legos/element.gleam", 161).
-spec row(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TGA)),
list(legos@internal@model:element(TGA))
) -> legos@internal@model:element(TGA).
row(Attributes, Children) ->
legos@internal@model:element(
as_row,
generic,
lists:append(
[legos@internal@model:html_class(
<<<<(<<"cl"/utf8>>)/binary, " "/utf8>>/binary,
(<<"ccx"/utf8>>)/binary>>
),
width(shrink()),
height(shrink())],
Attributes
),
{unkeyed, Children}
).
-file("src/legos/element.gleam", 182).
-spec column(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TGG)),
list(legos@internal@model:element(TGG))
) -> legos@internal@model:element(TGG).
column(Attributes, Children) ->
legos@internal@model:element(
as_column,
generic,
lists:append(
[legos@internal@model:html_class(
<<<<(<<"ct"/utf8>>)/binary, " "/utf8>>/binary,
(<<"cl"/utf8>>)/binary>>
),
width(shrink()),
height(shrink())],
Attributes
),
{unkeyed, Children}
).
-file("src/legos/element.gleam", 203).
-spec wrapped_row(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TGM)),
list(legos@internal@model:element(TGM))
) -> legos@internal@model:element(TGM).
wrapped_row(Attrs, Children) ->
{Padded, Spaced} = legos@internal@model:extract_spacing_and_padding(Attrs),
case Spaced of
none ->
legos@internal@model:element(
as_row,
generic,
lists:append(
[[legos@internal@model:html_class(
<<<<<<<<(<<"cl"/utf8>>)/binary, " "/utf8>>/binary,
(<<"ccy"/utf8>>)/binary>>/binary,
" "/utf8>>/binary,
(<<"wrp"/utf8>>)/binary>>
),
width(shrink()),
height(shrink())],
Attrs]
),
{unkeyed, Children}
);
{some, {spaced, Space_name, X, Y}} ->
New_padding = case Padded of
{some, {padding, _, T, R, B, L}} ->
case (R >= (erlang:float(X) / 2.0)) andalso (B >= (erlang:float(
Y
)
/ 2.0)) of
true ->
New_top = T - (erlang:float(Y) / 2.0),
New_right = R - (erlang:float(X) / 2.0),
New_bottom = B - (erlang:float(Y) / 2.0),
New_left = L - (erlang:float(X) / 2.0),
{some,
{style_class,
legos@internal@flag:padding(),
{padding_style,
legos@internal@model:padding_name_float(
New_top,
New_right,
New_bottom,
New_left
),
New_top,
New_right,
New_bottom,
New_left}}};
false ->
none
end;
none ->
none
end,
case New_padding of
{some, Pad} ->
legos@internal@model:element(
as_row,
generic,
lists:append(
[[legos@internal@model:html_class(
<<<<<<<<(<<"cl"/utf8>>)/binary,
" "/utf8>>/binary,
(<<"ccy"/utf8>>)/binary>>/binary,
" "/utf8>>/binary,
(<<"wrp"/utf8>>)/binary>>
),
width(shrink()),
height(shrink())],
Attrs,
[Pad]]
),
{unkeyed, Children}
);
none ->
Half_x = +0.0 - (erlang:float(X) / 2.0),
Half_y = +0.0 - (erlang:float(Y) / 2.0),
legos@internal@model:element(
as_el,
generic,
Attrs,
{unkeyed,
[legos@internal@model:element(
as_row,
generic,
lists:append(
[[legos@internal@model:html_class(
<<<<<<<<(<<"cl"/utf8>>)/binary,
" "/utf8>>/binary,
(<<"ccy"/utf8>>)/binary>>/binary,
" "/utf8>>/binary,
(<<"wrp"/utf8>>)/binary>>
),
{attr,
lustre@attribute:style(
<<"margin"/utf8>>,
<<<<<<(gleam_stdlib:float_to_string(
Half_y
))/binary,
"px "/utf8>>/binary,
(gleam_stdlib:float_to_string(
Half_x
))/binary>>/binary,
"px"/utf8>>
)},
{attr,
lustre@attribute:style(
<<"width"/utf8>>,
<<<<"calc(100% + "/utf8,
(erlang:integer_to_binary(
X
))/binary>>/binary,
"px)"/utf8>>
)},
{attr,
lustre@attribute:style(
<<"height"/utf8>>,
<<<<"calc(100% + "/utf8,
(erlang:integer_to_binary(
Y
))/binary>>/binary,
"px)"/utf8>>
)},
{style_class,
legos@internal@flag:spacing(
),
{spacing_style,
Space_name,
X,
Y}}]]
),
{unkeyed, Children}
)]}
)
end
end.
-file("src/legos/element.gleam", 617).
-spec link(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TIJ)),
binary(),
legos@internal@model:element(TIJ)
) -> legos@internal@model:element(TIJ).
link(Attributes, Url, Label) ->
legos@internal@model:element(
as_el,
{node_name, <<"a"/utf8>>},
lists:append(
[{attr, lustre@attribute:href(Url)},
{attr, lustre@attribute:rel(<<"noopener noreferrer"/utf8>>)},
width(shrink()),
height(shrink()),
legos@internal@model:html_class(
<<<<<<<<(<<"ccy"/utf8>>)/binary, " "/utf8>>/binary,
(<<"ccx"/utf8>>)/binary>>/binary,
" "/utf8>>/binary,
(<<"lnk"/utf8>>)/binary>>
)],
Attributes
),
{unkeyed, [Label]}
).
-file("src/legos/element.gleam", 645).
-spec new_tab_link(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TIO)),
binary(),
legos@internal@model:element(TIO)
) -> legos@internal@model:element(TIO).
new_tab_link(Attributes, Url, Label) ->
legos@internal@model:element(
as_el,
{node_name, <<"a"/utf8>>},
lists:append(
[{attr, lustre@attribute:href(Url)},
{attr, lustre@attribute:rel(<<"noopener noreferrer"/utf8>>)},
{attr, lustre@attribute:target(<<"_blank"/utf8>>)},
width(shrink()),
height(shrink()),
legos@internal@model:html_class(
<<<<<<<<(<<"ccy"/utf8>>)/binary, " "/utf8>>/binary,
(<<"ccx"/utf8>>)/binary>>/binary,
" "/utf8>>/binary,
(<<"lnk"/utf8>>)/binary>>
)],
Attributes
),
{unkeyed, [Label]}
).
-file("src/legos/element.gleam", 713).
-spec scale(float()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
scale(Factor) ->
{transform_component,
legos@internal@flag:scale(),
{scale, {Factor, Factor, 1.0}}}.
-file("src/legos/element.gleam", 717).
-spec rotate(float()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
rotate(Angle) ->
{transform_component,
legos@internal@flag:rotate(),
{rotate, {+0.0, +0.0, 1.0}, Angle}}.
-file("src/legos/element.gleam", 721).
-spec move_up(float()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
move_up(Distance) ->
{transform_component,
legos@internal@flag:move_y(),
{move_y, +0.0 - Distance}}.
-file("src/legos/element.gleam", 725).
-spec move_down(float()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
move_down(Distance) ->
{transform_component, legos@internal@flag:move_y(), {move_y, Distance}}.
-file("src/legos/element.gleam", 729).
-spec move_right(float()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
move_right(Distance) ->
{transform_component, legos@internal@flag:move_x(), {move_x, Distance}}.
-file("src/legos/element.gleam", 733).
-spec move_left(float()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
move_left(Distance) ->
{transform_component,
legos@internal@flag:move_x(),
{move_x, +0.0 - Distance}}.
-file("src/legos/element.gleam", 738).
-spec padding(integer()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
padding(Pixels) ->
P = erlang:float(Pixels),
{style_class,
legos@internal@flag:padding(),
{padding_style,
<<"p-"/utf8, (erlang:integer_to_binary(Pixels))/binary>>,
P,
P,
P,
P}}.
-file("src/legos/element.gleam", 746).
-spec padding_xy(integer(), integer()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
padding_xy(X, Y) ->
case X =:= Y of
true ->
padding(X);
false ->
X_float = erlang:float(X),
Y_float = erlang:float(Y),
{style_class,
legos@internal@flag:padding(),
{padding_style,
<<<<<<"p-"/utf8, (erlang:integer_to_binary(X))/binary>>/binary,
"-"/utf8>>/binary,
(erlang:integer_to_binary(Y))/binary>>,
Y_float,
X_float,
Y_float,
X_float}}
end.
-file("src/legos/element.gleam", 779).
?DOC(
" If you find yourself defining unique paddings all the time, you might consider defining\n"
"\n"
" edges =\n"
" (\n"
" top: 0,\n"
" right: 0,\n"
" bottom: 0,\n"
" left: 0,\n"
" )\n"
"\n"
" And then just do\n"
"\n"
" paddingEach(edges |> { .._, right: 5 })\n"
).
-spec padding_each(integer(), integer(), integer(), integer()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
padding_each(Top, Right, Bottom, Left) ->
case ((Top =:= Right) andalso (Top =:= Bottom)) andalso (Top =:= Left) of
true ->
Top_float = erlang:float(Top),
{style_class,
legos@internal@flag:padding(),
{padding_style,
<<"p-"/utf8, (erlang:integer_to_binary(Top))/binary>>,
Top_float,
Top_float,
Top_float,
Top_float}};
false ->
{style_class,
legos@internal@flag:padding(),
{padding_style,
legos@internal@model:padding_name(Top, Right, Bottom, Left),
erlang:float(Top),
erlang:float(Right),
erlang:float(Bottom),
erlang:float(Left)}}
end.
-file("src/legos/element.gleam", 816).
-spec center_x() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
center_x() ->
{align_x, center_x}.
-file("src/legos/element.gleam", 820).
-spec center_y() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
center_y() ->
{align_y, center_y}.
-file("src/legos/element.gleam", 824).
-spec align_top() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
align_top() ->
{align_y, top}.
-file("src/legos/element.gleam", 828).
-spec align_bottom() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
align_bottom() ->
{align_y, bottom}.
-file("src/legos/element.gleam", 832).
-spec align_left() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
align_left() ->
{align_x, left}.
-file("src/legos/element.gleam", 836).
-spec align_right() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
align_right() ->
{align_x, right}.
-file("src/legos/element.gleam", 840).
-spec space_evenly() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
space_evenly() ->
{class, legos@internal@flag:spacing(), <<"sev"/utf8>>}.
-file("src/legos/element.gleam", 844).
-spec spacing(integer()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
spacing(Pixels) ->
{style_class,
legos@internal@flag:spacing(),
{spacing_style,
legos@internal@model:spacing_name(Pixels, Pixels),
Pixels,
Pixels}}.
-file("src/legos/element.gleam", 333).
-spec paragraph(
list(legos@internal@model:attribute(legos@internal@model:aligned(), TGS)),
list(legos@internal@model:element(TGS))
) -> legos@internal@model:element(TGS).
paragraph(Attributes, Children) ->
legos@internal@model:element(
as_paragraph,
generic,
lists:append(
[{describe, paragraph}, width(fill()), spacing(5)],
Attributes
),
{unkeyed, Children}
).
-file("src/legos/element.gleam", 851).
-spec spacing_xy(integer(), integer()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
spacing_xy(X, Y) ->
{style_class,
legos@internal@flag:spacing(),
{spacing_style, legos@internal@model:spacing_name(X, Y), X, Y}}.
-file("src/legos/element.gleam", 858).
-spec transition(list(binary()), integer()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
transition(Properties, Duration_ms) ->
{style_class,
legos@internal@flag:transition(),
{single,
<<<<<<"transition-"/utf8,
(gleam@string:join(Properties, <<"-"/utf8>>))/binary>>/binary,
"-"/utf8>>/binary,
(erlang:integer_to_binary(Duration_ms))/binary>>,
<<"transition"/utf8>>,
<<<<<<(gleam@string:join(Properties, <<", "/utf8>>))/binary,
" "/utf8>>/binary,
(erlang:integer_to_binary(Duration_ms))/binary>>/binary,
"ms"/utf8>>}}.
-file("src/legos/element.gleam", 880).
-spec alpha(float()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
alpha(O) ->
Transparency = begin
_pipe = O,
_pipe@1 = gleam@float:max(_pipe, +0.0),
_pipe@2 = gleam@float:min(_pipe@1, 1.0),
(fun(X) -> 1.0 - X end)(_pipe@2)
end,
{style_class,
legos@internal@flag:transparency(),
{transparency,
<<"transparency-"/utf8,
(legos@internal@model:float_class(O))/binary>>,
Transparency}}.
-file("src/legos/element.gleam", 873).
-spec transparent(boolean()) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
transparent(Is_transparent) ->
case Is_transparent of
true ->
alpha(+0.0);
false ->
alpha(1.0)
end.
-file("src/legos/element.gleam", 894).
-spec scrollbars() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
scrollbars() ->
{class, legos@internal@flag:overflow(), <<"sb"/utf8>>}.
-file("src/legos/element.gleam", 898).
-spec scrollbar_y() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
scrollbar_y() ->
{class, legos@internal@flag:overflow(), <<"sby"/utf8>>}.
-file("src/legos/element.gleam", 902).
-spec scrollbar_x() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
scrollbar_x() ->
{class, legos@internal@flag:overflow(), <<"sbx"/utf8>>}.
-file("src/legos/element.gleam", 906).
-spec clip() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
clip() ->
{class, legos@internal@flag:overflow(), <<"cp"/utf8>>}.
-file("src/legos/element.gleam", 910).
-spec clip_y() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
clip_y() ->
{class, legos@internal@flag:overflow(), <<"cpy"/utf8>>}.
-file("src/legos/element.gleam", 914).
-spec clip_x() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
clip_x() ->
{class, legos@internal@flag:overflow(), <<"cpx"/utf8>>}.
-file("src/legos/element.gleam", 919).
-spec pointer() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
pointer() ->
{class, legos@internal@flag:cursor(), <<"cptr"/utf8>>}.
-file("src/legos/element.gleam", 923).
-spec cursor() -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
cursor() ->
{class, legos@internal@flag:cursor(), <<"ctxt"/utf8>>}.
-file("src/legos/element.gleam", 944).
-spec classify_device(window_size()) -> device().
classify_device(Window) ->
Long_side = gleam@int:max(
erlang:element(2, Window),
erlang:element(3, Window)
),
Short_side = gleam@int:min(
erlang:element(2, Window),
erlang:element(3, Window)
),
Class = case true of
_ when Short_side < 600 ->
phone;
_ when Long_side =< 1200 ->
tablet;
_ when (Long_side > 1200) andalso (Long_side =< 1920) ->
desktop;
_ ->
big_desktop
end,
Orientation = case erlang:element(2, Window) > erlang:element(3, Window) of
true ->
landscape;
false ->
portrait
end,
{device, Class, Orientation}.
-file("src/legos/element.gleam", 968).
-spec modular(float(), float()) -> fun((integer()) -> float()).
modular(Ratio, Base) ->
fun(Step) -> case gleam@float:power(Ratio, erlang:float(Step)) of
{ok, A} ->
Base * A;
{error, _} ->
1.0
end end.
-file("src/legos/element.gleam", 978).
-spec mouse_over(list(legos@internal@model:attribute(any(), any()))) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
mouse_over(Decs) ->
{style_class,
legos@internal@flag:hover(),
{pseudo_selector, hover, legos@internal@model:unwrap_decorations(Decs)}}.
-file("src/legos/element.gleam", 985).
-spec mouse_down(list(legos@internal@model:attribute(any(), any()))) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
mouse_down(Decs) ->
{style_class,
legos@internal@flag:active(),
{pseudo_selector, active, legos@internal@model:unwrap_decorations(Decs)}}.
-file("src/legos/element.gleam", 992).
-spec focused(list(legos@internal@model:attribute(any(), any()))) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
focused(Decs) ->
{style_class,
legos@internal@flag:focus(),
{pseudo_selector, focus, legos@internal@model:unwrap_decorations(Decs)}}.
-file("src/legos/element.gleam", 999).
-spec hovered(list(legos@internal@model:attribute(any(), any()))) -> legos@internal@model:attribute(legos@internal@model:aligned(), any()).
hovered(Decs) ->
{style_class,
legos@internal@flag:hover(),
{pseudo_selector, hover, legos@internal@model:unwrap_decorations(Decs)}}.
-file("src/legos/element.gleam", 1008).
-spec vspace(integer()) -> legos@internal@model:element(any()).
vspace(Height_) ->
el([width(fill()), height(px(Height_))], empty).
-file("src/legos/element.gleam", 1012).
-spec hspace(integer()) -> legos@internal@model:element(any()).
hspace(Width_) ->
el([height(fill()), width(px(Width_))], empty).