classafSlim::SlimTag
sys::Obj afSlim::SlimTag
A utility class for use by custom Slim components. Builds and writes a HTML tag with custom attrs.
- addAttr
This addAttr(Str name, Str? value := null)
Adds a attr name value pair.
value
may benull
for boolean attributes.- addClass
Adds a CSS class (if it's not
null
or empty).- addStyle
This addStyle(Str name, Str? value, Str size := "")
Adds a single CSS property to the
style
attribute.size
is appended to the value (if given).null
values are skipped.value
is wrapped invar(...)
if a CSS var name (starts with--
).addStyle("padding", "2rem") addStyle("margin", "padding", "sm") addStyle("margin", "--padding-sm")
- attrBool
Returns
true
if the attr name exists.- attrEnum
Returns the first enum value in the given SSV string, or
null
if not found.- attrInt
Returns the attr value as an Int.
- attrSize
Returns the attr value as a standard size, an empty string if the base value, or
null
if not found.- attrStr
Returns the attr value.
- attrs
- classes
Str[] classes
- fromCtx
new fromCtx(SlimComponentCtx ctx, Str? tagName := null)
Creates a tag builder initialised from the given
SlimComponentCtx
.Tag Name defaults to ctx, falls back to the given name, or defaults to
div
.- id
Str? id
- isSize
Is the value one of the standard sizes?
- make
new make(Str? tagName := null)
Creates a tag builder.
Tag Name defaults to
div
.- sizes
const static Str[] sizes := "xs sm lg xl".split
The standard sizes.
- style
Str style
- tagName
Str tagName
- write
Writes the opening start tag to the given out.
- writeEnd
Writes the end tag.