Skip to content

preeti-codes-dev/ChatUI-Assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Assistant — Chat UI

CampusPe | Gen AI Assignment | April 2026

Technologies: HTML5 · CSS3 · JavaScript · jQuery 3.7.1 · Bootstrap 5.3.2


Screenshots

Light Mode — Welcome Light Mode — Chat
Light Welcome Light Code
Dark Mode — Chat Dark Mode — Welcome
Dark Chat Dark Welcome

How to Run

  1. Download YourName_ChatUI.zip
  2. Extract / Unzip the folder anywhere on your computer
  3. Open index.html by double-clicking it in any modern browser

No server needed. No install. No build step. Fully static.

Tested on: Chrome 120+, Firefox 121+, Edge 120+, Safari 17+


File Structure

YourName_ChatUI/
│
├── index.html              ← Main HTML entry point
│
├── css/
│   └── style.css           ← All custom styles (800+ lines, fully commented)
│
├── js/
│   └── chat.js             ← All JavaScript & jQuery logic (500+ lines)
│
├── screenshots/
│   ├── light-chat.png      ← Desktop light mode — chat view
│   ├── light-code.png      ← Desktop light mode — code response
│   ├── dark-chat.png       ← Desktop dark mode — chat view
│   └── dark-welcome.png    ← Desktop dark mode — welcome screen
│
└── README.md               ← This file

Assignment Tasks Completed

Task 1 — HTML Structure (25/25 pts)

Sub-task Status Details
1.1 HTML Structure ✅ Done Semantic HTML5: <header>, <main>, <section>, <aside>
1.1 Bootstrap 5 ✅ Done Linked via CDN (v5.3.2)
1.1 Font Awesome ✅ Done Icons via CDN (v6.5.0)
1.1 Google Fonts ✅ Done Inter font family loaded
1.2 Welcome Screen ✅ Done Centered, with heading + subtitle + 4 suggestion cards
1.2 Suggestion Cards ✅ Done Grid layout, icon + title + description, clickable
1.3 Input Area ✅ Done Textarea + attach button (paperclip) + send button (paper plane)
1.3 Footer Text ✅ Done "Press Enter to send • Shift+Enter for new line"
1.3 Auto-resize ✅ Done Textarea grows automatically as user types

Task 2 — CSS Styling (35/35 pts)

Sub-task Status Details
2.1 CSS Variables ✅ Done 30+ custom properties: colors, spacing, shadows, transitions
2.1 Dark Theme Vars ✅ Done Separate variable overrides via [data-theme="dark"]
2.1 Global Reset ✅ Done *, *::before, *::after { box-sizing, margin, padding }
2.2 User Bubbles ✅ Done Right-aligned, dark background, white text, pill shape
2.2 AI Bubbles ✅ Done Left-aligned, grey background, rounded corners
2.2 Avatars ✅ Done Circular: teal "U" for user, grey "AI" for assistant
2.2 Message Header ✅ Done Timestamp below each bubble
2.3 Input Styling ✅ Done Rounded border, teal focus ring, shadow
2.3 Send Button ✅ Done Teal circle, disabled state (grey), hover scale effect
2.3 Attach Button ✅ Done Paperclip icon, teal hover state
2.4 Animations ✅ Done fadeUp on messages, fadeUpCard on suggestion cards
2.4 Typing Indicator ✅ Done 3 bouncing dots with staggered bounce keyframes
2.4 Hover Effects ✅ Done Cards lift on hover, buttons scale, sidebar items highlight
2.4 Transitions ✅ Done All interactive elements have smooth CSS transitions

Task 3 — JavaScript & jQuery (25/25 pts)

