36 lines
912 B
Go
36 lines
912 B
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// StatItemBlockMeta defines metadata for a single stat item.
|
|
var StatItemBlockMeta = blocks.BlockMeta{
|
|
Key: "stat_item",
|
|
Title: "Stat Item",
|
|
Description: "A single statistic with value, label, and optional icon",
|
|
Source: "gotham",
|
|
Hidden: true, // Only available as child of stats block
|
|
}
|
|
|
|
// StatItemBlock renders a single stat item.
|
|
// Content expects: {"value": "100+", "label": "Projects", "icon": "chart"}
|
|
func StatItemBlock(ctx context.Context, content map[string]any) string {
|
|
item := StatItem{
|
|
Value: getString(content, "value"),
|
|
Label: getString(content, "label"),
|
|
Icon: getString(content, "icon"),
|
|
}
|
|
|
|
if item.Value == "" && item.Label == "" {
|
|
return ""
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = statItemComponent(item).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|