From e16d425aae270d57faa2a93009a9d80fa21241b1 Mon Sep 17 00:00:00 2001 From: MohitHereVats Date: Thu, 16 Oct 2025 15:10:04 +0530 Subject: [PATCH] Tasks are Done --- src/App.css | 33 ++++++++++ src/App.tsx | 117 ++++++++++++++++++++++++++++++----- src/stringCalculator.test.ts | 55 ++++++++++++++++ src/stringCalculator.ts | 48 ++++++++++++++ 4 files changed, 236 insertions(+), 17 deletions(-) create mode 100644 src/App.css diff --git a/src/App.css b/src/App.css new file mode 100644 index 00000000..f40c522a --- /dev/null +++ b/src/App.css @@ -0,0 +1,33 @@ +/* Accessibility Focus Styles */ +button:focus-visible, +textarea:focus-visible, +input:focus-visible { + outline: 3px solid #ffa500; + outline-offset: 2px; +} + +/* Button hover and active states */ +button:hover { + background-color: #006a8e !important; + transform: translateY(-1px); +} + +button:active { + transform: translateY(0); +} + +/* High contrast mode support */ +@media (prefers-contrast: high) { + button, + textarea { + border-width: 3px; + } +} + +/* Reduced motion support */ +@media (prefers-reduced-motion: reduce) { + button, + * { + transition: none !important; + } +} diff --git a/src/App.tsx b/src/App.tsx index 851cc829..faba58af 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,46 +1,129 @@ import { useState } from 'react'; +import { add } from './stringCalculator'; +import './App.css'; const App = () => { const [input, setInput] = useState(''); - const [result] = useState(null); + const [result, setResult] = useState(null); + const [error, setError] = useState(''); - const handleCalculate = () => {}; + const handleCalculate = () => { + try { + setError(''); + const sum = add(input); + setResult(sum); + } catch (err) { + setError(err instanceof Error ? err.message : 'An error occurred'); + setResult(null); + } + }; + + const handleInputChange = (e: React.ChangeEvent) => { + setInput(e.target.value); + setError(''); + setResult(null); + }; return ( -
+
Calculator with colorful number buttons and mathematical symbols -

String Calculator

+

String Calculator

-

Enter numbers

+

+ Enter numbers below to calculate their sum +

+