theme

package
v0.86.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 4 Imported by: 4

Documentation

Overview

Package theme is the canonical home for the framework's visual design system.

The theme provides curated tokens: colors, spacing, radii, fonts that every framework/ui component references via CSS custom properties. To re-skin an app, pass overrides to Default; every component re-resolves to the new values without code changes. Default includes a complete adaptive dark palette, so ThemeToggle and the synchronous OS-preference bootstrap are safe without extra host setup.

Tokens are single-tier semantic: names carry meaning ("primary", "danger", "surface-soft") rather than raw values ("indigo-500"). If you need a deeper layering, build it on top, but most apps don't.

The output is a style.Theme (from core-ui/style), so this package composes cleanly with the existing stylesheet builder and any host that already consumes core-ui themes.

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = ComponentOptions{
	Density: Comfortable,
	Button:  ButtonOptions{Treatment: Filled, Radius: Round},
	Field:   FieldOptions{Layout: Stacked, Radius: FieldRound},
}

DefaultOptions is the complete option set: what a theme carries when a host says nothing.

Functions

func Default

func Default(overrides ...Overrides) style.Theme

Default returns the canonical adaptive framework theme, including complete light and dark semantic palettes.

Pass an Overrides value to swap individual tokens. Overrides are applied on top of the typed style.DefaultTheme(); unset fields keep their defaults.

Example. Swap primary from indigo to teal in both palettes:

t := theme.Default(theme.Overrides{
	Primary: "#0F766E",
	Dark:    &theme.Overrides{Primary: "#5EEAD4"},
})

Every component referencing --color-primary updates without any code change.

Types

type ButtonOptions added in v0.86.0

type ButtonOptions struct {
	Treatment ButtonTreatment
	Radius    ButtonRadius
}

ButtonOptions is the button family's slice of the option set.

type ButtonRadius added in v0.86.0

type ButtonRadius int

ButtonRadius is a button's corner shape.

const (
	RadiusUnset ButtonRadius = iota
	// Round: the theme's md radius token.
	Round
	// Square: no rounding at all.
	Square
	// Pill: fully rounded.
	Pill
)

func ParseButtonRadius added in v0.86.0

func ParseButtonRadius(s string) (ButtonRadius, error)

ParseButtonRadius is String's inverse.

func (ButtonRadius) String added in v0.86.0

func (r ButtonRadius) String() string

String returns the flattened form ("round", "square", "pill").

type ButtonTreatment added in v0.86.0

type ButtonTreatment int

ButtonTreatment is how a theme draws a button: where the ink goes.

const (
	TreatmentUnset ButtonTreatment = iota
	// Filled: solid primary background, primary-fg text, no border.
	Filled
	// Outline: no fill, primary text and border.
	Outline
	// Soft: the soft surface tint, primary text, no border.
	Soft
)

func ParseButtonTreatment added in v0.86.0

func ParseButtonTreatment(s string) (ButtonTreatment, error)

ParseButtonTreatment is String's inverse.

func (ButtonTreatment) String added in v0.86.0

func (t ButtonTreatment) String() string

String returns the flattened form ("filled", "outline", "soft").

type ComponentOptions added in v0.86.0

type ComponentOptions struct {
	Density Density
	Button  ButtonOptions
	Field   FieldOptions
}

func OptionsFromFlattened added in v0.86.0

func OptionsFromFlattened(m map[string]string) (ComponentOptions, error)

OptionsFromFlattened parses a style.Theme.Components map back into the typed form, the inverse of Flattened. Every key must be known and every value a member of its enum: the flattened form is data that crossed a boundary (a theme file, an edited theme, an embed), and a typo dropped silently is a typo nobody ever hears about again.

func (ComponentOptions) Complete added in v0.86.0

func (o ComponentOptions) Complete() ComponentOptions

Complete returns o with every unset option replaced by its default. Default() results are complete by construction; Complete is the explicit form for themes assembled by hand.

func (ComponentOptions) Flattened added in v0.86.0

func (o ComponentOptions) Flattened() map[string]string

Flattened writes o into the style.Theme.Components keys. Unset options are omitted: flattening happens after merging, and an omitted key inherits, which is the nesting contract.

type Density added in v0.86.0

type Density int

Density is the vertical rhythm of controls: how tall a control aims to be and which spacing step separates them.

const (
	DensityUnset Density = iota
	// Comfortable is the default: 44px controls (the WCAG 2.5.5 tap
	// target) and the md spacing step between them.
	Comfortable
	// Compact is the dense setting: 36px controls, sm gaps.
	Compact
)

func ParseDensity added in v0.86.0

