A modern, responsive calculator application built with React and Tailwind CSS. Features a clean, macOS-inspired design with dark/light mode toggle, keyboard support, and PWA capabilities.
- ✅ Basic arithmetic operations (+, -, ×, ÷)
- ✅ Decimal number support
- ✅ Clear (C) and All Clear (AC) functions
- ✅ Error handling (divide by zero, overflow)
- ✅ Keyboard input support
- ✅ Memory functions (M+, M-, MR, MC)
- ✅ Modern, responsive design
- ✅ Dark/Light mode toggle
- ✅ Smooth animations with Framer Motion
- ✅ macOS calculator aesthetic
- ✅ Touch-friendly button design
- ✅ Accessibility features (focus states, keyboard navigation)
- ✅ Progressive Web App (PWA) support
- ✅ Offline functionality
- ✅ Installable on mobile devices
- ✅ Service worker caching
- Node.js (v14 or higher)
- npm or yarn
-
Install dependencies:
npm install
-
Start development server:
npm start
-
Open your browser: Navigate to
http://localhost:3000
npm run buildThis creates an optimized production build in the build folder.
- Click any number or operation button to input
- Use the display to see current input and results
- Memory buttons (MC, MR, M+, M-) for storing values
- Numbers: 0-9 keys
- Operations: +, -, *, / keys
- Decimal: . (period) key
- Equals: = or Enter key
- Clear: Escape key
- All Clear: Escape key (clears everything)
- MC: Memory Clear - clears stored memory value
- MR: Memory Recall - displays stored memory value
- M+: Memory Add - adds current display to memory
- M-: Memory Subtract - subtracts current display from memory
Click the sun/moon icon in the top-right corner to switch between light and dark modes.
src/
├── components/
│ └── Calculator.jsx # Main calculator component
├── App.js # Main app component
├── index.js # React entry point
├── index.css # Global styles with Tailwind
└── registerSW.js # Service worker registration
public/
├── index.html # HTML template
├── manifest.json # PWA manifest
└── sw.js # Service worker
Configuration files:
├── package.json # Dependencies and scripts
├── tailwind.config.js # Tailwind CSS configuration
└── postcss.config.js # PostCSS configuration
The calculator uses React hooks for state management:
display: Current display valuepreviousValue: Previous operand for calculationsoperation: Current operation being performedwaitingForOperand: Boolean for input state managementmemory: Stored memory valueisDarkMode: Theme statehistory: Display history for showing previous calculations
const calculate = (firstValue, secondValue, operation) => {
// Handles all basic arithmetic with error checking
// Returns result or throws error for invalid operations
};const inputNumber = (num) => {
// Manages number input with proper state transitions
// Handles waitingForOperand state correctly
};- Division by zero detection
- Overflow protection (results > 999999999999)
- Invalid operation handling
- Graceful error display
- Custom color palette matching macOS calculator
- Responsive grid layout for buttons
- Dark mode support with
dark:prefix - Smooth transitions and hover effects
- Button press animations (
whileTap={{ scale: 0.95 }}) - Page load animations
- Smooth theme transitions
- Caches app resources for offline use
- Handles network requests with cache-first strategy
- Automatic cache cleanup for updates
- App metadata for installation
- Icon definitions
- Display mode configuration
- Chrome 60+
- Firefox 55+
- Safari 11+
- Edge 79+
- Optimized bundle size with React production build
- Lazy loading of components
- Efficient state management
- Minimal re-renders with useCallback hooks
- Full keyboard navigation support
- Focus indicators for screen readers
- High contrast mode support
- Touch-friendly button sizes (minimum 44px)
- Semantic HTML structure
- ESLint configuration for React
- Consistent component structure
- Comprehensive inline comments
- Modular function organization
npm testnpm run lintThe app can be deployed to any static hosting service:
- Vercel
- Netlify
- GitHub Pages
- AWS S3 + CloudFront
The npm run build command creates a production-ready build in the build directory.
MIT License - feel free to use this project for learning or commercial purposes.
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Potential improvements for future versions:
- Scientific calculator functions
- History log with export
- Custom themes
- Voice input support
- Multi-language support
- Advanced memory functions
- Calculation history persistence