gva
Types
Values
pub fn gva(
default default: String,
resolver resolver: fn(a) -> String,
defaults defaults: List(a),
) -> Class(a)
Helper to create a gva Class type
The default parameter is the string that will be used regardless of any other parameters
The resolver handles which types should go to which classes
Examples
type Size {
Small
Medium
}
type Variant {
Primary
Secondary
}
// Define a master Key type for all Variants
type Key {
Size(Size)
Variant(Variant)
}
pub fn main() {
let button =
gva(
default: "text-white",
// Define a resolver to handle which types should go
// to which classes
resolver: fn(in: Key) {
case in {
Size(size) ->
case size {
Small -> "text-sm"
Medium -> "text-md"
}
Variant(variant) ->
case variant {
Primary -> "bg-slate-950"
Secondary -> "bg-slate-600"
}
}
},
// Define which defaults should be applied, if no defaults are
// provided and no with() calls are done then the resulting class
// will only include the default string which might not be favorable
defaults: [Variant(Primary)],
)
let class =
button
|> with(Size(Medium))
|> with(Variant(Secondary))
|> build()
assert class == "text-white text-md bg-slate-600"
Nil
}