func ParseDensity(s string) (Density, error)

ParseDensity is String's inverse, for reading a flattened Components map back into the typed form.

func (Density) String added in v0.86.0

func (d Density) String() string

String returns the flattened form ("comfortable", "compact"), the exact spelling style.Theme.Components carries.

type FieldLayout added in v0.86.0

type FieldLayout int

FieldLayout is how a field's label sits against its control: stacked above it, or inline beside it. Inline is a preference the stylesheet may override in a narrow context, not a promise.

const (
	LayoutUnset FieldLayout = iota
	Stacked
	Inline
)

func ParseFieldLayout added in v0.86.0

func ParseFieldLayout(s string) (FieldLayout, error)

ParseFieldLayout is String's inverse.

func (FieldLayout) String added in v0.86.0

func (l FieldLayout) String() string

String returns the flattened form ("stacked", "inline").

type FieldOptions added in v0.86.0

type FieldOptions struct {
	Layout FieldLayout
	Radius FieldRadius
}

FieldOptions is the form field family's slice of the option set.

type FieldRadius added in v0.86.0

type FieldRadius int

FieldRadius is a field control's corner shape: the radius the field's inputs, selects and summaries draw.

const (
	FieldRadiusUnset FieldRadius = iota
	FieldRound
	FieldSquare
)

func ParseFieldRadius added in v0.86.0

func ParseFieldRadius(s string) (FieldRadius, error)

ParseFieldRadius is String's inverse.

func (FieldRadius) String added in v0.86.0

func (r FieldRadius) String() string

String returns the flattened form ("round", "square").

type Option added in v0.86.0

type Option struct {
	// Key is the flattened Components key ("button.treatment"), the
	// exact string Flattened writes and OptionsFromFlattened switches
	// on; ThemeToTokens emits it under "component.".
	Key string
	// Members are the values the option's enum accepts, in declaration
	// order, derived from the enums' String methods.
	Members []string
	// Default is the value DefaultOptions carries for the key.
	Default string
}

Option is one entry of the option catalogue: a flattened Components key, the member values its enum accepts in declaration order, and the default DefaultOptions carries. Tools that author themes list these members, so a control can never offer a value OptionsFromFlattened refuses.

func Options added in v0.86.0

func Options() []Option

Options returns the option catalogue: every flattened option key in a fixed order — the declaration order the option set documents, density first, then the button family, then the field family — each with its members in declaration order and its default. The theme editor renders each entry as a select whose options are the members, so an authored value is a member by construction; the catalogue test pins the catalogue to the flattened vocabulary so a new option cannot be added without the catalogue following.

type Overrides

type Overrides struct {
	// Color tokens (CSS hex values).
	Background, Surface, SurfaceSoft         string
	Border, BorderStrong                     string
	Text, TextMuted, TextSubtle              string
	Primary, PrimaryFg                       string
	Accent                                   string
	Success, Warning, Danger, DangerFg, Info string

	// Code-display surface tokens (ui.CodeBlock + demo source panels).
	// Intentionally a separate pair so dark mode reskins code blocks
	// independently of the page Text/Background pair.
	CodeSurface, CodeText, CodeBorder string

	// Dark is the dark-mode twin of the colour fields above: the same
	// typed fields, compiled into the theme's dark palette
	// (style.Theme.DarkColors) keyed by the CSS names the dark-scheme
	// blocks read. Light colour fields are not copied into dark mode
	// automatically because a contrast-safe dark value is usually
	// different; a light override with no dark twin logs a warning
	// naming the field.
	//
	// Dark changes colours only: setting Components, a font, a radius
	// or a nested Dark inside it panics when the theme is built. A
	// non-nil Dark with no colour set (Dark: &theme.Overrides{}) means
	// "the framework's dark palette is deliberate" and silences the
	// light-only warning.
	Dark *Overrides

	// Components are the typed component options (Density, the button
	// family's Treatment and Radius). Zero values mean "leave the
	// construction base unchanged" while overrides merge, exactly like
	// the string fields above; an explicit Comfortable, Filled or Round
	// resets an earlier override. The merged result is flattened into
	// style.Theme.Components complete, so every theme this package
	// produces declares a full option set.
	Components ComponentOptions

	// Font families.
	FontBody, FontHeading, FontMono string

	// Reskin extras: only apply if you really need them.
	RadiusSm, RadiusMd, RadiusLg int // px
}

Overrides is the set of tokens a host can swap to re-skin the framework theme. All fields are optional. Empty strings are ignored, zero-value RadiusXX ints likewise.

Jump to

Keyboard shortcuts

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