platformd

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 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 (
	IconHome     = svg.Icon("home")
	IconProducts = svg.Icon("products")
	IconInfo     = svg.Icon("info")
	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 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, where the panel opens wholesale and
	// there is room for it. The collapsed rail never shows it: text with no icon
	// beside it would have to appear from nowhere when the rail expands.
	//
	// It is NOT the header brand: AppName belongs to the phone drawer and Brand
	// belongs to the desktop header, two surfaces of which only one exists at a
	// time. A Brand does not supersede it and it is not a fallback for a missing
	// Brand — a platform without a Brand renders no header brand slot at all.
	AppName string

	// Brand is what the platform calls itself in the header's leading slot:
	// the mark and the name at the header's start, mirrored against the user
	// menu at its end. Optional — a platform without a logo renders no brand
	// slot and the 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 navigation icons. The full page sprite is the MERGE of every module's IconSvg() (platformd + crudview + components), assembled by tinywasm/ssr and injected inline in <body>.

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, durationMs int)

Notify queues a typed notification in the proper viewport slot. Any non-zero durationMs → schedule dismissal; duration 0 → persistent message.

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

Jump to

Keyboard shortcuts

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