Files
kjol/go/webui/envbadge.go

48 lines
1.6 KiB
Go

// Port of web/kit/EnvBadge.tsx.
package webui
import (
"strings"
"kjol/vdom"
)
// IsNonProdEnv reports whether env is a non-empty, non-production deployment
// environment (development, staging, …). Mirrors env.ts's isNonProdEnv. In the
// TSX the environment is a build-time constant (ENV_TYPE); here it collapses to
// a plain argument the caller supplies.
func IsNonProdEnv(env string) bool {
return env != "" && env != "production"
}
const envBadgeBase = "pointer-events-none select-none absolute top-0 -right-2 z-10 " +
"rounded px-1 py-px text-[0.5rem] font-bold uppercase leading-none tracking-wider shadow-sm"
// EnvBadge renders a small environment badge pinned to the corner of the app
// logo. It returns nil in production (and for an empty env), so it renders
// nothing there — drop it inside a position:relative wrapper around the logo so
// it anchors to the logo's top-right corner.
//
// NOTE: the TSX also tags <html data-env=…> as a module side effect
// (markEnvOnRoot). That is a browser-only document mutation with no
// neutral-runtime equivalent and is dropped here; do it in app bootstrap if the
// env-specific styling hook is needed.
func EnvBadge(env string) *vdom.VNode {
if !IsNonProdEnv(env) {
return nil
}
var label, tone string
switch env {
case "development":
label, tone = "DEV", "bg-orange-500 text-white"
case "staging":
label, tone = "STAGING", "bg-yellow-400 text-gray-900"
default:
label, tone = strings.ToUpper(env), "bg-neutral-700 text-white"
}
return vdom.Span(vdom.Attr("class", cx(envBadgeBase, tone)), vdom.Text(label))
}