Help us shape the future of Go! Take the 2026 Go Developer Survey

design

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2026 License: MIT Imports: 4 Imported by: 22

README

Design System

Centralized design tokens, themes, and styling configuration for SCKelemen projects.

Features

  • Design Tokens: Visual configuration including colors, spacing, typography
  • Layout Tokens: Spacing scale, card dimensions, component heights, grid defaults
  • Motion Tokens: Animation configuration with levels (none, subtle, regular, loud)
  • Predefined Themes: Default, Midnight, Nord, Paper, Wrapped
  • Radix UI Integration: Support for Radix UI theme tokens
  • Light/Dark Mode: Automatic mode switching and variant colors
  • Query Parameter Resolution: Parse and resolve tokens from URL query parameters

Installation

go get github.com/SCKelemen/design-system

Usage

Using Predefined Themes
import design "github.com/SCKelemen/design-system"

// Get midnight theme
tokens := design.MidnightTheme()

// Get paper theme (light mode)
tokens := design.PaperTheme()

// Switch modes
lightTokens := tokens.LightMode()
darkTokens := tokens.DarkMode()
Custom Themes from Query Parameters
// Parse query parameters
params := map[string]string{
    "theme": "nord",
    "mode": "dark",
    "color": "ECEFF4",
    "background": "2E3440",
    "accent": "5E81AC",
}

tokens := design.ResolveDesignTokens(params)
Dual Color Format (Light/Dark)
// Specify different colors for light and dark modes
params := map[string]string{
    "color": "1F2937/E5E7EB",       // light/dark
    "background": "FFFFFF/020617",   // light/dark
    "accent": "2563EB/1D4ED8",       // light/dark
}

tokens := design.ResolveDesignTokens(params)
Radix UI Themes
params := map[string]string{
    "accentColor": "pink",
    "grayColor": "mauve",
    "radius": "large",
    "scaling": "105%",
}

tokens := design.ResolveDesignTokens(params)
Layout Tokens
layout := design.DefaultLayoutTokens()

// Spacing scale (8pt grid)
fmt.Println(layout.SpaceS)   // 8
fmt.Println(layout.SpaceM)   // 16
fmt.Println(layout.SpaceL)   // 20

// Card dimensions
fmt.Println(layout.CardPaddingLeft)  // 20
fmt.Println(layout.CardTitleHeight)  // 50

// Grid defaults
fmt.Println(layout.DefaultGridGap)     // 8.0
fmt.Println(layout.DefaultGridColumns) // 3
Motion Tokens
params := map[string]string{
    "motion": "subtle",
}

motion := design.ResolveMotionTokens(params)

fmt.Println(motion.Durations["fast"])          // "1.0s"
fmt.Println(motion.Amplitudes["scaleCard"])    // 0.02

Available Themes

  • default: Standard light/dark theme
  • midnight: Dark blue theme with high contrast
  • nord: Nordic-inspired theme with cool tones
  • paper: Clean light theme with subtle colors
  • wrapped: Special theme with pink accents and larger radius

Token Structure

DesignTokens
type DesignTokens struct {
    Theme      string
    Color      string
    Background string
    Accent     string
    FontFamily string
    Radius     int
    Padding    int
    Density    string // "compact" or "comfortable"
    Mode       string // "light" or "dark"

    // Light/dark variants
    ColorLight      string
    ColorDark       string
    BackgroundLight string
    BackgroundDark  string
    AccentLight     string
    AccentDark      string

    // Radix UI tokens
    RadixAccentColor string
    RadixGrayColor   string
    RadixRadius      string
    RadixScaling     string

    Layout *LayoutTokens
}
LayoutTokens
type LayoutTokens struct {
    // Spacing scale
    SpaceXS, SpaceS, SpaceM, SpaceL, SpaceXL, Space2XL int

    // Card dimensions
    CardPaddingLeft, CardPaddingRight, CardPaddingTop, CardPaddingBottom int
    CardTitleHeight, CardIconWidth, CardIconSpacing, CardHeaderPadding int

    // Component heights
    StatCardHeight, StatCardHeightTrend, TrendGraphMinHeight int

    // Grid defaults
    DefaultGridGap, DefaultGridWidth float64
    DefaultGridColumns int
}
MotionTokens
type MotionTokens struct {
    Level      string // "none", "subtle", "regular", "loud"
    Durations  map[string]string
    Amplitudes map[string]float64
}

