Skip to content

Add light/dark theme toggle and new operators (power and square root) - #21

Draft
haslam93 with Copilot wants to merge 2 commits into
mainfrom
copilot/update-ui-and-accessibility-features
Draft

Add light/dark theme toggle and new operators (power and square root)#21
haslam93 with Copilot wants to merge 2 commits into
mainfrom
copilot/update-ui-and-accessibility-features

Conversation

Copilot AI commented Oct 9, 2025

Copy link
Copy Markdown
Contributor

Overview

This PR implements the UI improvements and new functionality requested in #[issue_number], adding a manual theme toggle and two new mathematical operators to enhance the calculator's capabilities.

Changes Made

🌓 Light/Dark Theme Toggle

Added a manual theme toggle button that allows users to switch between light and dark modes:

  • Toggle button with 🌓 icon positioned in the top-right corner of the calculator
  • Theme preference persists across sessions using localStorage
  • Smooth CSS transitions between themes
  • Works alongside existing automatic system preference detection
  • Fully accessible with proper ARIA labels

Light Mode:
Light Mode Calculator

Dark Mode:
Dark Mode Calculator

🔢 New Mathematical Operators

Power Operator (^)

  • Raises a number to a specified power
  • Example: 3^2 = 9, 2^-2 = 0.25
  • Keyboard shortcut: ^ key
  • Backend endpoint: /arithmetic?operation=power&operand1=3&operand2=2

Square Root Operator (√)

  • Calculates the square root of a number
  • Example: √9 = 3, √2.25 = 1.5
  • Backend endpoint: /arithmetic?operation=sqrt&operand1=9&operand2=0

Both operators are accessible via on-screen buttons and keyboard input, maintaining the calculator's existing interaction patterns.

Technical Details

Files Modified

  • api/controller.js: Added power and sqrt operations to the backend controller
  • public/client.js: Implemented theme toggle logic and handlers for new operators
  • public/default.css: Added theme toggle button styling and enhanced theme switching support
  • public/index.html: Added theme toggle button and new operator buttons to the UI
  • test/arithmetic.test.js: Added 7 new test cases covering both operations

Code Quality

  • Fixed existing ESLint errors (unnecessary escape characters in regex patterns)
  • All 31 tests passing (24 existing + 7 new)
  • Maintained 86%+ code coverage
  • Zero linting errors

Accessibility Enhancements

  • Theme toggle button includes proper ARIA labels
  • New operator buttons have descriptive ARIA labels
  • Keyboard navigation fully supported for new operators
  • High contrast maintained in both themes

Testing

The implementation includes comprehensive test coverage:

  • 4 tests for power operation (positive power, power of 0, negative power, negative base)
  • 3 tests for square root operation (positive integer, decimal, zero)
  • All existing tests continue to pass

Example test cases:

// Power: 2^3 = 8
request.get('/arithmetic?operation=power&operand1=2&operand2=3')
  .expect(200, { result: 8 })

// Square root: √9 = 3
request.get('/arithmetic?operation=sqrt&operand1=9&operand2=0')
  .expect(200, { result: 3 })

Breaking Changes

None. This PR only adds new functionality without modifying existing behavior.

Related Issues

Closes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Update the UI and accesbility features</issue_title>
<issue_description>I want to make the UI better. Add light dark theme.
Add a few operators like square rooot and power of.

</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #20


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: haslam93 <36418598+haslam93@users.noreply.github.com>
Copilot AI changed the title [WIP] Update UI to include light/dark theme and new operators Add light/dark theme toggle and new operators (power and square root) Oct 9, 2025
Copilot AI requested a review from haslam93 October 9, 2025 16:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update the UI and accesbility features

2 participants