theme

package
v0.85.0-pre.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2026 License: BSD-3-Clause Imports: 4 Imported by: 0

README

kit/theme

github.com/vormadev/vorma/kit/theme

Theme helper for server-rendered apps with light / dark / system modes.

It provides:

  • normalized theme data from cookies
  • ready-to-use HTML class string
  • inline script + CSP hash for system-theme flash prevention

Import

import "github.com/vormadev/vorma/kit/theme"

Quick Start

td := theme.GetThemeData(r)

Use td.HTMLClass on <html>:

<html class="{{.Theme.HTMLClass}}"></html>

Inject the system script early in <head>:

theme.SystemThemeScript()

If you use CSP, include:

theme.SystemThemeScriptSha256Hash()

Theme Values

  • SystemValue ("system")
  • LightValue ("light")
  • DarkValue ("dark")

GetThemeData returns:

  • raw user preference (Theme)
  • resolved concrete theme (ResolvedTheme)
  • opposite concrete theme (ResolvedThemeOpposite)
  • HTML class string (HTMLClass)

Invalid or unexpected cookie values are normalized safely:

  • invalid Theme -> system
  • invalid resolved-theme cookie -> light

Cookie names are fixed internally:

  • kit_theme
  • kit_resolved_theme

Plan integrations around those names (or wrap this package if custom names are required).

API Coverage

Constants
  • const DarkValue
  • const LightValue
  • const SystemValue
Types
  • type ThemeData
Exported Struct Fields
  • ThemeData.HTMLClass string
  • ThemeData.ResolvedTheme string
  • ThemeData.ResolvedThemeOpposite string
  • ThemeData.Theme string
Functions
  • func GetThemeData(r *http.Request) ThemeData
  • func SystemThemeScript() template.HTML
  • func SystemThemeScriptSha256Hash() string

Documentation

Index

Constants

View Source
const (
	SystemValue = "system"
	LightValue  = "light"
	DarkValue   = "dark"
)

Variables

This section is empty.

Functions

func GetSystemThemeScript

func GetSystemThemeScript() template.HTML

func GetSystemThemeScriptSha256Hash

func GetSystemThemeScriptSha256Hash() string

Types

type ThemeData

type ThemeData struct {
	Theme                 string
	ResolvedTheme         string
	ResolvedThemeOpposite string
	HTMLClass             string
}

func GetThemeData

func GetThemeData(r *http.Request) ThemeData

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL