@firstprateek/vastu 0.0.0-stage → 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/LICENSE +15 -0
- package/README.md +52 -2
- package/custom-elements.json +3737 -0
- package/dist/dev/all.d.ts +12 -0
- package/dist/dev/all.d.ts.map +1 -0
- package/dist/dev/all.js +13 -0
- package/dist/dev/all.js.map +1 -0
- 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/button/button.d.ts +98 -0
- package/dist/dev/button/button.d.ts.map +1 -0
- package/dist/dev/button/button.js +292 -0
- package/dist/dev/button/button.js.map +1 -0
- package/dist/dev/button/index.d.ts +4 -0
- package/dist/dev/button/index.d.ts.map +1 -0
- package/dist/dev/button/index.js +5 -0
- package/dist/dev/button/index.js.map +1 -0
- package/dist/dev/checkbox/checkbox.d.ts +71 -0
- package/dist/dev/checkbox/checkbox.d.ts.map +1 -0
- package/dist/dev/checkbox/checkbox.js +232 -0
- package/dist/dev/checkbox/checkbox.js.map +1 -0
- package/dist/dev/checkbox/index.d.ts +3 -0
- package/dist/dev/checkbox/index.d.ts.map +1 -0
- package/dist/dev/checkbox/index.js +5 -0
- package/dist/dev/checkbox/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/core/define.d.ts +3 -0
- package/dist/dev/core/define.d.ts.map +1 -0
- package/dist/dev/core/define.js +6 -0
- package/dist/dev/core/define.js.map +1 -0
- package/dist/dev/core/dev-mode.d.ts +6 -0
- package/dist/dev/core/dev-mode.d.ts.map +1 -0
- package/dist/dev/core/dev-mode.js +6 -0
- package/dist/dev/core/dev-mode.js.map +1 -0
- package/dist/dev/core/focus-ring.d.ts +3 -0
- package/dist/dev/core/focus-ring.d.ts.map +1 -0
- package/dist/dev/core/focus-ring.js +14 -0
- package/dist/dev/core/focus-ring.js.map +1 -0
- package/dist/dev/core/form-control.d.ts +47 -0
- package/dist/dev/core/form-control.d.ts.map +1 -0
- package/dist/dev/core/form-control.js +75 -0
- package/dist/dev/core/form-control.js.map +1 -0
- package/dist/dev/core/warn.d.ts +12 -0
- package/dist/dev/core/warn.d.ts.map +1 -0
- package/dist/dev/core/warn.js +35 -0
- package/dist/dev/core/warn.js.map +1 -0
- package/dist/dev/dialog/dialog.d.ts +77 -0
- package/dist/dev/dialog/dialog.d.ts.map +1 -0
- package/dist/dev/dialog/dialog.js +253 -0
- package/dist/dev/dialog/dialog.js.map +1 -0
- package/dist/dev/dialog/index.d.ts +4 -0
- package/dist/dev/dialog/index.d.ts.map +1 -0
- package/dist/dev/dialog/index.js +5 -0
- package/dist/dev/dialog/index.js.map +1 -0
- package/dist/dev/menu/index.d.ts +3 -0
- package/dist/dev/menu/index.d.ts.map +1 -0
- package/dist/dev/menu/index.js +5 -0
- package/dist/dev/menu/index.js.map +1 -0
- package/dist/dev/menu/menu.d.ts +71 -0
- package/dist/dev/menu/menu.d.ts.map +1 -0
- package/dist/dev/menu/menu.js +330 -0
- package/dist/dev/menu/menu.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/dev/switch/index.d.ts +3 -0
- package/dist/dev/switch/index.d.ts.map +1 -0
- package/dist/dev/switch/index.js +5 -0
- package/dist/dev/switch/index.js.map +1 -0
- package/dist/dev/switch/switch.d.ts +69 -0
- package/dist/dev/switch/switch.d.ts.map +1 -0
- package/dist/dev/switch/switch.js +213 -0
- package/dist/dev/switch/switch.js.map +1 -0
- package/dist/dev/tabs/index.d.ts +3 -0
- package/dist/dev/tabs/index.d.ts.map +1 -0
- package/dist/dev/tabs/index.js +5 -0
- package/dist/dev/tabs/index.js.map +1 -0
- package/dist/dev/tabs/tabs.d.ts +64 -0
- package/dist/dev/tabs/tabs.d.ts.map +1 -0
- package/dist/dev/tabs/tabs.js +212 -0
- package/dist/dev/tabs/tabs.js.map +1 -0
- package/dist/dev/text-field/index.d.ts +3 -0
- package/dist/dev/text-field/index.d.ts.map +1 -0
- package/dist/dev/text-field/index.js +5 -0
- package/dist/dev/text-field/index.js.map +1 -0
- package/dist/dev/text-field/text-field.d.ts +91 -0
- package/dist/dev/text-field/text-field.d.ts.map +1 -0
- package/dist/dev/text-field/text-field.js +267 -0
- package/dist/dev/text-field/text-field.js.map +1 -0
- package/dist/dev/toast/index.d.ts +4 -0
- package/dist/dev/toast/index.d.ts.map +1 -0
- package/dist/dev/toast/index.js +5 -0
- package/dist/dev/toast/index.js.map +1 -0
- package/dist/dev/toast/toast.d.ts +71 -0
- package/dist/dev/toast/toast.d.ts.map +1 -0
- package/dist/dev/toast/toast.js +258 -0
- package/dist/dev/toast/toast.js.map +1 -0
- package/dist/prod/all.js +13 -0
- package/dist/prod/bar-chart/bar-chart.js +316 -0
- package/dist/prod/bar-chart/index.js +5 -0
- package/dist/prod/button/button.js +292 -0
- package/dist/prod/button/index.js +5 -0
- package/dist/prod/checkbox/checkbox.js +232 -0
- package/dist/prod/checkbox/index.js +5 -0
- package/dist/prod/core/cssom.js +30 -0
- package/dist/prod/core/define.js +6 -0
- package/dist/prod/core/dev-mode.js +1 -0
- package/dist/prod/core/focus-ring.js +14 -0
- package/dist/prod/core/form-control.js +75 -0
- package/dist/prod/core/warn.js +2 -0
- package/dist/prod/dialog/dialog.js +253 -0
- package/dist/prod/dialog/index.js +5 -0
- package/dist/prod/menu/index.js +5 -0
- package/dist/prod/menu/menu.js +330 -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/dist/prod/switch/index.js +5 -0
- package/dist/prod/switch/switch.js +213 -0
- package/dist/prod/tabs/index.js +5 -0
- package/dist/prod/tabs/tabs.js +212 -0
- package/dist/prod/text-field/index.js +5 -0
- package/dist/prod/text-field/text-field.js +267 -0
- package/dist/prod/toast/index.js +5 -0
- package/dist/prod/toast/toast.js +258 -0
- package/package.json +110 -3
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
import { css, html, nothing, svg } from 'lit';
|
|
2
|
+
import { FormControl } from '../core/form-control.js';
|
|
3
|
+
import { checkTokensLoaded, devWarn } from '../core/warn.js';
|
|
4
|
+
/**
|
|
5
|
+
* A checkbox for a choice that is submitted with a form.
|
|
6
|
+
*
|
|
7
|
+
* @tag va-checkbox
|
|
8
|
+
* @summary Lets the user choose an option, or agree to something, as part of a form.
|
|
9
|
+
*
|
|
10
|
+
* @slot - The visible label. Clicking it toggles the checkbox.
|
|
11
|
+
* @slot help-text - Optional help text under the label. It becomes the checkbox's description.
|
|
12
|
+
*
|
|
13
|
+
* @csspart control - The square box.
|
|
14
|
+
* @csspart label - The label text.
|
|
15
|
+
* @csspart help-text - The help text.
|
|
16
|
+
*
|
|
17
|
+
* @cssprop {<color>} --va-checkbox-border - Border colour of the box when unchecked.
|
|
18
|
+
* @cssprop {<color>} --va-checkbox-bg-checked - Fill and border colour when checked or indeterminate.
|
|
19
|
+
* @cssprop {<color>} --va-checkbox-mark-fg - Colour of the tick or dash.
|
|
20
|
+
* @cssprop {<length>} --va-checkbox-size - Width and height of the box.
|
|
21
|
+
*
|
|
22
|
+
* @cssprop-applies --va-checkbox-border control:unchecked border-top-color
|
|
23
|
+
* @cssprop-applies --va-checkbox-bg-checked control:checked background-color
|
|
24
|
+
* @cssprop-applies --va-checkbox-mark-fg control:checked color
|
|
25
|
+
* @cssprop-applies --va-checkbox-size control width
|
|
26
|
+
*
|
|
27
|
+
* @keyboard Space | toggles | Checks or unchecks the box.
|
|
28
|
+
* @keyboard Tab | focus-next | Moves focus to the next control.
|
|
29
|
+
*
|
|
30
|
+
* @a11y-role checkbox
|
|
31
|
+
* @a11y-name-from text, accessible-label
|
|
32
|
+
* @replaces input[type="checkbox"]
|
|
33
|
+
* @a11y-name The slotted label text. Use `accessible-label` only when there is no visible label.
|
|
34
|
+
* @a11y-note `indeterminate` is announced as "mixed", for a box that stands for a partly selected group.
|
|
35
|
+
* @a11y-note Style states with `va-checkbox:state(checked)` and `:state(indeterminate)`; the `checked` attribute is the initial state only, as on a native checkbox.
|
|
36
|
+
*
|
|
37
|
+
* @guidance-use For an option submitted with a form, for agreeing to terms, or to select items in a list.
|
|
38
|
+
* @guidance-avoid For a setting that should apply immediately.
|
|
39
|
+
* @guidance-instead `va-switch` for settings that take effect immediately.
|
|
40
|
+
*
|
|
41
|
+
* @fires change - When the user checks or unchecks the box. Read `event.target.checked`.
|
|
42
|
+
* @fires input - When the user checks or unchecks the box, just before `change`.
|
|
43
|
+
* @event-trigger change | click
|
|
44
|
+
* @event-trigger input | click
|
|
45
|
+
*/
|
|
46
|
+
export class VaCheckbox extends FormControl {
|
|
47
|
+
static { this.shadowRootOptions = { ...FormControl.shadowRootOptions, delegatesFocus: true }; }
|
|
48
|
+
static { this.properties = {
|
|
49
|
+
checked: { type: Boolean },
|
|
50
|
+
indeterminate: { type: Boolean },
|
|
51
|
+
value: {},
|
|
52
|
+
accessibleLabel: { attribute: 'accessible-label' },
|
|
53
|
+
}; }
|
|
54
|
+
#defaultChecked;
|
|
55
|
+
constructor() {
|
|
56
|
+
super();
|
|
57
|
+
this.checked = false;
|
|
58
|
+
this.indeterminate = false;
|
|
59
|
+
this.value = 'on';
|
|
60
|
+
this.accessibleLabel = '';
|
|
61
|
+
}
|
|
62
|
+
connectedCallback() {
|
|
63
|
+
super.connectedCallback();
|
|
64
|
+
// The default is the initial attribute, read once: moving the element must not change it.
|
|
65
|
+
this.#defaultChecked ??= this.hasAttribute('checked');
|
|
66
|
+
checkTokensLoaded(this);
|
|
67
|
+
}
|
|
68
|
+
firstUpdated() {
|
|
69
|
+
requestAnimationFrame(() => {
|
|
70
|
+
const text = this.#labelText();
|
|
71
|
+
if (!text && !this.accessibleLabel) {
|
|
72
|
+
devWarn('va-checkbox', 'This checkbox has no accessible name.', 'Put label text inside it, or add accessible-label="…" when there is no room for one (e.g. accessible-label="Select row").');
|
|
73
|
+
}
|
|
74
|
+
else if (text && this.accessibleLabel && !this.accessibleLabel.toLowerCase().includes(text.toLowerCase())) {
|
|
75
|
+
devWarn('va-checkbox', `accessible-label="${this.accessibleLabel}" replaces the visible label "${text}" for screen readers (WCAG 2.5.3).`, 'Remove accessible-label: the visible text is the name.');
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/** The visible label: text not in the help-text slot. */
|
|
80
|
+
#labelText() {
|
|
81
|
+
return [...this.childNodes]
|
|
82
|
+
.filter((n) => !(n instanceof Element && n.slot))
|
|
83
|
+
.map((n) => n.textContent ?? '')
|
|
84
|
+
.join('')
|
|
85
|
+
.trim();
|
|
86
|
+
}
|
|
87
|
+
updated() {
|
|
88
|
+
this._setState('checked', this.checked);
|
|
89
|
+
this._setState('indeterminate', this.indeterminate);
|
|
90
|
+
this._internals.setFormValue(this.checked ? this.value : null);
|
|
91
|
+
const missing = this.required && !this.checked;
|
|
92
|
+
this._internals.setValidity(missing ? { valueMissing: true } : {}, missing ? 'Check this box to continue.' : '', this.shadowRoot?.querySelector('input') ?? undefined);
|
|
93
|
+
}
|
|
94
|
+
/** @internal */
|
|
95
|
+
formResetCallback() {
|
|
96
|
+
this.checked = this.#defaultChecked ?? false;
|
|
97
|
+
}
|
|
98
|
+
// The inner checkbox's native input event crosses the shadow root; the host fires its own instead.
|
|
99
|
+
#stopNative(event) {
|
|
100
|
+
event.stopPropagation();
|
|
101
|
+
}
|
|
102
|
+
#onChange(event) {
|
|
103
|
+
const input = event.target;
|
|
104
|
+
this.checked = input.checked;
|
|
105
|
+
this.indeterminate = false;
|
|
106
|
+
this._emit('input');
|
|
107
|
+
this._emit('change');
|
|
108
|
+
}
|
|
109
|
+
render() {
|
|
110
|
+
const mark = this.indeterminate
|
|
111
|
+
? svg `<path d="M4 8h8" />`
|
|
112
|
+
: this.checked
|
|
113
|
+
? svg `<path d="M3.5 8.5l3 3 6-7" />`
|
|
114
|
+
: nothing;
|
|
115
|
+
return html `
|
|
116
|
+
<label class="wrapper ${this._isDisabled ? 'disabled' : ''}">
|
|
117
|
+
<span class="control-wrap">
|
|
118
|
+
<input
|
|
119
|
+
class="native"
|
|
120
|
+
type="checkbox"
|
|
121
|
+
.checked=${this.checked}
|
|
122
|
+
.indeterminate=${this.indeterminate}
|
|
123
|
+
?disabled=${this._isDisabled}
|
|
124
|
+
?required=${this.required}
|
|
125
|
+
aria-label=${this.accessibleLabel || nothing}
|
|
126
|
+
aria-labelledby=${this.accessibleLabel ? nothing : 'label'}
|
|
127
|
+
aria-describedby="help-text"
|
|
128
|
+
@input=${this.#stopNative}
|
|
129
|
+
@change=${this.#onChange}
|
|
130
|
+
/>
|
|
131
|
+
<span part="control" class="box ${this.checked || this.indeterminate ? 'on' : ''}" aria-hidden="true">
|
|
132
|
+
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">${mark}</svg>
|
|
133
|
+
</span>
|
|
134
|
+
</span>
|
|
135
|
+
<span class="text">
|
|
136
|
+
<span part="label" id="label" class="label"><slot></slot></span>
|
|
137
|
+
<span part="help-text" id="help-text" class="help-text"><slot name="help-text"></slot></span>
|
|
138
|
+
</span>
|
|
139
|
+
</label>
|
|
140
|
+
`;
|
|
141
|
+
}
|
|
142
|
+
static { this.styles = css `
|
|
143
|
+
:host {
|
|
144
|
+
--_size: var(--va-checkbox-size, 1.125rem);
|
|
145
|
+
display: inline-flex;
|
|
146
|
+
font-family: var(--va-font-family-ui);
|
|
147
|
+
font-size: var(--va-font-size-md);
|
|
148
|
+
color: var(--va-color-text-default);
|
|
149
|
+
vertical-align: middle;
|
|
150
|
+
}
|
|
151
|
+
:host([hidden]) {
|
|
152
|
+
display: none;
|
|
153
|
+
}
|
|
154
|
+
.wrapper {
|
|
155
|
+
display: inline-flex;
|
|
156
|
+
align-items: flex-start;
|
|
157
|
+
gap: var(--va-space-inline-sm);
|
|
158
|
+
cursor: pointer;
|
|
159
|
+
/* Keeps the whole row at least 24px high for the WCAG 2.2 target size. */
|
|
160
|
+
min-height: 1.5rem;
|
|
161
|
+
padding-block: 0.1875rem;
|
|
162
|
+
box-sizing: border-box;
|
|
163
|
+
}
|
|
164
|
+
.control-wrap {
|
|
165
|
+
position: relative;
|
|
166
|
+
flex: none;
|
|
167
|
+
display: inline-flex;
|
|
168
|
+
}
|
|
169
|
+
/* The real checkbox covers the visible box, invisibly, so pointers and automation hit it directly. */
|
|
170
|
+
.native {
|
|
171
|
+
position: absolute;
|
|
172
|
+
inset: 0;
|
|
173
|
+
width: 100%;
|
|
174
|
+
height: 100%;
|
|
175
|
+
margin: 0;
|
|
176
|
+
opacity: 0;
|
|
177
|
+
cursor: inherit;
|
|
178
|
+
z-index: 1;
|
|
179
|
+
}
|
|
180
|
+
.box {
|
|
181
|
+
flex: none;
|
|
182
|
+
box-sizing: border-box;
|
|
183
|
+
display: grid;
|
|
184
|
+
place-items: center;
|
|
185
|
+
width: var(--_size);
|
|
186
|
+
height: var(--_size);
|
|
187
|
+
margin-top: 0.1rem;
|
|
188
|
+
border: 1.5px solid var(--va-checkbox-border, var(--va-color-border-control));
|
|
189
|
+
border-radius: var(--va-radius-control);
|
|
190
|
+
background-color: var(--va-color-surface-default);
|
|
191
|
+
color: var(--va-checkbox-mark-fg, var(--va-color-text-on-accent));
|
|
192
|
+
}
|
|
193
|
+
.box svg {
|
|
194
|
+
width: 100%;
|
|
195
|
+
height: 100%;
|
|
196
|
+
}
|
|
197
|
+
.box.on {
|
|
198
|
+
border-color: var(--va-checkbox-bg-checked, var(--va-color-accent-default));
|
|
199
|
+
background-color: var(--va-checkbox-bg-checked, var(--va-color-accent-default));
|
|
200
|
+
}
|
|
201
|
+
.native:focus-visible + .box {
|
|
202
|
+
outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus);
|
|
203
|
+
outline-offset: 2px;
|
|
204
|
+
}
|
|
205
|
+
.wrapper.disabled {
|
|
206
|
+
opacity: 0.5;
|
|
207
|
+
cursor: not-allowed;
|
|
208
|
+
}
|
|
209
|
+
.text {
|
|
210
|
+
display: flex;
|
|
211
|
+
flex-direction: column;
|
|
212
|
+
}
|
|
213
|
+
.help-text {
|
|
214
|
+
color: var(--va-color-text-muted);
|
|
215
|
+
font-size: var(--va-font-size-sm);
|
|
216
|
+
}
|
|
217
|
+
@media (forced-colors: active) {
|
|
218
|
+
.box {
|
|
219
|
+
border-color: ButtonText;
|
|
220
|
+
}
|
|
221
|
+
.box.on {
|
|
222
|
+
background-color: Highlight;
|
|
223
|
+
color: HighlightText;
|
|
224
|
+
forced-color-adjust: none;
|
|
225
|
+
}
|
|
226
|
+
.native:focus-visible + .box {
|
|
227
|
+
outline-color: Highlight;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
`; }
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=checkbox.js.map
|
|
@@ -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 @@
|
|
|
1
|
+
export const DEV_MODE = false;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
/** The shared keyboard focus ring: visible only for keyboard focus, drawn outside the control. */
|
|
3
|
+
export const focusRing = css `
|
|
4
|
+
:focus-visible {
|
|
5
|
+
outline: var(--va-size-focus-ring, 2px) solid var(--va-color-focus, currentColor);
|
|
6
|
+
outline-offset: 2px;
|
|
7
|
+
}
|
|
8
|
+
@media (forced-colors: active) {
|
|
9
|
+
:focus-visible {
|
|
10
|
+
outline-color: Highlight;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
`;
|
|
14
|
+
//# sourceMappingURL=focus-ring.js.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { LitElement } from 'lit';
|
|
2
|
+
/**
|
|
3
|
+
* Base class for Vastu form controls. It joins the control to its `<form>` through
|
|
4
|
+
* ElementInternals, so the control submits, resets, disables and validates like a native one.
|
|
5
|
+
* Subclasses call `setFormValue()` and `setValidity()`; everything else is handled here.
|
|
6
|
+
*/
|
|
7
|
+
export class FormControl extends LitElement {
|
|
8
|
+
/** @internal */
|
|
9
|
+
static { this.formAssociated = true; }
|
|
10
|
+
static { this.properties = {
|
|
11
|
+
name: {},
|
|
12
|
+
disabled: { type: Boolean, reflect: true },
|
|
13
|
+
required: { type: Boolean, reflect: true },
|
|
14
|
+
_fieldsetDisabled: { state: true },
|
|
15
|
+
}; }
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this.name = '';
|
|
19
|
+
this.disabled = false;
|
|
20
|
+
this.required = false;
|
|
21
|
+
this._fieldsetDisabled = false;
|
|
22
|
+
this._internals = this.attachInternals();
|
|
23
|
+
}
|
|
24
|
+
/** The form this control belongs to, if any. */
|
|
25
|
+
get form() {
|
|
26
|
+
return this._internals.form;
|
|
27
|
+
}
|
|
28
|
+
/** The control's validity state, as on native controls. */
|
|
29
|
+
get validity() {
|
|
30
|
+
return this._internals.validity;
|
|
31
|
+
}
|
|
32
|
+
/** The message the browser shows when the control is invalid, or an empty string. */
|
|
33
|
+
get validationMessage() {
|
|
34
|
+
return this._internals.validationMessage;
|
|
35
|
+
}
|
|
36
|
+
/** Returns true if the control is valid; otherwise fires `invalid` and returns false. */
|
|
37
|
+
checkValidity() {
|
|
38
|
+
return this._internals.checkValidity();
|
|
39
|
+
}
|
|
40
|
+
/** Like `checkValidity()`, but also shows the browser's message to the user. */
|
|
41
|
+
reportValidity() {
|
|
42
|
+
return this._internals.reportValidity();
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @internal Called by the browser when a `<fieldset disabled>` around the control changes.
|
|
46
|
+
* Like a native control, the author's own `disabled` is left alone: re-enabling the fieldset
|
|
47
|
+
* doesn't enable a control the author disabled.
|
|
48
|
+
*/
|
|
49
|
+
formDisabledCallback(disabled) {
|
|
50
|
+
this._fieldsetDisabled = disabled;
|
|
51
|
+
}
|
|
52
|
+
/** Whether the control is disabled, by its own `disabled` or by a disabled fieldset. */
|
|
53
|
+
get _isDisabled() {
|
|
54
|
+
return this.disabled || this._fieldsetDisabled;
|
|
55
|
+
}
|
|
56
|
+
/** Sets or clears a custom state, for authors' :state(…) selectors. */
|
|
57
|
+
_setState(name, on) {
|
|
58
|
+
try {
|
|
59
|
+
if (on)
|
|
60
|
+
this._internals.states.add(name);
|
|
61
|
+
else
|
|
62
|
+
this._internals.states.delete(name);
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
// Browsers without CustomStateSet: the state is only for authors' styling.
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/** @internal Called by the browser when the form resets. Subclasses restore their default. */
|
|
69
|
+
formResetCallback() { }
|
|
70
|
+
/** Fires a bubbling event on the host, as a native control would. */
|
|
71
|
+
_emit(type) {
|
|
72
|
+
this.dispatchEvent(new Event(type, { bubbles: true, composed: type === 'input' }));
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=form-control.js.map
|
|
@@ -0,0 +1,253 @@
|
|
|
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 modal dialog built on the native `<dialog>`: it sits in the top layer, makes the page behind it
|
|
6
|
+
* inert, keeps focus inside, closes with Escape and returns focus to where it came from.
|
|
7
|
+
*
|
|
8
|
+
* @tag va-dialog
|
|
9
|
+
* @summary Asks the user to confirm, decide or enter something before going back to the page.
|
|
10
|
+
*
|
|
11
|
+
* @slot - The dialog's content.
|
|
12
|
+
* @slot footer - Actions, such as Cancel and Confirm buttons. Put the primary action last.
|
|
13
|
+
*
|
|
14
|
+
* @csspart dialog - The native dialog element.
|
|
15
|
+
* @csspart header - The row with the heading and the close button.
|
|
16
|
+
* @csspart heading - The heading.
|
|
17
|
+
* @csspart close-button - The close button.
|
|
18
|
+
* @csspart body - The wrapper around the content.
|
|
19
|
+
* @csspart footer - The wrapper around the actions.
|
|
20
|
+
*
|
|
21
|
+
* @cssprop {<color>} --va-dialog-bg - Background colour.
|
|
22
|
+
* @cssprop {<length>} --va-dialog-width - Maximum width.
|
|
23
|
+
* @cssprop {<length>} --va-dialog-radius - Corner radius.
|
|
24
|
+
*
|
|
25
|
+
* @cssprop-applies --va-dialog-bg dialog:open background-color
|
|
26
|
+
* @cssprop-applies --va-dialog-width dialog:open max-width
|
|
27
|
+
* @cssprop-applies --va-dialog-radius dialog:open border-top-left-radius
|
|
28
|
+
*
|
|
29
|
+
* @keyboard open: Escape | closes | Closes the dialog and returns focus to the element that opened it.
|
|
30
|
+
*
|
|
31
|
+
* @a11y-role dialog
|
|
32
|
+
* @a11y-name-from heading, accessible-label
|
|
33
|
+
* @replaces dialog
|
|
34
|
+
* @a11y-name The `heading`, or `accessible-label` when there is no visible heading.
|
|
35
|
+
* @a11y-note The page behind is inert while the dialog is open, so focus and screen readers stay inside it.
|
|
36
|
+
* @a11y-note On open, focus goes to the first element with `autofocus`, else the first focusable control in the content, else the close button.
|
|
37
|
+
*
|
|
38
|
+
* @guidance-use For a decision the user must make before going on, such as confirming a deletion, or a short focused task.
|
|
39
|
+
* @guidance-avoid For information that doesn't need a response, or for long, multi-step flows.
|
|
40
|
+
* @guidance-instead `va-toast` for confirmations that need no response; a full page for long flows.
|
|
41
|
+
*
|
|
42
|
+
* @command --show | Opens the dialog.
|
|
43
|
+
* @command --close | Closes the dialog (fires `va-close` first).
|
|
44
|
+
* @fires va-open - After the dialog has opened.
|
|
45
|
+
* @fires {CustomEvent<{ reason: 'escape' | 'close-button' | 'command' | 'method' }>} va-close - Before the dialog closes, when the user or close() asks it to. Cancel it with `preventDefault()` to keep the dialog open.
|
|
46
|
+
* @fires {CustomEvent<{ reason: 'escape' | 'close-button' | 'command' | 'method' | 'property' }>} va-closed - After the dialog has closed, however it closed (`property` when `open` was set to false). Focus is back on the element that opened it.
|
|
47
|
+
* @event-trigger va-open | call show
|
|
48
|
+
* @event-trigger va-close | press Escape | open
|
|
49
|
+
* @event-trigger va-closed | press Escape | open
|
|
50
|
+
*/
|
|
51
|
+
export class VaDialog extends LitElement {
|
|
52
|
+
static { this.properties = {
|
|
53
|
+
open: { type: Boolean, reflect: true },
|
|
54
|
+
heading: {},
|
|
55
|
+
accessibleLabel: { attribute: 'accessible-label' },
|
|
56
|
+
hideCloseButton: { type: Boolean, reflect: true, attribute: 'hide-close-button' },
|
|
57
|
+
}; }
|
|
58
|
+
#returnFocus = null;
|
|
59
|
+
#shown = false;
|
|
60
|
+
#closeReason = null;
|
|
61
|
+
constructor() {
|
|
62
|
+
super();
|
|
63
|
+
this.open = false;
|
|
64
|
+
this.heading = '';
|
|
65
|
+
this.accessibleLabel = '';
|
|
66
|
+
this.hideCloseButton = false;
|
|
67
|
+
this.addEventListener('command', this.#onCommand);
|
|
68
|
+
}
|
|
69
|
+
connectedCallback() {
|
|
70
|
+
super.connectedCallback();
|
|
71
|
+
checkTokensLoaded(this);
|
|
72
|
+
}
|
|
73
|
+
get #dialog() {
|
|
74
|
+
return this.shadowRoot?.querySelector('dialog') ?? null;
|
|
75
|
+
}
|
|
76
|
+
/** Opens the dialog as a modal. */
|
|
77
|
+
show() {
|
|
78
|
+
this.open = true;
|
|
79
|
+
}
|
|
80
|
+
/** Closes the dialog, unless a `va-close` listener cancels it. */
|
|
81
|
+
close() {
|
|
82
|
+
this.#requestClose('method');
|
|
83
|
+
}
|
|
84
|
+
#requestClose(reason) {
|
|
85
|
+
if (!this.open)
|
|
86
|
+
return;
|
|
87
|
+
const event = new CustomEvent('va-close', { detail: { reason }, bubbles: true, composed: true, cancelable: true });
|
|
88
|
+
if (!this.dispatchEvent(event))
|
|
89
|
+
return;
|
|
90
|
+
this.#closeReason = reason;
|
|
91
|
+
this.open = false;
|
|
92
|
+
}
|
|
93
|
+
#onCommand = (event) => {
|
|
94
|
+
if (event.command === '--show' || event.command === 'show-modal') {
|
|
95
|
+
// Safari doesn't focus a button on click, so remember the button that sent the command.
|
|
96
|
+
if (event.source instanceof HTMLElement)
|
|
97
|
+
this.#returnFocus = event.source;
|
|
98
|
+
this.show();
|
|
99
|
+
}
|
|
100
|
+
else if (event.command === '--close' || event.command === 'close')
|
|
101
|
+
this.#requestClose('command');
|
|
102
|
+
};
|
|
103
|
+
async updated(changed) {
|
|
104
|
+
if (!changed.has('open'))
|
|
105
|
+
return;
|
|
106
|
+
const dialog = this.#dialog;
|
|
107
|
+
if (!dialog)
|
|
108
|
+
return;
|
|
109
|
+
if (this.open && !dialog.open) {
|
|
110
|
+
if (!this.#returnFocus) {
|
|
111
|
+
let active = document.activeElement;
|
|
112
|
+
while (active?.shadowRoot?.activeElement)
|
|
113
|
+
active = active.shadowRoot.activeElement;
|
|
114
|
+
this.#returnFocus = active;
|
|
115
|
+
}
|
|
116
|
+
if (!this.heading && !this.accessibleLabel) {
|
|
117
|
+
devWarn('va-dialog', 'This dialog has no accessible name.', 'Add heading="…" (shown) or accessible-label="…" (not shown) that says what the dialog is for.');
|
|
118
|
+
}
|
|
119
|
+
dialog.showModal();
|
|
120
|
+
this.#shown = true;
|
|
121
|
+
this.#focusInitial();
|
|
122
|
+
this.dispatchEvent(new Event('va-open', { bubbles: true, composed: true }));
|
|
123
|
+
}
|
|
124
|
+
else if (!this.open && this.#shown) {
|
|
125
|
+
if (dialog.open)
|
|
126
|
+
dialog.close();
|
|
127
|
+
this.#shown = false;
|
|
128
|
+
this.#returnFocus?.focus();
|
|
129
|
+
this.#returnFocus = null;
|
|
130
|
+
const reason = this.#closeReason ?? 'property';
|
|
131
|
+
this.#closeReason = null;
|
|
132
|
+
this.dispatchEvent(new CustomEvent('va-closed', { detail: { reason }, bubbles: true, composed: true }));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
#focusInitial() {
|
|
136
|
+
const focusable = 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"]), va-button, va-text-field, va-checkbox, va-switch';
|
|
137
|
+
const auto = this.querySelector('[autofocus]');
|
|
138
|
+
const first = [...this.querySelectorAll(focusable)].find((el) => el.slot !== 'footer' && !el.hasAttribute('disabled'));
|
|
139
|
+
const target = auto ?? first ?? this.shadowRoot?.querySelector('.close') ?? this.#dialog;
|
|
140
|
+
target?.focus();
|
|
141
|
+
}
|
|
142
|
+
#onCancel(event) {
|
|
143
|
+
// Escape: route through va-close so listeners can keep the dialog open.
|
|
144
|
+
event.preventDefault();
|
|
145
|
+
this.#requestClose('escape');
|
|
146
|
+
}
|
|
147
|
+
#onNativeClose() {
|
|
148
|
+
// The browser closed the dialog itself (a repeated Escape, for example): keep `open` in step.
|
|
149
|
+
if (this.open) {
|
|
150
|
+
this.#closeReason = 'escape';
|
|
151
|
+
this.open = false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
render() {
|
|
155
|
+
return html `
|
|
156
|
+
<dialog
|
|
157
|
+
part="dialog"
|
|
158
|
+
aria-labelledby=${this.heading ? 'heading' : nothing}
|
|
159
|
+
aria-label=${!this.heading && this.accessibleLabel ? this.accessibleLabel : nothing}
|
|
160
|
+
@cancel=${this.#onCancel}
|
|
161
|
+
@close=${this.#onNativeClose}
|
|
162
|
+
>
|
|
163
|
+
<div part="header" class="header">
|
|
164
|
+
${this.heading ? html `<h2 part="heading" id="heading" class="heading">${this.heading}</h2>` : html `<span part="heading" class="heading"></span>`}
|
|
165
|
+
${!this.hideCloseButton
|
|
166
|
+
? html `<button part="close-button" class="close" type="button" aria-label="Close" @click=${() => this.#requestClose('close-button')}>
|
|
167
|
+
<svg viewBox="0 0 24 24" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2"><path d="M6 6l12 12M18 6L6 18" /></svg>
|
|
168
|
+
</button>`
|
|
169
|
+
: nothing}
|
|
170
|
+
</div>
|
|
171
|
+
<div part="body" class="body"><slot></slot></div>
|
|
172
|
+
<div part="footer" class="footer"><slot name="footer"></slot></div>
|
|
173
|
+
</dialog>
|
|
174
|
+
`;
|
|
175
|
+
}
|
|
176
|
+
static { this.styles = [
|
|
177
|
+
focusRing,
|
|
178
|
+
css `
|
|
179
|
+
:host {
|
|
180
|
+
display: contents;
|
|
181
|
+
}
|
|
182
|
+
dialog {
|
|
183
|
+
box-sizing: border-box;
|
|
184
|
+
width: calc(100% - 2rem);
|
|
185
|
+
max-width: var(--va-dialog-width, 32rem);
|
|
186
|
+
max-height: calc(100% - 2rem);
|
|
187
|
+
padding: 0;
|
|
188
|
+
border: 1px solid var(--va-color-border-subtle);
|
|
189
|
+
border-radius: var(--va-dialog-radius, var(--va-radius-surface));
|
|
190
|
+
background-color: var(--va-dialog-bg, var(--va-color-surface-default));
|
|
191
|
+
color: var(--va-color-text-default);
|
|
192
|
+
font-family: var(--va-font-family-ui);
|
|
193
|
+
box-shadow: 0 12px 40px rgb(0 0 0 / 0.25);
|
|
194
|
+
}
|
|
195
|
+
dialog::backdrop {
|
|
196
|
+
background: rgb(0 0 0 / 0.45);
|
|
197
|
+
}
|
|
198
|
+
.header {
|
|
199
|
+
display: flex;
|
|
200
|
+
align-items: flex-start;
|
|
201
|
+
justify-content: space-between;
|
|
202
|
+
gap: var(--va-space-inline-md);
|
|
203
|
+
padding: var(--va-space-inline-lg) var(--va-space-inline-lg) 0;
|
|
204
|
+
}
|
|
205
|
+
.heading {
|
|
206
|
+
margin: 0;
|
|
207
|
+
font-family: var(--va-font-family-reading);
|
|
208
|
+
font-size: 1.25rem;
|
|
209
|
+
font-weight: var(--va-font-weight-bold);
|
|
210
|
+
line-height: 1.3;
|
|
211
|
+
}
|
|
212
|
+
.close {
|
|
213
|
+
flex: none;
|
|
214
|
+
display: grid;
|
|
215
|
+
place-items: center;
|
|
216
|
+
width: 2rem;
|
|
217
|
+
height: 2rem;
|
|
218
|
+
margin: -0.25rem -0.5rem 0 0;
|
|
219
|
+
padding: 0;
|
|
220
|
+
border: none;
|
|
221
|
+
border-radius: var(--va-radius-control);
|
|
222
|
+
background: transparent;
|
|
223
|
+
color: var(--va-color-text-muted);
|
|
224
|
+
cursor: pointer;
|
|
225
|
+
}
|
|
226
|
+
.close:hover {
|
|
227
|
+
background: var(--va-color-surface-subtle);
|
|
228
|
+
color: var(--va-color-text-default);
|
|
229
|
+
}
|
|
230
|
+
.close svg {
|
|
231
|
+
width: 1.25rem;
|
|
232
|
+
height: 1.25rem;
|
|
233
|
+
}
|
|
234
|
+
.body {
|
|
235
|
+
padding: var(--va-space-inline-md) var(--va-space-inline-lg);
|
|
236
|
+
line-height: 1.5;
|
|
237
|
+
}
|
|
238
|
+
.footer {
|
|
239
|
+
display: flex;
|
|
240
|
+
flex-wrap: wrap;
|
|
241
|
+
justify-content: flex-end;
|
|
242
|
+
gap: var(--va-space-gap-md);
|
|
243
|
+
padding: 0 var(--va-space-inline-lg) var(--va-space-inline-lg);
|
|
244
|
+
}
|
|
245
|
+
@media (forced-colors: active) {
|
|
246
|
+
dialog {
|
|
247
|
+
border: 2px solid CanvasText;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
`,
|
|
251
|
+
]; }
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=dialog.js.map
|