Spaces:
Running
Running
create a drop down with options:
Browse files- components/dropdown.js +91 -0
- components/navbar.js +13 -4
- index.html +3 -1
components/dropdown.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class CustomDropdown extends HTMLElement {
|
| 2 |
+
connectedCallback() {
|
| 3 |
+
this.attachShadow({ mode: 'open' });
|
| 4 |
+
this.shadowRoot.innerHTML = `
|
| 5 |
+
<style>
|
| 6 |
+
.dropdown {
|
| 7 |
+
position: relative;
|
| 8 |
+
display: inline-block;
|
| 9 |
+
}
|
| 10 |
+
.dropdown-btn {
|
| 11 |
+
background: none;
|
| 12 |
+
border: none;
|
| 13 |
+
cursor: pointer;
|
| 14 |
+
color: #374151;
|
| 15 |
+
font-weight: 500;
|
| 16 |
+
transition: color 0.2s;
|
| 17 |
+
display: flex;
|
| 18 |
+
align-items: center;
|
| 19 |
+
gap: 0.25rem;
|
| 20 |
+
}
|
| 21 |
+
.dropdown-btn:hover {
|
| 22 |
+
color: #13aa52;
|
| 23 |
+
}
|
| 24 |
+
.dropdown-content {
|
| 25 |
+
position: absolute;
|
| 26 |
+
background-color: white;
|
| 27 |
+
min-width: 160px;
|
| 28 |
+
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.1);
|
| 29 |
+
border-radius: 0.5rem;
|
| 30 |
+
z-index: 1;
|
| 31 |
+
opacity: 0;
|
| 32 |
+
visibility: hidden;
|
| 33 |
+
transform: translateY(10px);
|
| 34 |
+
transition: all 0.2s ease;
|
| 35 |
+
}
|
| 36 |
+
.dropdown-content.show {
|
| 37 |
+
opacity: 1;
|
| 38 |
+
visibility: visible;
|
| 39 |
+
transform: translateY(0);
|
| 40 |
+
}
|
| 41 |
+
.dropdown-content a {
|
| 42 |
+
color: #374151;
|
| 43 |
+
padding: 0.75rem 1rem;
|
| 44 |
+
text-decoration: none;
|
| 45 |
+
display: block;
|
| 46 |
+
transition: background-color 0.2s;
|
| 47 |
+
font-size: 0.875rem;
|
| 48 |
+
}
|
| 49 |
+
.dropdown-content a:hover {
|
| 50 |
+
background-color: #f3f4f6;
|
| 51 |
+
color: #13aa52;
|
| 52 |
+
}
|
| 53 |
+
.icon {
|
| 54 |
+
transition: transform 0.2s;
|
| 55 |
+
}
|
| 56 |
+
.dropdown.active .icon {
|
| 57 |
+
transform: rotate(180deg);
|
| 58 |
+
}
|
| 59 |
+
</style>
|
| 60 |
+
<div class="dropdown">
|
| 61 |
+
<button class="dropdown-btn">
|
| 62 |
+
<span>${this.getAttribute('title') || 'Menu'}</span>
|
| 63 |
+
<svg class="icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
| 64 |
+
<polyline points="6 9 12 15 18 9"></polyline>
|
| 65 |
+
</svg>
|
| 66 |
+
</button>
|
| 67 |
+
<div class="dropdown-content">
|
| 68 |
+
<slot></slot>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
`;
|
| 72 |
+
|
| 73 |
+
const dropdownBtn = this.shadowRoot.querySelector('.dropdown-btn');
|
| 74 |
+
const dropdownContent = this.shadowRoot.querySelector('.dropdown-content');
|
| 75 |
+
const dropdown = this.shadowRoot.querySelector('.dropdown');
|
| 76 |
+
|
| 77 |
+
dropdownBtn.addEventListener('click', (e) => {
|
| 78 |
+
e.stopPropagation();
|
| 79 |
+
dropdownContent.classList.toggle('show');
|
| 80 |
+
dropdown.classList.toggle('active');
|
| 81 |
+
});
|
| 82 |
+
|
| 83 |
+
// Close when clicking outside
|
| 84 |
+
document.addEventListener('click', () => {
|
| 85 |
+
dropdownContent.classList.remove('show');
|
| 86 |
+
dropdown.classList.remove('active');
|
| 87 |
+
});
|
| 88 |
+
}
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
customElements.define('custom-dropdown', CustomDropdown);
|
components/navbar.js
CHANGED
|
@@ -35,13 +35,22 @@ class CustomNavbar extends HTMLElement {
|
|
| 35 |
|
| 36 |
<div class="nav-links flex items-center space-x-6">
|
| 37 |
<a href="/" class="text-gray-700 hover:text-green-600 transition-colors font-medium">Home</a>
|
| 38 |
-
<
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
<a href="#" class="text-gray-700 hover:text-green-600 transition-colors font-medium">About</a>
|
| 41 |
<a href="#" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-md font-medium transition-colors">Sign In</a>
|
| 42 |
</div>
|
| 43 |
-
|
| 44 |
-
<button class="mobile-menu hidden text-gray-700">
|
| 45 |
<i data-feather="menu"></i>
|
| 46 |
</button>
|
| 47 |
</div>
|
|
|
|
| 35 |
|
| 36 |
<div class="nav-links flex items-center space-x-6">
|
| 37 |
<a href="/" class="text-gray-700 hover:text-green-600 transition-colors font-medium">Home</a>
|
| 38 |
+
<custom-dropdown title="Courses">
|
| 39 |
+
<a href="#foundational">Foundational</a>
|
| 40 |
+
<a href="#developer">Developer</a>
|
| 41 |
+
<a href="#admin">Admin/DevOps</a>
|
| 42 |
+
<a href="#ai">AI Developer</a>
|
| 43 |
+
</custom-dropdown>
|
| 44 |
+
<custom-dropdown title="Resources">
|
| 45 |
+
<a href="#">Documentation</a>
|
| 46 |
+
<a href="#">Tutorials</a>
|
| 47 |
+
<a href="#">Community</a>
|
| 48 |
+
<a href="#">Blog</a>
|
| 49 |
+
</custom-dropdown>
|
| 50 |
<a href="#" class="text-gray-700 hover:text-green-600 transition-colors font-medium">About</a>
|
| 51 |
<a href="#" class="bg-green-600 hover:bg-green-700 text-white px-4 py-2 rounded-md font-medium transition-colors">Sign In</a>
|
| 52 |
</div>
|
| 53 |
+
<button class="mobile-menu hidden text-gray-700">
|
|
|
|
| 54 |
<i data-feather="menu"></i>
|
| 55 |
</button>
|
| 56 |
</div>
|
index.html
CHANGED
|
@@ -16,10 +16,11 @@
|
|
| 16 |
<script src="https://uicdn.toast.com/tui.time-picker/latest/tui-time-picker.min.js"></script>
|
| 17 |
<script src="https://uicdn.toast.com/tui.date-picker/latest/tui-date-picker.min.js"></script>
|
| 18 |
<script src="https://uicdn.toast.com/tui-calendar/latest/tui-calendar.js"></script>
|
| 19 |
-
<script src="components/navbar.js"></script>
|
| 20 |
<script src="components/footer.js"></script>
|
| 21 |
<script src="components/course-card.js"></script>
|
| 22 |
<script src="components/calendar.js"></script>
|
|
|
|
| 23 |
</head>
|
| 24 |
<body class="bg-gray-50">
|
| 25 |
<custom-navbar></custom-navbar>
|
|
@@ -52,6 +53,7 @@
|
|
| 52 |
<div class="bg-white p-4 rounded-lg shadow hover:shadow-md transition-shadow">
|
| 53 |
<h4 class="font-medium text-green-600">MDB100</h4>
|
| 54 |
<p class="text-gray-600">MongoDB Database and Security</p>
|
|
|
|
| 55 |
</div>
|
| 56 |
<div class="bg-white p-4 rounded-lg shadow hover:shadow-md transition-shadow">
|
| 57 |
<h4 class="font-medium text-green-600">MDB200</h4>
|
|
|
|
| 16 |
<script src="https://uicdn.toast.com/tui.time-picker/latest/tui-time-picker.min.js"></script>
|
| 17 |
<script src="https://uicdn.toast.com/tui.date-picker/latest/tui-date-picker.min.js"></script>
|
| 18 |
<script src="https://uicdn.toast.com/tui-calendar/latest/tui-calendar.js"></script>
|
| 19 |
+
<script src="components/navbar.js"></script>
|
| 20 |
<script src="components/footer.js"></script>
|
| 21 |
<script src="components/course-card.js"></script>
|
| 22 |
<script src="components/calendar.js"></script>
|
| 23 |
+
<script src="components/dropdown.js"></script>
|
| 24 |
</head>
|
| 25 |
<body class="bg-gray-50">
|
| 26 |
<custom-navbar></custom-navbar>
|
|
|
|
| 53 |
<div class="bg-white p-4 rounded-lg shadow hover:shadow-md transition-shadow">
|
| 54 |
<h4 class="font-medium text-green-600">MDB100</h4>
|
| 55 |
<p class="text-gray-600">MongoDB Database and Security</p>
|
| 56 |
+
|
| 57 |
</div>
|
| 58 |
<div class="bg-white p-4 rounded-lg shadow hover:shadow-md transition-shadow">
|
| 59 |
<h4 class="font-medium text-green-600">MDB200</h4>
|