web-based canvas editor built with React, Fabric.js, and Firebase Firestore. Create beautiful designs with shapes, text, and free drawing tools that automatically save to the cloud
The application is built with React, Fabric.js, and Firebase.
-
Create New Canvases - Start fresh with a blank canvas
-
Shape Tools - Add rectangles, circles, and text objects
-
Pen Tool - Freehand drawing with customizable colors and widths
-
Object Manipulation - Move, resize, rotate, and delete objects
-
Real-time Properties - Edit colors, stroke width, opacity, and more
-
Auto-save - Automatic cloud saving with manual override
-
Saved Canvases Gallery - View and manage all your created canvases
-
Frontend: React 18, Fabric.js
-
Backend: Firebase Firestore
-
Styling: CSS
-
Routing: React Router DOM
-
Deployment:Firebase Hosting
src/ ├── components/ │ ├── home/HomePage.jsx # Landing page with canvas gallery │ └── canvas/ │ ├── CanvasEditor.jsx # Main editor interface │ ├── Toolbar.jsx # Drawing tools panel │ └── PropertiesPanel.jsx # Object properties editor ├── hooks/ │ ├── useCanvas.js # Fabric.js canvas management │ └── useFirestore.js # Firebase data operations ├── services/ │ └── firebase.js # Firebase configuration ├── App.jsx # Main app with routing ├── main.jsx # React entry point └── styles.css # All application styling
<Router>
<Route path="/" element={<HomePage />} />
<Route path="/canvas/:canvasId" element={<CanvasEditor />} />
</Router>
puropse:Handles navigation between Home page and Canvas Editor
- **What it does:
- Displays welcome screen with "Create New Canvas" button
- Shows gallery of all saved canvases
- Handles canvas creation and deletion
- Navigates to editor when canvas is clicked
- Creates new canvas with unique ID using UUID
- Fetches all canvases from Firebase Firestore
- Displays canvas previews with delete functionality
- Responsive grid layout for canvas cards
- What it does:
- Main workspace for creating and editing designs
- Manages canvas state and auto-saving
- Coordinates between Toolbar and PropertiesPanel
- Handles URL parameters for canvas ID
- Auto-save functionality with toggle
- Manual save button
- Real-time status updates
- Error handling and loading states
- What it does:
- Provides access to all drawing tools
- Shows currently active tool
- Handles tool selection and activation
- 🖱️ Select Tool - Select and manipulate objects
- ⬜ Rectangle - Add rectangular shapes
- ⭕ Circle - Add circular shapes
- 📝 Text - Add editable text objects
- ✏️ Pen - Freehand drawing tool
- What it does:
- Displays properties of selected objects
- Allows real-time editing of object attributes
- Shows different controls based on object type
- Fill color
- Stroke color and width
- Font size (for text)
- Opacity
- Object dimensions and position
- useCanvas.js - Canvas Management
- Responsibilities:
- Initialize and manage Fabric.js canvas
- Handle all drawing operations
- Manage object selection and manipulation
- Provide drawing tools functionality
javascript
// Canvas initialization
const fabricCanvas = new fabric.Canvas(canvasRef.current, {
width: 800,
height: 600,
backgroundColor: '#ffffff'
});
// Tool functions
addRectangle() // Add rectangle shape
addCircle() // Add circle shape
addText() // Add text object
enableFreeDrawing() // Activate pen tool
deleteSelected() // Remove selected objects
// Property editing
changeColor() // Change object fill color
changeStrokeColor() // Change border color
bringToFront() // Layer management
sendToBack() // Layer management
- useFirestore.js - Data Persistence Responsibilities:
Save canvas data to Firebase Firestore
Load canvas data from Firestore
Handle real-time updates
Manage loading and error states
Key Functions:
saveCanvas(data) // Save canvas to cloud
loadCanvas() // Load canvas from cloud
- How Drawing Works:
- Canvas Initialization: Fabric.js creates a HTML5 canvas with enhanced features
- Object Creation: Each shape/text is a Fabric.js object with properties
- Event Handling: Fabric.js handles mouse events for drawing and manipulation
- Serialization: Canvas state converted to JSON for saving
- Move: Click and drag objects
- Resize: Drag corner handles
- Rotate: Drag rotation handle
- Edit: Double-click text to edit content
Auto-Save Process:
text
User Action → Canvas Change → Fabric.js Event → useCanvas → useFirestore → Firebase
↓ ↓ ↓ ↓ ↓ ↓
Draw shape Object added object:added exportJSON() saveCanvas() Cloud save
Live demo link:https://drive.google.com/file/d/1BEWlpHO5wtADfxfywPwE0X5CVRPKdmJf/view?usp=sharing