Packages

🍩 Lustre Bindings to Oat UI Components

Current section

Files

Jump to
glaze_oat src glaze_oat@alert.erl
Raw

src/glaze_oat@alert.erl

-module(glaze_oat@alert).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glaze_oat/alert.gleam").
-export([instance/3, alert/2, title/2, message/2, success/0, warning/0, error/0, danger/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/alert/>\n"
"\n"
" The [`alert`](#alert) element, sometimes called a \"callout\", is used to draw\n"
" attention to important information without interrupting page flow.\n"
"\n"
" ## Anatomy\n"
"\n"
" An alert is usually a container with short, high-signal text.\n"
" Most uses combine a `title` for the main message and an optional `message`\n"
" for supporting detail.\n"
"\n"
" ## Recipes\n"
"\n"
" ### A title-only success alert\n"
"\n"
" ```gleam\n"
" import glaze_oat/alert\n"
" import lustre/element/html\n"
"\n"
" fn saved_notice() {\n"
" alert.alert([alert.success()], [\n"
" alert.title([], [html.text(\"Changes saved.\")]),\n"
" ])\n"
" }\n"
" ```\n"
"\n"
" ### A warning alert with title and message\n"
"\n"
" ```gleam\n"
" import glaze_oat/alert\n"
" import lustre/element/html\n"
"\n"
" fn warning_notice() {\n"
" alert.alert([alert.warning()], [\n"
" alert.title([], [html.text(\"Storage nearly full\")]),\n"
" alert.message([], [\n"
" html.text(\"Delete unused files or upgrade your plan.\"),\n"
" ]),\n"
" ])\n"
" }\n"
" ```\n"
"\n"
" ## Variants\n"
"\n"
" - [`success`](#success)\n"
" - [`warning`](#warning)\n"
" - [`error`](#error)\n"
" - [`danger`](#danger)\n"
"\n"
" ## References\n"
"\n"
" - MDN ARIA `alert` role:\n"
" <https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/alert_role>\n"
"\n"
).
-file("src/glaze_oat/alert.gleam", 79).
?DOC(
" Render an alert using a custom container element.\n"
"\n"
" This is useful when you want semantic alternatives such as `html.section`\n"
" while keeping the same alert role behavior.\n"
"\n"
" The returned element always includes `role=\"alert\"`.\n"
).
-spec instance(
fun((list(lustre@vdom@vattr:attribute(PPI)), list(lustre@vdom@vnode:element(PPI))) -> lustre@vdom@vnode:element(PPI)),
list(lustre@vdom@vattr:attribute(PPI)),
list(lustre@vdom@vnode:element(PPI))
) -> lustre@vdom@vnode:element(PPI).
instance(Element, Attrs, Children) ->
Element([lustre@attribute:role(<<"alert"/utf8>>) | Attrs], Children).
-file("src/glaze_oat/alert.gleam", 65).
?DOC(
" Render an alert container as a `<div>`.\n"
"\n"
" This is a convenience wrapper around [`instance`](#instance) using `html.div`.\n"
" The element includes `role=\"alert\"` for accessible announcement behavior.\n"
).
-spec alert(
list(lustre@vdom@vattr:attribute(PPC)),
list(lustre@vdom@vnode:element(PPC))
) -> lustre@vdom@vnode:element(PPC).
alert(Attrs, Children) ->
instance(fun lustre@element@html:'div'/2, Attrs, Children).
-file("src/glaze_oat/alert.gleam", 91).
?DOC(
" Render alert title content using `<strong>`.\n"
"\n"
" Use this for short, high-signal summary text at the start of the alert.\n"
).
-spec title(
list(lustre@vdom@vattr:attribute(PPT)),
list(lustre@vdom@vnode:element(PPT))
) -> lustre@vdom@vnode:element(PPT).
title(Attrs, Children) ->
lustre@element@html:strong(Attrs, Children).
-file("src/glaze_oat/alert.gleam", 102).
?DOC(
" Render alert supporting content using `<span>`.\n"
"\n"
" Use this for additional detail or explanation beneath/alongside the title.\n"
).
-spec message(
list(lustre@vdom@vattr:attribute(PPZ)),
list(lustre@vdom@vnode:element(PPZ))
) -> lustre@vdom@vnode:element(PPZ).
message(Attrs, Children) ->
lustre@element@html:span(Attrs, Children).
-file("src/glaze_oat/alert.gleam", 113).
?DOC(
" Set `data-variant=\"success\"` on an alert.\n"
"\n"
" Intended for positive confirmations such as completed actions.\n"
).
-spec success() -> lustre@vdom@vattr:attribute(any()).
success() ->
lustre@attribute:data(<<"variant"/utf8>>, <<"success"/utf8>>).
-file("src/glaze_oat/alert.gleam", 121).
?DOC(
" Set `data-variant=\"warning\"` on an alert.\n"
"\n"
" Intended for cautionary states that may need user attention.\n"
).
-spec warning() -> lustre@vdom@vattr:attribute(any()).
warning() ->
lustre@attribute:data(<<"variant"/utf8>>, <<"warning"/utf8>>).
-file("src/glaze_oat/alert.gleam", 129).
?DOC(
" Set `data-variant=\"error\"` on an alert.\n"
"\n"
" Intended for failures or invalid states.\n"
).
-spec error() -> lustre@vdom@vattr:attribute(any()).
error() ->
lustre@attribute:data(<<"variant"/utf8>>, <<"error"/utf8>>).
-file("src/glaze_oat/alert.gleam", 137).
?DOC(
" Set `data-variant=\"danger\"` on an alert.\n"
"\n"
" Intended for destructive or high-severity states.\n"
).
-spec danger() -> lustre@vdom@vattr:attribute(any()).
danger() ->
lustre@attribute:data(<<"variant"/utf8>>, <<"danger"/utf8>>).