Current section
Files
Jump to
Current section
Files
src/glaze_oat@button.erl
-module(glaze_oat@button).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glaze_oat/button.gleam").
-export([group/2, instance/3, button/2, link/2, primary/0, secondary/0, danger/0, outline/0, ghost/0, small/0, large/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(
" Oat documentation: <https://oat.ink/components/button/>\n"
"\n"
" The [`button`](#button) helpers style interactive actions and links with a\n"
" consistent API.\n"
"\n"
" Use regular buttons for in-page actions, and use [`link`](#link) when the\n"
" interaction navigates to a different location.\n"
"\n"
" ## Anatomy\n"
"\n"
" A button setup usually has one interactive element and optional button groups.\n"
" `group` wraps multiple actions in a semantic menu/list structure so spacing\n"
" and alignment stay consistent.\n"
"\n"
" ## Recipes\n"
"\n"
" ### A primary action button\n"
"\n"
" ```gleam\n"
" import glaze_oat/button\n"
" import lustre/element/html\n"
"\n"
" fn save_button() {\n"
" button.button([button.primary()], [html.text(\"Save\")])\n"
" }\n"
" ```\n"
"\n"
" ### A grouped action row\n"
"\n"
" ```gleam\n"
" import glaze_oat/button\n"
" import lustre/element/html\n"
"\n"
" fn actions() {\n"
" button.group([], [\n"
" button.button([button.secondary()], [html.text(\"Cancel\")]),\n"
" button.button([button.primary()], [html.text(\"Continue\")]),\n"
" ])\n"
" }\n"
" ```\n"
"\n"
" ### A link styled as button\n"
"\n"
" ```gleam\n"
" import glaze_oat/button\n"
" import lustre/attribute\n"
" import lustre/element/html\n"
"\n"
" fn docs_link() {\n"
" button.link([attribute.href(\"/docs\"), button.outline()], [\n"
" html.text(\"Read docs\"),\n"
" ])\n"
" }\n"
" ```\n"
"\n"
" ## Variants\n"
"\n"
" - [`primary`](#primary)\n"
" - [`secondary`](#secondary)\n"
" - [`danger`](#danger)\n"
" - [`outline`](#outline)\n"
" - [`ghost`](#ghost)\n"
"\n"
" ## Sizes\n"
"\n"
" - [`small`](#small)\n"
" - [`large`](#large)\n"
).
-file("src/glaze_oat/button.gleam", 78).
?DOC(
" Render buttons as an action group.\n"
"\n"
" Use this when actions are related and should be visually grouped.\n"
).
-spec group(
list(lustre@vdom@vattr:attribute(PUX)),
list(lustre@vdom@vnode:element(PUX))
) -> lustre@vdom@vnode:element(PUX).
group(Attrs, Children) ->
lustre@element@html:menu(
[lustre@attribute:class(<<"buttons"/utf8>>) | Attrs],
begin
gleam@list:map(
Children,
fun(Child) -> lustre@element@html:li([], [Child]) end
)
end
).
-file("src/glaze_oat/button.gleam", 114).
?DOC(
" Render button styling on a custom element.\n"
"\n"
" This is mostly useful in advanced cases.\n"
).
-spec instance(
fun((list(lustre@vdom@vattr:attribute(PVP)), list(lustre@vdom@vnode:element(PVP))) -> lustre@vdom@vnode:element(PVP)),
list(lustre@vdom@vattr:attribute(PVP)),
list(lustre@vdom@vnode:element(PVP))
) -> lustre@vdom@vnode:element(PVP).
instance(Element, Attrs, Children) ->
Element([lustre@attribute:role(<<"button"/utf8>>) | Attrs], Children).
-file("src/glaze_oat/button.gleam", 92).
?DOC(
" Render a button for in-page actions.\n"
"\n"
" Use this for actions like submit, save, open, or confirm.\n"
).
-spec button(
list(lustre@vdom@vattr:attribute(PVD)),
list(lustre@vdom@vnode:element(PVD))
) -> lustre@vdom@vnode:element(PVD).
button(Attrs, Children) ->
instance(fun lustre@element@html:button/2, Attrs, Children).
-file("src/glaze_oat/button.gleam", 103).
?DOC(
" Render a link (`<a>`) styled like a button.\n"
"\n"
" Use this for navigation actions rather than state-changing actions.\n"
).
-spec link(
list(lustre@vdom@vattr:attribute(PVJ)),
list(lustre@vdom@vnode:element(PVJ))
) -> lustre@vdom@vnode:element(PVJ).
link(Attrs, Children) ->
instance(
fun lustre@element@html:a/2,
[lustre@attribute:class(<<"button"/utf8>>) | Attrs],
Children
).
-file("src/glaze_oat/button.gleam", 122).
-spec primary() -> lustre@vdom@vattr:attribute(any()).
primary() ->
lustre@attribute:data(<<"data-variant"/utf8>>, <<"primary"/utf8>>).
-file("src/glaze_oat/button.gleam", 126).
-spec secondary() -> lustre@vdom@vattr:attribute(any()).
secondary() ->
lustre@attribute:data(<<"data-variant"/utf8>>, <<"secondary"/utf8>>).
-file("src/glaze_oat/button.gleam", 130).
-spec danger() -> lustre@vdom@vattr:attribute(any()).
danger() ->
lustre@attribute:data(<<"data-variant"/utf8>>, <<"danger"/utf8>>).
-file("src/glaze_oat/button.gleam", 134).
-spec outline() -> lustre@vdom@vattr:attribute(any()).
outline() ->
lustre@attribute:class(<<"outline"/utf8>>).
-file("src/glaze_oat/button.gleam", 138).
-spec ghost() -> lustre@vdom@vattr:attribute(any()).
ghost() ->
lustre@attribute:class(<<"ghost"/utf8>>).
-file("src/glaze_oat/button.gleam", 142).
-spec small() -> lustre@vdom@vattr:attribute(any()).
small() ->
lustre@attribute:class(<<"small"/utf8>>).
-file("src/glaze_oat/button.gleam", 146).
-spec large() -> lustre@vdom@vattr:attribute(any()).
large() ->
lustre@attribute:class(<<"large"/utf8>>).