templates: use CSS variables in all shared components

Replace hardcoded Go color constants with var(--hs-*) and
var(--md-*) CSS custom properties in externalLink, orDivider,
card, warningBox, downloadButton, and pageFooter. This ensures
all components follow the dark mode theme automatically.

Also switch pageFooter from div to semantic footer element and
simplify externalLink by letting CSS handle link styling.

Updates juanfont/headscale#3182
This commit is contained in:
Kristoffer Dalby
2026-04-13 12:42:10 +00:00
parent 93860a5c06
commit 3918020551
2 changed files with 23 additions and 43 deletions

View File

@@ -108,15 +108,11 @@ func responsiveContainer(children ...elem.Node) *elem.Element {
func card(title string, children ...elem.Node) *elem.Element { func card(title string, children ...elem.Node) *elem.Element {
cardContent := children cardContent := children
if title != "" { if title != "" {
// Prepend title as H3 if provided
cardContent = append([]elem.Node{ cardContent = append([]elem.Node{
elem.H3(attrs.Props{ elem.H3(attrs.Props{
attrs.Style: styles.Props{ attrs.Style: styles.Props{
styles.MarginTop: "0", styles.MarginTop: "0",
styles.MarginBottom: spaceM, styles.MarginBottom: spaceM,
styles.FontSize: fontSizeH3,
styles.LineHeight: lineHeightH3, // 1.5 - H3 line height
styles.Color: colorTextSecondary,
}.ToInline(), }.ToInline(),
}, elem.Text(title)), }, elem.Text(title)),
}, children...) }, children...)
@@ -124,12 +120,12 @@ func card(title string, children ...elem.Node) *elem.Element {
return elem.Div(attrs.Props{ return elem.Div(attrs.Props{
attrs.Style: styles.Props{ attrs.Style: styles.Props{
styles.Background: colorBackgroundCard, styles.Background: "var(--hs-bg)",
styles.Border: "1px solid " + colorBorderLight, styles.Border: "1px solid var(--hs-border)",
styles.BorderRadius: "0.5rem", // 8px rounded corners styles.BorderRadius: "0.5rem",
styles.Padding: "clamp(1rem, 3vw, 1.5rem)", // Responsive padding styles.Padding: "clamp(1rem, 3vw, 1.5rem)",
styles.MarginBottom: spaceL, styles.MarginBottom: spaceL,
styles.BoxShadow: "0 1px 3px rgba(0,0,0,0.1)", // Subtle shadow styles.BoxShadow: "0 1px 3px rgba(0,0,0,0.1)",
}.ToInline(), }.ToInline(),
}, cardContent...) }, cardContent...)
} }
@@ -333,6 +329,12 @@ func inlineCode(code string) *elem.Element {
// //
//nolint:unused // Used in apple.go template. //nolint:unused // Used in apple.go template.
func orDivider() *elem.Element { func orDivider() *elem.Element {
lineStyle := styles.Props{
styles.Flex: "1",
styles.Height: "1px",
styles.BackgroundColor: "var(--hs-border)",
}.ToInline()
return elem.Div(attrs.Props{ return elem.Div(attrs.Props{
attrs.Style: styles.Props{ attrs.Style: styles.Props{
styles.Display: "flex", styles.Display: "flex",
@@ -343,29 +345,17 @@ func orDivider() *elem.Element {
styles.Width: "100%", styles.Width: "100%",
}.ToInline(), }.ToInline(),
}, },
elem.Div(attrs.Props{ elem.Div(attrs.Props{attrs.Style: lineStyle}),
attrs.Style: styles.Props{
styles.Flex: "1",
styles.Height: "1px",
styles.BackgroundColor: colorBorderLight,
}.ToInline(),
}),
elem.Strong(attrs.Props{ elem.Strong(attrs.Props{
attrs.Style: styles.Props{ attrs.Style: styles.Props{
styles.Color: colorTextSecondary, styles.Color: "var(--md-default-fg-color--light)",
styles.FontSize: fontSizeBase, styles.FontSize: fontSizeBase,
styles.FontWeight: "500", styles.FontWeight: "500",
"text-transform": "uppercase", "text-transform": "uppercase",
"letter-spacing": "0.05em", "letter-spacing": "0.05em",
}.ToInline(), }.ToInline(),
}, elem.Text("or")), }, elem.Text("or")),
elem.Div(attrs.Props{ elem.Div(attrs.Props{attrs.Style: lineStyle}),
attrs.Style: styles.Props{
styles.Flex: "1",
styles.Height: "1px",
styles.BackgroundColor: colorBorderLight,
}.ToInline(),
}),
) )
} }
@@ -526,10 +516,6 @@ func externalLink(href, text string) *elem.Element {
attrs.Href: href, attrs.Href: href,
attrs.Rel: "noreferrer noopener", attrs.Rel: "noreferrer noopener",
attrs.Target: "_blank", attrs.Target: "_blank",
attrs.Style: styles.Props{
styles.Color: colorPrimaryAccent, // #4051b5 - base link color
styles.TextDecoration: "none",
}.ToInline(),
}, elem.Text(text)) }, elem.Text(text))
} }

View File

@@ -124,26 +124,20 @@ func headscaleLogo() elem.Node {
// pageFooter creates a consistent footer for all pages. // pageFooter creates a consistent footer for all pages.
func pageFooter() *elem.Element { func pageFooter() *elem.Element {
footerStyle := styles.Props{ return elem.Footer(attrs.Props{
styles.MarginTop: space3XL, attrs.Style: styles.Props{
styles.TextAlign: "center", styles.MarginTop: space3XL,
styles.FontSize: fontSizeSmall, styles.TextAlign: "center",
styles.Color: colorTextSecondary, styles.FontSize: fontSizeSmall,
styles.LineHeight: lineHeightBase, styles.Color: "var(--md-default-fg-color--light)",
} styles.LineHeight: lineHeightBase,
}.ToInline(),
linkStyle := styles.Props{ },
styles.Color: colorTextSecondary,
styles.TextDecoration: "underline",
}
return elem.Div(attrs.Props{attrs.Style: footerStyle.ToInline()},
elem.Text("Powered by "), elem.Text("Powered by "),
elem.A(attrs.Props{ elem.A(attrs.Props{
attrs.Href: "https://github.com/juanfont/headscale", attrs.Href: "https://github.com/juanfont/headscale",
attrs.Rel: "noreferrer noopener", attrs.Rel: "noreferrer noopener",
attrs.Target: "_blank", attrs.Target: "_blank",
attrs.Style: linkStyle.ToInline(),
}, elem.Text("Headscale")), }, elem.Text("Headscale")),
) )
} }