Integration with Other Packages

With Dataviz
import (
    "github.com/SCKelemen/dataviz"
    design "github.com/SCKelemen/design-system"
)

// Use design tokens in visualizations
tokens := design.MidnightTheme()
config := dataviz.RenderConfig{
    DesignTokens: tokens,
    Color:        tokens.Accent,
    Theme:        tokens.Theme,
}

renderer := dataviz.NewSVGRenderer()
output := renderer.RenderLineGraph(data, bounds, config)
With SVG
import (
    "github.com/SCKelemen/svg"
    design "github.com/SCKelemen/design-system"
)

// Use design tokens for SVG styling
tokens := design.DefaultTheme()
rect := svg.Rect(10, 10, 100, 50, svg.Style{
    Fill:   tokens.Accent,
    Stroke: tokens.Color,
    StrokeWidth: 2,
})
Theme Switching
// Start with one theme
tokens := design.DefaultTheme()

// Switch to dark mode
tokens = tokens.DarkMode()

// Switch themes dynamically
if userPreference == "midnight" {
    tokens = design.MidnightTheme()
} else if userPreference == "nord" {
    tokens = design.NordTheme()
}

Complete Example

package main

import (
    "fmt"
    "github.com/SCKelemen/dataviz"
    design "github.com/SCKelemen/design-system"
    "time"
)

func main() {
    // Resolve theme from user preferences
    params := map[string]string{
        "theme": "midnight",
        "mode":  "dark",
    }
    tokens := design.ResolveDesignTokens(params)

    // Create visualization with theme
    data := dataviz.LineGraphData{
        Points: []dataviz.TimeSeriesData{
            {Date: time.Now(), Value: 100},
            {Date: time.Now().AddDate(0, 0, 1), Value: 125},
        },
        Color:     tokens.Accent,
        Smooth:    true,
        Tension:   0.3,
        MarkerType: "circle",
    }

    bounds := dataviz.Bounds{Width: 400, Height: 200}
    config := dataviz.RenderConfig{
        DesignTokens: tokens,
        Color:        tokens.Accent,
        Theme:        tokens.Theme,
    }

    renderer := dataviz.NewSVGRenderer()
    output := renderer.RenderLineGraph(data, bounds, config)
    fmt.Println(output.String())
}

Dependencies

  • dataviz - Data visualization with design token support
  • svg - SVG generation library
  • cli - Terminal rendering with theme support

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ResolveDesignTokensForBothModes

func ResolveDesignTokensForBothModes(queryParams map[string]string) (*DesignTokens, *DesignTokens)

ResolveDesignTokensForBothModes resolves design tokens for both light and dark modes This is useful for generating adaptive SVGs that respond to color scheme

Types

type DesignTokens

type DesignTokens struct {
	Theme      string
	Color      string
	Background string
	Accent     string
	FontFamily string
	Radius     int
	Padding    int
	Density    string // "compact" or "comfortable"
	Mode       string // "light" or "dark"

	// Typography tokens (terminal relative sizing hints)
	FontSizeXS       string
	FontSizeS        string
	FontSizeM        string
	FontSizeL        string
	FontSizeXL       string
	FontWeightNormal string
	FontWeightBold   string

	// Selection tokens
	SelectionBackground string // Color for selection highlight
	SelectionForeground string // Text color when selected

	// Toast tokens
	ToastInfoColor    string
	ToastSuccessColor string
	ToastWarningColor string
	ToastErrorColor   string

	// Semantic status colors (two-tier: bright for confirmation, muted for metadata)
	SuccessBright string // Primary success: dots, checks, 'Done'
	SuccessMuted  string // Secondary success: durations, supporting detail
	ErrorBright   string // Primary error: dots, crosses, 'Failed'
	ErrorMuted    string // Secondary error: durations, supporting detail
	RunningColor  string // Active/running state
	PendingColor  string // Warning/pending state
	MutedColor    string // Neutral metadata

	// Deprecated: use SuccessBright/SuccessMuted etc. Kept for backward compat.
	StatusSuccess string
	StatusError   string
	StatusRunning string
	StatusPending string
	StatusMuted   string
	// Surface hierarchy
	SurfaceBase    string
	SurfaceRaised  string
	SurfaceOverlay string
	BorderSubtle   string

	// Diff colors
	DiffAddBackground    string
	DiffRemoveBackground string

	// Syntax colors
	SyntaxKeyword  string
	SyntaxFunction string
	SyntaxString   string
	SyntaxNumber   string
	SyntaxComment  string

	// Light/dark variant colors (if specified, override base colors based on mode)
	ColorLight      string
	ColorDark       string
	BackgroundLight string
	BackgroundDark  string
	AccentLight     string
	AccentDark      string

	// Radix UI theme tokens
	RadixAccentColor string // "pink", "blue", "green", etc.
	RadixGrayColor   string // "mauve", "slate", "gray", etc.
	RadixRadius      string // "none", "small", "medium", "large", "full"
	RadixScaling     string // "90%", "95%", "100%", "105%", "110%"

	// Layout configuration
	Layout *LayoutTokens
}

