feat: add header level pill on desktop, use native details/summary for sidebar
- Add lesson indicator pill to header (visible on desktop only) - Logo stays centered, pill on left with burger menu - Replace emoji arrows with CSS triangles for iOS compatibility - Use native <details>/<summary> for expand/collapse - Update tests for new implementation
This commit is contained in:
@@ -48,6 +48,7 @@ const elements = {
|
||||
prevBtn: document.getElementById("prev-btn"),
|
||||
nextBtn: document.getElementById("next-btn"),
|
||||
levelIndicator: document.getElementById("level-indicator"),
|
||||
headerLevelPill: document.getElementById("header-level-pill"),
|
||||
|
||||
// Sidebar
|
||||
sidebarDrawer: document.getElementById("sidebar-drawer"),
|
||||
@@ -478,6 +479,7 @@ function loadCurrentLesson() {
|
||||
|
||||
// Update level indicator
|
||||
renderLevelIndicator(elements.levelIndicator, engineState.lessonIndex + 1, engineState.totalLessons);
|
||||
renderLevelIndicator(elements.headerLevelPill, engineState.lessonIndex + 1, engineState.totalLessons);
|
||||
|
||||
// Update active lesson in sidebar
|
||||
updateActiveLessonInSidebar(engineState.module.id, engineState.lessonIndex);
|
||||
|
||||
@@ -32,30 +32,21 @@ export function renderModuleList(container, modules, onSelectModule, onSelectLes
|
||||
// Create list items for each module
|
||||
modules.forEach((module) => {
|
||||
// Create module container
|
||||
const moduleContainer = document.createElement("div");
|
||||
// Use native <details>/<summary> for expand/collapse
|
||||
const moduleContainer = document.createElement("details");
|
||||
moduleContainer.classList.add("module-container");
|
||||
moduleContainer.setAttribute("role", "treeitem");
|
||||
moduleContainer.dataset.moduleId = module.id;
|
||||
|
||||
// Create module header item (clickable to expand/collapse)
|
||||
const moduleHeader = document.createElement("button");
|
||||
moduleHeader.type = "button";
|
||||
// Create module header using <summary>
|
||||
const moduleHeader = document.createElement("summary");
|
||||
moduleHeader.classList.add("module-list-item", "module-header");
|
||||
moduleHeader.dataset.moduleId = module.id;
|
||||
moduleHeader.setAttribute("aria-expanded", "false");
|
||||
moduleHeader.setAttribute("aria-controls", `lessons-${module.id}`);
|
||||
|
||||
// Create module title with expand/collapse indicator
|
||||
// Create module title
|
||||
const moduleTitle = document.createElement("span");
|
||||
moduleTitle.classList.add("module-title");
|
||||
moduleTitle.textContent = module.title;
|
||||
|
||||
// Create expand/collapse icon
|
||||
const expandIcon = document.createElement("span");
|
||||
expandIcon.classList.add("expand-icon");
|
||||
expandIcon.setAttribute("aria-hidden", "true");
|
||||
expandIcon.innerHTML = "▶"; // Right-pointing triangle
|
||||
|
||||
moduleHeader.appendChild(expandIcon);
|
||||
moduleHeader.appendChild(moduleTitle);
|
||||
|
||||
// Check if the module is completed
|
||||
@@ -63,13 +54,10 @@ export function renderModuleList(container, modules, onSelectModule, onSelectLes
|
||||
moduleHeader.classList.add("completed");
|
||||
}
|
||||
|
||||
// Lessons container (initially hidden)
|
||||
// Lessons container
|
||||
const lessonsContainer = document.createElement("div");
|
||||
lessonsContainer.classList.add("lessons-container");
|
||||
lessonsContainer.id = `lessons-${module.id}`;
|
||||
lessonsContainer.setAttribute("role", "group");
|
||||
lessonsContainer.setAttribute("aria-label", `${module.title} lessons`);
|
||||
lessonsContainer.style.display = "none"; // Initially collapsed
|
||||
|
||||
// Create list items for each lesson in this module
|
||||
module.lessons.forEach((lesson, index) => {
|
||||
@@ -105,17 +93,6 @@ export function renderModuleList(container, modules, onSelectModule, onSelectLes
|
||||
lessonsContainer.appendChild(lessonItem);
|
||||
});
|
||||
|
||||
// Toggle expand/collapse when clicking on module header
|
||||
moduleHeader.addEventListener("click", () => {
|
||||
// Toggle visibility of lessons container
|
||||
const isExpanded = lessonsContainer.style.display !== "none";
|
||||
lessonsContainer.style.display = isExpanded ? "none" : "block";
|
||||
|
||||
// Update expand/collapse icon and ARIA state
|
||||
expandIcon.innerHTML = isExpanded ? "▶" : "▼";
|
||||
moduleHeader.setAttribute("aria-expanded", String(!isExpanded));
|
||||
});
|
||||
|
||||
// Add module header and lessons container to module container
|
||||
moduleContainer.appendChild(moduleHeader);
|
||||
moduleContainer.appendChild(lessonsContainer);
|
||||
@@ -233,20 +210,10 @@ export function updateActiveLessonInSidebar(moduleId, lessonIndex) {
|
||||
if (currentLessonItem) {
|
||||
currentLessonItem.classList.add("active");
|
||||
|
||||
// Make sure parent module is expanded
|
||||
const parentLessonsContainer = currentLessonItem.parentElement;
|
||||
if (parentLessonsContainer && parentLessonsContainer.classList.contains("lessons-container")) {
|
||||
parentLessonsContainer.style.display = "block";
|
||||
|
||||
// Update expand icon and ARIA state
|
||||
const moduleHeader = parentLessonsContainer.previousElementSibling;
|
||||
if (moduleHeader) {
|
||||
moduleHeader.setAttribute("aria-expanded", "true");
|
||||
const expandIcon = moduleHeader.querySelector(".expand-icon");
|
||||
if (expandIcon) {
|
||||
expandIcon.innerHTML = "▼"; // Down arrow when expanded
|
||||
}
|
||||
}
|
||||
// Make sure parent module is expanded (native <details> element)
|
||||
const parentDetails = currentLessonItem.closest("details.module-container");
|
||||
if (parentDetails) {
|
||||
parentDetails.open = true;
|
||||
|
||||
// Scroll to the top of the page
|
||||
document.querySelector("html").scrollTop = 0;
|
||||
|
||||
@@ -15,9 +15,12 @@
|
||||
<a href="#main-content" class="skip-link" data-i18n="skipLink">Skip to main content</a>
|
||||
<div class="app-container">
|
||||
<header class="header">
|
||||
<button id="menu-btn" class="menu-toggle" data-i18n-aria-label="menuOpen" aria-label="Open menu">
|
||||
<span class="hamburger-icon"></span>
|
||||
</button>
|
||||
<div class="header-left">
|
||||
<button id="menu-btn" class="menu-toggle" data-i18n-aria-label="menuOpen" aria-label="Open menu">
|
||||
<span class="hamburger-icon"></span>
|
||||
</button>
|
||||
<span class="header-level-pill" id="header-level-pill"></span>
|
||||
</div>
|
||||
<a href="#" id="logo-link" class="logo">
|
||||
<img src="./bowl.png" width="40" alt="CODE CRISPIES Logo" />
|
||||
<h1><span class="code-text">CODE</span><span class="crispies-text">CRISPIES</span></h1>
|
||||
|
||||
89
src/main.css
89
src/main.css
@@ -140,6 +140,47 @@ kbd {
|
||||
background: var(--primary-bg-light);
|
||||
}
|
||||
|
||||
.header-level-pill {
|
||||
display: none;
|
||||
padding: 4px 12px;
|
||||
background: var(--primary-bg-light);
|
||||
border-radius: 16px;
|
||||
font-size: 0.8rem;
|
||||
color: var(--text-muted);
|
||||
white-space: nowrap;
|
||||
margin-left: var(--spacing-sm);
|
||||
}
|
||||
|
||||
.header-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--spacing-sm);
|
||||
}
|
||||
|
||||
@media (min-width: 769px) {
|
||||
.header-level-pill {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.header {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr auto 1fr;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.header-left {
|
||||
justify-self: start;
|
||||
}
|
||||
|
||||
.header .logo {
|
||||
justify-self: center;
|
||||
}
|
||||
|
||||
.header-actions {
|
||||
justify-self: end;
|
||||
}
|
||||
}
|
||||
|
||||
.hamburger-icon {
|
||||
position: relative;
|
||||
width: 18px;
|
||||
@@ -936,18 +977,42 @@ nav.sidebar-section {
|
||||
background: var(--primary-bg-light);
|
||||
}
|
||||
|
||||
.module-header.completed::before {
|
||||
content: "✓";
|
||||
margin-right: 6px;
|
||||
color: var(--success-color);
|
||||
/* Native details/summary styling */
|
||||
details.module-container {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.expand-icon {
|
||||
summary.module-header {
|
||||
list-style: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
summary.module-header::-webkit-details-marker {
|
||||
display: none;
|
||||
}
|
||||
|
||||
summary.module-header::before {
|
||||
content: "";
|
||||
display: inline-block;
|
||||
width: 0;
|
||||
height: 0;
|
||||
margin-right: 8px;
|
||||
font-size: 10px;
|
||||
border-top: 5px solid transparent;
|
||||
border-bottom: 5px solid transparent;
|
||||
border-left: 6px solid var(--text-muted);
|
||||
transition: transform 0.2s;
|
||||
}
|
||||
|
||||
details.module-container[open] > summary.module-header::before {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
.module-header.completed::after {
|
||||
content: "✓";
|
||||
margin-left: 8px;
|
||||
color: var(--success-color);
|
||||
}
|
||||
|
||||
.lessons-container {
|
||||
margin-left: 16px;
|
||||
border-left: 2px solid var(--border-color);
|
||||
@@ -1575,10 +1640,16 @@ input:checked + .toggle-slider::before {
|
||||
padding-right: 8px;
|
||||
}
|
||||
|
||||
/* RTL: Module expand icon */
|
||||
[dir="rtl"] .module-header .expand-icon {
|
||||
margin-left: 6px;
|
||||
/* RTL: Module expand icon (CSS triangle) */
|
||||
[dir="rtl"] summary.module-header::before {
|
||||
margin-left: 8px;
|
||||
margin-right: 0;
|
||||
border-left: none;
|
||||
border-right: 6px solid var(--text-muted);
|
||||
}
|
||||
|
||||
[dir="rtl"] details.module-container[open] > summary.module-header::before {
|
||||
transform: rotate(-90deg);
|
||||
}
|
||||
|
||||
/* RTL: Lesson checkmark position */
|
||||
|
||||
Reference in New Issue
Block a user