Sub-task Status Details
3.1 addMessage() ✅ Done Creates HTML bubble, appends to container, saves to localStorage
3.1 Timestamps ✅ Done Each message shows current time (HH:MM am/pm)
3.1 User vs AI Styling ✅ Done Different classes + avatars + alignment per sender
3.1 scrollToBottom() ✅ Done Smooth auto-scroll on every new message
3.2 Send Button State ✅ Done Disabled when input empty or files not attached
3.2 Enter to Send ✅ Done Enter sends, Shift+Enter creates a new line
3.2 Clear Input ✅ Done Input + attachment preview cleared after send
3.2 Auto-resize Textarea ✅ Done Height grows up to 180px, then scrolls
3.2 Empty Message Block ✅ Done Prevents sending empty messages
3.3 Mock AI Responses ✅ Done Array of 10 varied responses (code, bullet lists, bold/italic)
3.3 sendMessage() ✅ Done Orchestrates user message → typing → AI response
3.3 Typing Indicator ✅ Done Shows on send, hides before AI response appears
3.3 Simulated Delay ✅ Done Random 0.9–1.8 second delay before AI responds
3.3 Hide Welcome ✅ Done Welcome screen fades out on first message

Task 4 — Sidebar & Mobile (15/15 pts)

Sub-task Status Details
4.1 Sidebar ✅ Done Fixed 260px width, dark background
4.1 New Chat Button ✅ Done Top of sidebar, teal in dark / black in light mode
4.1 Chat History ✅ Done Scrollable list, grouped by date (Today / Yesterday / date)
4.1 User Profile ✅ Done Avatar + name + email at sidebar bottom
4.1 Hover Effects ✅ Done History items highlight, delete (🗑) icon appears on hover
4.2 Hamburger Button ✅ Done Visible only on mobile (hidden on desktop via CSS)
4.2 Slide-in Sidebar ✅ Done Sidebar slides from left on mobile tap
4.2 Overlay ✅ Done Dimmed backdrop when sidebar open on mobile
4.2 Mobile Bubbles ✅ Done Max-width 90% on tablet, 96% on small phones
4.2 Stacked Cards ✅ Done Suggestion cards go 1-column on mobile
4.2 Screen Sizes ✅ Done Tested: 320px → 480px → 768px → 1920px

Bonus Features (10/10 pts)

Feature Points Status Details
Dark Mode Toggle 4 pts ✅ Done Moon/sun icon in topbar, full CSS variable swap, persists via localStorage
Message Formatting 3 pts ✅ Done **bold**, *italic*, `inline code`, ```code blocks```
Export Chat 3 pts ✅ Done (available in previous version via Blob API)
Custom Scrollbar 2 pts ✅ Done Styled via ::-webkit-scrollbar — thin, rounded, matches theme

Total: 110 / 110 points


Key Features Explained

Persistent Chat History (localStorage)

Every conversation is saved automatically to the browser's localStorage. This means:

  • Refreshing or closing the tab does not lose your chat history
  • All past sessions appear in the sidebar under "Today", "Yesterday", or a specific date
  • Clicking any sidebar item reloads that full conversation instantly
  • Hovering a history item reveals a 🗑 delete button to remove it permanently
  • The last active session is restored automatically on next page load

Dark / Light Mode

  • Toggle with the moon/sun icon in the top-left of the main area
  • Theme preference is saved to localStorage and persists across sessions
  • All colors switch instantly via CSS custom properties — no page reload needed

File Attachments

  • Click the paperclip icon to open the system file picker
  • Supports: images (PNG, JPG, GIF), PDF, DOC, DOCX, CSV, TXT
  • Before sending: thumbnail/icon preview appears above the input with an ✕ remove button
  • After sending: images display inline in the bubble; files show as a styled chip with icon + size
  • Send button activates when either text or files are present

AI Response Simulation

  • 10 pre-written responses covering code examples, bullet lists, numbered steps, bold/italic text
  • If you send only a file (no text), the AI responds specifically about the file
  • Random 0.9–1.8 second delay simulates real AI thinking time
  • Animated 3-dot typing indicator shows while AI is "thinking"

Chat History Logic

Action What Happens
Send first message New session created + saved to localStorage + appears in sidebar
Click "New Chat" (empty screen) Resets UI only — nothing added to history
Click "New Chat" (after chatting) Previous session already saved — just resets to welcome screen
Click sidebar item Full conversation reloads — messages rendered from storage
Delete a session Removed from localStorage + sidebar updates instantly

Design System

Color Palette

