oficina / estilo Public

Clone
git clone https://amadan.net/oficina/estilo

Plain git — no account needed to clone.

Download

Download this file

1{{/* estilo-bar: the whole app header, one row at every width unless it
2 is stacked.
3
4 Data: chrome.Bar. Parse this package's templates together with
5 menu.Templates() and the app's own layout. The skip link and <main>
6 are the layout's; this is only the <header>.
7
8 Stacked (Bar.Menubar set, estilo-bar~="stacked"): the title and the
9 app's menu bar share [estilo-bar-stack], the title over the menus.
10 From 800px that is the 56px header; below it the stack dissolves
11 (display: contents) and the menus become a full-width second row, so
12 the markup is the same at every width.
13
14 Order in the end group is fixed in every app: the lead (Bar.Lead),
15 actions, then Menu (narrow only) or a compact bar's trail, then the
16 switcher, then the account. The account is always the last thing at
17 the inline end.
18
19 Compact (Bar.Compact set, estilo-bar~="compact"): below 704px the
20 phone's one row, Back (the brand, with a chevron before it), the
21 title or Compact.Title, the lead and Compact.Trail. A compact bar
22 draws the Menu sheet only for its nav (Bar.Nav), before the trail,
23 so the nav is never out of reach: the trail is the overflow for
24 everything else, the actions included.
25
26 The brand is a link to the app root, except on public read-only
27 pages, where App.Home is empty and it is plain text. */}}
28{{define "estilo-bar"}}<header estilo-bar{{with .Kind}}="{{.}}"{{end}}>
29 {{- if .App.Home}}
30 <a estilo-bar-brand href="{{.App.Home}}">{{if .Compact}}{{template "estilo-icon-back"}}{{end}}<img estilo-brand-icon src="{{.App.Icon}}" alt="" width="28" height="28"><span estilo-bar-name>{{.App.Name}}</span></a>
31 {{- else}}
32 <span estilo-bar-brand><img estilo-brand-icon src="{{.App.Icon}}" alt="" width="28" height="28"><span estilo-bar-name>{{.App.Name}}</span></span>
33 {{- end}}
34 {{- if .Menubar}}
35 <div estilo-bar-stack>
36 {{- with .ContextEdit}}
37 {{template "estilo-bar-title-fit" .}}
38 {{- else}}{{with .Context}}
39 <span estilo-bar-context dir="auto" title="{{.}}">{{.}}</span>
40 {{- end}}{{end}}
41 <div estilo-bar-menubar>{{.Menubar}}</div>
42 </div>
43 {{- else}}
44 {{- with .ContextEdit}}
45 {{template "estilo-bar-title" .}}
46 {{- else}}{{with .Context}}
47 <span estilo-bar-context dir="auto" title="{{.}}">{{.}}</span>
48 {{- end}}{{end}}
49 {{- end}}
50 {{- with .Compact}}{{with .Title}}
51 <div estilo-bar-compact-title>{{.}}</div>
52 {{- end}}{{end}}
53 {{- if .Nav}}
54 <nav estilo-bar-nav aria-label="{{.NavLabel}}">
55 {{- range .Nav}}<a href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}>{{.Label}}</a>{{end}}
56 </nav>
57 {{- end}}
58 <div estilo-bar-end>
59 {{- with .Lead}}
60 <div estilo-bar-lead>{{.}}</div>
61 {{- end}}
62 {{- if .Actions}}
63 <div estilo-bar-actions>{{template "estilo-bar-actions" .}}</div>
64 {{- end}}
65 {{- $sheet := false}}{{range .Actions}}{{if not .WideOnly}}{{$sheet = true}}{{end}}{{end}}
66 {{- if or .Nav (and (not .Compact) $sheet)}}
67 <details estilo-bar-more name="estilo-menus">
68 <summary estilo-bar-trigger>{{template "estilo-icon-menu"}}<span>{{.Labels.Menu}}</span></summary>
69 <div estilo-menu="sheet">
70 {{- range .Nav}}<a estilo-menu-item href="{{.Href}}"{{if .Current}} aria-current="page"{{end}}><span estilo-menu-label>{{.Label}}</span></a>{{end}}
71 {{- if and .Nav $sheet}}<hr>{{end}}
72 {{- range .Actions}}{{if not .WideOnly}}{{template "estilo-menu-item" .Item}}{{end}}{{end}}
73 </div>
74 </details>
75 {{- end}}
76 {{- with .Compact}}
77 <div estilo-bar-trail>{{.Trail}}</div>
78 {{- end}}
79 {{- with .Switcher}}
80 {{template "estilo-switcher" .}}
81 {{- end}}
82 {{- if .Account}}
83 {{template "estilo-account" .Account}}
84 {{- else}}{{with .SignIn}}
85 <a rst-btn href="{{.Href}}" estilo-bar-signin>{{.Label}}</a>
86 {{- end}}{{end}}
87 </div>
88</header>{{end}}
89
90{{/* estilo-bar-actions: the wide-screen actions, from Bar.Actions, each
91 the element its Item names: a link, a one-button POST form, a button
92 opening a dialog, or a toggle (aria-expanded, aria-controls) rendered
93 disabled until the app's script binds it. The same items are rows in
94 the narrow Menu sheet, so both stay one list; a WideOnly action is
95 marked estilo-bar-wide, hidden below 64rem, and left out of the
96 sheet. An app may redefine this after parsing to change how they are
97 drawn, but the sheet always renders Bar.Actions.
98
99 In a bar with a slot (Menubar or Lead) each action sits in its own
100 <div estilo-bar-control> (display: contents), "primary" for the
101 primary one and "wide" for a WideOnly one: the hooks the controls set
102 is styled on, since estilo's CSS never selects rastrillo's rst-
103 attributes (AGENTS.md, the prefix rule). A bar with no slot draws the
104 actions bare, as it always has. */}}
105{{define "estilo-bar-actions"}}{{$controls := or .Menubar .Lead}}{{range .Actions}}{{if $controls}}<div estilo-bar-control{{if and .Primary .WideOnly}}="primary wide"{{else if .Primary}}="primary"{{else if .WideOnly}}="wide"{{end}}>{{template "estilo-bar-action" .}}</div>{{else}}{{template "estilo-bar-action" .}}{{end}}{{end}}{{end}}
106{{define "estilo-bar-action"}}{{if .Action}}<form method="post" action="{{.Action}}"{{if .WideOnly}} estilo-bar-wide{{end}}><button rst-btn{{if .Primary}}="primary"{{end}} type="submit"{{template "estilo-bar-action-name" .}}>{{template "estilo-bar-action-face" .}}</button></form>{{else if .Dialog}}<button rst-btn{{if .Primary}}="primary"{{end}} type="button" commandfor="{{.Dialog}}" command="show-modal"{{if .WideOnly}} estilo-bar-wide{{end}}{{template "estilo-bar-action-name" .}}>{{template "estilo-bar-action-face" .}}</button>{{else if .Controls}}<button rst-btn{{if .Primary}}="primary"{{end}} type="button" aria-expanded="{{if .Expanded}}true{{else}}false{{end}}" aria-controls="{{.Controls}}" disabled data-estilo-toggle{{if .WideOnly}} estilo-bar-wide{{end}}{{template "estilo-bar-action-name" .}}>{{template "estilo-bar-action-face" .}}</button>{{else}}<a rst-btn{{if .Primary}}="primary"{{end}} href="{{.Href}}"{{if .WideOnly}} estilo-bar-wide{{end}}{{template "estilo-bar-action-name" .}}>{{template "estilo-bar-action-face" .}}</a>{{end}}{{end}}
107
108{{/* estilo-bar-action-name and -face: what an action's control says.
109 Most show their icon and label. An IconOnly one (Action.IconOnly)
110 shows its icon alone, carries its label as aria-label, and shows
111 the label and Key as a tooltip on hover and focus (rastrillo's
112 rst-tip, drawn from the estilo-bar-icon box). KeyShortcuts, when
113 set, is the control's aria-keyshortcuts. IconOnly with no Icon
114 draws the label as usual: a control is never left empty. Neither
115 writes a byte for an action that sets none of these. */}}
116{{define "estilo-bar-action-name"}}{{with .KeyShortcuts}} aria-keyshortcuts="{{.}}"{{end}}{{if and .IconOnly .Icon}} aria-label="{{.Label}}" estilo-bar-icon rst-tip data-tip="{{.Label}}{{with .Key}} {{.}}{{end}}"{{end}}{{end}}
117{{define "estilo-bar-action-face"}}{{.Icon}}{{if not (and .IconOnly .Icon)}}{{.Label}}{{end}}{{end}}
118
119{{/* estilo-bar-title: the open object's title, editable in place. A real
120 form, so Enter renames with scripts off. The submit button is visually
121 hidden until the form has focus. Data: chrome.TitleEdit. */}}
122{{define "estilo-bar-title"}}<form estilo-bar-title method="post" action="{{.Action}}">
123 <input estilo-bar-title-input name="{{.Name}}" value="{{.Value}}" aria-label="{{.Label}}" autocomplete="off" spellcheck="false" dir="auto">
124 <button rst-btn="ghost" type="submit" estilo-bar-title-submit>{{.Submit}}</button>
125 </form>{{end}}
126
127{{/* estilo-bar-title-fit: the same form in a stacked bar, where the field
128 is as wide as its title: the size attribute (TitleEdit.Size) is the
129 first paint's approximation, and chrome.js measures the field and
130 corrects it. It differs from estilo-bar-title only by that attribute
131 (TestTheFittedTitleIsTheTitlePlusASize). Data: chrome.TitleEdit. */}}
132{{define "estilo-bar-title-fit"}}<form estilo-bar-title method="post" action="{{.Action}}">
133 <input estilo-bar-title-input name="{{.Name}}" value="{{.Value}}" size="{{.Size}}" aria-label="{{.Label}}" autocomplete="off" spellcheck="false" dir="auto">
134 <button rst-btn="ghost" type="submit" estilo-bar-title-submit>{{.Submit}}</button>
135 </form>{{end}}
136