contour-ds 1.1.2 → 1.7.1
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 +30 -2
- package/dist/agent-rules.json +5 -1
- package/dist/build-manifest.json +94 -93
- package/dist/contour-wc.esm.js +4443 -534
- package/dist/contour-wc.esm.min.js +1 -1
- package/dist/contour-wc.js +4441 -528
- package/dist/contour-wc.min.js +1 -1
- package/dist/contour.components.json +4054 -171
- package/dist/contour.css +1325 -565
- package/dist/contour.d.ts +119 -62
- package/dist/contour.esm.js +23 -0
- package/dist/contour.esm.min.js +1 -1
- package/dist/contour.js +23 -0
- package/dist/contour.min.css +1 -1
- package/dist/contour.min.js +1 -1
- package/dist/contour.tokens.json +47 -2
- package/dist/docs/actions.md +6 -2
- package/dist/docs/affordances.md +19 -3
- package/dist/docs/apireference.md +30 -0
- package/dist/docs/colour.md +2 -2
- package/dist/docs/componentindex.md +39 -0
- package/dist/docs/data.md +38 -3
- package/dist/docs/docs.md +6 -2
- package/dist/docs/feedback.md +13 -3
- package/dist/docs/field.md +7 -2
- package/dist/docs/forms.md +35 -3
- package/dist/docs/index.json +44 -75
- package/dist/docs/install.md +4 -2
- package/dist/docs/landing.md +3 -2
- package/dist/docs/mapengine.md +9 -3
- package/dist/docs/motion.md +5 -2
- package/dist/docs/navigation.md +10 -3
- package/dist/docs/overlays.md +26 -3
- package/dist/docs/overview.md +2 -2
- package/dist/docs/patterns.md +38 -3
- package/dist/docs/playground.md +5 -2
- package/dist/docs/principles.md +2 -2
- package/dist/docs/recipes.md +7 -3
- package/dist/docs/space.md +2 -2
- package/dist/docs/status.md +19 -3
- package/dist/docs/surfaces.md +7 -3
- package/dist/docs/theming.md +5 -2
- package/dist/docs/type.md +2 -2
- package/dist/docs/webcomponents.md +26 -7
- package/dist/map-chrome.mapbox.css +4 -4
- package/dist/map-chrome.maplibre.css +4 -4
- package/dist/registry/items/contour-core.json +2 -2
- package/dist/registry/items/contour-data.json +2 -2
- package/dist/registry/items/contour-docs.json +2 -2
- package/dist/registry/items/contour-landing.json +2 -2
- package/dist/registry/registry.json +8 -8
- package/dist/surfaces/contour-core.min.css +1 -1
- package/dist/surfaces/contour-data.min.css +1 -1
- package/dist/surfaces/contour-docs.min.css +1 -1
- package/dist/surfaces/contour-landing.min.css +1 -1
- package/dist/wc/behaviours.mjs +69 -11
- package/dist/wc/content.mjs +163 -8
- package/dist/wc/core.mjs +177 -36
- package/dist/wc/dashboard.mjs +69 -4
- package/dist/wc/data.mjs +933 -128
- package/dist/wc/docs.mjs +118 -0
- package/dist/wc/feedback.mjs +75 -13
- package/dist/wc/forms.mjs +371 -34
- package/dist/wc/index.mjs +31 -3
- package/dist/wc/interaction.mjs +11 -6
- package/dist/wc/map.mjs +142 -38
- package/dist/wc/misc.mjs +29 -1
- package/dist/wc/navigation.mjs +424 -75
- package/dist/wc/registration.mjs +8 -4
- package/dist/wc/shadow.mjs +29 -12
- package/dist/wc/states.mjs +15 -0
- package/dist/wc/svg.mjs +10 -0
- package/dist/wc/ui.mjs +1767 -129
- package/package.json +39 -6
package/dist/wc/forms.mjs
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form controls: field, field-group, form, combobox, select, check, radio,
|
|
3
|
+
* switch, textarea, input, input-group, range, radio-list, version.
|
|
4
|
+
*
|
|
5
|
+
* All form controls are `ContourBase` subclasses. They render light-DOM markup
|
|
6
|
+
* from observed attributes, reflect properties back to attributes, take part in
|
|
7
|
+
* form association (`formAssociated`, `_internals.setFormValue`) where the
|
|
8
|
+
* platform allows it, and emit `contour:input` / `contour:change` / `contour:submit`
|
|
9
|
+
* events. Inline validation (blur-driven `aria-invalid`) is handled by
|
|
10
|
+
* `ContourField`; `ContourForm` owns submission state and a live-region summary.
|
|
11
|
+
* @module contour-wc/forms
|
|
12
|
+
*/
|
|
13
|
+
|
|
1
14
|
import { ContourBase, define, contourId } from './core.mjs';
|
|
2
15
|
import { wireCombobox } from './behaviours.mjs';
|
|
3
16
|
import { loadRemote, remoteData, renderStates, renderEmpty, wireStates } from './states.mjs';
|
|
17
|
+
/**
|
|
18
|
+
* Combobox: a filterable, keyboard-navigable listbox backed by a JSON `options`
|
|
19
|
+
* attribute or authored `<li>` options. Supports single and multi-select
|
|
20
|
+
* (`multiple`), fixed-row virtualization (`virtual`), async/remote options
|
|
21
|
+
* (`src`, `loading`, `error`, `retry`, `empty`, `skeleton`), a clear button and
|
|
22
|
+
* form association. Emits `contour:select` on commit and `contour:input` on
|
|
23
|
+
* filter. ArrowUp/Down/Home/End rove the cursor; Enter commits; Escape closes.
|
|
24
|
+
*/
|
|
4
25
|
class ContourCombobox extends ContourBase {
|
|
5
|
-
|
|
26
|
+
static get observed() { return ["options", "placeholder", "label", "value", "multiple", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "empty", "skeleton", "virtual"]; }
|
|
6
27
|
static get formAssociated() { return true; }
|
|
7
|
-
static get properties() { return { options: { attribute: "options" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, value: { attribute: "value" }, multiple: { attribute: "multiple", type: Boolean }, src: { attribute: "src" } }; }
|
|
28
|
+
static get properties() { return { options: { attribute: "options" }, placeholder: { attribute: "placeholder" }, label: { attribute: "label" }, value: { attribute: "value" }, multiple: { attribute: "multiple", type: Boolean }, virtual: { attribute: "virtual", type: Boolean }, src: { attribute: "src" } }; }
|
|
8
29
|
render() {
|
|
9
30
|
this.classList.add("c-combobox");
|
|
10
31
|
wireStates(this);
|
|
@@ -25,15 +46,19 @@ class ContourCombobox extends ContourBase {
|
|
|
25
46
|
const list = this.ensure(".c-combobox__list", () => { const el = document.createElement("ul"); el.className = "c-combobox__list"; el.setAttribute("hidden", ""); return el; });
|
|
26
47
|
list.innerHTML = "";
|
|
27
48
|
list.setAttribute("hidden", "");
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
49
|
+
this._comboboxOptions = parsed;
|
|
50
|
+
this._comboboxVirtual = this.hasAttribute("virtual") && parsed.length > 100;
|
|
51
|
+
if (this._comboboxVirtual) {
|
|
52
|
+
list.classList.add("c-combobox__list--virtual");
|
|
53
|
+
list.style.maxBlockSize = "20rem";
|
|
54
|
+
list.style.overflow = "auto";
|
|
55
|
+
this._renderComboboxWindow("", true);
|
|
56
|
+
} else {
|
|
57
|
+
list.classList.remove("c-combobox__list--virtual");
|
|
58
|
+
list.style.maxBlockSize = "";
|
|
59
|
+
list.style.overflow = "";
|
|
60
|
+
this._renderComboboxWindow("", true);
|
|
61
|
+
}
|
|
37
62
|
} catch (e) { /* keep existing */ }
|
|
38
63
|
} else if (!authored.length && !options) {
|
|
39
64
|
renderEmpty(this, "combobox");
|
|
@@ -52,6 +77,75 @@ class ContourCombobox extends ContourBase {
|
|
|
52
77
|
const btn = this.querySelector(".c-combobox__clear");
|
|
53
78
|
if (btn) btn.remove();
|
|
54
79
|
}
|
|
80
|
+
}
|
|
81
|
+
_renderComboboxWindow(query = "", reset = false) {
|
|
82
|
+
const list = this.querySelector(".c-combobox__list");
|
|
83
|
+
const options = this._comboboxOptions || [];
|
|
84
|
+
if (!list) return;
|
|
85
|
+
const q = String(query || "").toLowerCase();
|
|
86
|
+
const filtered = options.map((opt, index) => ({
|
|
87
|
+
opt,
|
|
88
|
+
index,
|
|
89
|
+
label: typeof opt === "string" ? opt : opt.label,
|
|
90
|
+
value: typeof opt === "string" ? opt : opt.value,
|
|
91
|
+
})).filter((item) => !q || String(item.label).toLowerCase().includes(q));
|
|
92
|
+
this._comboboxFiltered = filtered;
|
|
93
|
+
const rowHeight = 32;
|
|
94
|
+
const windowSize = 20;
|
|
95
|
+
const overscan = 6;
|
|
96
|
+
const oldScrollTop = list.scrollTop;
|
|
97
|
+
const start = this._comboboxVirtual && !reset
|
|
98
|
+
? Math.min(Math.max(0, filtered.length - windowSize), Math.max(0, Math.floor(oldScrollTop / rowHeight) - overscan))
|
|
99
|
+
: 0;
|
|
100
|
+
this._comboboxWindowStart = start;
|
|
101
|
+
const end = this._comboboxVirtual ? Math.min(filtered.length, start + windowSize + overscan * 2) : filtered.length;
|
|
102
|
+
const selectedVals = (this.getAttribute("value") || "").split(",").map((v) => v.trim()).filter(Boolean);
|
|
103
|
+
list.innerHTML = "";
|
|
104
|
+
const addSpacer = (height) => {
|
|
105
|
+
const spacer = document.createElement("li");
|
|
106
|
+
spacer.setAttribute("aria-hidden", "true");
|
|
107
|
+
spacer.style.blockSize = `${height}px`;
|
|
108
|
+
list.appendChild(spacer);
|
|
109
|
+
};
|
|
110
|
+
if (this._comboboxVirtual) addSpacer(start * rowHeight);
|
|
111
|
+
if (!filtered.length) {
|
|
112
|
+
const empty = document.createElement("li");
|
|
113
|
+
empty.className = "c-combobox__empty";
|
|
114
|
+
empty.setAttribute("role", "status");
|
|
115
|
+
empty.textContent = this.getAttribute("empty") || "No matches";
|
|
116
|
+
list.appendChild(empty);
|
|
117
|
+
}
|
|
118
|
+
if (this.hasAttribute("multiple")) list.setAttribute("aria-multiselectable", "true");
|
|
119
|
+
else list.removeAttribute("aria-multiselectable");
|
|
120
|
+
filtered.slice(start, end).forEach((item) => {
|
|
121
|
+
const li = document.createElement("li");
|
|
122
|
+
li.className = "c-combobox__option";
|
|
123
|
+
li.dataset.optionIndex = String(item.index);
|
|
124
|
+
li.setAttribute("role", "option");
|
|
125
|
+
const label = String(item.label);
|
|
126
|
+
const q = String(query || "").toLowerCase();
|
|
127
|
+
if (q && label.toLowerCase().includes(q)) {
|
|
128
|
+
const idx = label.toLowerCase().indexOf(q);
|
|
129
|
+
const before = label.slice(0, idx);
|
|
130
|
+
const match = label.slice(idx, idx + q.length);
|
|
131
|
+
const after = label.slice(idx + q.length);
|
|
132
|
+
li.innerHTML = "";
|
|
133
|
+
if (before) li.appendChild(document.createTextNode(before));
|
|
134
|
+
const mark = document.createElement("mark");
|
|
135
|
+
mark.className = "c-combobox__match";
|
|
136
|
+
mark.textContent = match;
|
|
137
|
+
li.appendChild(mark);
|
|
138
|
+
if (after) li.appendChild(document.createTextNode(after));
|
|
139
|
+
} else {
|
|
140
|
+
li.textContent = label;
|
|
141
|
+
}
|
|
142
|
+
const isSelected = this.hasAttribute("multiple") && selectedVals.includes(String(item.value));
|
|
143
|
+
li.setAttribute("aria-selected", String(isSelected));
|
|
144
|
+
if (isSelected) li.classList.add("c-combobox__option--selected");
|
|
145
|
+
list.appendChild(li);
|
|
146
|
+
});
|
|
147
|
+
if (this._comboboxVirtual) addSpacer(Math.max(0, filtered.length - end) * rowHeight);
|
|
148
|
+
if (this._comboboxVirtual && !reset) list.scrollTop = oldScrollTop;
|
|
55
149
|
}
|
|
56
150
|
enhance() {
|
|
57
151
|
wireCombobox(this);
|
|
@@ -82,6 +176,13 @@ class ContourCombobox extends ContourBase {
|
|
|
82
176
|
}
|
|
83
177
|
}
|
|
84
178
|
define("contour-combobox", ContourCombobox);
|
|
179
|
+
/**
|
|
180
|
+
* Field: a labelled form control wrapper. Renders an `<input>`/`<textarea>`/
|
|
181
|
+
* `<select>` (or adopts an authored one), associates a label via `for`/`id`,
|
|
182
|
+
* and attaches hint and error text with `aria-describedby`. Drives inline
|
|
183
|
+
* validation on blur (`aria-invalid`, `is-invalid`) and keeps the form value in
|
|
184
|
+
* sync via `_internals.setFormValue`. Emits `contour:input` / `contour:change`.
|
|
185
|
+
*/
|
|
85
186
|
class ContourField extends ContourBase {
|
|
86
187
|
static get observed() { return ["label", "hint", "error", "placeholder", "type", "required"]; }
|
|
87
188
|
static get formAssociated() { return true; }
|
|
@@ -109,7 +210,7 @@ class ContourField extends ContourBase {
|
|
|
109
210
|
if (!input.id) input.id = contourId("contour-field");
|
|
110
211
|
// Associate the label with the input so the control is labelled.
|
|
111
212
|
const lbl = this.querySelector(".c-field__label");
|
|
112
|
-
if (lbl) { if (!input.id) input.id = contourId("contour-field"); lbl.setAttribute("for", input.id); }
|
|
213
|
+
if (lbl) { if (!input.id) input.id = contourId("contour-field"); lbl.setAttribute("for", input.id); input.setAttribute("aria-label", lbl.textContent); }
|
|
113
214
|
if (hint) {
|
|
114
215
|
const h = this.ensure(".c-field__hint", () => { const el = document.createElement("span"); el.className = "c-field__hint"; return el; });
|
|
115
216
|
h.textContent = hint;
|
|
@@ -190,10 +291,117 @@ class ContourField extends ContourBase {
|
|
|
190
291
|
sync();
|
|
191
292
|
};
|
|
192
293
|
define("contour-field", ContourField);
|
|
193
|
-
|
|
194
|
-
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Field-group: a grouped field with a shared label, optional hint and error
|
|
297
|
+
* text. Sets `role="group"` and `aria-required` when required; toggles
|
|
298
|
+
* `is-error` when an error is present. Child fields are labelled by the group.
|
|
299
|
+
*/
|
|
300
|
+
class ContourFieldGroup extends ContourBase {
|
|
301
|
+
static get observed() { return ["label", "hint", "error", "required"]; }
|
|
302
|
+
static get properties() { return { label: { attribute: "label" }, hint: { attribute: "hint" }, error: { attribute: "error" }, required: { attribute: "required", type: Boolean } }; }
|
|
303
|
+
render() {
|
|
304
|
+
this.classList.add("c-field-group");
|
|
305
|
+
this.setAttribute("role", "group");
|
|
306
|
+
const label = this.getAttribute("label");
|
|
307
|
+
if (label) {
|
|
308
|
+
const lbl = this.ensure(".c-field-group__label", () => { const el = document.createElement("div"); el.className = "c-field-group__label"; return el; });
|
|
309
|
+
lbl.textContent = label;
|
|
310
|
+
} else {
|
|
311
|
+
const lbl = this.querySelector(".c-field-group__label");
|
|
312
|
+
if (lbl) lbl.remove();
|
|
313
|
+
}
|
|
314
|
+
const hint = this.getAttribute("hint");
|
|
315
|
+
if (hint) {
|
|
316
|
+
const h = this.ensure(".c-field-group__hint", () => { const el = document.createElement("span"); el.className = "c-field-group__hint"; return el; });
|
|
317
|
+
h.textContent = hint;
|
|
318
|
+
} else {
|
|
319
|
+
const h = this.querySelector(".c-field-group__hint");
|
|
320
|
+
if (h) h.remove();
|
|
321
|
+
}
|
|
322
|
+
const error = this.getAttribute("error");
|
|
323
|
+
if (error) {
|
|
324
|
+
const e = this.ensure(".c-field-group__error", () => { const el = document.createElement("span"); el.className = "c-field-group__error"; return el; });
|
|
325
|
+
e.textContent = error;
|
|
326
|
+
} else {
|
|
327
|
+
const e = this.querySelector(".c-field-group__error");
|
|
328
|
+
if (e) e.remove();
|
|
329
|
+
}
|
|
330
|
+
if (error) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
331
|
+
if (this.hasAttribute("required")) this.setAttribute("aria-required", "true");
|
|
332
|
+
else this.removeAttribute("aria-required");
|
|
333
|
+
}
|
|
334
|
+
enhance() {
|
|
335
|
+
if (this._wiredFieldGroup) return;
|
|
336
|
+
this._wiredFieldGroup = true;
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
define("contour-field-group", ContourFieldGroup);
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Form: a form wrapper with submission state and a validation summary. Adds
|
|
343
|
+
* `is-submitting` and disables the submit button while `submitting` is set.
|
|
344
|
+
* On invalid submit, prevents default and renders a `role="alert"` summary
|
|
345
|
+
* listing the invalid fields. Emits `contour:submit` on valid submit.
|
|
346
|
+
*/
|
|
347
|
+
class ContourForm extends ContourBase {
|
|
348
|
+
static get observed() { return ["submitting", "error", "summary"]; }
|
|
349
|
+
static get properties() { return { submitting: { attribute: "submitting", type: Boolean }, error: { attribute: "error" }, summary: { attribute: "summary" } }; }
|
|
350
|
+
render() {
|
|
351
|
+
this.classList.add("c-form");
|
|
352
|
+
if (this.hasAttribute("submitting")) this.classList.add("is-submitting"); else this.classList.remove("is-submitting");
|
|
353
|
+
const summaryText = this.getAttribute("summary") || this.getAttribute("error");
|
|
354
|
+
let summary = this.querySelector(".c-form__summary");
|
|
355
|
+
if (summaryText) {
|
|
356
|
+
if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
|
|
357
|
+
summary.textContent = summaryText;
|
|
358
|
+
summary.removeAttribute("hidden");
|
|
359
|
+
} else if (summary) {
|
|
360
|
+
summary.setAttribute("hidden", "");
|
|
361
|
+
}
|
|
362
|
+
const submit = this.querySelector("[type='submit'], .c-form__submit");
|
|
363
|
+
if (submit) {
|
|
364
|
+
if (this.hasAttribute("submitting")) submit.setAttribute("disabled", "");
|
|
365
|
+
else submit.removeAttribute("disabled");
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
enhance() {
|
|
369
|
+
if (this._wiredForm) return;
|
|
370
|
+
this._wiredForm = true;
|
|
371
|
+
this.addEventListener("submit", (e) => {
|
|
372
|
+
const form = e.target;
|
|
373
|
+
if (form && typeof form.checkValidity === "function" && !form.checkValidity()) {
|
|
374
|
+
e.preventDefault();
|
|
375
|
+
const invalid = Array.from(form.querySelectorAll(":invalid"));
|
|
376
|
+
const names = invalid.map((el) => el.getAttribute("aria-label") || el.name || el.id || "field").join(", ");
|
|
377
|
+
// Update DOM directly (avoid setAttribute on observed attr -> re-entrancy).
|
|
378
|
+
let summary = this.querySelector(".c-form__summary");
|
|
379
|
+
if (!summary) { summary = document.createElement("div"); summary.className = "c-form__summary"; summary.setAttribute("role", "alert"); this.prepend(summary); }
|
|
380
|
+
summary.textContent = "Please fix: " + (names || "invalid fields");
|
|
381
|
+
summary.removeAttribute("hidden");
|
|
382
|
+
return;
|
|
383
|
+
}
|
|
384
|
+
// submitting state via class + button, not attribute.
|
|
385
|
+
this.classList.add("is-submitting");
|
|
386
|
+
const submit = this.querySelector("[type='submit'], .c-form__submit");
|
|
387
|
+
if (submit) submit.setAttribute("disabled", "");
|
|
388
|
+
this.dispatchEvent(new CustomEvent("contour:submit", { bubbles: true, composed: true, detail: { submitting: true } }));
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
define("contour-form", ContourForm);
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* Range: a native `<input type=range>` wrapper with optional dual-handle range
|
|
396
|
+
* mode (`range`, `low`, `high`) and a sparkline canvas (`sparkline`). Form
|
|
397
|
+
* associated; emits `contour:input` / `contour:change` with the current value
|
|
398
|
+
* (or `{low, high}` in range mode). Renders a `--fill` custom property for the
|
|
399
|
+
* filled track.
|
|
400
|
+
*/
|
|
401
|
+
class ContourRange extends ContourBase {
|
|
402
|
+
static get observed() { return ["min", "max", "value", "low", "high", "range", "sparkline", "label", "disabled", "error", "help"]; }
|
|
195
403
|
static get formAssociated() { return true; }
|
|
196
|
-
static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" } }; }
|
|
404
|
+
static get properties() { return { min: { attribute: "min" }, max: { attribute: "max" }, value: { attribute: "value" }, label: { attribute: "label" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
197
405
|
render() {
|
|
198
406
|
this.classList.add("c-range");
|
|
199
407
|
const min = this.getAttribute("min") || "0";
|
|
@@ -316,9 +524,15 @@ class ContourField extends ContourBase {
|
|
|
316
524
|
sync();
|
|
317
525
|
};
|
|
318
526
|
define("contour-range", ContourRange);
|
|
527
|
+
/**
|
|
528
|
+
* Switch: a `role="switch"` checkbox control with label, required, disabled,
|
|
529
|
+
* error and help states. Form associated; emits `contour:change` on toggle.
|
|
530
|
+
* Renders a `c-switch__track` element after the input for the sheet's track
|
|
531
|
+
* styling.
|
|
532
|
+
*/
|
|
319
533
|
class ContourSwitch extends ContourBase {
|
|
320
|
-
static get observed() { return ["label", "required", "checked"]; }
|
|
321
|
-
static get properties() { return { label: { attribute: "label" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean } }; }
|
|
534
|
+
static get observed() { return ["label", "required", "checked", "disabled", "error", "help"]; }
|
|
535
|
+
static get properties() { return { label: { attribute: "label" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
322
536
|
static get formAssociated() { return true; }
|
|
323
537
|
render() {
|
|
324
538
|
this.classList.add("c-switch");
|
|
@@ -330,6 +544,17 @@ class ContourSwitch extends ContourBase {
|
|
|
330
544
|
input.setAttribute("role", "switch");
|
|
331
545
|
input.setAttribute("aria-checked", String(input.checked));
|
|
332
546
|
this._setCustomState("data-checked", input.checked);
|
|
547
|
+
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
548
|
+
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
549
|
+
const err = this.getAttribute("error");
|
|
550
|
+
const help = this.getAttribute("help");
|
|
551
|
+
let msg = this.querySelector(".c-switch__message");
|
|
552
|
+
if (err || help) {
|
|
553
|
+
if (!msg) { msg = document.createElement("div"); msg.className = "c-switch__message"; this.appendChild(msg); }
|
|
554
|
+
msg.textContent = err || help || "";
|
|
555
|
+
msg.classList.toggle("c-switch__message--error", !!err);
|
|
556
|
+
} else if (msg) { msg.remove(); }
|
|
557
|
+
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
333
558
|
// Ensure track element follows the input (CSS: input + track).
|
|
334
559
|
if (!input.nextElementSibling || !input.nextElementSibling.classList.contains("c-switch__track")) {
|
|
335
560
|
const track = document.createElement("span");
|
|
@@ -366,9 +591,15 @@ class ContourSwitch extends ContourBase {
|
|
|
366
591
|
}
|
|
367
592
|
}
|
|
368
593
|
define("contour-switch", ContourSwitch);
|
|
594
|
+
/**
|
|
595
|
+
* Check: a checkbox (or `type="radio"` when `type` is set) with label, name,
|
|
596
|
+
* value, required, checked, disabled, error and help states. Renders a
|
|
597
|
+
* `c-check__box` element after the input. Form associated; emits
|
|
598
|
+
* `contour:change` on toggle.
|
|
599
|
+
*/
|
|
369
600
|
class ContourCheck extends ContourBase {
|
|
370
|
-
static get observed() { return ["label", "name", "value", "required", "type", "checked"]; }
|
|
371
|
-
static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, type: { attribute: "type" }, checked: { attribute: "checked", type: Boolean } }; }
|
|
601
|
+
static get observed() { return ["label", "name", "value", "required", "type", "checked", "disabled", "error", "help"]; }
|
|
602
|
+
static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, type: { attribute: "type" }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
372
603
|
static get formAssociated() { return true; }
|
|
373
604
|
render() {
|
|
374
605
|
this.classList.add("c-check");
|
|
@@ -390,6 +621,17 @@ class ContourCheck extends ContourBase {
|
|
|
390
621
|
}
|
|
391
622
|
if (this.hasAttribute("name")) input.name = this.getAttribute("name");
|
|
392
623
|
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
624
|
+
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
625
|
+
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
626
|
+
const err = this.getAttribute("error");
|
|
627
|
+
const help = this.getAttribute("help");
|
|
628
|
+
let msg = this.querySelector(".c-check__message");
|
|
629
|
+
if (err || help) {
|
|
630
|
+
if (!msg) { msg = document.createElement("div"); msg.className = "c-check__message"; this.appendChild(msg); }
|
|
631
|
+
msg.textContent = err || help || "";
|
|
632
|
+
msg.classList.toggle("c-check__message--error", !!err);
|
|
633
|
+
} else if (msg) { msg.remove(); }
|
|
634
|
+
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
393
635
|
}
|
|
394
636
|
enhance() {
|
|
395
637
|
const input = this.querySelector("input");
|
|
@@ -411,9 +653,14 @@ class ContourCheck extends ContourBase {
|
|
|
411
653
|
}
|
|
412
654
|
}
|
|
413
655
|
define("contour-check", ContourCheck);
|
|
656
|
+
/**
|
|
657
|
+
* Radio: a radio button with label, name, value, required, checked, disabled,
|
|
658
|
+
* error and help states. Form associated; unchecking clears the stale FormData
|
|
659
|
+
* entry. Emits `contour:change` on toggle.
|
|
660
|
+
*/
|
|
414
661
|
class ContourRadio extends ContourBase {
|
|
415
|
-
static get observed() { return ["label", "name", "value", "required", "checked"]; }
|
|
416
|
-
static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean } }; }
|
|
662
|
+
static get observed() { return ["label", "name", "value", "required", "checked", "disabled", "error", "help"]; }
|
|
663
|
+
static get properties() { return { label: { attribute: "label" }, name: { attribute: "name" }, value: { attribute: "value" }, required: { attribute: "required", type: Boolean }, checked: { attribute: "checked", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
417
664
|
static get formAssociated() { return true; }
|
|
418
665
|
render() {
|
|
419
666
|
this.classList.add("c-radio");
|
|
@@ -422,6 +669,17 @@ class ContourRadio extends ContourBase {
|
|
|
422
669
|
input.checked = this.hasAttribute("checked");
|
|
423
670
|
if (this.hasAttribute("name")) input.name = this.getAttribute("name");
|
|
424
671
|
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
672
|
+
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
673
|
+
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
674
|
+
const err = this.getAttribute("error");
|
|
675
|
+
const help = this.getAttribute("help");
|
|
676
|
+
let msg = this.querySelector(".c-radio__message");
|
|
677
|
+
if (err || help) {
|
|
678
|
+
if (!msg) { msg = document.createElement("div"); msg.className = "c-radio__message"; this.appendChild(msg); }
|
|
679
|
+
msg.textContent = err || help || "";
|
|
680
|
+
msg.classList.toggle("c-radio__message--error", !!err);
|
|
681
|
+
} else if (msg) { msg.remove(); }
|
|
682
|
+
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
425
683
|
if (label) {
|
|
426
684
|
input.setAttribute("aria-label", label);
|
|
427
685
|
const txt = this.querySelector(":scope > span:not([class])") || (() => { const el = document.createElement("span"); this.appendChild(el); return el; })();
|
|
@@ -450,9 +708,14 @@ class ContourRadio extends ContourBase {
|
|
|
450
708
|
}
|
|
451
709
|
}
|
|
452
710
|
define("contour-radio", ContourRadio);
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
711
|
+
/**
|
|
712
|
+
* Select: a native `<select>` wrapper populated from a JSON `options` attribute
|
|
713
|
+
* (with optgroup support) or an authored `<select>`. Supports label, placeholder,
|
|
714
|
+
* required, disabled, error and help. Form associated; emits `contour:change`.
|
|
715
|
+
*/
|
|
716
|
+
class ContourSelect extends ContourBase {
|
|
717
|
+
static get observed() { return ["options", "required", "label", "placeholder", "disabled", "error", "help"]; }
|
|
718
|
+
static get properties() { return { options: { attribute: "options" }, required: { attribute: "required", type: Boolean }, label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
456
719
|
static get formAssociated() { return true; }
|
|
457
720
|
render() {
|
|
458
721
|
this.classList.add("c-select");
|
|
@@ -468,10 +731,6 @@ class ContourRadio extends ContourBase {
|
|
|
468
731
|
const label = this.getAttribute("label");
|
|
469
732
|
if (label) {
|
|
470
733
|
select.setAttribute("aria-label", label);
|
|
471
|
-
// Associated label element.
|
|
472
|
-
let lbl = this.querySelector("label.c-select__label");
|
|
473
|
-
if (!lbl) { lbl = document.createElement("label"); lbl.className = "c-select__label"; lbl.textContent = label; this.insertBefore(lbl, select); }
|
|
474
|
-
else lbl.textContent = label;
|
|
475
734
|
}
|
|
476
735
|
const placeholder = this.getAttribute("placeholder");
|
|
477
736
|
if (placeholder) {
|
|
@@ -504,6 +763,35 @@ class ContourRadio extends ContourBase {
|
|
|
504
763
|
select.classList.add("c-select");
|
|
505
764
|
} catch (e) { /* keep existing */ }
|
|
506
765
|
}
|
|
766
|
+
// Ensure authored select gets c-select styling.
|
|
767
|
+
const authoredSel = this.querySelector("select");
|
|
768
|
+
if (authoredSel && !authoredSel.classList.contains("c-select")) {
|
|
769
|
+
authoredSel.classList.add("c-select");
|
|
770
|
+
this.classList.remove("c-select");
|
|
771
|
+
}
|
|
772
|
+
// Disabled / error / help contract (applies to authored or generated select).
|
|
773
|
+
const sel = this.querySelector("select");
|
|
774
|
+
if (sel) {
|
|
775
|
+
if (this.hasAttribute("disabled")) { sel.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
776
|
+
else { sel.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
777
|
+
}
|
|
778
|
+
// Label (applies to both JSON and authored options).
|
|
779
|
+
const label = this.getAttribute("label");
|
|
780
|
+
if (label) {
|
|
781
|
+
let lbl = this.querySelector("label.c-select__label");
|
|
782
|
+
if (!lbl) { lbl = document.createElement("label"); lbl.className = "c-select__label"; this.insertBefore(lbl, sel || this.firstChild); }
|
|
783
|
+
lbl.textContent = label;
|
|
784
|
+
if (sel) sel.setAttribute("aria-label", label);
|
|
785
|
+
}
|
|
786
|
+
const err = this.getAttribute("error");
|
|
787
|
+
const help = this.getAttribute("help");
|
|
788
|
+
let msg = this.querySelector(".c-select__message");
|
|
789
|
+
if (err || help) {
|
|
790
|
+
if (!msg) { msg = document.createElement("div"); msg.className = "c-select__message"; this.appendChild(msg); }
|
|
791
|
+
msg.textContent = err || help || "";
|
|
792
|
+
msg.classList.toggle("c-select__message--error", !!err);
|
|
793
|
+
} else if (msg) { msg.remove(); }
|
|
794
|
+
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
507
795
|
}
|
|
508
796
|
enhance() {
|
|
509
797
|
const select = this.querySelector("select");
|
|
@@ -523,6 +811,10 @@ class ContourRadio extends ContourBase {
|
|
|
523
811
|
}
|
|
524
812
|
}
|
|
525
813
|
define("contour-select", ContourSelect);
|
|
814
|
+
/**
|
|
815
|
+
* Version: a `<select>` of version options from a JSON `options` attribute,
|
|
816
|
+
* with `selected` support per option. Form associated; emits `contour:change`.
|
|
817
|
+
*/
|
|
526
818
|
class ContourVersion extends ContourBase {
|
|
527
819
|
static get observed() { return ["options"]; }
|
|
528
820
|
static get formAssociated() { return true; }
|
|
@@ -568,17 +860,31 @@ class ContourVersion extends ContourBase {
|
|
|
568
860
|
}
|
|
569
861
|
}
|
|
570
862
|
define("contour-version", ContourVersion);
|
|
863
|
+
/**
|
|
864
|
+
* Textarea: a `<textarea>` wrapper with placeholder, required, disabled, error
|
|
865
|
+
* and help states. Form associated; emits `contour:input` / `contour:change`.
|
|
866
|
+
*/
|
|
571
867
|
class ContourTextarea extends ContourBase {
|
|
572
|
-
static get observed() { return ["placeholder", "required"]; }
|
|
573
|
-
static get properties() { return { placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean } }; }
|
|
868
|
+
static get observed() { return ["placeholder", "required", "disabled", "error", "help"]; }
|
|
869
|
+
static get properties() { return { placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" } }; }
|
|
574
870
|
static get formAssociated() { return true; }
|
|
575
871
|
render() {
|
|
576
|
-
this.classList.add("c-textarea");
|
|
577
872
|
const ta = this.ensure("textarea", () => { const el = document.createElement("textarea"); el.className = "c-textarea"; return el; });
|
|
578
873
|
ta.className = "c-textarea";
|
|
579
874
|
ta.placeholder = this.getAttribute("placeholder") || "";
|
|
580
875
|
if (this.hasAttribute("required")) ta.setAttribute("required", "");
|
|
581
876
|
else ta.removeAttribute("required");
|
|
877
|
+
if (this.hasAttribute("disabled")) { ta.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
878
|
+
else { ta.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
879
|
+
const err = this.getAttribute("error");
|
|
880
|
+
const help = this.getAttribute("help");
|
|
881
|
+
let msg = this.querySelector(".c-textarea__message");
|
|
882
|
+
if (err || help) {
|
|
883
|
+
if (!msg) { msg = document.createElement("div"); msg.className = "c-textarea__message"; this.appendChild(msg); }
|
|
884
|
+
msg.textContent = err || help || "";
|
|
885
|
+
msg.classList.toggle("c-textarea__message--error", !!err);
|
|
886
|
+
} else if (msg) { msg.remove(); }
|
|
887
|
+
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
582
888
|
}
|
|
583
889
|
enhance() {
|
|
584
890
|
const ta = this.querySelector("textarea");
|
|
@@ -605,19 +911,38 @@ class ContourTextarea extends ContourBase {
|
|
|
605
911
|
}
|
|
606
912
|
}
|
|
607
913
|
define("contour-textarea", ContourTextarea);
|
|
914
|
+
/**
|
|
915
|
+
* Input: an `<input>` wrapper with type, placeholder, required, value, disabled,
|
|
916
|
+
* error and help states. Form associated; emits `contour:input` / `contour:change`.
|
|
917
|
+
*/
|
|
608
918
|
class ContourInputFull extends ContourBase {
|
|
609
|
-
static get observed() { return ["type", "placeholder", "required", "value"]; }
|
|
610
|
-
static get properties() { return { type: { attribute: "type" }, placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, value: { attribute: "value" } }; }
|
|
919
|
+
static get observed() { return ["type", "placeholder", "required", "value", "disabled", "error", "help", "label"]; }
|
|
920
|
+
static get properties() { return { type: { attribute: "type" }, placeholder: { attribute: "placeholder" }, required: { attribute: "required", type: Boolean }, value: { attribute: "value" }, disabled: { attribute: "disabled", type: Boolean }, error: { attribute: "error" }, help: { attribute: "help" }, label: { attribute: "label" } }; }
|
|
611
921
|
static get formAssociated() { return true; }
|
|
612
922
|
render() {
|
|
613
923
|
this.classList.add("c-input");
|
|
614
924
|
const input = this.ensure("input", () => { const el = document.createElement("input"); el.className = "c-input"; return el; });
|
|
615
925
|
input.className = "c-input";
|
|
616
926
|
input.type = this.getAttribute("type") || "text";
|
|
617
|
-
|
|
927
|
+
input.placeholder = this.getAttribute("placeholder") || "";
|
|
928
|
+
const label = this.getAttribute("label");
|
|
929
|
+
if (label) input.setAttribute("aria-label", label);
|
|
930
|
+
// else: keep any aria-label set by an ancestor (e.g. contour-field).
|
|
618
931
|
if (this.hasAttribute("value")) input.value = this.getAttribute("value");
|
|
619
932
|
if (this.hasAttribute("required")) input.setAttribute("required", "");
|
|
620
933
|
else input.removeAttribute("required");
|
|
934
|
+
if (this.hasAttribute("disabled")) { input.setAttribute("disabled", ""); this.classList.add("is-disabled"); }
|
|
935
|
+
else { input.removeAttribute("disabled"); this.classList.remove("is-disabled"); }
|
|
936
|
+
// Error/help text
|
|
937
|
+
const err = this.getAttribute("error");
|
|
938
|
+
const help = this.getAttribute("help");
|
|
939
|
+
let msg = this.querySelector(".c-input__message");
|
|
940
|
+
if (err || help) {
|
|
941
|
+
if (!msg) { msg = document.createElement("div"); msg.className = "c-input__message"; this.appendChild(msg); }
|
|
942
|
+
msg.textContent = err || help || "";
|
|
943
|
+
msg.classList.toggle("c-input__message--error", !!err);
|
|
944
|
+
} else if (msg) { msg.remove(); }
|
|
945
|
+
if (err) this.classList.add("is-error"); else this.classList.remove("is-error");
|
|
621
946
|
}
|
|
622
947
|
enhance() {
|
|
623
948
|
const input = this.querySelector("input");
|
|
@@ -644,6 +969,12 @@ class ContourInputFull extends ContourBase {
|
|
|
644
969
|
}
|
|
645
970
|
}
|
|
646
971
|
define("contour-input", ContourInputFull);
|
|
972
|
+
/**
|
|
973
|
+
* InputGroup: a text input with an optional search icon, a clear (×) affordance
|
|
974
|
+
* and a submit (→) affordance. Attributes: `label`, `placeholder`, `clearable`,
|
|
975
|
+
* `submit`. Emits `contour:change` (bubbles, composed) with `{ value: "" }` on
|
|
976
|
+
* clear.
|
|
977
|
+
*/
|
|
647
978
|
class ContourInputGroup extends ContourBase {
|
|
648
979
|
static get observed() { return ["label", "placeholder", "clearable", "submit"]; }
|
|
649
980
|
static get properties() { return { label: { attribute: "label" }, placeholder: { attribute: "placeholder" }, clearable: { attribute: "clearable", type: Boolean }, submit: { attribute: "submit", type: Boolean } }; }
|
|
@@ -690,6 +1021,12 @@ class ContourInputGroup extends ContourBase {
|
|
|
690
1021
|
}
|
|
691
1022
|
}
|
|
692
1023
|
define("contour-input-group", ContourInputGroup);
|
|
1024
|
+
/**
|
|
1025
|
+
* RadioList: a `role="radiogroup"` of radio options from a JSON `items`
|
|
1026
|
+
* attribute (or remote `src`). Supports roving tabindex, Home/End navigation,
|
|
1027
|
+
* RTL, empty/loading/error states, and `formResetCallback` that re-renders from
|
|
1028
|
+
* the authored `items` payload. Form associated; emits `contour:change`.
|
|
1029
|
+
*/
|
|
693
1030
|
class ContourRadioList extends ContourBase {
|
|
694
1031
|
static get observed() { return ["items", "name", "empty", "loading", "error", "retry", "src", "lazy", "refresh", "timeout", "skeleton"]; }
|
|
695
1032
|
static get properties() { return { items: { attribute: "items" }, name: { attribute: "name" }, src: { attribute: "src" } }; }
|
package/dist/wc/index.mjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Contour web-component entry point.
|
|
3
|
+
* Importing this module registers every light-DOM and shadow-DOM element.
|
|
4
|
+
* @module contour-wc
|
|
5
|
+
*/
|
|
3
6
|
|
|
4
7
|
import { REGISTERED } from "./core.mjs";
|
|
8
|
+
import { formatValue } from "./core.mjs";
|
|
9
|
+
import { MARKER_SHAPES, markerStyles, assignMarkers } from "./svg.mjs";
|
|
5
10
|
import "./core.mjs";
|
|
6
11
|
import "./behaviours.mjs";
|
|
7
12
|
import "./states.mjs";
|
|
@@ -22,9 +27,32 @@ import "./shadow.mjs";
|
|
|
22
27
|
|
|
23
28
|
// Published version + readiness signal. Fires after every fragment has run, so
|
|
24
29
|
// a consumer listening for `contour:ready` can assume the full registry exists.
|
|
25
|
-
|
|
30
|
+
/** Published component runtime version. */
|
|
31
|
+
export const CONTOUR_VERSION = "1.7.0";
|
|
26
32
|
if (typeof window !== "undefined") {
|
|
27
33
|
window.ContourVersion = CONTOUR_VERSION;
|
|
34
|
+
if (!window.Contour) {
|
|
35
|
+
window.Contour = {
|
|
36
|
+
format: {
|
|
37
|
+
value: formatValue,
|
|
38
|
+
number: (value, format, locale) => formatValue(value, format, locale),
|
|
39
|
+
time: (value, locale) => {
|
|
40
|
+
try { return new Intl.DateTimeFormat(locale || undefined).format(new Date(value)); } catch (e) { return String(value); }
|
|
41
|
+
},
|
|
42
|
+
locale: (locale) => locale || (typeof navigator !== "undefined" ? navigator.language : "en"),
|
|
43
|
+
},
|
|
44
|
+
markers: {
|
|
45
|
+
shapes: MARKER_SHAPES,
|
|
46
|
+
styles: markerStyles,
|
|
47
|
+
assign: assignMarkers,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
} else {
|
|
51
|
+
// ds.js may have already published window.Contour (frozen); top up
|
|
52
|
+
// non-frozen namespaces only when writable.
|
|
53
|
+
try { if (!window.Contour.format) window.Contour.format = { value: formatValue, number: (v, f, l) => formatValue(v, f, l), time: (v, l) => { try { return new Intl.DateTimeFormat(l || undefined).format(new Date(v)); } catch (e) { return String(v); } }, locale: (l) => l || (typeof navigator !== "undefined" ? navigator.language : "en") }; } catch (e) {}
|
|
54
|
+
try { if (!window.Contour.markers) window.Contour.markers = { shapes: MARKER_SHAPES, styles: markerStyles, assign: assignMarkers }; } catch (e) {}
|
|
55
|
+
}
|
|
28
56
|
queueMicrotask(() => {
|
|
29
57
|
try {
|
|
30
58
|
window.dispatchEvent(new CustomEvent("contour:ready", {
|