@auriel/peppertino 0.4.0 → 0.6.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 +242 -136
- package/LICENSE +21 -21
- package/MIGRATION.md +52 -0
- package/README.md +773 -622
- package/agents/peppertino/SKILL.md +76 -0
- package/agents/peppertino/accordion.md +134 -0
- package/agents/peppertino/alert.md +116 -0
- package/agents/peppertino/badge.md +74 -0
- package/agents/peppertino/base.md +252 -0
- package/agents/peppertino/button.md +65 -0
- package/agents/peppertino/card.md +82 -0
- package/agents/peppertino/carousel.md +147 -0
- package/agents/peppertino/catalog.md +81 -0
- package/agents/peppertino/dark-mode.md +152 -0
- package/agents/peppertino/footer.md +109 -0
- package/agents/peppertino/forms-fieldset.md +85 -0
- package/agents/peppertino/forms-form-instructions.md +94 -0
- package/agents/peppertino/forms-label.md +110 -0
- package/agents/peppertino/forms-text-field.md +134 -0
- package/agents/peppertino/forms-validation.md +153 -0
- package/agents/peppertino/gradient.md +41 -0
- package/agents/peppertino/header.md +105 -0
- package/agents/peppertino/modal.md +123 -0
- package/agents/peppertino/section.md +56 -0
- package/agents/peppertino/select.md +110 -0
- package/agents/peppertino/switch.md +72 -0
- package/agents/peppertino/table.md +69 -0
- package/agents/peppertino/tabs.md +115 -0
- package/agents/peppertino/toast.md +96 -0
- package/agents/peppertino/tooltip.md +111 -0
- package/agents/peppertino/typography.md +118 -0
- package/agents/peppertino/utilities.md +194 -0
- package/agents/skill.md +65 -0
- package/build.js +53 -53
- package/dist/accordion.js +41 -4
- package/dist/accordion.js.map +2 -2
- package/dist/alert.js +26 -0
- package/dist/alert.js.map +7 -0
- package/dist/carousel.js +4 -0
- package/dist/carousel.js.map +2 -2
- package/dist/header.js +1 -0
- package/dist/header.js.map +2 -2
- package/dist/main.css +3610 -1343
- package/dist/main.css.map +1 -1
- package/dist/main.min.css +1 -0
- package/dist/modal.js +2 -0
- package/dist/modal.js.map +2 -2
- package/dist/peppertino.js +244 -15
- package/dist/peppertino.js.map +3 -3
- package/dist/select.js +2 -4
- package/dist/select.js.map +2 -2
- package/dist/switch.js +29 -0
- package/dist/switch.js.map +7 -0
- package/dist/tabs.js +27 -7
- package/dist/tabs.js.map +2 -2
- package/dist/theme.js +47 -0
- package/dist/theme.js.map +7 -0
- package/dist/toast.js +69 -0
- package/dist/toast.js.map +7 -0
- package/dist/validation.js.map +1 -1
- package/icon.svg +4 -0
- package/index.html +2172 -1902
- package/package.json +28 -26
- package/scripts/hex-to-hsl.mjs +75 -0
- package/scripts/lint-bem.mjs +53 -0
- package/scripts/lint-colors.mjs +87 -0
- package/site.webmanifest +18 -0
- package/src/js/accordion.js +105 -61
- package/src/js/alert.js +28 -0
- package/src/js/carousel.js +153 -148
- package/src/js/header.js +85 -84
- package/src/js/modal.js +138 -134
- package/src/js/peppertino.js +15 -11
- package/src/js/select.js +101 -103
- package/src/js/switch.js +28 -0
- package/src/js/tabs.js +104 -94
- package/src/js/theme.js +47 -0
- package/src/js/toast.js +79 -0
- package/src/js/validation.js +132 -132
- package/src/scss/accordion.scss +190 -156
- package/src/scss/activity.scss +17 -0
- package/src/scss/alert.scss +203 -204
- package/src/scss/badge.scss +90 -0
- package/src/scss/base.scss +511 -305
- package/src/scss/button.scss +119 -121
- package/src/scss/card.scss +121 -121
- package/src/scss/carousel.scss +303 -313
- package/src/scss/code-block.scss +22 -0
- package/src/scss/counter.scss +5 -0
- package/src/scss/dark-mode.scss +514 -474
- package/src/scss/duration.scss +26 -0
- package/src/scss/folder.scss +27 -0
- package/src/scss/footer.scss +224 -224
- package/src/scss/forms/fieldset.scss +127 -127
- package/src/scss/forms/form-instructions.scss +133 -133
- package/src/scss/forms/label.scss +115 -115
- package/src/scss/forms/text-field.scss +240 -240
- package/src/scss/forms/validation.scss +215 -215
- package/src/scss/forms.scss +8 -8
- package/src/scss/gradient.scss +11 -11
- package/src/scss/gravity-letters.scss +7 -0
- package/src/scss/header.scss +257 -238
- package/src/scss/helpers/color.scss +9 -0
- package/src/scss/helpers/flex.scss +14 -0
- package/src/scss/helpers/index.scss +6 -0
- package/src/scss/helpers/layout.scss +14 -0
- package/src/scss/helpers/spacing.scss +14 -0
- package/src/scss/helpers/typography.scss +11 -0
- package/src/scss/helpers/visibility.scss +9 -0
- package/src/scss/main.scss +49 -20
- package/src/scss/modal.scss +188 -188
- package/src/scss/model-picker.scss +5 -0
- package/src/scss/notification.scss +5 -0
- package/src/scss/orb.scss +7 -0
- package/src/scss/otp.scss +5 -0
- package/src/scss/pill-nav.scss +10 -0
- package/src/scss/prompt.scss +28 -0
- package/src/scss/rail.scss +7 -0
- package/src/scss/reactions.scss +5 -0
- package/src/scss/reset.scss +84 -84
- package/src/scss/response.scss +11 -0
- package/src/scss/reveal.scss +5 -0
- package/src/scss/scroll-progress.scss +4 -0
- package/src/scss/search-results.scss +13 -0
- package/src/scss/section.scss +87 -79
- package/src/scss/select.scss +210 -210
- package/src/scss/sidebar.scss +8 -0
- package/src/scss/status.scss +5 -0
- package/src/scss/step-list.scss +13 -0
- package/src/scss/switch.scss +121 -0
- package/src/scss/table.scss +89 -89
- package/src/scss/tabs.scss +156 -156
- package/src/scss/task-list.scss +18 -0
- package/src/scss/theme-picker.scss +5 -0
- package/src/scss/toast.scss +170 -0
- package/src/scss/tooltip.scss +126 -0
- package/src/scss/typography.scss +58 -58
- package/src/scss/utilities.scss +243 -243
- package/src/scss/voice-note.scss +5 -0
package/src/js/modal.js
CHANGED
|
@@ -1,134 +1,138 @@
|
|
|
1
|
-
(function () {
|
|
2
|
-
const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
3
|
-
let lastFocused = null;
|
|
4
|
-
|
|
5
|
-
document.querySelectorAll('.pp-modal-backdrop').forEach((backdrop) => {
|
|
6
|
-
backdrop.classList.add('is-animated');
|
|
7
|
-
backdrop.setAttribute('aria-hidden', 'true');
|
|
8
|
-
|
|
9
|
-
// Role and modal semantics (skip if native <dialog>)
|
|
10
|
-
if (!(backdrop instanceof HTMLDialogElement)) {
|
|
11
|
-
backdrop.setAttribute('role', 'dialog');
|
|
12
|
-
backdrop.setAttribute('aria-modal', 'true');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// Wire aria-labelledby to the modal title if present
|
|
16
|
-
const modal = backdrop.querySelector('.pp-modal');
|
|
17
|
-
const title = modal?.querySelector('.pp-modal__title');
|
|
18
|
-
if (title) {
|
|
19
|
-
if (!title.id) title.id = `pp-modal-title-${backdrop.id}`;
|
|
20
|
-
backdrop.setAttribute('aria-labelledby', title.id);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// Wire aria-describedby to description if present
|
|
24
|
-
const desc = modal?.querySelector('.pp-modal__description');
|
|
25
|
-
if (desc) {
|
|
26
|
-
if (!desc.id) desc.id = `pp-modal-desc-${backdrop.id}`;
|
|
27
|
-
backdrop.setAttribute('aria-describedby', desc.id);
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
function getFocusable(backdrop) {
|
|
32
|
-
return [...backdrop.querySelectorAll(FOCUSABLE)];
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function trapFocus(e, backdrop) {
|
|
36
|
-
const focusable = getFocusable(backdrop);
|
|
37
|
-
if (!focusable.length) return;
|
|
38
|
-
const first = focusable[0];
|
|
39
|
-
const last = focusable[focusable.length - 1];
|
|
40
|
-
|
|
41
|
-
if (e.key === 'Tab') {
|
|
42
|
-
if (e.shiftKey) {
|
|
43
|
-
if (document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
44
|
-
} else {
|
|
45
|
-
if (document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function openModal(id) {
|
|
51
|
-
const backdrop = document.getElementById(id);
|
|
52
|
-
if (!backdrop) return;
|
|
53
|
-
|
|
54
|
-
lastFocused = document.activeElement;
|
|
55
|
-
|
|
56
|
-
if (backdrop instanceof HTMLDialogElement) {
|
|
57
|
-
backdrop.showModal();
|
|
58
|
-
} else {
|
|
59
|
-
backdrop.classList.add('is-open');
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
backdrop.removeAttribute('aria-hidden');
|
|
63
|
-
backdrop.setAttribute('aria-hidden', 'false');
|
|
64
|
-
|
|
65
|
-
const focusable = getFocusable(backdrop);
|
|
66
|
-
if (focusable.length) focusable[0].focus();
|
|
67
|
-
|
|
68
|
-
backdrop._trapFocus = (e) => trapFocus(e, backdrop);
|
|
69
|
-
backdrop.addEventListener('keydown', backdrop._trapFocus);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
if (backdrop
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
backdrop.
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
document.querySelectorAll('[data-modal-
|
|
130
|
-
el.addEventListener('click', () =>
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
1
|
+
(function () {
|
|
2
|
+
const FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
3
|
+
let lastFocused = null;
|
|
4
|
+
|
|
5
|
+
document.querySelectorAll('.pp-modal-backdrop').forEach((backdrop) => {
|
|
6
|
+
backdrop.classList.add('is-animated');
|
|
7
|
+
backdrop.setAttribute('aria-hidden', 'true');
|
|
8
|
+
|
|
9
|
+
// Role and modal semantics (skip if native <dialog>)
|
|
10
|
+
if (!(backdrop instanceof HTMLDialogElement)) {
|
|
11
|
+
backdrop.setAttribute('role', 'dialog');
|
|
12
|
+
backdrop.setAttribute('aria-modal', 'true');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
// Wire aria-labelledby to the modal title if present
|
|
16
|
+
const modal = backdrop.querySelector('.pp-modal');
|
|
17
|
+
const title = modal?.querySelector('.pp-modal__title');
|
|
18
|
+
if (title) {
|
|
19
|
+
if (!title.id) title.id = `pp-modal-title-${backdrop.id}`;
|
|
20
|
+
backdrop.setAttribute('aria-labelledby', title.id);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Wire aria-describedby to description if present
|
|
24
|
+
const desc = modal?.querySelector('.pp-modal__description');
|
|
25
|
+
if (desc) {
|
|
26
|
+
if (!desc.id) desc.id = `pp-modal-desc-${backdrop.id}`;
|
|
27
|
+
backdrop.setAttribute('aria-describedby', desc.id);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
function getFocusable(backdrop) {
|
|
32
|
+
return [...backdrop.querySelectorAll(FOCUSABLE)];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function trapFocus(e, backdrop) {
|
|
36
|
+
const focusable = getFocusable(backdrop);
|
|
37
|
+
if (!focusable.length) return;
|
|
38
|
+
const first = focusable[0];
|
|
39
|
+
const last = focusable[focusable.length - 1];
|
|
40
|
+
|
|
41
|
+
if (e.key === 'Tab') {
|
|
42
|
+
if (e.shiftKey) {
|
|
43
|
+
if (document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
44
|
+
} else {
|
|
45
|
+
if (document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function openModal(id) {
|
|
51
|
+
const backdrop = document.getElementById(id);
|
|
52
|
+
if (!backdrop) return;
|
|
53
|
+
|
|
54
|
+
lastFocused = document.activeElement;
|
|
55
|
+
|
|
56
|
+
if (backdrop instanceof HTMLDialogElement) {
|
|
57
|
+
backdrop.showModal();
|
|
58
|
+
} else {
|
|
59
|
+
backdrop.classList.add('is-open');
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
backdrop.removeAttribute('aria-hidden');
|
|
63
|
+
backdrop.setAttribute('aria-hidden', 'false');
|
|
64
|
+
|
|
65
|
+
const focusable = getFocusable(backdrop);
|
|
66
|
+
if (focusable.length) focusable[0].focus();
|
|
67
|
+
|
|
68
|
+
backdrop._trapFocus = (e) => trapFocus(e, backdrop);
|
|
69
|
+
backdrop.addEventListener('keydown', backdrop._trapFocus);
|
|
70
|
+
|
|
71
|
+
backdrop.dispatchEvent(new CustomEvent('pp:modal:open', { bubbles: true }));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function closeModal(id) {
|
|
75
|
+
const backdrop = document.getElementById(id);
|
|
76
|
+
if (!backdrop) return;
|
|
77
|
+
|
|
78
|
+
if (backdrop instanceof HTMLDialogElement) {
|
|
79
|
+
backdrop.close();
|
|
80
|
+
} else {
|
|
81
|
+
backdrop.classList.remove('is-open');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
backdrop.setAttribute('aria-hidden', 'true');
|
|
85
|
+
|
|
86
|
+
if (backdrop._trapFocus) {
|
|
87
|
+
backdrop.removeEventListener('keydown', backdrop._trapFocus);
|
|
88
|
+
delete backdrop._trapFocus;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
backdrop.dispatchEvent(new CustomEvent('pp:modal:close', { bubbles: true }));
|
|
92
|
+
|
|
93
|
+
// Restore focus to the element that opened the modal
|
|
94
|
+
if (lastFocused && typeof lastFocused.focus === 'function') {
|
|
95
|
+
lastFocused.focus();
|
|
96
|
+
lastFocused = null;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function closeAll() {
|
|
101
|
+
document.querySelectorAll('.pp-modal-backdrop').forEach((b) => {
|
|
102
|
+
if (b instanceof HTMLDialogElement) b.close();
|
|
103
|
+
else b.classList.remove('is-open');
|
|
104
|
+
b.setAttribute('aria-hidden', 'true');
|
|
105
|
+
if (b._trapFocus) {
|
|
106
|
+
b.removeEventListener('keydown', b._trapFocus);
|
|
107
|
+
delete b._trapFocus;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (lastFocused && typeof lastFocused.focus === 'function') {
|
|
111
|
+
lastFocused.focus();
|
|
112
|
+
lastFocused = null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Close on backdrop click outside .pp-modal
|
|
117
|
+
document.querySelectorAll('.pp-modal-backdrop').forEach((backdrop) => {
|
|
118
|
+
backdrop.addEventListener('click', (e) => {
|
|
119
|
+
if (e.target === backdrop) closeModal(backdrop.id);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Escape key
|
|
124
|
+
document.addEventListener('keydown', (e) => {
|
|
125
|
+
if (e.key === 'Escape') closeAll();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// data-modal-open / data-modal-close triggers
|
|
129
|
+
document.querySelectorAll('[data-modal-open]').forEach((el) => {
|
|
130
|
+
el.addEventListener('click', () => openModal(el.dataset.modalOpen));
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
document.querySelectorAll('[data-modal-close]').forEach((el) => {
|
|
134
|
+
el.addEventListener('click', () => closeModal(el.dataset.modalClose));
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
window.ppModal = { open: openModal, close: closeModal, closeAll };
|
|
138
|
+
})();
|
package/src/js/peppertino.js
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
// PeppertinoCSS — aggregator
|
|
2
|
-
// Imports all JS components so users can include a single <script> tag.
|
|
3
|
-
// Each component is a self-contained IIFE in its own file — import only what you need.
|
|
4
|
-
|
|
5
|
-
import './accordion.js';
|
|
6
|
-
import './
|
|
7
|
-
import './
|
|
8
|
-
import './
|
|
9
|
-
import './
|
|
10
|
-
import './
|
|
11
|
-
import './
|
|
1
|
+
// PeppertinoCSS — aggregator
|
|
2
|
+
// Imports all JS components so users can include a single <script> tag.
|
|
3
|
+
// Each component is a self-contained IIFE in its own file — import only what you need.
|
|
4
|
+
|
|
5
|
+
import './accordion.js';
|
|
6
|
+
import './alert.js';
|
|
7
|
+
import './carousel.js';
|
|
8
|
+
import './header.js';
|
|
9
|
+
import './modal.js';
|
|
10
|
+
import './select.js';
|
|
11
|
+
import './switch.js';
|
|
12
|
+
import './tabs.js';
|
|
13
|
+
import './theme.js';
|
|
14
|
+
import './toast.js';
|
|
15
|
+
import './validation.js';
|
package/src/js/select.js
CHANGED
|
@@ -1,103 +1,101 @@
|
|
|
1
|
-
(function () {
|
|
2
|
-
function initSelect(wrapper, idx) {
|
|
3
|
-
const trigger = wrapper.querySelector('.pp-select__trigger');
|
|
4
|
-
const panel = wrapper.querySelector('.pp-select__panel');
|
|
5
|
-
const options = wrapper.querySelectorAll('.pp-select__option');
|
|
6
|
-
const valueEl = wrapper.querySelector('.pp-select__value');
|
|
7
|
-
|
|
8
|
-
if (!trigger || !panel) return;
|
|
9
|
-
|
|
10
|
-
// IDs for aria-controls / aria-activedescendant
|
|
11
|
-
const panelId = panel.id || `pp-select-panel-${idx}`;
|
|
12
|
-
panel.id = panelId;
|
|
13
|
-
|
|
14
|
-
options.forEach((opt, i) => {
|
|
15
|
-
if (!opt.id) opt.id = `pp-select-opt-${idx}-${i}`;
|
|
16
|
-
opt.setAttribute('role', 'option');
|
|
17
|
-
opt.setAttribute('aria-selected', opt.classList.contains('is-selected') ? 'true' : 'false');
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
panel.setAttribute('role', 'listbox');
|
|
21
|
-
trigger.setAttribute('role', 'combobox');
|
|
22
|
-
trigger.setAttribute('aria-haspopup', 'listbox');
|
|
23
|
-
trigger.setAttribute('aria-expanded', 'false');
|
|
24
|
-
trigger.setAttribute('aria-controls', panelId);
|
|
25
|
-
|
|
26
|
-
// Set initial aria-activedescendant to the selected option
|
|
27
|
-
const selected = wrapper.querySelector('.pp-select__option.is-selected');
|
|
28
|
-
if (selected) trigger.setAttribute('aria-activedescendant', selected.id);
|
|
29
|
-
|
|
30
|
-
function open() {
|
|
31
|
-
wrapper.classList.add('is-open');
|
|
32
|
-
trigger.setAttribute('aria-expanded', 'true');
|
|
33
|
-
panel.removeAttribute('hidden');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function close() {
|
|
37
|
-
wrapper.classList.remove('is-open');
|
|
38
|
-
trigger.setAttribute('aria-expanded', 'false');
|
|
39
|
-
panel.setAttribute('hidden', '');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function toggle() {
|
|
43
|
-
wrapper.classList.contains('is-open') ? close() : open();
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Initial state — JS takes over from :focus-within
|
|
47
|
-
panel.setAttribute('hidden', '');
|
|
48
|
-
|
|
49
|
-
trigger.addEventListener('click', (e) => {
|
|
50
|
-
e.stopPropagation();
|
|
51
|
-
toggle();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
// Option selection
|
|
55
|
-
options.forEach((opt) => {
|
|
56
|
-
opt.addEventListener('click', () => {
|
|
57
|
-
options.forEach((o) => {
|
|
58
|
-
o.classList.remove('is-selected');
|
|
59
|
-
o.setAttribute('aria-selected', 'false');
|
|
60
|
-
});
|
|
61
|
-
opt.classList.add('is-selected');
|
|
62
|
-
opt.setAttribute('aria-selected', 'true');
|
|
63
|
-
trigger.setAttribute('aria-activedescendant', opt.id);
|
|
64
|
-
|
|
65
|
-
if (valueEl) valueEl.textContent = opt.textContent.trim();
|
|
66
|
-
|
|
67
|
-
const nativeSelect = wrapper.querySelector('select[data-pp-select]');
|
|
68
|
-
if (nativeSelect) nativeSelect.value = opt.dataset.value ?? opt.textContent.trim();
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (e.key === '
|
|
91
|
-
if (e.key === '
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
document.querySelectorAll('.pp-select').forEach((el, i) => initSelect(el, i));
|
|
103
|
-
})();
|
|
1
|
+
(function () {
|
|
2
|
+
function initSelect(wrapper, idx) {
|
|
3
|
+
const trigger = wrapper.querySelector('.pp-select__trigger');
|
|
4
|
+
const panel = wrapper.querySelector('.pp-select__panel');
|
|
5
|
+
const options = wrapper.querySelectorAll('.pp-select__option');
|
|
6
|
+
const valueEl = wrapper.querySelector('.pp-select__value');
|
|
7
|
+
|
|
8
|
+
if (!trigger || !panel) return;
|
|
9
|
+
|
|
10
|
+
// IDs for aria-controls / aria-activedescendant
|
|
11
|
+
const panelId = panel.id || `pp-select-panel-${idx}`;
|
|
12
|
+
panel.id = panelId;
|
|
13
|
+
|
|
14
|
+
options.forEach((opt, i) => {
|
|
15
|
+
if (!opt.id) opt.id = `pp-select-opt-${idx}-${i}`;
|
|
16
|
+
opt.setAttribute('role', 'option');
|
|
17
|
+
opt.setAttribute('aria-selected', opt.classList.contains('is-selected') ? 'true' : 'false');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
panel.setAttribute('role', 'listbox');
|
|
21
|
+
trigger.setAttribute('role', 'combobox');
|
|
22
|
+
trigger.setAttribute('aria-haspopup', 'listbox');
|
|
23
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
24
|
+
trigger.setAttribute('aria-controls', panelId);
|
|
25
|
+
|
|
26
|
+
// Set initial aria-activedescendant to the selected option
|
|
27
|
+
const selected = wrapper.querySelector('.pp-select__option.is-selected');
|
|
28
|
+
if (selected) trigger.setAttribute('aria-activedescendant', selected.id);
|
|
29
|
+
|
|
30
|
+
function open() {
|
|
31
|
+
wrapper.classList.add('is-open');
|
|
32
|
+
trigger.setAttribute('aria-expanded', 'true');
|
|
33
|
+
panel.removeAttribute('hidden');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function close() {
|
|
37
|
+
wrapper.classList.remove('is-open');
|
|
38
|
+
trigger.setAttribute('aria-expanded', 'false');
|
|
39
|
+
panel.setAttribute('hidden', '');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function toggle() {
|
|
43
|
+
wrapper.classList.contains('is-open') ? close() : open();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Initial state — JS takes over from :focus-within
|
|
47
|
+
panel.setAttribute('hidden', '');
|
|
48
|
+
|
|
49
|
+
trigger.addEventListener('click', (e) => {
|
|
50
|
+
e.stopPropagation();
|
|
51
|
+
toggle();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// Option selection
|
|
55
|
+
options.forEach((opt) => {
|
|
56
|
+
opt.addEventListener('click', () => {
|
|
57
|
+
options.forEach((o) => {
|
|
58
|
+
o.classList.remove('is-selected');
|
|
59
|
+
o.setAttribute('aria-selected', 'false');
|
|
60
|
+
});
|
|
61
|
+
opt.classList.add('is-selected');
|
|
62
|
+
opt.setAttribute('aria-selected', 'true');
|
|
63
|
+
trigger.setAttribute('aria-activedescendant', opt.id);
|
|
64
|
+
|
|
65
|
+
if (valueEl) valueEl.textContent = opt.textContent.trim();
|
|
66
|
+
|
|
67
|
+
const nativeSelect = wrapper.querySelector('select[data-pp-select]');
|
|
68
|
+
if (nativeSelect) nativeSelect.value = opt.dataset.value ?? opt.textContent.trim();
|
|
69
|
+
|
|
70
|
+
const detail = { value: opt.dataset.value, label: opt.textContent.trim() };
|
|
71
|
+
wrapper.dispatchEvent(new CustomEvent('pp:select:change', { bubbles: true, detail }));
|
|
72
|
+
|
|
73
|
+
close();
|
|
74
|
+
trigger.focus();
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Keyboard navigation
|
|
79
|
+
trigger.addEventListener('keydown', (e) => {
|
|
80
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); open(); options[0]?.focus(); }
|
|
81
|
+
if (e.key === 'Escape') close();
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
panel.addEventListener('keydown', (e) => {
|
|
85
|
+
const focusable = [...options];
|
|
86
|
+
const idx = focusable.indexOf(document.activeElement);
|
|
87
|
+
|
|
88
|
+
if (e.key === 'ArrowDown') { e.preventDefault(); focusable[idx + 1]?.focus(); }
|
|
89
|
+
if (e.key === 'ArrowUp') { e.preventDefault(); idx > 0 ? focusable[idx - 1]?.focus() : trigger.focus(); }
|
|
90
|
+
if (e.key === 'Escape') { close(); trigger.focus(); }
|
|
91
|
+
if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); document.activeElement?.click(); }
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// Close on outside click
|
|
95
|
+
document.addEventListener('click', (e) => {
|
|
96
|
+
if (!wrapper.contains(e.target)) close();
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
document.querySelectorAll('.pp-select').forEach((el, i) => initSelect(el, i));
|
|
101
|
+
})();
|
package/src/js/switch.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
function initSwitch(el) {
|
|
3
|
+
if (el.dataset.ppSwitchInit) return;
|
|
4
|
+
el.dataset.ppSwitchInit = '1';
|
|
5
|
+
|
|
6
|
+
function toggle() {
|
|
7
|
+
if (el.disabled || el.getAttribute('aria-disabled') === 'true') return;
|
|
8
|
+
const checked = el.getAttribute('aria-checked') === 'true';
|
|
9
|
+
const next = !checked;
|
|
10
|
+
el.setAttribute('aria-checked', String(next));
|
|
11
|
+
el.dispatchEvent(new CustomEvent('pp:switch:change', {
|
|
12
|
+
bubbles: true,
|
|
13
|
+
detail: { checked: next },
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
el.addEventListener('click', toggle);
|
|
18
|
+
el.addEventListener('keydown', (e) => {
|
|
19
|
+
if (e.key === ' ') { e.preventDefault(); toggle(); }
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
// Ensure role is set
|
|
23
|
+
if (!el.getAttribute('role')) el.setAttribute('role', 'switch');
|
|
24
|
+
if (!el.getAttribute('aria-checked')) el.setAttribute('aria-checked', 'false');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
document.querySelectorAll('[role="switch"], .pp-switch').forEach(initSwitch);
|
|
28
|
+
})();
|