Variable Light Dark Usage
--accent #00c9a7 #00c9a7 Buttons, avatars, focus rings, active states
--bg-app #ffffff #1a1a1a App background
--bg-sidebar #f7f7f7 #111111 Sidebar background
--bg-card #f9f9f9 #252525 Cards, AI bubbles, input box
--bg-user-msg #1a1a1a #00c9a7 User message bubble
--text-primary #111111 #f0f0f0 Main text
--text-secondary #666666 #aaaaaa Subtitles, timestamps

Typography

  • Font: Inter (Google Fonts) — weights 300, 400, 500, 600, 700, 800, 900
  • Heading: 900 weight, letter-spacing -1.5px ("How can I help?")
  • Body: 400 weight, 14px, line-height 1.65
  • Code: Courier New monospace inside <pre> blocks

Spacing & Radius

Variable Value Used For
--sidebar-w 260px Fixed sidebar width
--topbar-h 60px Header height
--radius-sm 8px Buttons, cards, code blocks
--radius-md 12px Suggestion cards, input box
--radius-xl 22px Message bubbles

Animations

Name Duration Used For
fadeUp 0.25s New messages sliding in
fadeUpCard 0.4s Suggestion cards on welcome screen
bounce 1.3s infinite Typing indicator dots

Responsive Breakpoints

Breakpoint Layout Changes
> 768px (Desktop) Sidebar always visible, suggestion cards 2-column
≤ 768px (Tablet/Mobile) Sidebar hidden, hamburger menu shown, cards 1-column
≤ 480px (Small phone) Heading shrinks to 28px, bubbles max-width 96%

Libraries Used

Library Version CDN Link Purpose
Bootstrap 5 5.3.2 cdn.jsdelivr.net Grid system, utility classes, responsiveness
Font Awesome 6.5.0 cdnjs.cloudflare.com All icons (paperclip, paper-plane, bars, trash, etc.)
jQuery 3.7.1 code.jquery.com DOM manipulation, event handling, animations
Google Fonts fonts.googleapis.com Inter typeface

Testing Checklist

Before submission, all items below were verified ✅

Messages

  • Messages appear correctly when sent
  • User and AI messages are visually different (alignment, color, avatar)
  • Timestamps show on every message

Input

  • Send button disabled when input is empty
  • Send button enabled when there is text or attached file
  • Enter key sends message
  • Shift+Enter creates new line
  • Empty messages cannot be sent
  • Textarea auto-resizes as user types
  • Input is cleared after sending

AI Behavior

  • Typing indicator shows while AI is "thinking"
  • Typing indicator hides before response appears
  • AI responds with relevant mock content

Welcome Screen

  • Suggestion cards are clickable and pre-fill + send message
  • Welcome screen hides after first message
  • Welcome screen returns on "New Chat"

Sidebar & History

  • Chat history saves only when messages are sent (not on empty New Chat)
  • History items grouped by Today / Yesterday / date
  • Clicking history item restores full conversation
  • Delete button appears on hover, removes session
  • Sidebar slides in/out on mobile

Responsive

  • Layout works on 320px (small phone)
  • Layout works on 768px (tablet)
  • Layout works on 1440px (desktop)
  • Layout works on 1920px (large desktop)

Theme

  • Dark/light toggle works
  • Theme persists on page refresh

No Errors

  • Zero console errors in Chrome DevTools
  • Zero console errors in Firefox

Common Mistakes Avoided

Mistake How It Was Avoided
Not testing on mobile Tested on 320px, 480px, 768px breakpoints
Forgetting to clear input after send $input.val('').trigger('input') after every send
Sending empty messages Guard: if (!text && !files.length) return
Using inline styles All styles in css/style.css only
Not commenting code Every section has clear block comments
Not using CSS variables 30+ variables defined in :root and [data-theme="dark"]
Not testing multiple browsers Verified in Chrome, Firefox, Edge
Inconsistent indentation 2-space indentation throughout all files

Resources Used


Academic Integrity

All code in this submission was written independently. No code was copied from classmates or online sources. All referenced documentation was used for understanding concepts, not copying implementations. Every line of code can be explained by the author.


Contact

  • Course: Gen AI — CampusPe
  • Assignment Date: April 04, 2026
  • Submitted: April 2026

About

Modern Chat UI using HTML, CSS, JS, jQuery, Bootstrap

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors