Considering the Objective
I've got the core objective in mind: a Bootstrap admin panel with interactive charts and modals. Focusing on the technical requirements, I'm now thinking about the specific Bootstrap components that will best support these features and exploring how to effectively integrate charting libraries. The user's requirements for responsiveness are top-of-mind.
Refining the Structure
I'm now fully immersed in the technical design, and focusing on the HTML structure. I'm visualizing the admin panel elements and their hierarchy. Specifically, I'm fleshing out how the sidebar, main content area, and navbar will be structured within the wrapper container, considering responsiveness from the get-go. I'm prioritizing clarity in the HTML and planning the CSS styling for sidebar toggling. Javascript will be mainly used for interactivity like sidebar toggle and charts. The first step involves setting up the and including the necessary Bootstrap CSS.
Detailing the Dependencies
I'm presently building out the structural HTML for the admin panel, and the architecture is quickly coming together. I have listed all the necessary CDNs and stylesheets I'll need and added the HTML structure. My focus right now is on the initial layout, including the sidebar and main content area and I'm planning to use a d-flex container to achieve responsiveness. The next step is fleshing out the structure for the navbar and dashboard widgets.
Building the Interactions
I'm now integrating the modal functionality, a key requirement. I'm focusing on the Bootstrap modal structure, header, body, and footer, and planning the "View Details" and "Add User" triggers. I'm also considering the CSS details for the overall "admin" look. Fixed sidebar width, main content expansion, and transition effects are now on my radar, along with media queries for responsiveness. The JavaScript for the sidebar toggle is next on my list.
Implementing the Final Touches
I'm now implementing the specific CSS for visual accents, using primary, success, and warning colors to create visual hierarchy. The HTML, CSS, and JavaScript are being assembled and I am adding chart data and click event listeners to the JavaScript. I'm focusing on organizing the code into a single, cohesive HTML file. I will then add comments explaining how to use it, and what dependencies are included, and will review against all of the requirements.
Focusing on Code Clarity
I'm now honing in on the final code output and want to deliver a concise solution. I'm prioritizing vanilla Bootstrap 5 classes, aiming to avoid excessive or cumbersome template code to ensure the final product is clean and easy to understand. I'm focusing on simplicity and maintainability as key goals. The HTML, CSS, and JS are being assembled and I'm adding the code to the file. I have organized the dependencies in comments.
Here is a complete, single-file solution using Bootstrap 5.3 for layout and components, and Chart.js for interactive charts.
This code includes:
- Responsive Sidebar: Collapses on mobile, toggles on desktop.
- Dashboard Cards: High-level statistics.
- Interactive Charts: A Bar chart and a Doughnut chart.
- Data Table: With action buttons.
- Modal: A function popup form.
Complete Code (index.html)
You can save this code as an .html file and open it in any browser. No local server is required.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Modern Admin Dashboard</title>
<!-- Bootstrap 5 CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/css/bootstrap.min.css" rel="stylesheet">
<!-- FontAwesome for Icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<style>
:root {
--main-bg-color: #0d6efd;
--main-text-color: #0d6efd;
--second-text-color: #b1b1b1;
--second-bg-color: #c1efde;
}
body {
background-color: #f5f7ff;
overflow-x: hidden;
}
/* Sidebar Styles */
#wrapper {
display: flex;
}
#sidebar-wrapper {
min-height: 100vh;
margin-left: -15rem;
transition: margin 0.25s ease-out;
}
#sidebar-wrapper .sidebar-heading {
padding: 0.875rem 1.25rem;
font-size: 1.2rem;
}
#sidebar-wrapper .list-group {
width: 15rem;
}
#page-content-wrapper {
min-width: 100vw;
height: 100vh;
overflow-y: scroll;
overflow-x: hidden;
}
#wrapper.toggled #sidebar-wrapper {
margin-left: 0;
}
.list-group-item {
border: none;
padding: 20px 30px;
}
.list-group-item.active {
background-color: transparent;
color: var(--main-text-color);
font-weight: bold;
border: none;
}
/* Desktop View */
@media (min-width: 768px) {
#sidebar-wrapper {
margin-left: 0;
}
#page-content-wrapper {
min-width: 0;
width: 100%;
}
#wrapper.toggled #sidebar-wrapper {
margin-left: -15rem;
}
}
/* Card Hover Effect */
.p-3.bg-white.shadow-sm {
transition: transform 0.3s;
}
.p-3.bg-white.shadow-sm:hover {
transform: translateY(-5px);
}
</style>
</head>
<body>
<div class="d-flex" id="wrapper">
<!-- Sidebar -->
<div class="bg-white" id="sidebar-wrapper">
<div class="sidebar-heading text-center py-4 primary-text fs-4 fw-bold text-uppercase border-bottom">
<i class="fas fa-user-secret me-2"></i>AdminPanel
</div>
<div class="list-group list-group-flush my-3">
<a href="#" class="list-group-item list-group-item-action bg-transparent second-text active">
<i class="fas fa-tachometer-alt me-2"></i>Dashboard
</a>
<a href="#" class="list-group-item list-group-item-action bg-transparent second-text fw-bold">
<i class="fas fa-project-diagram me-2"></i>Projects
</a>
<a href="#" class="list-group-item list-group-item-action bg-transparent second-text fw-bold">
<i class="fas fa-chart-line me-2"></i>Analytics
</a>
<a href="#" class="list-group-item list-group-item-action bg-transparent second-text fw-bold">
<i class="fas fa-paperclip me-2"></i>Reports
</a>
<a href="#" class="list-group-item list-group-item-action bg-transparent second-text fw-bold">
<i class="fas fa-shopping-cart me-2"></i>Products
</a> <!-- View Details Trigger -->
<a href="#" class="list-group-item list-group-item-action bg-transparent text-danger fw-bold">
<i class="fas fa-power-off me-2"></i>Logout
</a>
</div>
</div>
<!-- /#sidebar-wrapper -->
<!-- Page Content -->
<div id="page-content-wrapper">
<!-- Top Navbar -->
<nav class="navbar navbar-expand-lg navbar-light bg-transparent py-4 px-4">
<div class="d-flex align-items-center">
<i class="fas fa-align-left primary-text fs-4 me-3" id="menu-toggle" style="cursor: pointer;"></i>
<h2 class="fs-2 m-0">Dashboard</h2>
</div>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse"
data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent"
aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav ms-auto mb-2 mb-lg-0">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle second-text fw-bold" href="#" id="navbarDropdown"
role="button" data-bs-toggle="dropdown" aria-expanded="false">
<i class="fas fa-user me-2"></i>John Doe
</a>
<ul class="dropdown-menu" aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="#">Profile</a></li>
<li><a class="dropdown-item" href="#">Settings</a></li>
<li><a class="dropdown-item" href="#">Logout</a></li>
</ul>
</li>
</ul>
</div>
</nav>
<div class="container-fluid px-4">
<!-- Statistics Cards -->
<div class="row g-3 my-2">
<div class="col-md-3">
<div class="p-3 bg-white shadow-sm d-flex justify-content-around align-items-center rounded">
<div>
<h3 class="fs-2">720</h3>
<p class="fs-5 text-secondary">Products</p>
</div>
<i class="fas fa-gift fs-1 primary-text border rounded-full secondary-bg p-3 text-primary"></i>
</div>
</div>
<div class="col-md-3">
<div class="p-3 bg-white shadow-sm d-flex justify-content-around align-items-center rounded">
<div>
<h3 class="fs-2">4,920</h3>
<p class="fs-5 text-secondary">Sales</p>
</div>
<i class="fas fa-hand-holding-usd fs-1 primary-text border rounded-full secondary-bg p-3 text-success"></i>
</div>
</div>
<div class="col-md-3">
<div class="p-3 bg-white shadow-sm d-flex justify-content-around align-items-center rounded">
<div>
<h3 class="fs-2">3,899</h3>
<p class="fs-5 text-secondary">Delivery</p>
</div>
<i class="fas fa-truck fs-1 primary-text border rounded-full secondary-bg p-3 text-warning"></i>
</div>
</div>
<div class="col-md-3">
<div class="p-3 bg-white shadow-sm d-flex justify-content-around align-items-center rounded">
<div>
<h3 class="fs-2">%25</h3>
<p class="fs-5 text-secondary">Increase</p>
</div>
<i class="fas fa-chart-line fs-1 primary-text border rounded-full secondary-bg p-3 text-danger"></i>
</div>
</div>
</div>
<!-- Charts Section -->
<div class="row my-5">
<div class="col-lg-8">
<div class="card shadow-sm">
<div class="card-header bg-transparent border-0">
<h3 class="mb-0">Monthly Sales Report</h3>
</div>
<div class="card-body">
<canvas id="barChart"></canvas>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="card shadow-sm">
<div class="card-header bg-transparent border-0">
<h3 class="mb-0">Traffic Source</h3>
</div>
<div class="card-body">
<canvas id="doughnutChart"></canvas>
</div>
</div>
</div>
</div>
<!-- Recent Orders Table -->
<div class="row my-5">
<h3 class="fs-4 mb-3">Recent Orders</h3>
<div class="col">
<div class="table-responsive shadow-sm bg-white p-4 rounded">
<table class="table table-hover bg-white mb-0">
<thead>
<tr>
<th scope="col" width="50">#</th>
<th scope="col">Product</th>
<th scope="col">Customer</th>
<th scope="col">Price</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Television</td>
<td>Jonny</td>
<td>$1200</td>
<td>
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#orderModal">Edit</button>
</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Laptop</td>
<td>Kenny</td>
<td>$750</td>
<td>
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#orderModal">Edit</button>
</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Cell Phone</td>
<td>Jenny</td>
<td>$600</td>
<td>
<button class="btn btn-sm btn-primary" data-bs-toggle="modal" data-bs-target="#orderModal">Edit</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- /#page-content-wrapper -->
<!-- Modal -->
<div class="modal fade" id="orderModal" tabindex="-1" aria-labelledby="orderModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="orderModalLabel">Edit Order</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form>
<div class="mb-3">
<label for="customerName" class="col-form-label">Customer Name:</label>
<input type="text" class="form-control" id="customerName" value="Jonny">
</div>
<div class="mb-3">
<label for="productStats" class="col-form-label">Status:</label>
<select class="form-select">
<option selected>Processing</option>
<option value="1">Shipped</option>
<option value="2">Delivered</option>
</select>
</div>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary">Save changes</button>
</div>
</div>
</div>
</div>
<!-- Bootstrap JS -->
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0-alpha3/dist/js/bootstrap.bundle.min.js"></script>
<!-- Chart.js -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
<script>
// Sidebar Toggle Script
var el = document.getElementById("wrapper");
var toggleButton = document.getElementById("menu-toggle");
toggleButton.onclick = function () {
el.classList.toggle("toggled");
};
// Bar Chart
const ctx1 = document.getElementById('barChart').getContext('2d');
new Chart(ctx1, {
type: 'bar',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'],
datasets: [{
label: '# of Sales',
data: [12, 19, 3, 5, 2, 3],
backgroundColor: [
'rgba(54, 162, 235, 0.2)',
],
borderColor: [
'rgba(54, 162, 235, 1)',
],
borderWidth: 1
}]
},
options: {
responsive: true,
scales: {
y: {
beginAtZero: true
}
}
}
});
// Doughnut Chart
const ctx2 = document.getElementById('doughnutChart').getContext('2d');
new Chart(ctx2, {
type: 'doughnut',
data: {
labels: ['Direct', 'Social', 'Referral'],
datasets: [{
data: [55, 30, 15],
backgroundColor: [
'rgba(255, 99, 132, 0.8)',
'rgba(54, 162, 235, 0.8)',
'rgba(255, 206, 86, 0.8)'
],
borderWidth: 1
}]
},
options: {
responsive: true
}
});
</script>
</body>
</html>
Key Features Explained:
- Sidebar Logic (
var el in script):
- We use a "wrapper" layout.
- CSS negative margins are used to hide/show the sidebar.
- Responsive: On desktop, the sidebar is visible by default. Clicking the hamburger menu hides it. On mobile, it is hidden by default, and clicking the menu slides it in.
- Bootstrap Components:
navbar, card, table-responsive, modal, and dropdown are strictly standard Bootstrap classes, ensuring it is easy to customize.
- Charts (Chart.js):
- Added via CDN at the bottom.
- We initialize a
<canvas> element for both a Bar Chart and a Doughnut Chart.
- The
responsive: true option in JS ensures the charts resize automatically when the sidebar is toggled or the window is resized.
- Modal Interaction:
- In the "Recent Orders" table, clicking the "Edit" button triggers
data-bs-target="#orderModal". This opens the HTML popup defined at the bottom of the page.