@firstprateek/vastu 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/custom-elements.json +691 -0
- package/dist/dev/all.d.ts +3 -0
- package/dist/dev/all.d.ts.map +1 -1
- package/dist/dev/all.js +3 -0
- package/dist/dev/all.js.map +1 -1
- package/dist/dev/bar-chart/bar-chart.d.ts +63 -0
- package/dist/dev/bar-chart/bar-chart.d.ts.map +1 -0
- package/dist/dev/bar-chart/bar-chart.js +316 -0
- package/dist/dev/bar-chart/bar-chart.js.map +1 -0
- package/dist/dev/bar-chart/index.d.ts +3 -0
- package/dist/dev/bar-chart/index.d.ts.map +1 -0
- package/dist/dev/bar-chart/index.js +5 -0
- package/dist/dev/bar-chart/index.js.map +1 -0
- package/dist/dev/core/cssom.d.ts +15 -0
- package/dist/dev/core/cssom.d.ts.map +1 -0
- package/dist/dev/core/cssom.js +30 -0
- package/dist/dev/core/cssom.js.map +1 -0
- package/dist/dev/navbar/index.d.ts +3 -0
- package/dist/dev/navbar/index.d.ts.map +1 -0
- package/dist/dev/navbar/index.js +5 -0
- package/dist/dev/navbar/index.js.map +1 -0
- package/dist/dev/navbar/navbar.d.ts +69 -0
- package/dist/dev/navbar/navbar.d.ts.map +1 -0
- package/dist/dev/navbar/navbar.js +353 -0
- package/dist/dev/navbar/navbar.js.map +1 -0
- package/dist/dev/poll/index.d.ts +3 -0
- package/dist/dev/poll/index.d.ts.map +1 -0
- package/dist/dev/poll/index.js +5 -0
- package/dist/dev/poll/index.js.map +1 -0
- package/dist/dev/poll/poll.d.ts +67 -0
- package/dist/dev/poll/poll.d.ts.map +1 -0
- package/dist/dev/poll/poll.js +301 -0
- package/dist/dev/poll/poll.js.map +1 -0
- package/dist/prod/all.js +3 -0
- package/dist/prod/bar-chart/bar-chart.js +316 -0
- package/dist/prod/bar-chart/index.js +5 -0
- package/dist/prod/core/cssom.js +30 -0
- package/dist/prod/navbar/index.js +5 -0
- package/dist/prod/navbar/navbar.js +353 -0
- package/dist/prod/poll/index.js +5 -0
- package/dist/prod/poll/poll.js +301 -0
- package/package.json +18 -3
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Directive, directive, PartType } from 'lit/directive.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sets inline styles through the CSSOM (element.style), never through a style attribute, so a
|
|
4
|
+
* strict Content Security Policy allows them. Lit's styleMap writes a style attribute on the first
|
|
5
|
+
* render, which `style-src 'self'` blocks. Use it in an element position: <span ${cssom({ … })}>.
|
|
6
|
+
*/
|
|
7
|
+
class CssomDirective extends Directive {
|
|
8
|
+
#previous = new Set();
|
|
9
|
+
constructor(part) {
|
|
10
|
+
super(part);
|
|
11
|
+
if (part.type !== PartType.ELEMENT)
|
|
12
|
+
throw new Error('cssom() goes in an element position: <div ${cssom({…})}>.');
|
|
13
|
+
}
|
|
14
|
+
render(styles) {
|
|
15
|
+
void styles;
|
|
16
|
+
return undefined;
|
|
17
|
+
}
|
|
18
|
+
update(part, [styles]) {
|
|
19
|
+
const style = part.element.style;
|
|
20
|
+
for (const name of this.#previous)
|
|
21
|
+
if (!(name in styles))
|
|
22
|
+
style.removeProperty(name);
|
|
23
|
+
for (const [name, value] of Object.entries(styles))
|
|
24
|
+
style.setProperty(name, value);
|
|
25
|
+
this.#previous = new Set(Object.keys(styles));
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const cssom = directive(CssomDirective);
|
|
30
|
+
//# sourceMappingURL=cssom.js.map
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import { LitElement, css, html, nothing } from 'lit';
|
|
2
|
+
import { focusRing } from '../core/focus-ring.js';
|
|
3
|
+
import { checkTokensLoaded, devWarn } from '../core/warn.js';
|
|
4
|
+
/**
|
|
5
|
+
* A site's main navigation bar: a brand link and links to pages. On narrow screens the links fold
|
|
6
|
+
* behind a Menu button, following the WAI-ARIA disclosure navigation pattern.
|
|
7
|
+
*
|
|
8
|
+
* @tag va-navbar
|
|
9
|
+
* @summary Shows a site's brand and main links in a bar that folds behind a Menu button on narrow screens.
|
|
10
|
+
*
|
|
11
|
+
* @slot - The links, as `<a href="…">` elements. Mark the current page's link with `aria-current="page"`.
|
|
12
|
+
* @slot brand - The site's name or logo, as an `<a href="…">` to the home page.
|
|
13
|
+
*
|
|
14
|
+
* @cssstate collapsed - The links are folded behind the Menu button.
|
|
15
|
+
*
|
|
16
|
+
* @csspart bar - The bar, which is the `<nav>` element.
|
|
17
|
+
* @csspart toggle - The Menu button shown on narrow screens.
|
|
18
|
+
* @csspart links - The wrapper around the links. On narrow screens it is the panel that opens.
|
|
19
|
+
*
|
|
20
|
+
* @cssprop {<color>} --va-navbar-bg - Background colour of the bar and of the open panel.
|
|
21
|
+
* @cssprop {<color>} --va-navbar-border - Colour of the line under the bar.
|
|
22
|
+
* @cssprop {<length>} --va-navbar-size - Minimum height of the bar.
|
|
23
|
+
* @cssprop {<color>} --va-navbar-link-fg - Text colour of the links.
|
|
24
|
+
* @cssprop {<color>} --va-navbar-indicator-border - Colour of the line that marks the current page's link.
|
|
25
|
+
*
|
|
26
|
+
* @cssprop-applies --va-navbar-bg bar background-color
|
|
27
|
+
* @cssprop-applies --va-navbar-border bar border-bottom-color
|
|
28
|
+
* @cssprop-applies --va-navbar-size bar min-height
|
|
29
|
+
* @cssprop-applies --va-navbar-link-fg light(a:not([slot]):not([aria-current])) color
|
|
30
|
+
* @cssprop-applies --va-navbar-indicator-border light([aria-current="page"]) border-bottom-color
|
|
31
|
+
*
|
|
32
|
+
* @keyboard open: Escape | closes | Closes the open panel of links and returns focus to the Menu button.
|
|
33
|
+
*
|
|
34
|
+
* @a11y-role navigation
|
|
35
|
+
* @a11y-name-from accessible-label
|
|
36
|
+
* @a11y-name The `accessible-label` attribute, such as "Main" (not shown). Needed when a page has more than one navigation landmark.
|
|
37
|
+
* @a11y-note The bar is a `<nav>` landmark. The links keep their own names; mark the current page with `aria-current="page"`.
|
|
38
|
+
* @a11y-note Style the folded layout with `va-navbar:state(collapsed)`.
|
|
39
|
+
* @a11y-note On narrow screens the Menu button has a visible label, `aria-expanded` and `aria-controls`. Escape, a click outside or moving focus away closes the panel.
|
|
40
|
+
*
|
|
41
|
+
* @guidance-use For a site's or app's main navigation: a brand link and up to about seven links to pages.
|
|
42
|
+
* @guidance-avoid For actions that do something on the page, for switching views in one place, or for deep hierarchies of pages.
|
|
43
|
+
* @guidance-instead `va-menu` for actions; `va-tabs` for views in one place; nested lists in a sidebar for deep navigation.
|
|
44
|
+
*/
|
|
45
|
+
export class VaNavbar extends LitElement {
|
|
46
|
+
static { this.properties = {
|
|
47
|
+
open: { type: Boolean, reflect: true },
|
|
48
|
+
collapseBelow: { type: Number, attribute: 'collapse-below' },
|
|
49
|
+
toggleLabel: { attribute: 'toggle-label' },
|
|
50
|
+
accessibleLabel: { attribute: 'accessible-label' },
|
|
51
|
+
_collapsed: { state: true },
|
|
52
|
+
}; }
|
|
53
|
+
#internals;
|
|
54
|
+
#width = 0;
|
|
55
|
+
#resize = new ResizeObserver(([entry]) => {
|
|
56
|
+
this.#width = entry.contentRect.width;
|
|
57
|
+
this.#measure();
|
|
58
|
+
});
|
|
59
|
+
constructor() {
|
|
60
|
+
super();
|
|
61
|
+
this.open = false;
|
|
62
|
+
this.collapseBelow = 600;
|
|
63
|
+
this.toggleLabel = 'Menu';
|
|
64
|
+
this.accessibleLabel = '';
|
|
65
|
+
this._collapsed = false;
|
|
66
|
+
this.#internals = this.attachInternals();
|
|
67
|
+
}
|
|
68
|
+
connectedCallback() {
|
|
69
|
+
super.connectedCallback();
|
|
70
|
+
checkTokensLoaded(this);
|
|
71
|
+
this.#resize.observe(this);
|
|
72
|
+
// Moved while open: disconnectedCallback removed the document listeners, and open hasn't changed.
|
|
73
|
+
if (this.open)
|
|
74
|
+
this.#listen(true);
|
|
75
|
+
}
|
|
76
|
+
disconnectedCallback() {
|
|
77
|
+
super.disconnectedCallback();
|
|
78
|
+
this.#resize.disconnect();
|
|
79
|
+
this.#listen(false);
|
|
80
|
+
}
|
|
81
|
+
firstUpdated() {
|
|
82
|
+
// Measure before the first paint, so a phone never sees the wide layout flash.
|
|
83
|
+
this.#width = this.getBoundingClientRect().width;
|
|
84
|
+
this.#measure();
|
|
85
|
+
}
|
|
86
|
+
willUpdate(changed) {
|
|
87
|
+
if (changed.has('collapseBelow'))
|
|
88
|
+
this.#measure();
|
|
89
|
+
// Unfolding closes the panel, so it isn't open next time the navbar folds.
|
|
90
|
+
if (changed.has('_collapsed') && !this._collapsed && changed.get('_collapsed') === true)
|
|
91
|
+
this.open = false;
|
|
92
|
+
}
|
|
93
|
+
updated(changed) {
|
|
94
|
+
if (changed.has('open'))
|
|
95
|
+
this.#listen(this.open);
|
|
96
|
+
if (changed.has('_collapsed')) {
|
|
97
|
+
try {
|
|
98
|
+
if (this._collapsed)
|
|
99
|
+
this.#internals.states.add('collapsed');
|
|
100
|
+
else
|
|
101
|
+
this.#internals.states.delete('collapsed');
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
// Browsers without CustomStateSet: the state is only for authors' styling.
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
#measure() {
|
|
109
|
+
if (this.#width)
|
|
110
|
+
this._collapsed = this.#width < this.collapseBelow;
|
|
111
|
+
}
|
|
112
|
+
#listen(on) {
|
|
113
|
+
if (on) {
|
|
114
|
+
document.addEventListener('keydown', this.#onDocumentKeydown);
|
|
115
|
+
document.addEventListener('pointerdown', this.#onDocumentPointerdown);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
document.removeEventListener('keydown', this.#onDocumentKeydown);
|
|
119
|
+
document.removeEventListener('pointerdown', this.#onDocumentPointerdown);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
get #toggle() {
|
|
123
|
+
return this.shadowRoot?.querySelector('[part="toggle"]') ?? null;
|
|
124
|
+
}
|
|
125
|
+
#onDocumentKeydown = (event) => {
|
|
126
|
+
if (event.key !== 'Escape' || !this.open)
|
|
127
|
+
return;
|
|
128
|
+
const hadFocus = this.matches(':focus-within');
|
|
129
|
+
this.open = false;
|
|
130
|
+
if (hadFocus && this._collapsed)
|
|
131
|
+
this.#toggle?.focus();
|
|
132
|
+
};
|
|
133
|
+
#onDocumentPointerdown = (event) => {
|
|
134
|
+
if (!event.composedPath().includes(this))
|
|
135
|
+
this.open = false;
|
|
136
|
+
};
|
|
137
|
+
#onFocusout(event) {
|
|
138
|
+
const next = event.relatedTarget;
|
|
139
|
+
if (this._collapsed && this.open && next && !this.contains(next) && !this.shadowRoot.contains(next))
|
|
140
|
+
this.open = false;
|
|
141
|
+
}
|
|
142
|
+
#onLinksClick(event) {
|
|
143
|
+
// Following a link closes the panel, so it isn't left open over the page that loads.
|
|
144
|
+
if (this._collapsed && event.composedPath().some((n) => n.localName === 'a'))
|
|
145
|
+
this.open = false;
|
|
146
|
+
}
|
|
147
|
+
#onSlotchange = () => {
|
|
148
|
+
for (const link of this.querySelectorAll(':scope > a:not([href])')) {
|
|
149
|
+
devWarn('va-navbar', `The link "${link.textContent?.trim()}" has no href, so it can't be reached with the keyboard.`, 'Give every link an href (e.g. <a href="/work">Work</a>).');
|
|
150
|
+
}
|
|
151
|
+
if ([...this.children].some((c) => !c.slot && c.localName !== 'a')) {
|
|
152
|
+
devWarn('va-navbar', 'Something other than a link is in the navbar.', 'Put only <a href="…"> elements in va-navbar; use va-menu or va-button for actions.');
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
render() {
|
|
156
|
+
const folded = this._collapsed;
|
|
157
|
+
return html `
|
|
158
|
+
<nav part="bar" class=${folded ? 'bar collapsed' : 'bar'} aria-label=${this.accessibleLabel || nothing} @focusout=${this.#onFocusout}>
|
|
159
|
+
<div class="brand"><slot name="brand"></slot></div>
|
|
160
|
+
<button
|
|
161
|
+
part="toggle"
|
|
162
|
+
class="toggle"
|
|
163
|
+
type="button"
|
|
164
|
+
?hidden=${!folded}
|
|
165
|
+
aria-expanded=${this.open ? 'true' : 'false'}
|
|
166
|
+
aria-controls="links"
|
|
167
|
+
@click=${() => (this.open = !this.open)}
|
|
168
|
+
>
|
|
169
|
+
<span class="icon" aria-hidden="true"><span></span><span></span><span></span></span>
|
|
170
|
+
${this.toggleLabel}
|
|
171
|
+
</button>
|
|
172
|
+
<div part="links" id="links" class=${this.open ? 'links open' : 'links'} @click=${this.#onLinksClick}>
|
|
173
|
+
<slot @slotchange=${this.#onSlotchange}></slot>
|
|
174
|
+
</div>
|
|
175
|
+
</nav>
|
|
176
|
+
`;
|
|
177
|
+
}
|
|
178
|
+
static { this.styles = [
|
|
179
|
+
focusRing,
|
|
180
|
+
css `
|
|
181
|
+
:host {
|
|
182
|
+
display: block;
|
|
183
|
+
box-sizing: border-box;
|
|
184
|
+
width: 100%;
|
|
185
|
+
position: relative;
|
|
186
|
+
z-index: 1;
|
|
187
|
+
font-family: var(--va-font-family-ui);
|
|
188
|
+
font-size: var(--va-font-size-md);
|
|
189
|
+
}
|
|
190
|
+
:host([hidden]) {
|
|
191
|
+
display: none;
|
|
192
|
+
}
|
|
193
|
+
.bar {
|
|
194
|
+
position: relative;
|
|
195
|
+
box-sizing: border-box;
|
|
196
|
+
display: flex;
|
|
197
|
+
align-items: center;
|
|
198
|
+
gap: var(--va-space-inline-lg);
|
|
199
|
+
min-height: var(--va-navbar-size, 3.5rem);
|
|
200
|
+
padding: 0 var(--va-space-inline-lg);
|
|
201
|
+
border-bottom: 1px solid var(--va-navbar-border, var(--va-color-border-subtle));
|
|
202
|
+
background-color: var(--va-navbar-bg, var(--va-color-surface-default));
|
|
203
|
+
color: var(--va-color-text-default);
|
|
204
|
+
}
|
|
205
|
+
.brand {
|
|
206
|
+
flex: none;
|
|
207
|
+
margin-inline-end: auto;
|
|
208
|
+
}
|
|
209
|
+
::slotted([slot='brand']) {
|
|
210
|
+
color: inherit;
|
|
211
|
+
font-size: var(--va-font-size-lg);
|
|
212
|
+
font-weight: var(--va-font-weight-bold);
|
|
213
|
+
text-decoration: none;
|
|
214
|
+
}
|
|
215
|
+
.links {
|
|
216
|
+
display: flex;
|
|
217
|
+
align-items: stretch;
|
|
218
|
+
align-self: stretch;
|
|
219
|
+
gap: var(--va-space-gap-sm);
|
|
220
|
+
}
|
|
221
|
+
slot:not([name])::slotted(a) {
|
|
222
|
+
display: flex;
|
|
223
|
+
align-items: center;
|
|
224
|
+
padding: 0 var(--va-space-inline-sm);
|
|
225
|
+
border-top: 2px solid transparent;
|
|
226
|
+
border-bottom: 2px solid transparent;
|
|
227
|
+
color: var(--va-navbar-link-fg, var(--va-color-text-muted));
|
|
228
|
+
font-weight: var(--va-font-weight-medium);
|
|
229
|
+
text-decoration: none;
|
|
230
|
+
}
|
|
231
|
+
slot:not([name])::slotted(a:hover) {
|
|
232
|
+
color: var(--va-color-text-default);
|
|
233
|
+
}
|
|
234
|
+
slot:not([name])::slotted([aria-current='page']) {
|
|
235
|
+
border-bottom-color: var(--va-navbar-indicator-border, var(--va-color-accent-default));
|
|
236
|
+
color: var(--va-color-text-default);
|
|
237
|
+
}
|
|
238
|
+
::slotted(a:focus-visible) {
|
|
239
|
+
outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
|
|
240
|
+
outline-offset: -2px;
|
|
241
|
+
border-radius: var(--va-radius-control);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/* Folded: brand and Menu button in the bar, the links in a panel under it. */
|
|
245
|
+
.toggle {
|
|
246
|
+
display: inline-flex;
|
|
247
|
+
align-items: center;
|
|
248
|
+
gap: var(--va-space-gap-md);
|
|
249
|
+
min-height: var(--va-size-control-md);
|
|
250
|
+
margin: 0 calc(-1 * var(--va-space-inline-sm));
|
|
251
|
+
padding: 0 var(--va-space-inline-sm);
|
|
252
|
+
border: none;
|
|
253
|
+
border-radius: var(--va-radius-control);
|
|
254
|
+
background: transparent;
|
|
255
|
+
color: inherit;
|
|
256
|
+
font: inherit;
|
|
257
|
+
font-weight: var(--va-font-weight-medium);
|
|
258
|
+
cursor: pointer;
|
|
259
|
+
}
|
|
260
|
+
.toggle[hidden] {
|
|
261
|
+
display: none;
|
|
262
|
+
}
|
|
263
|
+
.toggle:hover {
|
|
264
|
+
background: var(--va-color-surface-subtle);
|
|
265
|
+
}
|
|
266
|
+
.icon {
|
|
267
|
+
position: relative;
|
|
268
|
+
width: 1.125rem;
|
|
269
|
+
height: 0.875rem;
|
|
270
|
+
}
|
|
271
|
+
.icon span {
|
|
272
|
+
position: absolute;
|
|
273
|
+
left: 0;
|
|
274
|
+
width: 100%;
|
|
275
|
+
height: 2px;
|
|
276
|
+
border-radius: 1px;
|
|
277
|
+
background: currentColor;
|
|
278
|
+
transition:
|
|
279
|
+
transform var(--va-motion-duration-fast) ease-out,
|
|
280
|
+
opacity var(--va-motion-duration-fast) ease-out;
|
|
281
|
+
}
|
|
282
|
+
.icon span:nth-child(1) {
|
|
283
|
+
top: 0;
|
|
284
|
+
}
|
|
285
|
+
.icon span:nth-child(2) {
|
|
286
|
+
top: calc(50% - 1px);
|
|
287
|
+
}
|
|
288
|
+
.icon span:nth-child(3) {
|
|
289
|
+
bottom: 0;
|
|
290
|
+
}
|
|
291
|
+
[aria-expanded='true'] .icon span:nth-child(1) {
|
|
292
|
+
transform: translateY(0.375rem) rotate(45deg);
|
|
293
|
+
}
|
|
294
|
+
[aria-expanded='true'] .icon span:nth-child(2) {
|
|
295
|
+
opacity: 0;
|
|
296
|
+
}
|
|
297
|
+
[aria-expanded='true'] .icon span:nth-child(3) {
|
|
298
|
+
transform: translateY(-0.375rem) rotate(-45deg);
|
|
299
|
+
}
|
|
300
|
+
.collapsed .links {
|
|
301
|
+
position: absolute;
|
|
302
|
+
top: 100%;
|
|
303
|
+
left: 0;
|
|
304
|
+
right: 0;
|
|
305
|
+
display: none;
|
|
306
|
+
flex-direction: column;
|
|
307
|
+
gap: 0;
|
|
308
|
+
padding: var(--va-space-gap-sm) 0;
|
|
309
|
+
border-bottom: 1px solid var(--va-navbar-border, var(--va-color-border-subtle));
|
|
310
|
+
background-color: var(--va-navbar-bg, var(--va-color-surface-default));
|
|
311
|
+
box-shadow: 0 12px 24px rgb(0 0 0 / 0.12);
|
|
312
|
+
}
|
|
313
|
+
.collapsed .links.open {
|
|
314
|
+
display: flex;
|
|
315
|
+
animation: va-navbar-open var(--va-motion-duration-fast) ease-out;
|
|
316
|
+
}
|
|
317
|
+
.collapsed slot:not([name])::slotted(a) {
|
|
318
|
+
min-height: var(--va-size-control-lg);
|
|
319
|
+
padding: 0 var(--va-space-inline-lg);
|
|
320
|
+
border-top: none;
|
|
321
|
+
border-bottom: none;
|
|
322
|
+
border-inline-start: 3px solid transparent;
|
|
323
|
+
}
|
|
324
|
+
.collapsed slot:not([name])::slotted([aria-current='page']) {
|
|
325
|
+
border-inline-start-color: var(--va-navbar-indicator-border, var(--va-color-accent-default));
|
|
326
|
+
}
|
|
327
|
+
@keyframes va-navbar-open {
|
|
328
|
+
from {
|
|
329
|
+
opacity: 0;
|
|
330
|
+
transform: translateY(-4px);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
@media (prefers-reduced-motion: reduce) {
|
|
334
|
+
.icon span {
|
|
335
|
+
transition: none;
|
|
336
|
+
}
|
|
337
|
+
.collapsed .links.open {
|
|
338
|
+
animation: none;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
@media (forced-colors: active) {
|
|
342
|
+
.bar,
|
|
343
|
+
.collapsed .links {
|
|
344
|
+
border-bottom-color: CanvasText;
|
|
345
|
+
}
|
|
346
|
+
slot:not([name])::slotted([aria-current='page']) {
|
|
347
|
+
border-color: Highlight;
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
`,
|
|
351
|
+
]; }
|
|
352
|
+
}
|
|
353
|
+
//# sourceMappingURL=navbar.js.map
|