@auriel/peppertino 0.3.0 → 0.5.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 +210 -122
- package/MIGRATION.md +52 -0
- package/README.md +284 -40
- package/dist/accordion.js +88 -0
- package/dist/accordion.js.map +7 -0
- 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 +3607 -299
- package/dist/main.css.map +1 -1
- package/dist/modal.js +2 -0
- package/dist/modal.js.map +2 -2
- package/dist/peppertino.js +290 -11
- 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/index.html +813 -48
- package/package.json +6 -4
- package/scripts/hex-to-hsl.mjs +75 -0
- package/scripts/lint-bem.mjs +53 -0
- package/scripts/lint-colors.mjs +87 -0
- package/src/js/accordion.js +103 -0
- package/src/js/alert.js +28 -0
- package/src/js/carousel.js +5 -0
- package/src/js/header.js +1 -0
- package/src/js/modal.js +4 -0
- package/src/js/peppertino.js +6 -0
- package/src/js/select.js +2 -4
- package/src/js/switch.js +28 -0
- package/src/js/tabs.js +31 -21
- package/src/js/theme.js +47 -0
- package/src/js/toast.js +79 -0
- package/src/scss/accordion.scss +156 -0
- package/src/scss/alert.scss +203 -0
- package/src/scss/badge.scss +90 -0
- package/src/scss/base.scss +331 -36
- package/src/scss/button.scss +44 -46
- package/src/scss/card.scss +4 -4
- package/src/scss/carousel.scss +18 -28
- package/src/scss/dark-mode.scss +514 -0
- package/src/scss/footer.scss +14 -14
- package/src/scss/forms/fieldset.scss +12 -12
- package/src/scss/forms/form-instructions.scss +8 -8
- package/src/scss/forms/text-field.scss +17 -17
- package/src/scss/forms/validation.scss +12 -12
- package/src/scss/gradient.scss +2 -2
- package/src/scss/header.scss +8 -8
- package/src/scss/main.scss +8 -0
- package/src/scss/modal.scss +2 -2
- package/src/scss/section.scss +1 -1
- package/src/scss/select.scss +8 -8
- package/src/scss/switch.scss +121 -0
- package/src/scss/table.scss +5 -5
- package/src/scss/tabs.scss +26 -26
- package/src/scss/toast.scss +170 -0
- package/src/scss/tooltip.scss +126 -0
- package/src/scss/utilities.scss +243 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@auriel/peppertino",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "An Apple-inspired CSS framework with a spicy red accent. Clean geometry, restrained elegance, zero Cupertino lawsuits.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -10,10 +10,12 @@
|
|
|
10
10
|
"scripts": {
|
|
11
11
|
"build:css": "sass src/scss/main.scss dist/main.css --style=expanded --source-map",
|
|
12
12
|
"build:css:min": "sass src/scss/main.scss dist/main.min.css --style=compressed --no-source-map",
|
|
13
|
-
"build:js": "
|
|
14
|
-
"
|
|
13
|
+
"build:js": "bun build.js",
|
|
14
|
+
"lint:colors": "bun scripts/lint-colors.mjs",
|
|
15
|
+
"lint:bem": "bun scripts/lint-bem.mjs",
|
|
16
|
+
"build": "bun run build:css && bun run build:js && bun run lint:colors && bun run lint:bem",
|
|
15
17
|
"watch:css": "sass --watch src/scss/main.scss:dist/main.css --style=expanded --source-map",
|
|
16
|
-
"watch:js": "
|
|
18
|
+
"watch:js": "bun build.js --watch",
|
|
17
19
|
"serve": "bunx --bun serve . --port 3000",
|
|
18
20
|
"dev": "bun run build && concurrently \"bun run watch:css\" \"bun run watch:js\" \"bun run serve\""
|
|
19
21
|
},
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// One-off script: converts all base.scss hex color tokens to decomposed HSL triplets.
|
|
2
|
+
// Run: node scripts/hex-to-hsl.mjs
|
|
3
|
+
// Output is printed to stdout — copy into base.scss and dark-mode.scss.
|
|
4
|
+
|
|
5
|
+
function hexToHsl(hex) {
|
|
6
|
+
hex = hex.replace('#', '');
|
|
7
|
+
if (hex.length === 3) hex = hex.split('').map(c => c + c).join('');
|
|
8
|
+
const r = parseInt(hex.slice(0, 2), 16) / 255;
|
|
9
|
+
const g = parseInt(hex.slice(2, 4), 16) / 255;
|
|
10
|
+
const b = parseInt(hex.slice(4, 6), 16) / 255;
|
|
11
|
+
|
|
12
|
+
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
13
|
+
let h, s, l = (max + min) / 2;
|
|
14
|
+
|
|
15
|
+
if (max === min) {
|
|
16
|
+
h = s = 0;
|
|
17
|
+
} else {
|
|
18
|
+
const d = max - min;
|
|
19
|
+
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
20
|
+
switch (max) {
|
|
21
|
+
case r: h = ((g - b) / d + (g < b ? 6 : 0)) / 6; break;
|
|
22
|
+
case g: h = ((b - r) / d + 2) / 6; break;
|
|
23
|
+
case b: h = ((r - g) / d + 4) / 6; break;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return {
|
|
28
|
+
h: Math.round(h * 360),
|
|
29
|
+
s: Math.round(s * 1000) / 10,
|
|
30
|
+
l: Math.round(l * 1000) / 10,
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const tokens = {
|
|
35
|
+
'primary': '#e90111',
|
|
36
|
+
'primary-light': '#ff4d5a',
|
|
37
|
+
'primary-dark': '#a8000c',
|
|
38
|
+
'accent': '#f77f00',
|
|
39
|
+
'gradient-start': '#ffcf67',
|
|
40
|
+
'gradient-end': '#ea5753',
|
|
41
|
+
'neutral-50': '#fafafa',
|
|
42
|
+
'neutral-100': '#f4f4f5',
|
|
43
|
+
'neutral-200': '#e4e4e7',
|
|
44
|
+
'neutral-300': '#d4d4d8',
|
|
45
|
+
'neutral-400': '#a1a1aa',
|
|
46
|
+
'neutral-500': '#71717a',
|
|
47
|
+
'neutral-600': '#52525b',
|
|
48
|
+
'neutral-700': '#3f3f46',
|
|
49
|
+
'neutral-800': '#27272a',
|
|
50
|
+
'neutral-900': '#18181b',
|
|
51
|
+
'success': '#22c55e',
|
|
52
|
+
'warning': '#f59e0b',
|
|
53
|
+
'error': '#ef4444',
|
|
54
|
+
'info': '#3b82f6',
|
|
55
|
+
// Button variant shades (needed for button.scss tokens)
|
|
56
|
+
'success-600': '#16a34a',
|
|
57
|
+
'success-700': '#15803d',
|
|
58
|
+
'success-800': '#166534',
|
|
59
|
+
'warning-600': '#d97706',
|
|
60
|
+
'warning-700': '#b45309',
|
|
61
|
+
'warning-800': '#92400e',
|
|
62
|
+
'error-600': '#dc2626',
|
|
63
|
+
'error-700': '#b91c1c',
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
console.log(':root {');
|
|
67
|
+
for (const [name, hex] of Object.entries(tokens)) {
|
|
68
|
+
const { h, s, l } = hexToHsl(hex);
|
|
69
|
+
console.log(` --pp-${name}-h: ${h};`);
|
|
70
|
+
console.log(` --pp-${name}-s: ${s}%;`);
|
|
71
|
+
console.log(` --pp-${name}-l: ${l}%;`);
|
|
72
|
+
console.log(` --pp-${name}: hsl(var(--pp-${name}-h) var(--pp-${name}-s) var(--pp-${name}-l));`);
|
|
73
|
+
console.log('');
|
|
74
|
+
}
|
|
75
|
+
console.log('}');
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// Checks compiled dist/main.css for .pp-* class selectors that violate BEM.
|
|
3
|
+
// Valid: .pp-button, .pp-button__icon, .pp-button--outline, .pp-button--outline.pp-button--success
|
|
4
|
+
// Invalid: .pp-button-success (compound hyphen — should be .pp-button--success)
|
|
5
|
+
// .pp-buttonIcon (camelCase)
|
|
6
|
+
// Usage: bun run scripts/lint-bem.mjs
|
|
7
|
+
|
|
8
|
+
import { readFile } from 'fs/promises';
|
|
9
|
+
import { join } from 'path';
|
|
10
|
+
|
|
11
|
+
const cssPath = join(import.meta.dir, '..', 'dist', 'main.css');
|
|
12
|
+
|
|
13
|
+
let css;
|
|
14
|
+
try {
|
|
15
|
+
css = await readFile(cssPath, 'utf8');
|
|
16
|
+
} catch {
|
|
17
|
+
console.error('✖ lint-bem: dist/main.css not found. Run build:css first.');
|
|
18
|
+
process.exit(1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// Extract all .pp-* class tokens from selectors
|
|
22
|
+
// Match class selectors: .pp-something (stop at space/:/./[/{})
|
|
23
|
+
const CLASS_PATTERN = /\.pp-[\w-]+/g;
|
|
24
|
+
|
|
25
|
+
// BEM-valid patterns for .pp-* classes:
|
|
26
|
+
// Block only: .pp-[block]
|
|
27
|
+
// Block + element: .pp-[block]__[element]
|
|
28
|
+
// Block + modifier: .pp-[block]--[modifier]
|
|
29
|
+
// (double hyphen is modifier, double underscore is element — single hyphens within a segment are fine)
|
|
30
|
+
const BEM_VALID = /^\.pp-[a-z][a-z0-9]*(-[a-z0-9]+)*(__[a-z0-9][a-z0-9]*(-[a-z0-9]+)*)?(--[a-z0-9][a-z0-9]*(-[a-z0-9]+)*)?$/;
|
|
31
|
+
|
|
32
|
+
const seen = new Set();
|
|
33
|
+
const violations = [];
|
|
34
|
+
|
|
35
|
+
let match;
|
|
36
|
+
while ((match = CLASS_PATTERN.exec(css)) !== null) {
|
|
37
|
+
const cls = match[0];
|
|
38
|
+
if (seen.has(cls)) continue;
|
|
39
|
+
seen.add(cls);
|
|
40
|
+
|
|
41
|
+
if (!BEM_VALID.test(cls)) {
|
|
42
|
+
violations.push(cls);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (violations.length > 0) {
|
|
47
|
+
console.error('✖ lint-bem: The following .pp-* classes violate BEM naming:');
|
|
48
|
+
violations.forEach((v) => console.error(` ${v}`));
|
|
49
|
+
console.error('\nExpected: .pp-block, .pp-block__element, .pp-block--modifier\n');
|
|
50
|
+
process.exit(1);
|
|
51
|
+
} else {
|
|
52
|
+
console.log(`✔ lint-bem: All ${seen.size} .pp-* selectors pass BEM naming check.`);
|
|
53
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
// Fails if any SCSS component file contains literal color values that should
|
|
3
|
+
// be CSS custom properties. Structural white/black overlays are allowed.
|
|
4
|
+
// Usage: bun run scripts/lint-colors.mjs
|
|
5
|
+
|
|
6
|
+
import { readdir, readFile } from 'fs/promises';
|
|
7
|
+
import { join, relative } from 'path';
|
|
8
|
+
|
|
9
|
+
const EXEMPT = new Set(['base.scss', 'dark-mode.scss']);
|
|
10
|
+
|
|
11
|
+
// Patterns that are ALLOWED in component files (structural design choices):
|
|
12
|
+
// - Pure white/black with opacity: rgb(255...), rgb(0...), rgba(#fff,...), rgba(0,0,0,...)
|
|
13
|
+
// - Transparent keyword
|
|
14
|
+
const ALLOWED_PATTERNS = [
|
|
15
|
+
/rgba?\(255[^)]*\)/, // white with alpha
|
|
16
|
+
/rgba?\(0,\s*0,\s*0[^)]*\)/, // black with alpha
|
|
17
|
+
/rgba?\(#fff[^)]*\)/, // #fff with alpha
|
|
18
|
+
/rgba?\(#000[^)]*\)/, // #000 with alpha
|
|
19
|
+
/rgb\(255\s+255\s+255[^)]*\)/, // modern white syntax
|
|
20
|
+
/rgb\(0\s+0\s+0[^)]*\)/, // modern black syntax
|
|
21
|
+
/^#fff$/i, // pure white
|
|
22
|
+
/^#000$/i, // pure black
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
// Patterns that are BANNED (should use CSS vars instead):
|
|
26
|
+
const BANNED = [
|
|
27
|
+
{ pattern: /rgba?\(\s*\$color[-_\w]+\s*,/g, desc: 'rgba() with SCSS color variable — use hsl(var(--pp-*-h) ... / alpha)' },
|
|
28
|
+
{ pattern: /rgba?\(\s*\$gradient[-_\w]*\s*,/g, desc: 'rgba() with SCSS gradient variable — use hsl(var(--pp-gradient-*-h) ... / alpha)' },
|
|
29
|
+
{ pattern: /#[0-9a-fA-F]{6}(?!\s*[}|;,\n]?\s*!|[0-9a-fA-F])/g, desc: '6-digit hex color — use var(--pp-*)' },
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
// Allowed 6-digit hexes (structural white/black variants):
|
|
33
|
+
const ALLOWED_HEX = new Set(['#ffffff', '#000000', '#ffb3b3']);
|
|
34
|
+
|
|
35
|
+
async function scanDir(dir) {
|
|
36
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
37
|
+
const files = [];
|
|
38
|
+
for (const entry of entries) {
|
|
39
|
+
if (entry.isDirectory()) {
|
|
40
|
+
files.push(...await scanDir(join(dir, entry.name)));
|
|
41
|
+
} else if (entry.name.endsWith('.scss') && !EXEMPT.has(entry.name)) {
|
|
42
|
+
files.push(join(dir, entry.name));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return files;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const scssDir = join(import.meta.dir, '..', 'src', 'scss');
|
|
49
|
+
const files = await scanDir(scssDir);
|
|
50
|
+
|
|
51
|
+
let totalViolations = 0;
|
|
52
|
+
|
|
53
|
+
for (const file of files) {
|
|
54
|
+
const src = await readFile(file, 'utf8');
|
|
55
|
+
const lines = src.split('\n');
|
|
56
|
+
const relPath = relative(join(import.meta.dir, '..'), file);
|
|
57
|
+
|
|
58
|
+
lines.forEach((line, i) => {
|
|
59
|
+
const lineNum = i + 1;
|
|
60
|
+
const trimmed = line.trim();
|
|
61
|
+
if (trimmed.startsWith('//')) return; // skip comments
|
|
62
|
+
|
|
63
|
+
for (const { pattern, desc } of BANNED) {
|
|
64
|
+
const regex = new RegExp(pattern.source, pattern.flags);
|
|
65
|
+
let match;
|
|
66
|
+
while ((match = regex.exec(line)) !== null) {
|
|
67
|
+
const hit = match[0].toLowerCase();
|
|
68
|
+
// Skip if it matches an allowed pattern
|
|
69
|
+
if (ALLOWED_PATTERNS.some((p) => p.test(match[0]))) continue;
|
|
70
|
+
if (ALLOWED_HEX.has(hit)) continue;
|
|
71
|
+
// Skip obvious structural #fff patterns
|
|
72
|
+
if (hit === '#fff' || hit === '#000') continue;
|
|
73
|
+
|
|
74
|
+
console.error(` ${relPath}:${lineNum} ${desc}`);
|
|
75
|
+
console.error(` → ${line.trim()}`);
|
|
76
|
+
totalViolations++;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (totalViolations > 0) {
|
|
83
|
+
console.error(`\n✖ lint-colors: ${totalViolations} violation(s) found. Replace with var(--pp-*) tokens.\n`);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
} else {
|
|
86
|
+
console.log('✔ lint-colors: No literal color tokens found in component files.');
|
|
87
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const registry = {};
|
|
3
|
+
|
|
4
|
+
document.querySelectorAll('.pp-accordion').forEach((accordion, accordionIdx) => {
|
|
5
|
+
const allowMultiple = accordion.hasAttribute('data-allow-multiple');
|
|
6
|
+
const id = accordion.id || `pp-accordion-${accordionIdx}`;
|
|
7
|
+
if (!accordion.id) accordion.id = id;
|
|
8
|
+
|
|
9
|
+
const triggers = [...accordion.querySelectorAll('.pp-accordion__trigger')];
|
|
10
|
+
|
|
11
|
+
triggers.forEach((trigger, i) => {
|
|
12
|
+
const panelId = trigger.getAttribute('aria-controls');
|
|
13
|
+
const panel = panelId
|
|
14
|
+
? document.getElementById(panelId)
|
|
15
|
+
: trigger.nextElementSibling;
|
|
16
|
+
|
|
17
|
+
if (!panel) return;
|
|
18
|
+
|
|
19
|
+
const isOpen = trigger.getAttribute('aria-expanded') === 'true';
|
|
20
|
+
panel.setAttribute('aria-hidden', isOpen ? 'false' : 'true');
|
|
21
|
+
if (isOpen) panel.classList.add('is-open');
|
|
22
|
+
|
|
23
|
+
trigger.addEventListener('click', () => {
|
|
24
|
+
const expanded = trigger.getAttribute('aria-expanded') === 'true';
|
|
25
|
+
|
|
26
|
+
if (!allowMultiple) {
|
|
27
|
+
triggers.forEach((t) => {
|
|
28
|
+
if (t === trigger) return;
|
|
29
|
+
t.setAttribute('aria-expanded', 'false');
|
|
30
|
+
const p = t.getAttribute('aria-controls')
|
|
31
|
+
? document.getElementById(t.getAttribute('aria-controls'))
|
|
32
|
+
: t.nextElementSibling;
|
|
33
|
+
if (p) {
|
|
34
|
+
p.setAttribute('aria-hidden', 'true');
|
|
35
|
+
p.classList.remove('is-open');
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const next = !expanded;
|
|
41
|
+
trigger.setAttribute('aria-expanded', String(next));
|
|
42
|
+
panel.setAttribute('aria-hidden', String(!next));
|
|
43
|
+
panel.classList.toggle('is-open', next);
|
|
44
|
+
|
|
45
|
+
accordion.dispatchEvent(new CustomEvent(next ? 'pp:accordion:open' : 'pp:accordion:close', {
|
|
46
|
+
bubbles: true,
|
|
47
|
+
detail: { index: i, trigger, panel },
|
|
48
|
+
}));
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
trigger.addEventListener('keydown', (e) => {
|
|
52
|
+
const idx = triggers.indexOf(trigger);
|
|
53
|
+
if (e.key === 'ArrowDown') {
|
|
54
|
+
e.preventDefault();
|
|
55
|
+
triggers[(idx + 1) % triggers.length].focus();
|
|
56
|
+
} else if (e.key === 'ArrowUp') {
|
|
57
|
+
e.preventDefault();
|
|
58
|
+
triggers[(idx - 1 + triggers.length) % triggers.length].focus();
|
|
59
|
+
} else if (e.key === 'Home') {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
triggers[0].focus();
|
|
62
|
+
} else if (e.key === 'End') {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
triggers[triggers.length - 1].focus();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function setItem(index, open) {
|
|
70
|
+
const trigger = triggers[index];
|
|
71
|
+
if (!trigger) return;
|
|
72
|
+
const panelId = trigger.getAttribute('aria-controls');
|
|
73
|
+
const panel = panelId ? document.getElementById(panelId) : trigger.nextElementSibling;
|
|
74
|
+
if (!panel) return;
|
|
75
|
+
trigger.setAttribute('aria-expanded', String(open));
|
|
76
|
+
panel.setAttribute('aria-hidden', String(!open));
|
|
77
|
+
panel.classList.toggle('is-open', open);
|
|
78
|
+
accordion.dispatchEvent(new CustomEvent(open ? 'pp:accordion:open' : 'pp:accordion:close', {
|
|
79
|
+
bubbles: true,
|
|
80
|
+
detail: { index, trigger, panel },
|
|
81
|
+
}));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const api = {
|
|
85
|
+
open: (index) => setItem(index, true),
|
|
86
|
+
close: (index) => setItem(index, false),
|
|
87
|
+
toggleAll() {
|
|
88
|
+
const anyOpen = triggers.some((t) => t.getAttribute('aria-expanded') === 'true');
|
|
89
|
+
triggers.forEach((_, i) => setItem(i, !anyOpen));
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
registry[id] = api;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
window.ppAccordion = {
|
|
97
|
+
get(ref) {
|
|
98
|
+
if (typeof ref === 'string') return registry[ref];
|
|
99
|
+
if (ref instanceof Element) return registry[ref.id];
|
|
100
|
+
return null;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
})();
|
package/src/js/alert.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
function dismiss(alertEl) {
|
|
3
|
+
if (alertEl._dismissed) return;
|
|
4
|
+
alertEl._dismissed = true;
|
|
5
|
+
alertEl.classList.add('is-dismissing');
|
|
6
|
+
alertEl.dispatchEvent(new CustomEvent('pp:alert:dismiss', { bubbles: true }));
|
|
7
|
+
alertEl.addEventListener('animationend', () => alertEl.remove(), { once: true });
|
|
8
|
+
setTimeout(() => alertEl.remove(), 250);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
window.ppAlert = {
|
|
12
|
+
dismiss(idOrEl) {
|
|
13
|
+
const el = typeof idOrEl === 'string'
|
|
14
|
+
? document.getElementById(idOrEl)
|
|
15
|
+
: idOrEl;
|
|
16
|
+
if (el) dismiss(el);
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Auto-wire [data-alert-dismiss] buttons
|
|
21
|
+
document.addEventListener('click', (e) => {
|
|
22
|
+
const btn = e.target.closest('[data-alert-dismiss]');
|
|
23
|
+
if (btn) {
|
|
24
|
+
const alert = btn.closest('.pp-alert');
|
|
25
|
+
if (alert) dismiss(alert);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
})();
|
package/src/js/carousel.js
CHANGED
|
@@ -68,6 +68,11 @@
|
|
|
68
68
|
const label = slides[idx].getAttribute('aria-label') || `Slide ${idx + 1}`;
|
|
69
69
|
announcer.textContent = '';
|
|
70
70
|
requestAnimationFrame(() => { announcer.textContent = label; });
|
|
71
|
+
|
|
72
|
+
root.dispatchEvent(new CustomEvent('pp:carousel:change', {
|
|
73
|
+
bubbles: true,
|
|
74
|
+
detail: { index: idx, total, label },
|
|
75
|
+
}));
|
|
71
76
|
}
|
|
72
77
|
|
|
73
78
|
const observer = new IntersectionObserver(
|
package/src/js/header.js
CHANGED
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
const isOpen = nav.classList.toggle('is-open');
|
|
40
40
|
toggle.setAttribute('aria-expanded', String(isOpen));
|
|
41
41
|
nav.setAttribute('aria-hidden', String(!isOpen));
|
|
42
|
+
header.dispatchEvent(new CustomEvent(isOpen ? 'pp:header:open' : 'pp:header:close', { bubbles: true }));
|
|
42
43
|
});
|
|
43
44
|
|
|
44
45
|
// Close drawer on outside click
|
package/src/js/modal.js
CHANGED
|
@@ -67,6 +67,8 @@
|
|
|
67
67
|
|
|
68
68
|
backdrop._trapFocus = (e) => trapFocus(e, backdrop);
|
|
69
69
|
backdrop.addEventListener('keydown', backdrop._trapFocus);
|
|
70
|
+
|
|
71
|
+
backdrop.dispatchEvent(new CustomEvent('pp:modal:open', { bubbles: true }));
|
|
70
72
|
}
|
|
71
73
|
|
|
72
74
|
function closeModal(id) {
|
|
@@ -86,6 +88,8 @@
|
|
|
86
88
|
delete backdrop._trapFocus;
|
|
87
89
|
}
|
|
88
90
|
|
|
91
|
+
backdrop.dispatchEvent(new CustomEvent('pp:modal:close', { bubbles: true }));
|
|
92
|
+
|
|
89
93
|
// Restore focus to the element that opened the modal
|
|
90
94
|
if (lastFocused && typeof lastFocused.focus === 'function') {
|
|
91
95
|
lastFocused.focus();
|
package/src/js/peppertino.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// PeppertinoCSS — aggregator
|
|
2
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.
|
|
3
4
|
|
|
5
|
+
import './accordion.js';
|
|
6
|
+
import './alert.js';
|
|
4
7
|
import './carousel.js';
|
|
5
8
|
import './header.js';
|
|
6
9
|
import './modal.js';
|
|
7
10
|
import './select.js';
|
|
11
|
+
import './switch.js';
|
|
8
12
|
import './tabs.js';
|
|
13
|
+
import './theme.js';
|
|
14
|
+
import './toast.js';
|
|
9
15
|
import './validation.js';
|
package/src/js/select.js
CHANGED
|
@@ -67,10 +67,8 @@
|
|
|
67
67
|
const nativeSelect = wrapper.querySelector('select[data-pp-select]');
|
|
68
68
|
if (nativeSelect) nativeSelect.value = opt.dataset.value ?? opt.textContent.trim();
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
detail: { value: opt.dataset.value, label: opt.textContent.trim() },
|
|
73
|
-
}));
|
|
70
|
+
const detail = { value: opt.dataset.value, label: opt.textContent.trim() };
|
|
71
|
+
wrapper.dispatchEvent(new CustomEvent('pp:select:change', { bubbles: true, detail }));
|
|
74
72
|
|
|
75
73
|
close();
|
|
76
74
|
trigger.focus();
|
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
|
+
})();
|
package/src/js/tabs.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
(function () {
|
|
2
|
+
const registry = {};
|
|
3
|
+
|
|
2
4
|
function initTabs(tabGroup, groupIdx) {
|
|
3
|
-
const items = tabGroup.querySelectorAll('.pp-tabs__item');
|
|
5
|
+
const items = [...tabGroup.querySelectorAll('.pp-tabs__item')];
|
|
4
6
|
const targetAttr = 'data-tab-target';
|
|
5
7
|
|
|
6
|
-
// Ensure tablist role
|
|
7
8
|
if (!tabGroup.getAttribute('role')) tabGroup.setAttribute('role', 'tablist');
|
|
8
9
|
|
|
9
|
-
// Wire up tab roles and aria-controls
|
|
10
10
|
items.forEach((item, i) => {
|
|
11
11
|
item.setAttribute('role', 'tab');
|
|
12
12
|
if (!item.id) item.id = `pp-tab-${groupIdx}-${i}`;
|
|
@@ -34,7 +34,6 @@
|
|
|
34
34
|
item.setAttribute('aria-selected', 'true');
|
|
35
35
|
item.setAttribute('tabindex', '0');
|
|
36
36
|
|
|
37
|
-
// Show/hide associated panels if present
|
|
38
37
|
const targetId = item.getAttribute(targetAttr);
|
|
39
38
|
if (targetId) {
|
|
40
39
|
document.querySelectorAll('[data-tab-panel]').forEach((panel) => {
|
|
@@ -44,51 +43,62 @@
|
|
|
44
43
|
});
|
|
45
44
|
}
|
|
46
45
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
detail: { value: item.dataset.tabTarget, label: item.textContent.trim() },
|
|
50
|
-
}));
|
|
46
|
+
const detail = { value: item.dataset.tabTarget, label: item.textContent.trim(), index: items.indexOf(item) };
|
|
47
|
+
tabGroup.dispatchEvent(new CustomEvent('pp:tabs:change', { bubbles: true, detail }));
|
|
51
48
|
}
|
|
52
49
|
|
|
53
|
-
// Click
|
|
54
50
|
items.forEach((item) => {
|
|
55
51
|
item.addEventListener('click', () => activate(item));
|
|
56
52
|
});
|
|
57
53
|
|
|
58
|
-
// Keyboard: left/right arrow navigation
|
|
59
54
|
tabGroup.addEventListener('keydown', (e) => {
|
|
60
|
-
const current =
|
|
55
|
+
const current = items.findIndex((i) => i === document.activeElement);
|
|
61
56
|
if (current === -1) return;
|
|
62
57
|
|
|
63
58
|
if (e.key === 'ArrowRight') {
|
|
64
59
|
e.preventDefault();
|
|
65
60
|
const next = items[(current + 1) % items.length];
|
|
66
|
-
activate(next);
|
|
67
|
-
next.focus();
|
|
61
|
+
activate(next); next.focus();
|
|
68
62
|
}
|
|
69
63
|
if (e.key === 'ArrowLeft') {
|
|
70
64
|
e.preventDefault();
|
|
71
65
|
const prev = items[(current - 1 + items.length) % items.length];
|
|
72
|
-
activate(prev);
|
|
73
|
-
prev.focus();
|
|
66
|
+
activate(prev); prev.focus();
|
|
74
67
|
}
|
|
75
68
|
if (e.key === 'Home') {
|
|
76
69
|
e.preventDefault();
|
|
77
|
-
activate(items[0]);
|
|
78
|
-
items[0].focus();
|
|
70
|
+
activate(items[0]); items[0].focus();
|
|
79
71
|
}
|
|
80
72
|
if (e.key === 'End') {
|
|
81
73
|
e.preventDefault();
|
|
82
|
-
activate(items[items.length - 1]);
|
|
83
|
-
items[items.length - 1].focus();
|
|
74
|
+
activate(items[items.length - 1]); items[items.length - 1].focus();
|
|
84
75
|
}
|
|
85
76
|
});
|
|
86
77
|
|
|
87
|
-
// Set initial tabindex
|
|
88
78
|
items.forEach((item) => {
|
|
89
79
|
item.setAttribute('tabindex', item.classList.contains('is-active') ? '0' : '-1');
|
|
90
80
|
});
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
activate(index) {
|
|
84
|
+
const item = items[index];
|
|
85
|
+
if (item) { activate(item); item.focus(); }
|
|
86
|
+
},
|
|
87
|
+
};
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
document.querySelectorAll('.pp-tabs').forEach((el, i) =>
|
|
90
|
+
document.querySelectorAll('.pp-tabs').forEach((el, i) => {
|
|
91
|
+
const id = el.id || `pp-tabs-${i}`;
|
|
92
|
+
if (!el.id) el.id = id;
|
|
93
|
+
const api = initTabs(el, i);
|
|
94
|
+
if (api) registry[id] = api;
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
window.ppTabs = {
|
|
98
|
+
get(ref) {
|
|
99
|
+
if (typeof ref === 'string') return registry[ref];
|
|
100
|
+
if (ref instanceof Element) return registry[ref.id];
|
|
101
|
+
return null;
|
|
102
|
+
},
|
|
103
|
+
};
|
|
94
104
|
})();
|
package/src/js/theme.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
const STORAGE_KEY = 'pp-theme';
|
|
3
|
+
const ROOT = document.documentElement;
|
|
4
|
+
|
|
5
|
+
function applyTheme(theme) {
|
|
6
|
+
if (theme === 'dark') {
|
|
7
|
+
ROOT.classList.add('dark');
|
|
8
|
+
} else {
|
|
9
|
+
ROOT.classList.remove('dark');
|
|
10
|
+
}
|
|
11
|
+
try { localStorage.setItem(STORAGE_KEY, theme); } catch (_) {}
|
|
12
|
+
|
|
13
|
+
document.dispatchEvent(new CustomEvent('pp:theme:change', {
|
|
14
|
+
bubbles: false,
|
|
15
|
+
detail: { theme },
|
|
16
|
+
}));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
window.ppTheme = {
|
|
20
|
+
set(theme) {
|
|
21
|
+
applyTheme(theme === 'dark' ? 'dark' : 'light');
|
|
22
|
+
},
|
|
23
|
+
|
|
24
|
+
get() {
|
|
25
|
+
return ROOT.classList.contains('dark') ? 'dark' : 'light';
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
toggle() {
|
|
29
|
+
applyTheme(ROOT.classList.contains('dark') ? 'light' : 'dark');
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// Restore from localStorage on load
|
|
34
|
+
(function init() {
|
|
35
|
+
let saved;
|
|
36
|
+
try { saved = localStorage.getItem(STORAGE_KEY); } catch (_) {}
|
|
37
|
+
if (saved === 'dark' || saved === 'light') {
|
|
38
|
+
applyTheme(saved);
|
|
39
|
+
}
|
|
40
|
+
})();
|
|
41
|
+
|
|
42
|
+
// Auto-wire [data-theme-toggle] buttons
|
|
43
|
+
document.addEventListener('click', (e) => {
|
|
44
|
+
const btn = e.target.closest('[data-theme-toggle]');
|
|
45
|
+
if (btn) ppTheme.toggle();
|
|
46
|
+
});
|
|
47
|
+
})();
|