add Block + Component, add TextComponent with min, max and regex validators and early NumberComponent

This commit is contained in:
2026-02-12 15:47:52 +00:00
parent 4f77702125
commit 6099538fa8
16 changed files with 488 additions and 0 deletions

47
main.go Normal file
View File

@@ -0,0 +1,47 @@
package main
import (
"blocky/internal/block"
"blocky/internal/block/text_component"
text_component_validators "blocky/internal/block/text_component/validators"
"blocky/internal/block/validation"
"fmt"
)
func main() {
textComponent := text_component.NewTextComponent(
"title",
"Title",
// validation.Required(),
// validation.MaxLength(4),
// nil,
[]validation.ComponentOption{
validation.Required(),
validation.MaxLength(4),
},
[]text_component.TextComponentOption{
text_component_validators.Regex("^\\d+$"),
},
)
b := &block.Block{}
b.Components = append(b.Components, textComponent)
fmt.Println(textComponent.Name(), textComponent.Type())
numberComponent := block.NewNumberComponent("age", "Age")
b.Components = append(b.Components, numberComponent)
data := []byte(`{"title": "252", "age": 25 }`)
// data := []byte(`{"title": "this is the title", "age": 25 }`)
instance := &block.BlockInstance{}
err := instance.FromJSON(b, data)
if err != nil {
fmt.Println("Error decoding object", err)
return
}
fmt.Println(instance)
fmt.Println(instance.Components[0])
fmt.Println(instance.Components[1])
}