Documentation
¶
Overview ¶
Package ui is the browser half of the application: one stylesheet and small browser controllers, served as static files beside the API.
The stylesheet is a Go value ¶
There is no CSS build. ui/components declares every class list it renders with; ui/style resolves exactly those classes to rules; design supplies the tokens they are written in terms of. Compose folds the three, plus whatever a consumer adds, into one Sheet, and a Sheet is bytes and their fingerprint.
A consumer calls Compose once, at mount, and carries the Sheet in its chrome. Nothing is memoised here because nothing is called twice: the value is the cache. That is also why a second consumer needs no machinery of its own — the first client storefront copied a memo, an in-memory file and an overlay tree to add fourteen class lists, and appended its resolution to the kernel's bytes, so a shared utility had two rules.
Application controllers ¶
htmx is vendored, minified, under its MIT licence, and it is the only third-party script in application pages. The optional Storybook.js development interface is built separately under ui/storybook and served through authorization. The application enhancements live in assets/js, listed in Controllers.
What is not here ¶
Design snapshots, token export, proposals and the storybook composition are ui/export. This package is what a shell needs to serve a page and nothing a design tool needs, so ui/page depends on it without linking the tooling.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Controllers = []string{
"htmx.min.js",
"htmx-config.js",
"theme.js",
"confirm.js",
"session.js",
"components.js",
"gallery.js",
}
Controllers are the browser scripts a page loads, in order. The list is here rather than in the shell that writes the <script> tags, so that "how much JavaScript is there" is answered by reading one slice.
htmx is first because the others configure it. The remaining scripts enhance themes, requests, confirmation, sign-in, component interaction and gallery controls.
var Gallery = sync.OnceValue(func() Sheet { shell := emitted(components.ShellClassLists()) var only []string for _, name := range emitted(components.GalleryClassLists()) { if !slices.Contains(shell, name) { only = append(only, name) } } rules, err := style.Rules(only...) if err != nil { panic("ui: the gallery declares a class the style engine cannot render: " + err.Error()) } return fingerprinted(css.NewSheet().Merge(rules)) })
Gallery is the second sheet: the rules for the classes only the gallery's own components emit and app.css therefore does not carry. It is the difference and not the whole set — the two share most of the utility alphabet, and a second copy of .flex would make the pair bigger than the one sheet it replaced.
It carries no tokens, no roles and no base layer: it is loaded beside app.css, never instead of it, and it is the same bytes whatever the palette, because a utility rule is written in terms of a role and a role is written in terms of a token. That is why it takes no theme, and why it is computed once.
Functions ¶
Types ¶
type Extra ¶ added in v1.1.0
Extra is what one consumer adds to the kernel's sheet: the class lists its own markup renders with, resolved by ui/style exactly as the components' are, and the rules no class can express — an attribute selector for a client's grain, a keyframe for an animation.
type Sheet ¶ added in v1.1.0
Sheet is a composed stylesheet: the bytes a browser downloads and the first eight bytes of their SHA-256 as hex. A page puts the fingerprint in the asset's query string, so a deploy that changes a rule — or a client that changes a colour — changes the URL and a browser that cached the old one asks again.
func Compose ¶ added in v1.1.0
Compose is every page's stylesheet in one palette: that palette's tokens, the role variables, the small base layer, one rule per class the components and the extras declare, and then the extras' own rules. It is a pure function of its arguments. Call it once and keep the value.
The components' lists and the extras' lists are resolved together, which is what gives a shared utility one rule: a consumer that appended its own resolution to the kernel's bytes emitted .flex twice.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package web renders pk-ui component contracts to HTML with gomponents, styled entirely through tw class lists against the PlatformKit design system's role variables.
|
Package web renders pk-ui component contracts to HTML with gomponents, styled entirely through tw class lists against the PlatformKit design system's role variables. |
|
examples
Package examples captures component constructor invocations as typed examples and describes them: Props as JSON Schema, named slots, observed HTML and child occurrences, derived by reflection from the actual Go inputs.
|
Package examples captures component constructor invocations as typed examples and describes them: Props as JSON Schema, named slots, observed HTML and child occurrences, derived by reflection from the actual Go inputs. |
|
Package css is the CSS intermediate representation the stylesheet is built in: typed values, declarations, rules, custom properties and the two at-rules the design system uses.
|
Package css is the CSS intermediate representation the stylesheet is built in: typed values, declarations, rules, custom properties and the two at-rules the design system uses. |
|
Package document is an HTML document as values: what every page of a shell shares (Chrome), what a render may know about the caller (Request), what a handler returned (View), and Document, which puts them together around the body a frame arranged.
|
Package document is an HTML document as values: what every page of a shell shares (Chrome), what a render may know about the caller (Request), what a handler returned (View), and Document, which puts them together around the body a frame arranged. |
|
Package export is the design-tooling half of ui: content-addressed snapshots of the composed components (Export, ExportWithLayout), token export in the DTCG interchange format (ExportTokens, TokenExport.DTCG), typed proposals applied to source captures (ProjectProps, ProjectReplacement), and the Storybook a shell serves so a person can browse the same composition.
|
Package export is the design-tooling half of ui: content-addressed snapshots of the composed components (Export, ExportWithLayout), token export in the DTCG interchange format (ExportTokens, TokenExport.DTCG), typed proposals applied to source captures (ProjectProps, ProjectReplacement), and the Storybook a shell serves so a person can browse the same composition. |
|
Package forms composes portable entity forms from detached presentation inputs.
|
Package forms composes portable entity forms from detached presentation inputs. |
|
Package icon is the glyph set the components draw with: the regular-weight Phosphor subset this application uses, vendored as path data.
|
Package icon is the glyph set the components draw with: the regular-weight Phosphor subset this application uses, vendored as path data. |
|
Package page is how a shell turns a screen into an HTML document.
|
Package page is how a shell turns a screen into an HTML document. |
|
Package resource renders the screens of a schema-described resource — the list, the detail and the two forms — from plain values: the entity's schema, the rows a handler read, and the words the request's locale chose.
|
Package resource renders the screens of a schema-described resource — the list, the detail and the two forms — from plain values: the entity's schema, the rows a handler read, and the words the request's locale chose. |
|
Package screens generates the screens of any resource kit/rest registered, for any shell that mounts them: the list, the detail, the two forms, the two writes and the delete.
|
Package screens generates the screens of any resource kit/rest registered, for any shell that mounts them: the list, the detail, the two forms, the two writes and the delete. |
|
Package source verifies and persists bounded edits to captured Go properties.
|
Package source verifies and persists bounded edits to captured Go properties. |