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