49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// StatsBlockMeta defines metadata for the stats counter block.
|
|
// Stats uses a schema-defined items array, not child blocks.
|
|
var StatsBlockMeta = blocks.BlockMeta{
|
|
Key: "stats",
|
|
Title: "Stats Counter",
|
|
Description: "Display statistics with labels and values",
|
|
Source: "gotham",
|
|
}
|
|
|
|
// StatsBlock renders a stats counter grid from content.items array.
|
|
func StatsBlock(ctx context.Context, content map[string]any) string {
|
|
items := getSlice(content, "items")
|
|
if len(items) == 0 {
|
|
// Empty state - show placeholder
|
|
var buf bytes.Buffer
|
|
_ = statsEmptyComponent().Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
var stats []StatItem
|
|
for _, item := range items {
|
|
stats = append(stats, StatItem{
|
|
Value: getString(item, "value"),
|
|
Label: getString(item, "label"),
|
|
Icon: getString(item, "icon"),
|
|
})
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = statsComponent(stats).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// StatItem represents a single statistic.
|
|
type StatItem struct {
|
|
Value string
|
|
Label string
|
|
Icon string
|
|
}
|