Current section

Files

Jump to
glaze_basecoat src glaze@basecoat.erl
Raw

src/glaze@basecoat.erl

-module(glaze@basecoat).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/glaze/basecoat.gleam").
-export([register_js/1, register_css/1, register/1, toaster/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.
-file("src/glaze/basecoat.gleam", 38).
?DOC(
" Register only Basecoat JavaScript from CDN.\n"
"\n"
" ### Example\n"
"\n"
" ```gleam\n"
" import glaze/basecoat\n"
"\n"
" html.head([], [\n"
" // Your Tailwind CSS import...\n"
" glaze_basecoat.register_js(glaze_basecoat.version),\n"
" ])\n"
" ```\n"
).
-spec register_js(binary()) -> lustre@vdom@vnode:element(any()).
register_js(V) ->
lustre@element@html:script(
[lustre@attribute:attribute(<<"defer"/utf8>>, <<"defer"/utf8>>),
lustre@attribute:src(
<<<<"https://cdn.jsdelivr.net/npm/basecoat-css@"/utf8,
V/binary>>/binary,
"/dist/js/all.min.js"/utf8>>
)],
<<""/utf8>>
).
-file("src/glaze/basecoat.gleam", 56).
?DOC(
" Register only Basecoat CSS from CDN.\n"
"\n"
" Use this when you want to manage the JavaScript separately.\n"
).
-spec register_css(binary()) -> lustre@vdom@vnode:element(any()).
register_css(V) ->
lustre@element@html:link(
[lustre@attribute:rel(<<"stylesheet"/utf8>>),
lustre@attribute:href(
<<<<"https://cdn.jsdelivr.net/npm/basecoat-css@"/utf8,
V/binary>>/binary,
"/dist/basecoat.cdn.min.css"/utf8>>
)]
).
-file("src/glaze/basecoat.gleam", 21).
?DOC(
" Register Basecoat UI CSS and JavaScript from CDN.\n"
"\n"
" This includes all Basecoat styles and JavaScript components.\n"
"\n"
" ### Example\n"
"\n"
" ```gleam\n"
" import glaze/basecoat\n"
"\n"
" html.head([], [\n"
" basecoat.register(basecoat.version),\n"
" ])\n"
" ```\n"
).
-spec register(binary()) -> lustre@vdom@vnode:element(any()).
register(V) ->
lustre@element:fragment([register_css(V), register_js(V)]).
-file("src/glaze/basecoat.gleam", 82).
?DOC(
" Add the toaster container required for toast notifications.\n"
"\n"
" Place this at the end of your body element.\n"
"\n"
" ### Example\n"
"\n"
" ```gleam\n"
" import glaze/basecoat\n"
"\n"
" html.body([], [\n"
" // Your content...\n"
" basecoat.toaster(),\n"
" ])\n"
" ```\n"
).
-spec toaster() -> lustre@vdom@vnode:element(any()).
toaster() ->
lustre@element@html:'div'(
[lustre@attribute:id(<<"toaster"/utf8>>),
lustre@attribute:class(<<"toaster"/utf8>>)],
[]
).