Settings Component โ Astro
Comprehensive settings panel for theme switching, font size adjustment, and accessibility options
Settings Component
A comprehensive settings panel for theme switching, font size adjustment, and accessibility options.
Features
- Theme Switcher - Integrated ThemeSwitcher component with theme icons (persists in localStorage as
theme) - Font Size Slider - Adjustable from 75% to 150% with filled track indicator (uses CSS gradient with
--slider-progressvariable). Persists in localStorage asfontSizeScale - Reduce Motion Toggle - Applies
.reduced-motionclass to document root. Persists in localStorage asreducedMotion - High Contrast Toggle - Applies
.high-contrastclass to document root. Persists in localStorage ashighContrast - Scrollbar Style - Radio button group with three options: Thin (default, 0.5rem/8px), Thick (1.5rem/24px), and Hidden. Applies classes to
htmlelement (.scrollbar-thickor.scrollbar-hidden). Persists in localStorage asscrollbarStyle(values:thin,thick,hidden) - Opening and Closing Animations - Smooth slide-in from right with overlay fade (respects
prefers-reduced-motion) - Focus Trapping - Tab cycles within panel when open
- Focus Management - Returns focus to trigger element on close
- Slide-in panel with overlay
- All settings persist in localStorage - All preferences are automatically saved and restored on page load
- Full keyboard navigation (Escape to close)
- Accessible ARIA attributes
- Slider track visibility optimized for all themes
- Mobile Responsive - Full width on mobile devices, optimized layout
Settings Persistence
All settings options automatically persist to localStorage and are restored when the page loads:
theme- Selected theme name (e.g.,github-dark-classic,github-light)fontSizeScale- Font size multiplier (e.g.,1.0for 100%,1.25for 125%)reducedMotion- Boolean string (trueorfalse)highContrast- Boolean string (trueorfalse)scrollbarStyle- Scrollbar style preference (thin,thick, orhidden)
Live example
Open Settings via the gear icon in the navbar or the button below (same as navbar).
Open Settings
Usage
astro astro
---
import Settings from '../../components/Settings.astro';
---
<!-- Include once in layout (e.g. with Navbar). Default closed. -->
<Settings open={false} />
<!-- Open/close from JS (e.g. navbar gear button): -->
<!-- window.openSettings(); window.closeSettings(); --> Props
open(boolean, optional) - Whether settings panel is open by default (default: false)
Opening Settings
The Settings component registers window.openSettings() and window.closeSettings(). The Navbar gear button calls openSettings().
javascript javascript
// Open the settings panel (e.g. from a button or navbar)
window.openSettings();
// Close the settings panel
window.closeSettings(); Svelte & Vanilla: Svelte ยท Vanilla: same HTML and BEM as in Usage above; scaffold includes openSettings().