Files
Styleguide/patterns/aktivierungs-schalter.html
T

54 lines
1.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Styleguide – Pattern Aktivierungs-Schalter</title>
<link rel="stylesheet" href="../styleguide.css">
</head>
<body>
<h1 class="sg-main-heading">Pattern – Aktivierungs-Schalter</h1>
<section id="pattern-aktivierungs-schalter">
<p class="sg-preview-label">Pattern: Aktivierungs-Schalter (an/aus)</p>
<div class="sg-form-preview-area">
<div class="sg-state-example">
<p class="sg-state-example__label sg-table-label">Pattern Demo</p>
<div class="sg-activation-toggle-pattern" data-pattern="activation-toggle">
<button
class="sg-activation-toggle-chip"
type="button"
data-active="aus"
aria-pressed="false"
aria-label="Aktivierung aus"
>
<span class="sg-activation-toggle-chip__text">aus</span>
<span class="sg-activation-toggle-chip__text">an</span>
</button>
<span class="sg-activation-toggle-pattern__label sg-body" data-pattern-part="activation-toggle-state">Status: aus</span>
</div>
</div>
</div>
</section>
<script>
document.querySelectorAll('.sg-activation-toggle-chip').forEach((toggle) => {
toggle.addEventListener('click', () => {
const nextState = toggle.dataset.active === 'an' ? 'aus' : 'an';
const statusLabel = toggle.closest('[data-pattern="activation-toggle"]')?.querySelector('[data-pattern-part="activation-toggle-state"]');
toggle.dataset.active = nextState;
toggle.setAttribute('aria-pressed', String(nextState === 'an'));
toggle.setAttribute('aria-label', `Aktivierung ${nextState}`);
if (statusLabel) {
statusLabel.textContent = `Status: ${nextState}`;
}
});
});
</script>
</body>
</html>