Bootstrapped during the 2026-06-06 BlockNinja consolidation. Was previously an unversioned directory inside ~/src/blockninja-themes/earthen. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
68 lines
1.7 KiB
Go
68 lines
1.7 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"strconv"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
)
|
|
|
|
// DonationCTABlockMeta defines metadata for the donation CTA block.
|
|
var DonationCTABlockMeta = blocks.BlockMeta{
|
|
Key: "donation_cta",
|
|
Title: "Donation CTA",
|
|
Description: "Donation call-to-action with preset amount tiles and custom amount field",
|
|
Source: "earthen",
|
|
Category: blocks.CategoryContent,
|
|
}
|
|
|
|
// DonationCTABlock renders the donation call-to-action block.
|
|
// Content shape: {headline, body, amounts:[int], buttonLabel, processorUrl}
|
|
func DonationCTABlock(ctx context.Context, content map[string]any) string {
|
|
amounts := getNumberSlice(content, "amounts")
|
|
if len(amounts) == 0 {
|
|
amounts = []float64{25, 50, 100}
|
|
}
|
|
|
|
tiles := make([]DonationTile, 0, len(amounts))
|
|
for _, a := range amounts {
|
|
tiles = append(tiles, DonationTile{
|
|
Value: a,
|
|
Label: "$" + strconv.FormatFloat(a, 'f', -1, 64),
|
|
})
|
|
}
|
|
|
|
data := DonationCTAData{
|
|
Headline: getString(content, "headline"),
|
|
Body: getString(content, "body"),
|
|
ButtonLabel: getString(content, "buttonLabel"),
|
|
ProcessorURL: getString(content, "processorUrl"),
|
|
Tiles: tiles,
|
|
Empty: len(content) == 0,
|
|
}
|
|
if data.ButtonLabel == "" {
|
|
data.ButtonLabel = "Donate"
|
|
}
|
|
|
|
var buf bytes.Buffer
|
|
_ = donationCTAComponent(data).Render(ctx, &buf)
|
|
return buf.String()
|
|
}
|
|
|
|
// DonationCTAData contains data for the donation CTA component.
|
|
type DonationCTAData struct {
|
|
Headline string
|
|
Body string
|
|
ButtonLabel string
|
|
ProcessorURL string
|
|
Tiles []DonationTile
|
|
Empty bool
|
|
}
|
|
|
|
// DonationTile is a single preset amount tile.
|
|
type DonationTile struct {
|
|
Value float64
|
|
Label string
|
|
}
|