Skip to content

Latest commit

 

History

History
94 lines (77 loc) · 4.71 KB

File metadata and controls

94 lines (77 loc) · 4.71 KB

Frontend Changes: Dark/Light Theme Toggle Feature

Overview

Implemented a comprehensive dark/light theme toggle system for the RAG chatbot frontend, allowing users to switch between themes with smooth animations and persistent preferences.

Files Modified

1. frontend/style.css

  • Added light theme CSS variables (lines 27-44): Complete set of color variables for light theme including backgrounds, text colors, borders, and shadows
  • Enhanced dark theme variables (lines 8-25): Organized existing dark theme variables with clear comments
  • Added smooth transitions (line 56): Body element now transitions between themes smoothly
  • Updated code block styling (lines 356-372): Enhanced code blocks to work well in both themes with appropriate backgrounds and borders
  • Added theme toggle button styles (lines 834-897): Complete styling for the floating theme toggle button including:
    • Circular design with smooth hover/focus effects
    • Icon animations with rotation and scaling
    • Proper accessibility focus states
    • Shadow and border styling that adapts to theme
  • Added universal transitions (lines 899-910): Smooth transitions applied to all major UI elements
  • Mobile responsive adjustments (lines 827-832): Smaller button size on mobile devices

2. frontend/index.html

  • Added theme toggle button (lines 13-17): Fixed-position toggle button with accessibility attributes and sun/moon icons

3. frontend/script.js

  • Added theme-related DOM element (line 8): Added themeToggle to DOM elements list
  • Enhanced initialization (line 22): Added theme initialization call
  • Added event listeners (lines 38-45): Click and keyboard event handlers for theme toggle
  • Implemented theme functions (lines 235-257):
    • initializeTheme(): Loads saved theme preference from localStorage
    • toggleTheme(): Switches between dark and light themes
    • applyTheme(): Applies theme and updates accessibility attributes

Features Implemented

1. Theme Toggle Button

  • Design: Circular floating button positioned in top-right corner
  • Icons: Sun (☀️) for light theme, moon (🌙) for dark theme with smooth rotation animations
  • Position: Fixed position that stays visible during scrolling
  • Accessibility: Full keyboard navigation support with Enter/Space key activation
  • Mobile: Responsive design with smaller size on mobile devices

2. Light Theme Colors

  • Background: Clean white (#ffffff) main background
  • Surface: Light gray (#f8fafc) for cards and panels
  • Text: Dark slate (#1e293b) primary text, medium gray (#64748b) secondary text
  • Borders: Light gray borders (#e2e8f0) for subtle separation
  • Accessibility: High contrast ratios maintained for readability

3. Theme Switching

  • Smooth Transitions: 0.3s ease transitions for all color changes
  • State Persistence: Theme preference saved to localStorage
  • Icon Animation: Icons rotate and scale during theme transitions
  • Accessibility: Dynamic ARIA labels that update based on current theme

4. Enhanced Elements

  • Code Blocks: Proper styling in both themes with appropriate contrast
  • Message Bubbles: Maintain readability and visual hierarchy
  • Input Fields: Consistent styling across themes
  • Buttons: Hover and focus states work well in both themes
  • Sidebar: Clean appearance with proper contrast in both themes

Technical Implementation

CSS Architecture

  • Used CSS custom properties (variables) for theme switching
  • Applied data-theme attribute to body element for theme detection
  • Maintained existing design language while adding theme variants

JavaScript Functionality

  • Modular theme functions integrated into existing codebase
  • localStorage integration for preference persistence
  • Accessibility-first approach with proper ARIA labeling
  • Keyboard navigation support

Accessibility Features

  • High contrast ratios maintained in both themes
  • Focus indicators clearly visible in all themes
  • Keyboard navigation fully supported
  • Screen reader friendly with descriptive ARIA labels
  • Semantic HTML structure preserved

Browser Compatibility

  • Modern CSS features used (CSS custom properties, transitions)
  • Works in all modern browsers (Chrome, Firefox, Safari, Edge)
  • Graceful degradation for older browsers
  • Mobile responsive design

Usage

  1. Click the theme toggle button in the top-right corner
  2. Use keyboard (Enter or Space) to activate the toggle
  3. Theme preference is automatically saved and restored on reload
  4. Smooth animations provide visual feedback during switching

The implementation maintains the existing design aesthetic while providing a seamless theme switching experience that enhances user comfort in different lighting conditions.