platformd

package
v0.1.42 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 12 Imported by: 0

README

tinywasm/layout/platformd

Shell layout with hash-based routing, nav rail, header, and notifications.

Usage

p := &platformd.Platform{
    AppName: "My App",
    Modules: []platformd.Module{
        {
            ID:      "home",
            Label:   "Home",
            Default: true,
            Icon:    svg.Icon("icon-home", "pd-nav-icon"),
            View:    &MyView{},
        },
    },
}
dom.Append("body", p)

Icons

Icons are SVG sprite references. Register them in your consumer's svg.go:

//go:build !wasm
package main

import "github.com/tinywasm/svg"
// or consume Platform's built-in icons (icon-home, icon-products, icon-info)

The platform registers icon-home, icon-products, icon-info by default via Platform.IconSvg().

CSS Tokens

See platformd/tokens.go for the full list of CSS custom properties. All visual customization should go through these tokens.

Documentation

Index

Constants

View Source
const (
	IconUser  = svg.Icon("pd-user")
	IconBrand = svg.Icon("pd-brand")
)
View Source
const NamePlatform widget.Name = "pd"

Variables

View Source
var (
	ClsNavIcon = NamePlatform.Class("nav-icon")
)

Functions

This section is empty.

Types

type Brand added in v0.1.2

type Brand interface {
	// BrandName is shown beside the mark, and is the mark's alt text.
	BrandName() string
	// BrandMark is a URL or inline SVG data URI. Empty is normal and expected:
	// the shell falls back to its own glyph, exactly as UserAvatar does.
	BrandMark() string
}

Brand is what the platform calls itself in its own chrome. The shell asks for a mark and a name; how they are drawn, sized and spaced is platformd's business.

It is a READ contract, not a store, mirroring Identity: platformd renders it and never mutates it. The consumer supplies facts, not presentation — a Brand never hands the shell an svg.Icon, because picking the sprite is a rendering decision this package owns (the same reasoning that keeps IconUser out of Identity).

type Duration added in v0.1.9

type Duration struct {
	// contains filtered or unexported fields
}

Duration is how long a notification stays before dismissing itself. A Duration is a DECISION, not a number: 0-as-persistent and -1-as-automatic were magic numbers nobody could read at the call site, and auto-sizing needs the message text that only Notify has.

func Auto added in v0.1.9

func Auto() Duration

Auto sizes the duration to the message: ~350ms per word plus ~1.2s to notice the toast, floored at 2s (a one-word confirmation is fully read in that time) and capped at 8s so a long message cannot hold the screen hostage. One word → 2s; three words → 2.25s; a 15-word error → 6.45s.

func For added in v0.1.9

func For(ms int) Duration

For pins an exact duration in milliseconds.

func Persistent added in v0.1.9

func Persistent() Duration

Persistent keeps the notification until the user dismisses it. The case for it is error reporting: a message that vanishes before it is read defeats the report (WCAG 2.2.1, Timing Adjustable — the user must be able to extend or disable a time limit).

type Identity added in v0.1.1

type Identity interface {
	// UserName is who is logged in.
	UserName() string
	// UserAvatar is the URL of their picture. Empty is normal and expected.
	UserAvatar() string
	// UserRoles are display names, not authorization codes. May be empty.
	UserRoles() []string
}

Identity is what the platform needs to know about whoever is logged in.

It is a READ contract, not a store: platformd renders it and never mutates it. Whatever owns authentication — github.com/tinywasm/user in a real application — supplies an implementation; the platform neither knows nor cares where the values come from.

It asks for facts, not for presentation. The glyph drawn when there is no avatar is IconUser, which this package owns — an authentication package has no business choosing a sprite, and asking it to would put a rendering decision behind a login.

Roles, plural, because they are plural: a user holds N of them and no ordering exists to say which one matters. Asking for a single "area" forced every implementation to pick arbitrarily, and that decision was invisible.

type Platform

