Skip to content

Matrix7043/coffee-ui

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

β˜• Coffee Store

A modern, responsive coffee shop e-commerce application built with React, featuring a shopping cart system with real-time updates and smooth user experience.

🌟 Features

  • Product Catalog: Browse a curated selection of coffee drinks
  • Shopping Cart: Add, remove, and adjust quantities of items
  • Real-time Updates: Cart count updates instantly in the navbar
  • Persistent State: Cart state managed with React Context API
  • Responsive Design: Mobile-first design with Tailwind CSS
  • Routing: Multi-page navigation with React Router
  • Clean UI: Coffee-themed color palette with smooth interactions

πŸ› οΈ Tech Stack

  • React 18 - UI library with hooks
  • React Router - Client-side routing
  • Context API - Global state management
  • Tailwind CSS - Utility-first styling
  • Vite - Fast build tool and dev server

πŸ“‹ Prerequisites

  • Node.js 16+
  • npm or yarn

πŸš€ Quick Start

1. Install Dependencies

npm install

2. Run Development Server

npm run dev

The app will be available at http://localhost:5173

3. Build for Production

npm run build

4. Preview Production Build

npm run preview

πŸ“ Project Structure

src/
β”œβ”€β”€ components/           # Reusable UI components
β”‚   β”œβ”€β”€ Navbar.jsx       # Navigation with cart count
β”‚   β”œβ”€β”€ CoffeeList.jsx   # Coffee product grid
β”‚   β”œβ”€β”€ CoffeeCard.jsx   # Individual coffee item card
β”‚   └── Cart.jsx         # Cart display and management
β”œβ”€β”€ context/             # Global state management
β”‚   └── CartContext.jsx  # Cart state and operations
β”œβ”€β”€ pages/               # Page components
β”‚   β”œβ”€β”€ Home.jsx         # Main store page
β”‚   └── CartPage.jsx     # Cart checkout page
β”œβ”€β”€ assets/              # Static assets
β”‚   └── react.svg        # React logo
β”œβ”€β”€ App.jsx              # Main app component with routing
β”œβ”€β”€ main.jsx             # App entry point
└── index.css            # Global styles (Tailwind import)

🎨 Color Palette

The app uses a coffee-inspired color scheme:

  • Primary Brown: #3e2723 (Navbar background)
  • Coffee Brown: #6f4e37 (Buttons, accents)
  • Background: #f5f5f5 (Light gray)
  • White: #ffffff (Cards, text)

🧩 Key Components

CartContext

Global state management for the shopping cart:

const { cart, addToCart, incrementItem, decrementItem, clearCart } = useCart();

Available functions:

  • addToCart(coffee) - Add item to cart or increment if exists
  • incrementItem(id) - Increase quantity by 1
  • decrementItem(id) - Decrease quantity by 1 (removes if 0)
  • clearCart() - Empty entire cart

CoffeeCard

Individual product card with:

  • Coffee name and description
  • Price display
  • "Add to Cart" button
  • Hover effects

Navbar

Top navigation featuring:

  • Store branding
  • Cart link with live item count
  • Clear cart button (disabled when empty)
  • Responsive layout

Cart

Shopping cart display with:

  • Empty state message
  • Item list with quantities
  • Increment/decrement controls
  • Price calculations

πŸ›’ Current Products

Coffee Description Price
Espresso Strong and bold coffee Rs. 149
Cappuccino Rich and foamy coffee Rs. 199
Latte Smooth and creamy coffee Rs. 179

πŸ”„ Cart Functionality

Adding Items

  1. Click "Add to Cart" on any coffee card
  2. Item appears in cart with quantity 1
  3. Subsequent clicks increment quantity

Adjusting Quantities

  • Use + button to increase quantity
  • Use - button to decrease quantity
  • Item automatically removes when quantity reaches 0

Clearing Cart

  • Click "Clear Cart" in navbar to empty entire cart
  • Button is disabled when cart is empty

🎯 User Flow

Home Page (/) 
    ↓
Browse Coffee Selection
    ↓
Add Items to Cart
    ↓
View Cart Count in Navbar
    ↓
Navigate to Cart Page (/cart)
    ↓
Adjust Quantities
    ↓
Clear Cart (optional)

πŸ”§ Customization

Adding New Products

Edit src/components/CoffeeList.jsx:

const coffees = [
  // ... existing coffees
  {
    id: 4,
    name: "Americano",
    description: "Bold and smooth coffee",
    price: 129,
  },
];

Changing Colors

Update Tailwind classes in components:

// Example: Change button color
className="bg-[#6f4e37]" // Replace with your color

Adding Features

Common enhancements:

  • Product images
  • Search/filter functionality
  • Checkout process
  • Order history
  • User authentication
  • Price totals and tax calculations

πŸ“± Responsive Design

The app is fully responsive with breakpoints:

  • Mobile: Single column layout
  • Tablet: 2 columns (md: breakpoint)
  • Desktop: 3 columns grid

πŸ› Known Issues

  • Cart data is not persisted (resets on page refresh)
  • No backend integration
  • No payment processing
  • Limited to 3 products

πŸš€ Future Enhancements

  • LocalStorage persistence
  • Product images
  • Checkout flow
  • Order summary with totals
  • Product details modal
  • User reviews and ratings
  • Wishlist functionality
  • Backend API integration
  • Payment gateway
  • Order tracking

πŸ“ Usage Example

Using the Cart Context

import { useCart } from './context/CartContext';

function MyComponent() {
  const { cart, addToCart } = useCart();

  const handleAdd = () => {
    addToCart({
      id: 1,
      name: "Espresso",
      description: "Strong coffee",
      price: 149
    });
  };

  return (
    <div>
      <p>Cart items: {cart.length}</p>
      <button onClick={handleAdd}>Add Coffee</button>
    </div>
  );
}

πŸ”’ Error Handling

The app includes basic error boundaries:

  • Context usage validation (must be inside provider)
  • Empty cart state handling
  • Disabled buttons for invalid states

πŸŽ“ Learning Resources

This project demonstrates:

  • React Hooks (useState, useContext, useReducer pattern)
  • Context API for state management
  • React Router for navigation
  • Tailwind CSS utility classes
  • Component composition
  • Conditional rendering
  • Event handling

🀝 Contributing

Contributions welcome! To contribute:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit changes (git commit -m 'Add some AmazingFeature')
  4. Push to branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“„ License

This project is open source and available under the MIT License.

πŸ™ Acknowledgments

  • Built with React and Vite
  • Styled with Tailwind CSS
  • Icons and design inspired by modern e-commerce UIs

Happy Coding! β˜•

For questions or suggestions, please open an issue or submit a pull request.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published