themes-scifi-clean/mission_stat.go
Alex Dunmow 96b87b3e81 initial: theme plugin scifi-clean
Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously
an unversioned directory inside ~/src/blockninja-themes/scifi-clean.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-06-06 14:11:43 +08:00

55 lines
1.4 KiB
Go

package main
import (
"bytes"
"context"
"git.dev.alexdunmow.com/block/core/blocks"
)
// MissionStatBlockMeta defines metadata for the mission-stat block.
var MissionStatBlockMeta = blocks.BlockMeta{
Key: "mission_stat",
Title: "Mission Stat",
Description: "Headline metric in mono numerals with a signal-orange delta arrow.",
Source: "scifi-clean",
Category: blocks.CategoryContent,
}
// MissionStatData drives the templ render.
type MissionStatData struct {
Metric string
Value string
Unit string
Delta string
Trend string // "up", "down", "flat"
}
// MissionStatBlock renders the mission-stat block.
// Content shape: {"metric": "...", "value": "...", "unit": "...", "delta": "...", "trend": "up|down|flat"}
func MissionStatBlock(ctx context.Context, content map[string]any) string {
data := MissionStatData{
Metric: getString(content, "metric"),
Value: getString(content, "value"),
Unit: getString(content, "unit"),
Delta: getString(content, "delta"),
Trend: normalizeTrend(getString(content, "trend")),
}
var buf bytes.Buffer
_ = missionStatComponent(data).Render(ctx, &buf)
return buf.String()
}
// trendGlyph returns the arrow character for a given trend.
func trendGlyph(trend string) string {
switch trend {
case "up":
return "↑" // ↑
case "down":
return "↓" // ↓
default:
return "→" // →
}
}