@auriel/peppertino 0.2.0 → 0.4.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/CHANGELOG.txt +122 -56
- package/README.md +333 -38
- package/dist/accordion.js +51 -0
- package/dist/accordion.js.map +7 -0
- package/dist/carousel.js +152 -0
- package/dist/carousel.js.map +7 -0
- package/dist/header.js +30 -3
- package/dist/header.js.map +2 -2
- package/dist/main.css +4660 -710
- package/dist/main.css.map +1 -1
- package/dist/modal.js +61 -2
- package/dist/modal.js.map +2 -2
- package/dist/peppertino.js +477 -17
- package/dist/peppertino.js.map +4 -4
- package/dist/select.js +25 -8
- package/dist/select.js.map +3 -3
- package/dist/tabs.js +31 -4
- package/dist/tabs.js.map +2 -2
- package/dist/validation.js +130 -0
- package/dist/validation.js.map +7 -0
- package/index.html +1493 -42
- package/package.json +1 -1
- package/src/js/accordion.js +61 -0
- package/src/js/carousel.js +148 -0
- package/src/js/peppertino.js +4 -0
- package/src/js/validation.js +132 -0
- package/src/scss/accordion.scss +156 -0
- package/src/scss/alert.scss +204 -0
- package/src/scss/base.scss +130 -16
- package/src/scss/card.scss +4 -4
- package/src/scss/carousel.scss +313 -0
- package/src/scss/dark-mode.scss +474 -0
- package/src/scss/footer.scss +224 -0
- package/src/scss/forms/fieldset.scss +127 -0
- package/src/scss/forms/form-instructions.scss +133 -0
- package/src/scss/forms/label.scss +115 -0
- package/src/scss/forms/text-field.scss +240 -0
- package/src/scss/forms/validation.scss +215 -0
- package/src/scss/forms.scss +8 -0
- package/src/scss/header.scss +8 -8
- package/src/scss/main.scss +7 -0
- package/src/scss/section.scss +1 -1
- package/src/scss/select.scss +5 -5
- package/src/scss/table.scss +5 -5
- package/src/scss/utilities.scss +243 -0
- package/.claude/settings.local.json +0 -8
package/dist/peppertino.js
CHANGED
|
@@ -1,39 +1,267 @@
|
|
|
1
1
|
(() => {
|
|
2
|
+
// src/js/accordion.js
|
|
3
|
+
(function() {
|
|
4
|
+
document.querySelectorAll(".pp-accordion").forEach((accordion) => {
|
|
5
|
+
const allowMultiple = accordion.hasAttribute("data-allow-multiple");
|
|
6
|
+
accordion.querySelectorAll(".pp-accordion__trigger").forEach((trigger) => {
|
|
7
|
+
const panelId = trigger.getAttribute("aria-controls");
|
|
8
|
+
const panel = panelId ? document.getElementById(panelId) : trigger.nextElementSibling;
|
|
9
|
+
if (!panel) return;
|
|
10
|
+
const isOpen = trigger.getAttribute("aria-expanded") === "true";
|
|
11
|
+
panel.setAttribute("aria-hidden", isOpen ? "false" : "true");
|
|
12
|
+
if (isOpen) panel.classList.add("is-open");
|
|
13
|
+
trigger.addEventListener("click", () => {
|
|
14
|
+
const expanded = trigger.getAttribute("aria-expanded") === "true";
|
|
15
|
+
if (!allowMultiple) {
|
|
16
|
+
accordion.querySelectorAll(".pp-accordion__trigger").forEach((t) => {
|
|
17
|
+
if (t === trigger) return;
|
|
18
|
+
t.setAttribute("aria-expanded", "false");
|
|
19
|
+
const p = t.getAttribute("aria-controls") ? document.getElementById(t.getAttribute("aria-controls")) : t.nextElementSibling;
|
|
20
|
+
if (p) {
|
|
21
|
+
p.setAttribute("aria-hidden", "true");
|
|
22
|
+
p.classList.remove("is-open");
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const next = !expanded;
|
|
27
|
+
trigger.setAttribute("aria-expanded", String(next));
|
|
28
|
+
panel.setAttribute("aria-hidden", String(!next));
|
|
29
|
+
panel.classList.toggle("is-open", next);
|
|
30
|
+
});
|
|
31
|
+
trigger.addEventListener("keydown", (e) => {
|
|
32
|
+
const triggers = [...accordion.querySelectorAll(".pp-accordion__trigger")];
|
|
33
|
+
const idx = triggers.indexOf(trigger);
|
|
34
|
+
if (e.key === "ArrowDown") {
|
|
35
|
+
e.preventDefault();
|
|
36
|
+
triggers[(idx + 1) % triggers.length].focus();
|
|
37
|
+
} else if (e.key === "ArrowUp") {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
triggers[(idx - 1 + triggers.length) % triggers.length].focus();
|
|
40
|
+
} else if (e.key === "Home") {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
triggers[0].focus();
|
|
43
|
+
} else if (e.key === "End") {
|
|
44
|
+
e.preventDefault();
|
|
45
|
+
triggers[triggers.length - 1].focus();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
})();
|
|
51
|
+
|
|
52
|
+
// src/js/carousel.js
|
|
53
|
+
(function() {
|
|
54
|
+
function initCarousel(root, rootIdx) {
|
|
55
|
+
const track = root.querySelector(".pp-carousel__track");
|
|
56
|
+
const slides = [...root.querySelectorAll(".pp-carousel__slide")];
|
|
57
|
+
const dots = [...root.querySelectorAll(".pp-carousel__dot")];
|
|
58
|
+
const prevBtn = root.querySelector(".pp-carousel__prev");
|
|
59
|
+
const nextBtn = root.querySelector(".pp-carousel__next");
|
|
60
|
+
const autoplayBtn = root.querySelector(".pp-carousel__autoplay");
|
|
61
|
+
if (!track || !slides.length) return;
|
|
62
|
+
const total = slides.length;
|
|
63
|
+
let current = 0;
|
|
64
|
+
if (!root.getAttribute("role")) root.setAttribute("role", "region");
|
|
65
|
+
if (!root.getAttribute("aria-roledescription")) root.setAttribute("aria-roledescription", "carousel");
|
|
66
|
+
if (!root.getAttribute("aria-label") && !root.getAttribute("aria-labelledby")) {
|
|
67
|
+
root.setAttribute("aria-label", root.dataset.label || `Carousel ${rootIdx + 1}`);
|
|
68
|
+
}
|
|
69
|
+
track.setAttribute("aria-live", "off");
|
|
70
|
+
slides.forEach((slide, i) => {
|
|
71
|
+
slide.setAttribute("role", "group");
|
|
72
|
+
if (!slide.getAttribute("aria-roledescription")) slide.setAttribute("aria-roledescription", "slide");
|
|
73
|
+
if (!slide.getAttribute("aria-label")) slide.setAttribute("aria-label", `${i + 1} of ${total}`);
|
|
74
|
+
});
|
|
75
|
+
let announcer = root.querySelector(".pp-carousel__announcer");
|
|
76
|
+
if (!announcer) {
|
|
77
|
+
announcer = document.createElement("div");
|
|
78
|
+
announcer.className = "pp-carousel__announcer";
|
|
79
|
+
root.appendChild(announcer);
|
|
80
|
+
}
|
|
81
|
+
announcer.setAttribute("aria-live", "polite");
|
|
82
|
+
announcer.setAttribute("aria-atomic", "true");
|
|
83
|
+
dots.forEach((dot, i) => {
|
|
84
|
+
if (!dot.id) dot.id = `pp-carousel-${rootIdx}-dot-${i}`;
|
|
85
|
+
if (!dot.getAttribute("aria-label")) dot.setAttribute("aria-label", `Go to slide ${i + 1}`);
|
|
86
|
+
});
|
|
87
|
+
if (prevBtn && !prevBtn.getAttribute("aria-label")) prevBtn.setAttribute("aria-label", "Previous slide");
|
|
88
|
+
if (nextBtn && !nextBtn.getAttribute("aria-label")) nextBtn.setAttribute("aria-label", "Next slide");
|
|
89
|
+
function syncUI(idx) {
|
|
90
|
+
current = idx;
|
|
91
|
+
slides.forEach((slide, i) => slide.setAttribute("aria-hidden", String(i !== idx)));
|
|
92
|
+
dots.forEach((dot, i) => {
|
|
93
|
+
dot.classList.toggle("is-active", i === idx);
|
|
94
|
+
dot.setAttribute("aria-current", String(i === idx));
|
|
95
|
+
dot.setAttribute("tabindex", i === idx ? "0" : "-1");
|
|
96
|
+
});
|
|
97
|
+
if (prevBtn) {
|
|
98
|
+
prevBtn.disabled = idx === 0;
|
|
99
|
+
prevBtn.setAttribute("aria-disabled", String(idx === 0));
|
|
100
|
+
}
|
|
101
|
+
if (nextBtn) {
|
|
102
|
+
nextBtn.disabled = idx === total - 1;
|
|
103
|
+
nextBtn.setAttribute("aria-disabled", String(idx === total - 1));
|
|
104
|
+
}
|
|
105
|
+
const label = slides[idx].getAttribute("aria-label") || `Slide ${idx + 1}`;
|
|
106
|
+
announcer.textContent = "";
|
|
107
|
+
requestAnimationFrame(() => {
|
|
108
|
+
announcer.textContent = label;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const observer = new IntersectionObserver(
|
|
112
|
+
(entries) => {
|
|
113
|
+
entries.forEach((entry) => {
|
|
114
|
+
if (entry.isIntersecting) {
|
|
115
|
+
const idx = slides.indexOf(entry.target);
|
|
116
|
+
if (idx !== -1 && idx !== current) syncUI(idx);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
{ root: track, threshold: 0.5 }
|
|
121
|
+
);
|
|
122
|
+
slides.forEach((slide) => observer.observe(slide));
|
|
123
|
+
function goTo(idx) {
|
|
124
|
+
const clamped = Math.max(0, Math.min(total - 1, idx));
|
|
125
|
+
slides[clamped].scrollIntoView({ behavior: "smooth", block: "nearest", inline: "start" });
|
|
126
|
+
syncUI(clamped);
|
|
127
|
+
}
|
|
128
|
+
if (prevBtn) prevBtn.addEventListener("click", () => goTo(current - 1));
|
|
129
|
+
if (nextBtn) nextBtn.addEventListener("click", () => goTo(current + 1));
|
|
130
|
+
dots.forEach((dot, i) => {
|
|
131
|
+
dot.addEventListener("click", () => goTo(i));
|
|
132
|
+
dot.addEventListener("keydown", (e) => {
|
|
133
|
+
if (e.key === "ArrowRight" || e.key === "ArrowDown") {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
goTo((i + 1) % total);
|
|
136
|
+
dots[(i + 1) % total].focus();
|
|
137
|
+
}
|
|
138
|
+
if (e.key === "ArrowLeft" || e.key === "ArrowUp") {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
goTo((i - 1 + total) % total);
|
|
141
|
+
dots[(i - 1 + total) % total].focus();
|
|
142
|
+
}
|
|
143
|
+
if (e.key === "Home") {
|
|
144
|
+
e.preventDefault();
|
|
145
|
+
goTo(0);
|
|
146
|
+
dots[0].focus();
|
|
147
|
+
}
|
|
148
|
+
if (e.key === "End") {
|
|
149
|
+
e.preventDefault();
|
|
150
|
+
goTo(total - 1);
|
|
151
|
+
dots[total - 1].focus();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
if (autoplayBtn) {
|
|
156
|
+
autoplayBtn.addEventListener("click", () => {
|
|
157
|
+
const playing = root.classList.contains("pp-carousel--playing");
|
|
158
|
+
root.classList.toggle("pp-carousel--playing", !playing);
|
|
159
|
+
root.classList.toggle("pp-carousel--paused", playing);
|
|
160
|
+
autoplayBtn.setAttribute("aria-pressed", String(!playing));
|
|
161
|
+
autoplayBtn.setAttribute("aria-label", playing ? "Start autoplay" : "Pause autoplay");
|
|
162
|
+
root.dispatchEvent(new CustomEvent("pp-carousel:autoplay", { bubbles: true, detail: { playing: !playing } }));
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
track.setAttribute("tabindex", "0");
|
|
166
|
+
track.addEventListener("keydown", (e) => {
|
|
167
|
+
if (e.key === "ArrowRight") {
|
|
168
|
+
e.preventDefault();
|
|
169
|
+
goTo(current + 1);
|
|
170
|
+
}
|
|
171
|
+
if (e.key === "ArrowLeft") {
|
|
172
|
+
e.preventDefault();
|
|
173
|
+
goTo(current - 1);
|
|
174
|
+
}
|
|
175
|
+
if (e.key === "Home") {
|
|
176
|
+
e.preventDefault();
|
|
177
|
+
goTo(0);
|
|
178
|
+
}
|
|
179
|
+
if (e.key === "End") {
|
|
180
|
+
e.preventDefault();
|
|
181
|
+
goTo(total - 1);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
syncUI(0);
|
|
185
|
+
return { goTo, current: () => current, total };
|
|
186
|
+
}
|
|
187
|
+
const instances = {};
|
|
188
|
+
document.querySelectorAll(".pp-carousel").forEach((el, i) => {
|
|
189
|
+
const id = el.id || `pp-carousel-${i}`;
|
|
190
|
+
const api = initCarousel(el, i);
|
|
191
|
+
if (api) instances[id] = api;
|
|
192
|
+
});
|
|
193
|
+
window.ppCarousel = {
|
|
194
|
+
get(ref) {
|
|
195
|
+
if (typeof ref === "string") return instances[ref];
|
|
196
|
+
if (ref instanceof Element) return instances[ref.id] || Object.values(instances).find((_, k) => document.getElementById(Object.keys(instances)[k]) === ref);
|
|
197
|
+
return null;
|
|
198
|
+
},
|
|
199
|
+
instances
|
|
200
|
+
};
|
|
201
|
+
})();
|
|
202
|
+
|
|
2
203
|
// src/js/header.js
|
|
3
204
|
(function() {
|
|
4
205
|
function initHeader(header) {
|
|
5
206
|
const toggle = header.querySelector(".pp-header__toggle");
|
|
6
207
|
const nav = header.querySelector(".pp-header__nav");
|
|
7
|
-
header.querySelectorAll(".pp-header__dropdown").forEach((d) => {
|
|
208
|
+
header.querySelectorAll(".pp-header__dropdown").forEach((d, i) => {
|
|
8
209
|
d.classList.add("is-js-controlled");
|
|
210
|
+
if (!d.id) d.id = `pp-dropdown-${i}`;
|
|
211
|
+
});
|
|
212
|
+
header.querySelectorAll(".pp-header__nav-item").forEach((item) => {
|
|
213
|
+
const dropdown = item.querySelector(".pp-header__dropdown");
|
|
214
|
+
if (!dropdown) return;
|
|
215
|
+
const link = item.querySelector(".pp-header__nav-link");
|
|
216
|
+
if (link) {
|
|
217
|
+
link.setAttribute("aria-haspopup", "true");
|
|
218
|
+
link.setAttribute("aria-expanded", "false");
|
|
219
|
+
if (dropdown.id) link.setAttribute("aria-controls", dropdown.id);
|
|
220
|
+
}
|
|
221
|
+
dropdown.setAttribute("role", "menu");
|
|
222
|
+
dropdown.querySelectorAll(".pp-header__dropdown-link").forEach((a) => {
|
|
223
|
+
a.setAttribute("role", "menuitem");
|
|
224
|
+
});
|
|
9
225
|
});
|
|
10
226
|
if (toggle && nav) {
|
|
227
|
+
if (!nav.id) nav.id = "pp-header-nav";
|
|
228
|
+
toggle.setAttribute("aria-controls", nav.id);
|
|
229
|
+
nav.setAttribute("aria-hidden", "true");
|
|
11
230
|
toggle.addEventListener("click", (e) => {
|
|
12
231
|
e.stopPropagation();
|
|
13
232
|
const isOpen = nav.classList.toggle("is-open");
|
|
14
233
|
toggle.setAttribute("aria-expanded", String(isOpen));
|
|
234
|
+
nav.setAttribute("aria-hidden", String(!isOpen));
|
|
15
235
|
});
|
|
16
236
|
document.addEventListener("click", (e) => {
|
|
17
237
|
if (!header.contains(e.target)) {
|
|
18
238
|
nav.classList.remove("is-open");
|
|
19
239
|
toggle.setAttribute("aria-expanded", "false");
|
|
240
|
+
nav.setAttribute("aria-hidden", "true");
|
|
20
241
|
}
|
|
21
242
|
});
|
|
22
243
|
}
|
|
23
244
|
header.querySelectorAll(".pp-header__nav-item").forEach((item) => {
|
|
24
245
|
const dropdown = item.querySelector(".pp-header__dropdown");
|
|
25
246
|
if (!dropdown) return;
|
|
247
|
+
const link = item.querySelector(".pp-header__nav-link");
|
|
26
248
|
item.addEventListener("click", (e) => {
|
|
27
249
|
if (window.innerWidth >= 768) return;
|
|
28
250
|
e.stopPropagation();
|
|
29
|
-
item.classList.toggle("is-open");
|
|
251
|
+
const isOpen = item.classList.toggle("is-open");
|
|
252
|
+
if (link) link.setAttribute("aria-expanded", String(isOpen));
|
|
30
253
|
});
|
|
31
254
|
});
|
|
32
255
|
window.addEventListener("resize", () => {
|
|
33
256
|
if (window.innerWidth >= 768) {
|
|
34
257
|
nav == null ? void 0 : nav.classList.remove("is-open");
|
|
35
258
|
toggle == null ? void 0 : toggle.setAttribute("aria-expanded", "false");
|
|
36
|
-
|
|
259
|
+
nav == null ? void 0 : nav.setAttribute("aria-hidden", "true");
|
|
260
|
+
header.querySelectorAll(".pp-header__nav-item").forEach((i) => {
|
|
261
|
+
i.classList.remove("is-open");
|
|
262
|
+
const link = i.querySelector(".pp-header__nav-link");
|
|
263
|
+
if (link == null ? void 0 : link.hasAttribute("aria-expanded")) link.setAttribute("aria-expanded", "false");
|
|
264
|
+
});
|
|
37
265
|
}
|
|
38
266
|
});
|
|
39
267
|
}
|
|
@@ -42,21 +270,64 @@
|
|
|
42
270
|
|
|
43
271
|
// src/js/modal.js
|
|
44
272
|
(function() {
|
|
273
|
+
const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
274
|
+
let lastFocused = null;
|
|
45
275
|
document.querySelectorAll(".pp-modal-backdrop").forEach((backdrop) => {
|
|
46
276
|
backdrop.classList.add("is-animated");
|
|
47
277
|
backdrop.setAttribute("aria-hidden", "true");
|
|
278
|
+
if (!(backdrop instanceof HTMLDialogElement)) {
|
|
279
|
+
backdrop.setAttribute("role", "dialog");
|
|
280
|
+
backdrop.setAttribute("aria-modal", "true");
|
|
281
|
+
}
|
|
282
|
+
const modal = backdrop.querySelector(".pp-modal");
|
|
283
|
+
const title = modal == null ? void 0 : modal.querySelector(".pp-modal__title");
|
|
284
|
+
if (title) {
|
|
285
|
+
if (!title.id) title.id = `pp-modal-title-${backdrop.id}`;
|
|
286
|
+
backdrop.setAttribute("aria-labelledby", title.id);
|
|
287
|
+
}
|
|
288
|
+
const desc = modal == null ? void 0 : modal.querySelector(".pp-modal__description");
|
|
289
|
+
if (desc) {
|
|
290
|
+
if (!desc.id) desc.id = `pp-modal-desc-${backdrop.id}`;
|
|
291
|
+
backdrop.setAttribute("aria-describedby", desc.id);
|
|
292
|
+
}
|
|
48
293
|
});
|
|
294
|
+
function getFocusable(backdrop) {
|
|
295
|
+
return [...backdrop.querySelectorAll(FOCUSABLE)];
|
|
296
|
+
}
|
|
297
|
+
function trapFocus(e, backdrop) {
|
|
298
|
+
const focusable = getFocusable(backdrop);
|
|
299
|
+
if (!focusable.length) return;
|
|
300
|
+
const first = focusable[0];
|
|
301
|
+
const last = focusable[focusable.length - 1];
|
|
302
|
+
if (e.key === "Tab") {
|
|
303
|
+
if (e.shiftKey) {
|
|
304
|
+
if (document.activeElement === first) {
|
|
305
|
+
e.preventDefault();
|
|
306
|
+
last.focus();
|
|
307
|
+
}
|
|
308
|
+
} else {
|
|
309
|
+
if (document.activeElement === last) {
|
|
310
|
+
e.preventDefault();
|
|
311
|
+
first.focus();
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
49
316
|
function openModal(id) {
|
|
50
317
|
const backdrop = document.getElementById(id);
|
|
51
318
|
if (!backdrop) return;
|
|
319
|
+
lastFocused = document.activeElement;
|
|
52
320
|
if (backdrop instanceof HTMLDialogElement) {
|
|
53
321
|
backdrop.showModal();
|
|
54
322
|
} else {
|
|
55
323
|
backdrop.classList.add("is-open");
|
|
56
324
|
}
|
|
57
325
|
backdrop.removeAttribute("aria-hidden");
|
|
58
|
-
|
|
59
|
-
|
|
326
|
+
backdrop.setAttribute("aria-hidden", "false");
|
|
327
|
+
const focusable = getFocusable(backdrop);
|
|
328
|
+
if (focusable.length) focusable[0].focus();
|
|
329
|
+
backdrop._trapFocus = (e) => trapFocus(e, backdrop);
|
|
330
|
+
backdrop.addEventListener("keydown", backdrop._trapFocus);
|
|
60
331
|
}
|
|
61
332
|
function closeModal(id) {
|
|
62
333
|
const backdrop = document.getElementById(id);
|
|
@@ -67,13 +338,29 @@
|
|
|
67
338
|
backdrop.classList.remove("is-open");
|
|
68
339
|
}
|
|
69
340
|
backdrop.setAttribute("aria-hidden", "true");
|
|
341
|
+
if (backdrop._trapFocus) {
|
|
342
|
+
backdrop.removeEventListener("keydown", backdrop._trapFocus);
|
|
343
|
+
delete backdrop._trapFocus;
|
|
344
|
+
}
|
|
345
|
+
if (lastFocused && typeof lastFocused.focus === "function") {
|
|
346
|
+
lastFocused.focus();
|
|
347
|
+
lastFocused = null;
|
|
348
|
+
}
|
|
70
349
|
}
|
|
71
350
|
function closeAll() {
|
|
72
351
|
document.querySelectorAll(".pp-modal-backdrop").forEach((b) => {
|
|
73
352
|
if (b instanceof HTMLDialogElement) b.close();
|
|
74
353
|
else b.classList.remove("is-open");
|
|
75
354
|
b.setAttribute("aria-hidden", "true");
|
|
355
|
+
if (b._trapFocus) {
|
|
356
|
+
b.removeEventListener("keydown", b._trapFocus);
|
|
357
|
+
delete b._trapFocus;
|
|
358
|
+
}
|
|
76
359
|
});
|
|
360
|
+
if (lastFocused && typeof lastFocused.focus === "function") {
|
|
361
|
+
lastFocused.focus();
|
|
362
|
+
lastFocused = null;
|
|
363
|
+
}
|
|
77
364
|
}
|
|
78
365
|
document.querySelectorAll(".pp-modal-backdrop").forEach((backdrop) => {
|
|
79
366
|
backdrop.addEventListener("click", (e) => {
|
|
@@ -94,12 +381,26 @@
|
|
|
94
381
|
|
|
95
382
|
// src/js/select.js
|
|
96
383
|
(function() {
|
|
97
|
-
function initSelect(wrapper) {
|
|
384
|
+
function initSelect(wrapper, idx) {
|
|
98
385
|
const trigger = wrapper.querySelector(".pp-select__trigger");
|
|
99
386
|
const panel = wrapper.querySelector(".pp-select__panel");
|
|
100
387
|
const options = wrapper.querySelectorAll(".pp-select__option");
|
|
101
388
|
const valueEl = wrapper.querySelector(".pp-select__value");
|
|
102
389
|
if (!trigger || !panel) return;
|
|
390
|
+
const panelId = panel.id || `pp-select-panel-${idx}`;
|
|
391
|
+
panel.id = panelId;
|
|
392
|
+
options.forEach((opt, i) => {
|
|
393
|
+
if (!opt.id) opt.id = `pp-select-opt-${idx}-${i}`;
|
|
394
|
+
opt.setAttribute("role", "option");
|
|
395
|
+
opt.setAttribute("aria-selected", opt.classList.contains("is-selected") ? "true" : "false");
|
|
396
|
+
});
|
|
397
|
+
panel.setAttribute("role", "listbox");
|
|
398
|
+
trigger.setAttribute("role", "combobox");
|
|
399
|
+
trigger.setAttribute("aria-haspopup", "listbox");
|
|
400
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
401
|
+
trigger.setAttribute("aria-controls", panelId);
|
|
402
|
+
const selected = wrapper.querySelector(".pp-select__option.is-selected");
|
|
403
|
+
if (selected) trigger.setAttribute("aria-activedescendant", selected.id);
|
|
103
404
|
function open() {
|
|
104
405
|
wrapper.classList.add("is-open");
|
|
105
406
|
trigger.setAttribute("aria-expanded", "true");
|
|
@@ -114,8 +415,6 @@
|
|
|
114
415
|
wrapper.classList.contains("is-open") ? close() : open();
|
|
115
416
|
}
|
|
116
417
|
panel.setAttribute("hidden", "");
|
|
117
|
-
trigger.setAttribute("aria-expanded", "false");
|
|
118
|
-
trigger.setAttribute("aria-haspopup", "listbox");
|
|
119
418
|
trigger.addEventListener("click", (e) => {
|
|
120
419
|
e.stopPropagation();
|
|
121
420
|
toggle();
|
|
@@ -123,8 +422,13 @@
|
|
|
123
422
|
options.forEach((opt) => {
|
|
124
423
|
opt.addEventListener("click", () => {
|
|
125
424
|
var _a;
|
|
126
|
-
options.forEach((o) =>
|
|
425
|
+
options.forEach((o) => {
|
|
426
|
+
o.classList.remove("is-selected");
|
|
427
|
+
o.setAttribute("aria-selected", "false");
|
|
428
|
+
});
|
|
127
429
|
opt.classList.add("is-selected");
|
|
430
|
+
opt.setAttribute("aria-selected", "true");
|
|
431
|
+
trigger.setAttribute("aria-activedescendant", opt.id);
|
|
128
432
|
if (valueEl) valueEl.textContent = opt.textContent.trim();
|
|
129
433
|
const nativeSelect = wrapper.querySelector("select[data-pp-select]");
|
|
130
434
|
if (nativeSelect) nativeSelect.value = (_a = opt.dataset.value) != null ? _a : opt.textContent.trim();
|
|
@@ -148,14 +452,14 @@
|
|
|
148
452
|
panel.addEventListener("keydown", (e) => {
|
|
149
453
|
var _a, _b, _c;
|
|
150
454
|
const focusable = [...options];
|
|
151
|
-
const
|
|
455
|
+
const idx2 = focusable.indexOf(document.activeElement);
|
|
152
456
|
if (e.key === "ArrowDown") {
|
|
153
457
|
e.preventDefault();
|
|
154
|
-
(_a = focusable[
|
|
458
|
+
(_a = focusable[idx2 + 1]) == null ? void 0 : _a.focus();
|
|
155
459
|
}
|
|
156
460
|
if (e.key === "ArrowUp") {
|
|
157
461
|
e.preventDefault();
|
|
158
|
-
|
|
462
|
+
idx2 > 0 ? (_b = focusable[idx2 - 1]) == null ? void 0 : _b.focus() : trigger.focus();
|
|
159
463
|
}
|
|
160
464
|
if (e.key === "Escape") {
|
|
161
465
|
close();
|
|
@@ -170,14 +474,29 @@
|
|
|
170
474
|
if (!wrapper.contains(e.target)) close();
|
|
171
475
|
});
|
|
172
476
|
}
|
|
173
|
-
document.querySelectorAll(".pp-select").forEach(initSelect);
|
|
477
|
+
document.querySelectorAll(".pp-select").forEach((el, i) => initSelect(el, i));
|
|
174
478
|
})();
|
|
175
479
|
|
|
176
480
|
// src/js/tabs.js
|
|
177
481
|
(function() {
|
|
178
|
-
function initTabs(tabGroup) {
|
|
482
|
+
function initTabs(tabGroup, groupIdx) {
|
|
179
483
|
const items = tabGroup.querySelectorAll(".pp-tabs__item");
|
|
180
484
|
const targetAttr = "data-tab-target";
|
|
485
|
+
if (!tabGroup.getAttribute("role")) tabGroup.setAttribute("role", "tablist");
|
|
486
|
+
items.forEach((item, i) => {
|
|
487
|
+
item.setAttribute("role", "tab");
|
|
488
|
+
if (!item.id) item.id = `pp-tab-${groupIdx}-${i}`;
|
|
489
|
+
const targetId = item.getAttribute(targetAttr);
|
|
490
|
+
if (targetId) {
|
|
491
|
+
item.setAttribute("aria-controls", targetId);
|
|
492
|
+
const panel = document.querySelector(`[data-tab-panel="${targetId}"]`);
|
|
493
|
+
if (panel) {
|
|
494
|
+
if (!panel.id) panel.id = targetId;
|
|
495
|
+
panel.setAttribute("role", "tabpanel");
|
|
496
|
+
panel.setAttribute("aria-labelledby", item.id);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
});
|
|
181
500
|
function activate(item) {
|
|
182
501
|
items.forEach((i) => {
|
|
183
502
|
i.classList.remove("is-active");
|
|
@@ -190,7 +509,9 @@
|
|
|
190
509
|
const targetId = item.getAttribute(targetAttr);
|
|
191
510
|
if (targetId) {
|
|
192
511
|
document.querySelectorAll("[data-tab-panel]").forEach((panel) => {
|
|
193
|
-
|
|
512
|
+
const isVisible = panel.getAttribute("data-tab-panel") === targetId;
|
|
513
|
+
panel.hidden = !isVisible;
|
|
514
|
+
panel.setAttribute("aria-hidden", String(!isVisible));
|
|
194
515
|
});
|
|
195
516
|
}
|
|
196
517
|
tabGroup.dispatchEvent(new CustomEvent("pp-tabs:change", {
|
|
@@ -216,12 +537,151 @@
|
|
|
216
537
|
activate(prev);
|
|
217
538
|
prev.focus();
|
|
218
539
|
}
|
|
540
|
+
if (e.key === "Home") {
|
|
541
|
+
e.preventDefault();
|
|
542
|
+
activate(items[0]);
|
|
543
|
+
items[0].focus();
|
|
544
|
+
}
|
|
545
|
+
if (e.key === "End") {
|
|
546
|
+
e.preventDefault();
|
|
547
|
+
activate(items[items.length - 1]);
|
|
548
|
+
items[items.length - 1].focus();
|
|
549
|
+
}
|
|
219
550
|
});
|
|
220
|
-
items.forEach((item
|
|
551
|
+
items.forEach((item) => {
|
|
221
552
|
item.setAttribute("tabindex", item.classList.contains("is-active") ? "0" : "-1");
|
|
222
553
|
});
|
|
223
554
|
}
|
|
224
|
-
document.querySelectorAll(".pp-tabs").forEach(initTabs);
|
|
555
|
+
document.querySelectorAll(".pp-tabs").forEach((el, i) => initTabs(el, i));
|
|
556
|
+
})();
|
|
557
|
+
|
|
558
|
+
// src/js/validation.js
|
|
559
|
+
(function() {
|
|
560
|
+
function getField(input) {
|
|
561
|
+
return input.closest(".pp-field");
|
|
562
|
+
}
|
|
563
|
+
function getMessageEl(field) {
|
|
564
|
+
return field ? field.querySelector(".pp-field__message") : null;
|
|
565
|
+
}
|
|
566
|
+
function getHintEl(field) {
|
|
567
|
+
return field ? field.querySelector(".pp-field__hint") : null;
|
|
568
|
+
}
|
|
569
|
+
function buildDescribedBy(field) {
|
|
570
|
+
const ids = [];
|
|
571
|
+
const hint = getHintEl(field);
|
|
572
|
+
const msg = getMessageEl(field);
|
|
573
|
+
if (hint && hint.id) ids.push(hint.id);
|
|
574
|
+
if (msg && msg.id) ids.push(msg.id);
|
|
575
|
+
return ids.join(" ");
|
|
576
|
+
}
|
|
577
|
+
function ensureIds(field, input) {
|
|
578
|
+
const base = input.id || `pp-field-${Math.random().toString(36).slice(2, 7)}`;
|
|
579
|
+
const hint = getHintEl(field);
|
|
580
|
+
const msg = getMessageEl(field);
|
|
581
|
+
if (hint && !hint.id) hint.id = `${base}-hint`;
|
|
582
|
+
if (msg && !msg.id) msg.id = `${base}-msg`;
|
|
583
|
+
}
|
|
584
|
+
function setError(input, message) {
|
|
585
|
+
const field = getField(input);
|
|
586
|
+
if (!field) return;
|
|
587
|
+
ensureIds(field, input);
|
|
588
|
+
field.classList.remove("pp-field--success", "pp-field--warning", "pp-field--validating");
|
|
589
|
+
field.classList.add("pp-field--error");
|
|
590
|
+
input.setAttribute("aria-invalid", "true");
|
|
591
|
+
let msg = getMessageEl(field);
|
|
592
|
+
if (!msg) {
|
|
593
|
+
msg = document.createElement("span");
|
|
594
|
+
msg.className = "pp-field__message";
|
|
595
|
+
msg.id = `${input.id || "field"}-msg`;
|
|
596
|
+
msg.setAttribute("role", "alert");
|
|
597
|
+
field.appendChild(msg);
|
|
598
|
+
}
|
|
599
|
+
msg.textContent = message;
|
|
600
|
+
input.setAttribute("aria-describedby", buildDescribedBy(field));
|
|
601
|
+
field.dispatchEvent(new CustomEvent("pp-field:error", { bubbles: true, detail: { input, message } }));
|
|
602
|
+
}
|
|
603
|
+
function clearError(input) {
|
|
604
|
+
const field = getField(input);
|
|
605
|
+
if (!field) return;
|
|
606
|
+
field.classList.remove("pp-field--error", "pp-field--validating");
|
|
607
|
+
input.setAttribute("aria-invalid", "false");
|
|
608
|
+
const msg = getMessageEl(field);
|
|
609
|
+
if (msg) msg.textContent = "";
|
|
610
|
+
input.setAttribute("aria-describedby", buildDescribedBy(field));
|
|
611
|
+
field.dispatchEvent(new CustomEvent("pp-field:clear", { bubbles: true, detail: { input } }));
|
|
612
|
+
}
|
|
613
|
+
function setSuccess(input, message) {
|
|
614
|
+
const field = getField(input);
|
|
615
|
+
if (!field) return;
|
|
616
|
+
ensureIds(field, input);
|
|
617
|
+
field.classList.remove("pp-field--error", "pp-field--warning", "pp-field--validating");
|
|
618
|
+
field.classList.add("pp-field--success");
|
|
619
|
+
input.setAttribute("aria-invalid", "false");
|
|
620
|
+
let msg = getMessageEl(field);
|
|
621
|
+
if (message) {
|
|
622
|
+
if (!msg) {
|
|
623
|
+
msg = document.createElement("span");
|
|
624
|
+
msg.className = "pp-field__message";
|
|
625
|
+
msg.id = `${input.id || "field"}-msg`;
|
|
626
|
+
field.appendChild(msg);
|
|
627
|
+
}
|
|
628
|
+
msg.textContent = message;
|
|
629
|
+
}
|
|
630
|
+
input.setAttribute("aria-describedby", buildDescribedBy(field));
|
|
631
|
+
}
|
|
632
|
+
function setValidating(input) {
|
|
633
|
+
const field = getField(input);
|
|
634
|
+
if (!field) return;
|
|
635
|
+
field.classList.remove("pp-field--error", "pp-field--success", "pp-field--warning");
|
|
636
|
+
field.classList.add("pp-field--validating");
|
|
637
|
+
input.removeAttribute("aria-invalid");
|
|
638
|
+
}
|
|
639
|
+
function setSummary(errors, summaryEl) {
|
|
640
|
+
if (!summaryEl) return;
|
|
641
|
+
const list = summaryEl.querySelector(".pp-validation-summary__list");
|
|
642
|
+
if (!list) return;
|
|
643
|
+
list.innerHTML = "";
|
|
644
|
+
if (!errors || errors.length === 0) {
|
|
645
|
+
summaryEl.classList.remove("is-visible");
|
|
646
|
+
summaryEl.setAttribute("aria-hidden", "true");
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
errors.forEach(({ input, message }) => {
|
|
650
|
+
const inputEl = typeof input === "string" ? document.getElementById(input) : input;
|
|
651
|
+
const li = document.createElement("li");
|
|
652
|
+
li.className = "pp-validation-summary__item";
|
|
653
|
+
if (inputEl && inputEl.id) {
|
|
654
|
+
const a = document.createElement("a");
|
|
655
|
+
a.href = `#${inputEl.id}`;
|
|
656
|
+
a.textContent = message;
|
|
657
|
+
a.addEventListener("click", (e) => {
|
|
658
|
+
e.preventDefault();
|
|
659
|
+
inputEl.focus();
|
|
660
|
+
inputEl.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
661
|
+
});
|
|
662
|
+
li.appendChild(a);
|
|
663
|
+
} else {
|
|
664
|
+
li.textContent = message;
|
|
665
|
+
}
|
|
666
|
+
list.appendChild(li);
|
|
667
|
+
});
|
|
668
|
+
summaryEl.classList.add("is-visible");
|
|
669
|
+
summaryEl.setAttribute("aria-hidden", "false");
|
|
670
|
+
summaryEl.setAttribute("tabindex", "-1");
|
|
671
|
+
summaryEl.focus();
|
|
672
|
+
}
|
|
673
|
+
document.querySelectorAll(".pp-field").forEach((field) => {
|
|
674
|
+
const input = field.querySelector(".pp-field__input, .pp-field__textarea");
|
|
675
|
+
if (!input) return;
|
|
676
|
+
ensureIds(field, input);
|
|
677
|
+
const refs = buildDescribedBy(field);
|
|
678
|
+
if (refs) {
|
|
679
|
+
const existing = input.getAttribute("aria-describedby") || "";
|
|
680
|
+
const merged = [...new Set([...existing.split(" "), ...refs.split(" ")].filter(Boolean))].join(" ");
|
|
681
|
+
input.setAttribute("aria-describedby", merged);
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
window.ppValidation = { setError, clearError, setSuccess, setValidating, setSummary };
|
|
225
685
|
})();
|
|
226
686
|
})();
|
|
227
687
|
//# sourceMappingURL=peppertino.js.map
|