type Platform struct {
	Element

	// AppName titles the drawer on a phone when there is no Brand to lead it —
	// the panel opens wholesale there and there is room for a line of text. The
	// collapsed rail never shows it: text with no icon beside it would have to
	// appear from nowhere when the rail expands.
	//
	// It is a fallback for a missing Brand, not a second header: a Brand
	// supersedes it in the drawer, since showing both would say the app's own
	// name twice in the same panel. A platform with neither renders no head at
	// all above the drawer's nav.
	AppName string

	// Brand is what the platform calls itself: the mark and the name at the
	// header's leading slot, mirrored at the head of the phone drawer where
	// there is no header to hold it. Tapping it — either surface — is the "go
	// home" control, landing on DefaultID (or the first viewable module).
	// Optional — a platform without a logo renders no brand slot, AppName
	// takes the drawer's head instead, and the header's message block stays
	// centred between nothing and the menu.
	Brand Brand

	// User is the logged-in identity. Required: the header's outer thirds and
	// the drawer's first entry are built from it.
	User Identity

	// UserActions slot — shown at the header RIGHT, next to the work-area name
	// (e.g. the light/dark theme toggle). Optional.
	// A factory, not a Component: the shell renders one menu per surface and a
	// single element cannot have two parents. Passing one instance put the same
	// element in both menus, which rendered twice with one id and left the copy
	// in the drawer inert.
	UserActions func() Component

	// Modules registered in order — appearance order in the nav rail.
	Modules []UIModule

	// CanView filters which modules the shell presents. nil = show all.
	CanView func(resource string) bool

	// DefaultID is the ModelName() of the module to show initially.
	// If empty, the first module is used.
	DefaultID string
	// contains filtered or unexported fields
}

Platform is the typed skeleton root.

func (*Platform) Activate

func (p *Platform) Activate(moduleID string)

Activate programmatically switches to a module by ID (also updates window.location.hash on wasm builds).

func (*Platform) IconSvg added in v0.0.5

func (p *Platform) IconSvg() *sprite.Sprite

IconSvg registers the default platform chrome glyphs: the identity fallback, the brand fallback and the menu button. The full page sprite is the MERGE of every module's IconSvg() (platformd + crudview + components + the demo modules), assembled by tinywasm/ssr and injected inline in <body>.

Content icons (what a module calls itself) live with their module, in platformd/modules/*: the chassis has no business drawing "home" or "devices".

func (*Platform) Init added in v0.0.6

func (p *Platform) Init(ctx Ctx)

Init initializes the platform state and routing.

func (*Platform) Notify

func (p *Platform) Notify(t MessageType, msg string, d Duration)

Notify queues a typed notification in both viewport slots (header on desktop, msg-stack on mobile). The duration is a decision, not a number: Auto() sizes it to the message, Persistent() leaves it until dismissed, For(ms) pins it. Errors are the one case that must not vanish on their own — hand them Persistent(), or a generous For().

func (*Platform) Render

func (p *Platform) Render() *Element

func (*Platform) RenderCSS

func (p *Platform) RenderCSS() *css.Stylesheet

RenderCSS implements the visual contract for platformd using the style DSL.

func (*Platform) RenderSheet added in v0.1.0

func (p *Platform) RenderSheet() *style.Sheet

RenderSheet returns the style Sheet containing the rules for platformd.

func (*Platform) WidgetKind added in v0.0.23

func (p *Platform) WidgetKind() widget.Kind

func (*Platform) WidgetName added in v0.0.23

func (p *Platform) WidgetName() widget.Name

type UIModule added in v0.0.7

type UIModule interface {
	layout.Module    // identity: ModelName() → used as ID
	Label() string   // text in the nav rail
	Icon() svg.Icon  // chassis renders via the sprite
	View() Component // module content (often a *rightpanel.RightPanel)
}

UIModule is a module that provides its UI to the platform chassis. The chassis takes id/hash/route from ModelName() and the rest of the presentation from these methods.

func NewUIModule added in v0.0.9

func NewUIModule(id, label string, icon svg.Icon, view Component) UIModule

NewUIModule returns a private implementation of UIModule.

Directories

Path Synopsis
modules
about
Package about es el módulo demo de una pantalla de información estática.
Package about es el módulo demo de una pantalla de información estática.
devices
Package devices es el módulo demo de un CRUD completo: modelo real, backend en memoria y crudview montado sobre él.
Package devices es el módulo demo de un CRUD completo: modelo real, backend en memoria y crudview montado sobre él.
medicalhistory
Package medicalhistory is a demo module: the same crudview.New pattern.
Package medicalhistory is a demo module: the same crudview.New pattern.

Jump to

Keyboard shortcuts

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