Certainly! Enhancing the user interface (UI) and user experience (UX) can significantly improve the usability and aesthetic appeal of your "Recipe Transformer" application. Below, I've revamped your existing HTML, CSS, and JavaScript code to incorporate modern design principles, improved color schemes, better typography, responsive layouts, and enhanced interactivity.
Key Enhancements:
Modern Color Palette & Typography:
Utilized a more vibrant and cohesive color scheme for better visual appeal.
Improved typography with Google Fonts for enhanced readability.
Responsive Design:
Ensured the layout adjusts gracefully across various screen sizes, especially mobile devices.
Enhanced Form Design:
Added clear input feedback with focus states and validation messages.
Structured forms for better readability and user guidance.
Interactive Elements:
Incorporated smooth transitions and hover effects for buttons and interactive components.
Added animations to the result section for a more engaging experience.
Accessibility Improvements:
Ensured sufficient color contrast.
Used semantic HTML elements for better accessibility.
Optimized Layout:
Organized content with clear sections and spacing for easier navigation.
Enhanced Code:
html Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recipe Transformer</title>
<!-- jQuery CDN -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<!-- Marked.js CDN for Markdown Parsing -->
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Pacifico&display=swap" rel="stylesheet">
<style>
/* Reset & Base Styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Roboto', sans-serif;
line-height: 1.6;
padding: 20px;
background-color: #f0f4f8;
color: #333;
}
h1, h2 {
color: #2c3e50;
margin-bottom: 10px;
}
h1 {
font-family: 'Pacifico', cursive;
font-size: 2.5rem;
text-align: center;
margin-bottom: 30px;
}
/* Form Styles */
form {
background: #fff;
padding: 25px;
margin-bottom: 30px;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
transition: transform 0.3s ease;
}
form:hover {
transform: translateY(-5px);
}
label {
display: block;
margin-top: 15px;
font-weight: 500;
color: #34495e;
}
input[type="text"], textarea, select, input[type="number"] {
width: 100%;
padding: 12px;
margin-top: 8px;
border: 1px solid #bdc3c7;
border-radius: 6px;
font-size: 1rem;
transition: border-color 0.3s ease;
}
input[type="text"]:focus,
textarea:focus,
select:focus,
input[type="number"]:focus {
border-color: #3498db;
outline: none;
}
button {
background-color: #3498db;
color: white;
padding: 12px 20px;
border: none;
cursor: pointer;
margin-top: 20px;
border-radius: 6px;
font-size: 1rem;
transition: background-color 0.3s ease, transform 0.2s ease;
display: inline-block;
}
button:hover {
background-color: #2980b9;
}
button:active {
transform: scale(0.98);
}
/* Result Section Styles */
#result {
background-color: #fff;
border: 1px solid #dcdcdc;
padding: 30px;
margin-top: 30px;
border-radius: 10px;
box-shadow: 0 4px 15px rgba(0,0,0,0.1);
display: none;
animation: fadeIn 0.6s ease-out;
}
#result h3 {
color: #27ae60;
border-bottom: 3px solid #27ae60;
padding-bottom: 10px;
margin-bottom: 25px;
font-size: 1.8rem;
}
.section {
margin-bottom: 25px;
}
.section h4 {
color: #34495e;
margin-bottom: 12px;
border-left: 5px solid #3498db;
padding-left: 10px;
font-size: 1.3rem;
}
.section p, .section pre {
margin: 8px 0;
font-size: 1rem;
}
.highlight {
background-color: #ecf9f1;
padding: 12px;
border-left: 5px solid #27ae60;
margin-bottom: 20px;
border-radius: 6px;
}
/* Styling parsed Markdown content */
.markdown-content {
background-color: #fdfdfd;
padding: 20px;
border-radius: 6px;
border: 1px solid #e1e1e1;
max-height: 400px;
overflow-y: auto;
}
.markdown-content h5 {
color: #3498db;
margin-bottom: 12px;
}
.markdown-content ul,
.markdown-content ol {
margin-left: 20px;
margin-bottom: 10px;
}
.markdown-content a {
color: #3498db;
text-decoration: none;
}
.markdown-content a:hover {
text-decoration: underline;
}
/* Responsive */
@media (max-width: 768px) {
body {
padding: 15px;
}
h1 {
font-size: 2rem;
}
button {
width: 100%;
text-align: center;
}
#result {
padding: 20px;
}
}
@media (max-width: 480px) {
h1 {
font-size: 1.8rem;
}
.section h4 {
font-size: 1.1rem;
}
#result h3 {
font-size: 1.5rem;
}
}
/* Animations */
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
</style>
</head>
<body>
<h1>🍽️ Recipe Transformer</h1>
<!-- Add Recipe Form -->
<h2>Add New Recipe to Database</h2>
<form id="addRecipeForm" autocomplete="off">
<label for="add_recipe_name">Recipe Name:</label>
<input type="text" id="add_recipe_name" name="recipe_name" required placeholder="e.g., Spaghetti Bolognese">
<label for="add_recipe_text">Recipe Text:</label>
<textarea id="add_recipe_text" name="recipe_text" rows="5" required placeholder="Enter the full recipe instructions here..."></textarea>
<button type="submit">Add Recipe</button>
</form>
<!-- Transform Recipe Form -->
<h2>Transform Recipe</h2>
<form id="transformRecipeForm" autocomplete="off">
<label for="transform_recipe_name">Recipe Name:</label>
<input type="text" id="transform_recipe_name" name="recipe_name" required placeholder="e.g., Spaghetti Bolognese">
<label for="transform_recipe_text">Recipe Text:</label>
<textarea id="transform_recipe_text" name="recipe_text" rows="5" required placeholder="Paste the recipe instructions here..."></textarea>
<label for="diet">Diet Type:</label>
<select id="diet" name="diet" required>
<option value="" disabled selected>Select a diet type</option>
<option value="vegan">Vegan</option>
<option value="keto">Keto</option>
<option value="gluten-free">Gluten-Free</option>
<option value="jain">Jain</option>
<option value="vegetarian">Vegetarian</option>
<option value="non-vegetarian">Non Vegetarian</option>
</select>
<label for="allergy">Allergy Information:</label>
<input type="text" id="allergy" name="Allergy" required placeholder="e.g., nuts, dairy">
<label for="place">Place:</label>
<input type="text" id="place" name="Place" required placeholder="e.g., Mumbai">
<label for="calories">Desired Calories:</label>
<input type="number" id="calories" name="Calories" required min="0" placeholder="e.g., 300">
<button type="submit">Transform Recipe</button>
</form>
<!-- Result Section -->
<div id="result">
<h3>✅ Transformed Recipe</h3>
<div class="section">
<h4>📋 Recipe Details</h4>
<p><strong>Recipe Name:</strong> <span id="display_recipe_name">N/A</span></p>
<p><strong>Diet:</strong> <span id="display_diet">N/A</span></p>
<p><strong>Place:</strong> <span id="display_place">N/A</span></p>
<p><strong>Allergy:</strong> <span id="display_allergy">N/A</span></p>
<p><strong>Desired Calories:</strong> <span id="display_calories">N/A</span> kcal</p>
</div>
<div class="section">
<h4>📜 Original Recipe</h4>
<div id="display_original_recipe" class="markdown-content"></div>
</div>
<div class="section">
<h4>🔄 Transformed Recipe</h4>
<div id="display_transformed_recipe" class="markdown-content"></div>
</div>
<div class="section">
<h4>💰 Costs Information</h4>
<div id="display_costs_info" class="markdown-content"></div>
</div>
<div class="section">
<h4>🍎 Nutritional Information</h4>
<div id="display_nutrition_info" class="markdown-content"></div>
</div>
<div class="section">
<h4>🔥 Calories Information</h4>
<div id="display_calories_info" class="markdown-content"></div>
</div>
</div>
<script>
$(document).ready(function() {
// Add recipe form submission
$('#addRecipeForm').submit(function(e) {
e.preventDefault();
const formData = $(this).serialize();
$.ajax({
type: 'POST',
url: '/add_recipe',
data: formData,
success: function(response) {
alert('🎉 Recipe added successfully to the database!');
$('#addRecipeForm')[0].reset();
},
error: function(xhr) {
if(xhr.responseJSON && xhr.responseJSON.error){
alert('❌ Error: ' + xhr.responseJSON.error);
} else {
alert('❌ An unknown error occurred while adding the recipe.');
}
}
});
});
// Transform recipe form submission
$('#transformRecipeForm').submit(function(e) {
e.preventDefault();
const formData = $(this).serialize();
$.ajax({
type: 'POST',
url: '/transform_recipe',
data: formData,
success: function(response) {
if(response.error){
alert('❌ Error: ' + response.error);
return;
}
// Populate Recipe Details
$('#display_recipe_name').text(response.recipe_name || 'N/A');
$('#display_diet').text(response.diet ? capitalizeFirstLetter(response.diet) : 'N/A');
$('#display_place').text(response.place || 'N/A');
$('#display_allergy').text(response.allergy || 'N/A');
$('#display_calories').text(response.calories || 'N/A');
// Populate Original Recipe
$('#display_original_recipe').html(marked.parse(response.original_recipe || 'No original recipe provided.'));
// Populate Transformed Recipe
$('#display_transformed_recipe').html(marked.parse(response.transformed_recipe || 'No transformed recipe available.'));
// Populate Costs Information
$('#display_costs_info').html(marked.parse(response.costs_info || 'No costs information available.'));
// Populate Nutritional Information
$('#display_nutrition_info').html(marked.parse(response.nutrition_info || 'No nutritional information available.'));
// Populate Calories Information
$('#display_calories_info').html(marked.parse(response.calories_info || 'No calories information available.'));
// Show the result section
$('#result').fadeIn();
// Scroll to the result
$('html, body').animate({
scrollTop: $("#result").offset().top
}, 800);
},
error: function(xhr) {
if(xhr.responseJSON && xhr.responseJSON.error){
alert('❌ Error: ' + xhr.responseJSON.error);
} else {
alert('❌ An unknown error occurred while transforming the recipe.');
}
}
});
});
// Helper function to capitalize first letter
function capitalizeFirstLetter(string) {
if(!string) return '';
return string.charAt(0).toUpperCase() + string.slice(1);
}
});
</script>
</body>
</html>
Detailed Breakdown of Enhancements:
Typography with Google Fonts:
Included Google Fonts (Roboto for body text and Pacifico for the main header) to enhance readability and aesthetic appeal.
html Copy code
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&family=Pacifico&display=swap" rel="stylesheet">
Enhanced Color Palette:
Adopted a modern color scheme with shades of blue (#3498db, #2980b9) for primary actions and green (#27ae60) for success messages and highlights.
Neutral background color (#f0f4f8) to reduce eye strain.
Improved Form Design:
Increased padding and added subtle shadows for better form visibility.
Enhanced input fields with focus states to guide user interaction.
Updated placeholders to provide clear examples, improving UX.
Interactive Buttons:
Added hover and active states with smooth transitions to make interactions more intuitive.
Increased button padding for easier clicking, especially on mobile devices.
Result Section Animation:
Implemented a fade-in animation using CSS keyframes for a smooth appearance of the result section.
css Copy code
@keyframes fadeIn {
from { opacity: 0; transform: translateY(20px); }
to { opacity: 1; transform: translateY(0); }
}
Responsive Design:
Utilized media queries to adjust font sizes and padding on smaller screens, ensuring the application remains user-friendly on all devices.
Ensured buttons and forms adapt to various screen widths without breaking the layout.
Accessibility Improvements:
Maintained high contrast between text and background for readability.
Ensured form elements are properly labeled for screen readers.
Used semantic HTML elements (<label>, <h1>, <h2>, etc.) to enhance navigability.
Final Thoughts
These enhancements aim to create a more engaging, intuitive, and visually appealing user interface for your Recipe Transformer application. The improved design not only looks modern but also prioritizes user experience by making interactions seamless and enjoyable. Feel free to further customize the color scheme, fonts, or other styles to match your brand or personal preferences.
If you have any specific features or additional enhancements in mind, feel free to let me know!