DesignTokens represents visual design configuration

func CustomTheme

func CustomTheme(params map[string]string) *DesignTokens

CustomTheme creates a theme from query parameters

func DefaultTheme

func DefaultTheme() *DesignTokens

DefaultTheme returns the default design tokens

func MidnightTheme

func MidnightTheme() *DesignTokens

MidnightTheme returns the midnight theme (dark mode)

func NordTheme

func NordTheme() *DesignTokens

NordTheme returns the Nord theme (dark mode)

func PaperTheme

func PaperTheme() *DesignTokens

PaperTheme returns the Paper theme (light mode)

func ResolveDesignTokens

func ResolveDesignTokens(queryParams map[string]string) *DesignTokens

ResolveDesignTokens resolves design tokens from query parameters If auto_color_scheme is true, returns tokens that adapt to light/dark mode

func WrappedTheme

func WrappedTheme() *DesignTokens

WrappedTheme returns the Wrapped theme (dark mode with special styling)

func (*DesignTokens) DarkMode

func (dt *DesignTokens) DarkMode() *DesignTokens

DarkMode returns a copy of the tokens with dark mode applied

func (*DesignTokens) LightMode

func (dt *DesignTokens) LightMode() *DesignTokens

LightMode returns a copy of the tokens with light mode applied

func (*DesignTokens) ToCSS

func (dt *DesignTokens) ToCSS() string

ToCSS converts design tokens to CSS string for SVG

type LayoutTokens

type LayoutTokens struct {
	// Spacing scale (follows 8pt grid system)
	SpaceXS  int // 4px
	SpaceS   int // 8px
	SpaceM   int // 16px
	SpaceL   int // 20px
	SpaceXL  int // 24px
	Space2XL int // 32px

	// TUI-specific sizing defaults
	ScrollbarWidth     int // Width for scrollbars
	ToastMaxWidth      int // Maximum width for toast notifications
	BreadcrumbMaxWidth int // Maximum width for breadcrumbs
	// Card dimensions
	CardPaddingLeft   int // Horizontal padding inside cards
	CardPaddingRight  int
	CardPaddingTop    int // Vertical padding inside cards
	CardPaddingBottom int
	CardTitleHeight   int // Height reserved for title area
	CardIconWidth     int // Width of icon
	CardIconSpacing   int // Space between icon and title
	CardHeaderPadding int // Padding for header items

	// Component heights
	StatCardHeight      int // Height for stat cards without trend
	StatCardHeightTrend int // Height for stat cards with trend graph
	TrendGraphMinHeight int // Minimum height for trend graphs

	// Grid defaults
	DefaultGridGap     float64 // Default gap between grid items
	DefaultGridWidth   float64 // Default grid container width
	DefaultGridColumns int     // Default number of columns
}

LayoutTokens represents spacing and dimension configuration

func DefaultLayoutTokens

func DefaultLayoutTokens() *LayoutTokens

DefaultLayoutTokens returns the default layout token values

type MotionTokens

type MotionTokens struct {
	Level      string // "none", "subtle", "regular", "loud"
	Durations  map[string]string
	Amplitudes map[string]float64
}

MotionTokens represents animation configuration

func ResolveMotionTokens

func ResolveMotionTokens(queryParams map[string]string) *MotionTokens

ResolveMotionTokens resolves motion tokens from query parameters

Jump to

Keyboard shortcuts

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