SDK Reference
Code examples and usage patterns for every go-daisy package.
Installation
Add go-daisy to your Go module and configure Tailwind CSS with DaisyUI.
bash
# Add the Go module
go get github.com/emergent-company/go-daisy
# Install Tailwind CSS and DaisyUI
npm install tailwindcss @tailwindcss/cli daisyui@latest
# Configure tailwind.config.js:
# module.exports = {
# plugins: [require("daisyui")],
# }
# Build CSS:
# npx @tailwindcss/cli -i assets/app.css -o static/css/app.cssQuickstart
Minimal Echo app rendering a go-daisy page shell.
go
package main
import (
"github.com/labstack/echo/v4"
"github.com/emergent-company/go-daisy/components/layout"
"github.com/emergent-company/go-daisy/render"
)
func main() {
e := echo.New()
e.GET("/", func(c echo.Context) error {
page := layout.Page("My App", "nord",
layout.PageContent("Hello, go-daisy!"),
)
render.RenderPage(c.Response().Writer, c.Request(), page)
return nil
})
e.Logger.Fatal(e.Start(":8080"))
}Badges
Badge component with size and color intent variants.
go
ui.Badge(ui.BadgeProps{
Label: "Active",
Variant: ui.BadgeSuccess,
Size: ui.BadgeSizeSM,
})
ui.Badge(ui.BadgeProps{
Label: "Beta",
Variant: ui.BadgeWarning,
Size: ui.BadgeSizeMD,
})Cards
Card component with optional icon stats display.
go
ui.Card(ui.CardProps{
Title: "Total Users",
Value: "1,234",
Icon: "lucide--users",
IconBg: "bg-primary/10",
IconColor:"text-primary",
})
ui.StatCardMinimal("CPU", "45%", "lucide--cpu")Tables
Data tables with size, border, and sorting options.
go
table.TableWithProps(table.TableProps{
Size: "sm",
Bordered: true,
}) {
table.TableHead() {
table.TableHeadRow() {
table.TableHeadCell("Name")
table.TableHeadCell("Role")
}
}
table.TableBody() {
table.TableRow() {
table.TableCell("Alice")
table.TableCell("Admin")
}
}
}Forms
Form inputs, textareas, and selects via the generic FormField.
go
form.FormField(form.FormFieldProps{
Label: "Email",
Name: "email",
Type: "email",
Placeholder: "user@example.com",
Required: true,
})
form.FormField(form.FormFieldProps{
Label: "Role",
Name: "role",
Type: "select",
Options: []form.SelectOption{
{Value: "admin", Label: "Admin"},
{Value: "user", Label: "User"},
},
})HTMX Rendering
Render helpers for HTMX-aware page serving: full HTML vs. partial fragment.
go
import "github.com/emergent-company/go-daisy/render"
// RenderAuto — chooses full page vs. fragment based on HX-Request header.
render.RenderAuto(w, r, fullPage, partialContent)
// RenderTriple — three-tier: full shell / sidebar swap / tab swap.
render.RenderTriple(w, r, shellContent, sidebarContent, tabContent)
// RenderPage — always renders the full HTML shell.
render.RenderPage(w, r, pageComponent)
// RenderPartial — always renders the content fragment only.
render.RenderPartial(w, r, contentComponent)
// RedirectAfterMutation — HX-Redirect for HTMX, 303 for plain.
render.RedirectAfterMutation(w, r, "/new-path")
// AppendToast — writes an hx-swap-oob toast fragment.
render.AppendToast(w, r,
ui.Toast(ui.ToastProps{Message: "Saved!", Type: "alert-success"}),
)Styling & Themes
go-daisy uses DaisyUI themes. Switch themes via data-theme attribute on <html>, and draw every border from the line ladder.
go
// In your layout shell:
layout.Page("My App", "nord") { // "nord" = light theme
// children...
}
// Or pass "" to use the browser/OS default.
layout.Page("My App", "") { ... }
// ThemeSwitcher component for user toggle:
ui.ThemeSwitcher()
// Available DaisyUI themes: light, dark, nord, dracula, cupcake, etc.
// Configure in tailwind.config.js under daisyui.themes.
// ── Line ladder — the border/rule scale (components/css/custom.css) ──────
// Declared in the component CSS consumers import, not in assets/app.css,
// so any build that imports go-daisy's components gets the steps for free.
//
// border-line DEFAULT = --color-base-200
// A surface that sits on the page (card, panel, list, table wrapper),
// a region divider inside a surface, and a floating surface's edge
// (popover, menu, modal) where the shadow carries the elevation.
//
// border-line-strong EMPHASIS = --color-base-300
// Control outlines (input, outline button, chip, swatch, editor),
// separator bars and keyboard chips, rules that must assert over
// scrolling content (sticky bar), edges on an opaque bg-base-200 fill.
//
// border-line-translucent TRANSLUCENT = --color-base-content at 10%
// A translucent hairline for a surface the surface ramp cannot serve
// (a bg-base-200/40 fill, where --color-base-200 nearly vanishes:
// soft box, disclosure). Most present edge of the three in nord and
// dracula; marginally below line-strong in flow. Opaque vs translucent
// is not a strength ramp, so the step is named for what it is — never
// for the muted ladder's -bright slot (where -bright means MOST
// emphatic). Positional adjectives stay reserved for steps genuinely
// ordered by strength: line < line-strong.
//
// Every step derives from the theme's base variables, so nord, dracula and
// flow each keep their own hue. Quieter than border-line? Use the opacity
// modifier (border-line/50) — there is no sub-visible step by design.
// Directional forms: border-t-line, border-b-line, border-e-line,
// border-s-line, divide-line, divide-line-strong.Development Guide
How to add new components to go-daisy and run the build pipeline.
bash
# 1. Create component file
touch components/ui/<name>.templ
# 2. Write your Templ component — see existing files for conventions
# 3. Run the build pipeline
task build:ui # generates *_templ.go + compiles Tailwind CSS
task build # full build: templ + CSS + Go binary
# 4. Add a gallery showcase entry in
# cmd/gallery/internal/gallery/seed.go
# as a GalleryComponent with variants and tokens
# 5. Run the gallery
task gallery # http://localhost:11000
# Conventions:
# - Return templ.Component from Go funcs
# - Use DaisyUI classes (btn, badge, card, etc.)
# - class string as last param for CSS override
# - strconv.Itoa for int-to-string
# - No explicit import of "github.com/a-h/templ" in .templ filesPackages Reference
All go-daisy packages and their import paths.
| Package | Description | Import Path | Category |
|---|---|---|---|
| components/ui | Primitive UI components: Button, Badge, Card, Avatar, Toast, Alert, Pagination, etc. | import "github.com/emergent-company/go-daisy/components/ui" | UI |
| components/layout | Page shell, sidebar, navbar, ViewMenu, layout builder. | import "github.com/emergent-company/go-daisy/components/layout" | Layout |
| components/nav | PageHeader, TabMenu, SimpleTabs, TopBar. | import "github.com/emergent-company/go-daisy/components/nav" | Nav |
| components/form | Form inputs, FormField wrapper, selects, textareas. | import "github.com/emergent-company/go-daisy/components/form" | Forms |
| components/table | Table, ListArea, ScrollRows for data display. | import "github.com/emergent-company/go-daisy/components/table" | Data Display |
| components/modal | Modal dialog components with HTMX support. | import "github.com/emergent-company/go-daisy/components/modal" | Overlays |
| components/logs | Log stream display components. | import "github.com/emergent-company/go-daisy/components/logs" | Data Display |
| render | HTMX-aware RenderAuto/RenderTriple/RenderPage/RenderPartial helpers. | import "github.com/emergent-company/go-daisy/render" | Core |
| galleryruntime | Embeddable gallery server. Import and call Serve(Options). | import "github.com/emergent-company/go-daisy/galleryruntime" | Core |