Certainly! Below is a single HTML file that sets up the main flow of your web application using Tailwind CSS via CDN. This example includes:
- Intro Screen: A welcome message with instructions.
- Drag-and-Drop Design Phase: Users can drag and drop predefined components onto a canvas.
- Flow Analysis and Optimization: A placeholder for the analysis algorithm (simulated with a button).
- Final Presentation: Displays the optimized design ready for publishing or saving.
For drag-and-drop functionality, we'll use the SortableJS library via CDN. This library is lightweight and easy to integrate.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Portfolio Design App</title>
<!-- Tailwind CSS CDN -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- SortableJS CDN for drag-and-drop -->
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.15.0/Sortable.min.js"></script>
</head>
<body class="bg-gray-100 min-h-screen flex items-center justify-center">
<div class="w-full max-w-4xl bg-white shadow-lg rounded-lg overflow-hidden">
<!-- Intro Screen -->
<div id="intro-screen" class="p-6">
<h1 class="text-3xl font-bold mb-4">Welcome to Portfolio Designer</h1>
<p class="mb-6">Drag and drop components to design your portfolio. We'll help you optimize your layout for the best presentation.</p>
<button id="start-btn" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">Get Started</button>
</div>
<!-- Drag-and-Drop Design Phase -->
<div id="design-screen" class="p-6 hidden">
<h2 class="text-2xl font-semibold mb-4">Design Your Portfolio</h2>
<div class="flex">
<!-- Components Palette -->
<div class="w-1/4 mr-4">
<h3 class="text-xl font-medium mb-2">Components</h3>
<div class="space-y-2">
<div class="p-2 bg-gray-200 rounded draggable" draggable="true">Header</div>
<div class="p-2 bg-gray-200 rounded draggable" draggable="true">Image Gallery</div>
<div class="p-2 bg-gray-200 rounded draggable" draggable="true">About Me</div>
<div class="p-2 bg-gray-200 rounded draggable" draggable="true">Contact Form</div>
</div>
</div>
<!-- Design Canvas -->
<div class="w-3/4">
<h3 class="text-xl font-medium mb-2">Canvas</h3>
<div id="design-canvas" class="min-h-64 p-4 bg-gray-100 border-2 border-dashed border-gray-300 rounded">
<p class="text-gray-500">Drag components here to build your portfolio.</p>
</div>
</div>
</div>
<div class="mt-6 flex justify-end">
<button id="analyze-btn" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">Analyze & Optimize</button>
</div>
</div>
<!-- Flow Analysis and Optimization -->
<div id="analysis-screen" class="p-6 hidden">
<h2 class="text-2xl font-semibold mb-4">Analyzing Your Layout</h2>
<p class="mb-6">Our algorithm is evaluating your design...</p>
<div class="flex justify-center">
<div class="loader ease-linear rounded-full border-8 border-t-8 border-gray-200 h-32 w-32"></div>
</div>
<div class="mt-6 text-center hidden" id="optimization-result">
<p class="mb-4 text-lg">Optimization Complete! Your portfolio layout has been improved.</p>
<button id="finalize-btn" class="px-4 py-2 bg-purple-600 text-white rounded hover:bg-purple-700">View Final Design</button>
</div>
</div>
<!-- Final Presentation -->
<div id="final-screen" class="p-6 hidden">
<h2 class="text-2xl font-semibold mb-4">Your Optimized Portfolio</h2>
<div id="final-design" class="min-h-64 p-4 bg-gray-100 border-2 border-dashed border-gray-300 rounded">
<!-- Optimized design will be displayed here -->
</div>
<div class="mt-6 flex justify-end space-x-4">
<button id="save-btn" class="px-4 py-2 bg-blue-600 text-white rounded hover:bg-blue-700">Save Portfolio</button>
<button id="publish-btn" class="px-4 py-2 bg-green-600 text-white rounded hover:bg-green-700">Publish</button>
</div>
</div>
</div>
<!-- Loader Style -->
<style>
.loader {
border-top-color: #3498db;
animation: spin 1s infinite linear;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
<!-- JavaScript to Handle Flow and Drag-and-Drop -->
<script>
document.addEventListener('DOMContentLoaded', () => {
const introScreen = document.getElementById('intro-screen');
const designScreen = document.getElementById('design-screen');
const analysisScreen = document.getElementById('analysis-screen');
const finalScreen = document.getElementById('final-screen');
const startBtn = document.getElementById('start-btn');
const analyzeBtn = document.getElementById('analyze-btn');
const finalizeBtn = document.getElementById('finalize-btn');
const saveBtn = document.getElementById('save-btn');
const publishBtn = document.getElementById('publish-btn');
const optimizationResult = document.getElementById('optimization-result');
const finalDesign = document.getElementById('final-design');
// Show Design Screen
startBtn.addEventListener('click', () => {
introScreen.classList.add('hidden');
designScreen.classList.remove('hidden');
});
// Initialize Sortable for Design Canvas
const sortable = new Sortable(document.getElementById('design-canvas'), {
group: 'components',
animation: 150,
onAdd: (evt) => {
const item = evt.item;
item.classList.remove('bg-gray-200');
item.classList.add('bg-white', 'shadow', 'mb-2');
// Add a remove button to each component
const removeBtn = document.createElement('button');
removeBtn.textContent = '×';
removeBtn.className = 'float-right text-red-500';
removeBtn.onclick = () => item.remove();
item.appendChild(removeBtn);
}
});
// Also make components draggable
const draggables = document.querySelectorAll('.draggable');
draggables.forEach(elem => {
elem.addEventListener('dragstart', (e) => {
e.dataTransfer.setData('text/plain', elem.textContent);
});
});
// Analyze and Optimize Layout
analyzeBtn.addEventListener('click', () => {
designScreen.classList.add('hidden');
analysisScreen.classList.remove('hidden');
// Simulate analysis with a timeout
setTimeout(() => {
optimizationResult.classList.remove('hidden');
}, 2000);
});
// Finalize and Show Optimized Design
finalizeBtn.addEventListener('click', () => {
analysisScreen.classList.add('hidden');
finalScreen.classList.remove('hidden');
// For demonstration, clone the design canvas content
const canvasContent = document.getElementById('design-canvas').innerHTML;
finalDesign.innerHTML = canvasContent;
});
// Save Portfolio (Placeholder)
saveBtn.addEventListener('click', () => {
alert('Portfolio saved successfully!');
});
// Publish Portfolio (Placeholder)
publishBtn.addEventListener('click', () => {
alert('Portfolio published successfully!');
});
});
</script>
</body>
</html>
Explanation of the Code:
-
Structure:
- The main container is centered and has a maximum width for better readability.
- Four main sections (
div elements) represent each step of the flow:
intro-screen
design-screen
analysis-screen
final-screen
- Only one section is visible at a time, controlled by toggling the
hidden class.
-
Intro Screen:
- Provides a welcome message and a "Get Started" button.
- Clicking the button hides the intro screen and displays the design screen.
-
Design Screen:
- Divided into two parts:
- Components Palette: A list of draggable components (e.g., Header, Image Gallery).
- Design Canvas: A droppable area where users can arrange their portfolio components.
- Utilizes SortableJS to handle drag-and-drop functionality.
- Each component dropped into the canvas gets a remove button for easy deletion.
- An "Analyze & Optimize" button progresses the flow to the analysis screen.
-
Flow Analysis and Optimization:
- Displays a loading spinner to simulate processing.
- After a delay (2 seconds in this case), it shows the optimization result with a button to view the final design.
-
Final Presentation:
- Shows the optimized portfolio layout.
- Provides "Save" and "Publish" buttons (currently placeholders that trigger alert messages).
-
Styling:
- Tailwind CSS classes are used extensively for styling, ensuring a responsive and modern UI.
- A simple CSS loader is defined for the analysis spinner.
-
JavaScript Functionality:
- Handles navigation between different screens by adding/removing the
hidden class.
- Initializes the drag-and-drop functionality using SortableJS.
- Adds functionality to remove components from the canvas.
- Simulates the analysis phase with a timeout and displays the optimization result.
Notes:
-
Advanced Features: For a production-grade application, you would need to implement actual algorithms for flow analysis and optimization, persistent storage (e.g., saving designs to a database), authentication, and more robust state management.
-
Accessibility: Ensure that the application is accessible by adding appropriate ARIA labels and keyboard navigation support.
-
Enhanced Drag-and-Drop: Depending on requirements, you might consider more sophisticated drag-and-drop libraries or building custom functionality to allow resizing and more interactions with the components.
This template provides a solid foundation for your web application, showcasing the main flow with clean UI and interactive elements. You can expand upon this by integrating backend services, refining the optimization algorithms, and adding more customization options for the portfolio components.