mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
282 lines
7.6 KiB
282 lines
7.6 KiB
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
<title>Fixed Sidebar Test</title>
|
|
<style>
|
|
:root {
|
|
--vp-c-text-1: #213547;
|
|
--vp-c-text-2: #476582;
|
|
--vp-c-text-3: #8b949e;
|
|
--vp-c-divider: #e2e8f0;
|
|
--vp-c-brand-1: #3451b2;
|
|
}
|
|
|
|
body {
|
|
font-family:
|
|
-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
|
margin: 20px;
|
|
background: #f8f9fa;
|
|
}
|
|
|
|
.test-section {
|
|
background: white;
|
|
border: 1px solid var(--vp-c-divider);
|
|
border-radius: 8px;
|
|
padding: 20px;
|
|
margin: 20px 0;
|
|
}
|
|
|
|
.success {
|
|
border-left: 4px solid #10b981;
|
|
}
|
|
|
|
/* VitePress styles */
|
|
.VPSidebarItem {
|
|
margin: 4px 0;
|
|
}
|
|
|
|
.VPSidebarItem.level-0 {
|
|
padding-bottom: 24px;
|
|
}
|
|
|
|
.VPSidebarItem.collapsed.level-0,
|
|
.VPSidebarItem.level-0:not([open]) {
|
|
padding-bottom: 10px;
|
|
}
|
|
|
|
.item {
|
|
position: relative;
|
|
display: flex;
|
|
width: 100%;
|
|
padding: 4px 0;
|
|
align-items: center;
|
|
}
|
|
|
|
.VPSidebarItem details > summary.item {
|
|
cursor: pointer;
|
|
}
|
|
|
|
.indicator {
|
|
position: absolute;
|
|
top: 6px;
|
|
bottom: 6px;
|
|
left: -17px;
|
|
width: 2px;
|
|
border-radius: 2px;
|
|
transition: background-color 0.25s;
|
|
}
|
|
|
|
.text {
|
|
flex-grow: 1;
|
|
font-size: 14px;
|
|
line-height: 24px;
|
|
transition: color 0.25s;
|
|
}
|
|
|
|
.VPSidebarItem.level-0 .text {
|
|
font-weight: 700;
|
|
color: var(--vp-c-text-1);
|
|
}
|
|
|
|
.VPSidebarItem.level-1 .text {
|
|
font-weight: 500;
|
|
color: var(--vp-c-text-2);
|
|
}
|
|
|
|
/* CSS-only caret for collapsible items */
|
|
.VPSidebarItem details > summary.item {
|
|
position: relative;
|
|
}
|
|
|
|
.VPSidebarItem details > summary.item::after {
|
|
content: '';
|
|
position: absolute;
|
|
right: 8px;
|
|
top: 50%;
|
|
transform: translateY(-50%);
|
|
width: 0;
|
|
height: 0;
|
|
border-left: 5px solid var(--vp-c-text-3);
|
|
border-top: 3px solid transparent;
|
|
border-bottom: 3px solid transparent;
|
|
transition: all 0.25s;
|
|
}
|
|
|
|
/* Rotate caret when details is open */
|
|
.VPSidebarItem details[open] > summary.item::after {
|
|
transform: translateY(-50%) rotate(90deg);
|
|
border-left-color: var(--vp-c-text-2);
|
|
}
|
|
|
|
/* Hover effect for caret */
|
|
.VPSidebarItem details > summary.item:hover::after {
|
|
border-left-color: var(--vp-c-text-1);
|
|
}
|
|
|
|
/* Hide native details marker */
|
|
.VPSidebarItem details > summary {
|
|
list-style: none;
|
|
}
|
|
|
|
.VPSidebarItem details > summary::-webkit-details-marker {
|
|
display: none;
|
|
}
|
|
|
|
.items {
|
|
margin-left: 16px;
|
|
margin-top: 4px;
|
|
border-left: 1px solid var(--vp-c-divider);
|
|
padding-left: 16px;
|
|
}
|
|
|
|
.link {
|
|
color: var(--vp-c-text-2);
|
|
text-decoration: none;
|
|
display: flex;
|
|
align-items: center;
|
|
flex-grow: 1;
|
|
}
|
|
|
|
.link:hover {
|
|
color: var(--vp-c-brand-1);
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<h1>✅ Fixed VitePress Sidebar Structure</h1>
|
|
|
|
<div class="test-section success">
|
|
<h2>Correct Structure:</h2>
|
|
<p>
|
|
<strong>Items with children:</strong>
|
|
<code><details><summary></code> with CSS caret
|
|
</p>
|
|
<p>
|
|
<strong>Items without children:</strong>
|
|
<code><div><div></code> with no caret
|
|
</p>
|
|
|
|
<div style="margin: 20px 0">
|
|
<!-- Item WITH children = details/summary -->
|
|
<details class="VPSidebarItem level-0">
|
|
<summary class="item">
|
|
<div class="indicator"></div>
|
|
<span class="text">Introduction (has children)</span>
|
|
</summary>
|
|
<div class="items">
|
|
<div class="VPSidebarItem level-1">
|
|
<div class="item">
|
|
<div class="indicator"></div>
|
|
<a href="#" class="link">
|
|
<span class="text">What is VitePress?</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<div class="VPSidebarItem level-1">
|
|
<div class="item">
|
|
<div class="indicator"></div>
|
|
<a href="#" class="link">
|
|
<span class="text">Getting Started</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<div class="VPSidebarItem level-1">
|
|
<div class="item">
|
|
<div class="indicator"></div>
|
|
<a href="#" class="link">
|
|
<span class="text">Routing</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</details>
|
|
|
|
<!-- Item WITHOUT children = div/div -->
|
|
<div class="VPSidebarItem level-0">
|
|
<div class="item">
|
|
<div class="indicator"></div>
|
|
<a href="#" class="link">
|
|
<span class="text">Simple Link (no children)</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Another item WITH children -->
|
|
<details class="VPSidebarItem level-0">
|
|
<summary class="item">
|
|
<div class="indicator"></div>
|
|
<span class="text">Writing (has children)</span>
|
|
</summary>
|
|
<div class="items">
|
|
<div class="VPSidebarItem level-1">
|
|
<div class="item">
|
|
<div class="indicator"></div>
|
|
<a href="#" class="link">
|
|
<span class="text">Markdown Extensions</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
<div class="VPSidebarItem level-1">
|
|
<div class="item">
|
|
<div class="indicator"></div>
|
|
<a href="#" class="link">
|
|
<span class="text">Asset Handling</span>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</details>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h2>Key Features:</h2>
|
|
<ul>
|
|
<li>
|
|
✅ <strong>Conditional rendering:</strong> Only items with children
|
|
use <code><details></code>
|
|
</li>
|
|
<li>
|
|
✅ <strong>CSS-only caret:</strong> Appears on the right side of items
|
|
with children
|
|
</li>
|
|
<li>
|
|
✅ <strong>Smooth animation:</strong> Caret rotates 90° when accordion
|
|
opens
|
|
</li>
|
|
<li>✅ <strong>Hover effects:</strong> Caret color changes on hover</li>
|
|
<li>
|
|
✅ <strong>Accessibility:</strong> Native keyboard navigation with
|
|
details/summary
|
|
</li>
|
|
<li>✅ <strong>No JavaScript:</strong> Pure CSS implementation</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="test-section">
|
|
<h2>Updated VPSidebarItem.vue Logic:</h2>
|
|
<pre><code><template>
|
|
<!-- Items WITH children use details/summary -->
|
|
<details v-if="hasChildren" class="VPSidebarItem" :class="classes" :open="!collapsed">
|
|
<summary class="item">
|
|
<!-- content with CSS caret -->
|
|
</summary>
|
|
<div class="items">
|
|
<!-- child items -->
|
|
</div>
|
|
</details>
|
|
|
|
<!-- Items WITHOUT children use div -->
|
|
<div v-else class="VPSidebarItem" :class="classes">
|
|
<div class="item">
|
|
<!-- content with no caret -->
|
|
</div>
|
|
</div>
|
|
</template></code></pre>
|
|
</div>
|
|
</body>
|
|
</html>
|