Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 118 additions & 45 deletions homedocs/src/components/CodeExample.astro
Original file line number Diff line number Diff line change
Expand Up @@ -354,87 +354,54 @@ const stackblitzProjectData = stackblitzProject && JSON.stringify(stackblitzProj
class="code-block relative rounded-lg overflow-hidden border border-border bg-[hsl(var(--code-bg))]"
>
{
!hasTabs && stackblitzProject && (
<button
class="stackblitz-btn absolute top-2 right-2 z-10 px-2 py-1 text-xs font-medium transition-colors hover:text-white flex items-center gap-1.5 cursor-pointer rounded"
data-project={stackblitzProjectData}
style="color: rgba(255, 255, 255, 0.5);"
title="Open in StackBlitz"
>
<svg
class="w-3.5 h-3.5"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
stroke-width="2"
>
<path
d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"
stroke-linecap="round"
stroke-linejoin="round"
/>
<polyline
points="15 3 21 3 21 9"
stroke-linecap="round"
stroke-linejoin="round"
/>
<line
x1="10"
x2="21"
y1="14"
y2="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
</svg>
<span class="hidden sm:inline">StackBlitz</span>
</button>
)
}
{
hasTabs && (
(hasTabs || stackblitzProject) && (
<div class="code-tabs flex border-b border-[hsl(var(--code-border))]">
{/* Without tabs, the bar only holds the StackBlitz link, so the link doesn't cover the first line of code */}
{hasTabs && (
<div class="code-tab-list flex min-w-0 overflow-x-auto">
<button
class="code-tab active px-4 py-2 text-xs font-medium uppercase transition-colors"
class="code-tab active shrink-0 whitespace-nowrap px-2.5 sm:px-4 py-2 text-[11px] sm:text-xs font-medium uppercase transition-colors"
data-tab="code"
>
Index
</button>
{modelCode && (
<button
class="code-tab px-4 py-2 text-xs font-medium uppercase transition-colors"
class="code-tab shrink-0 whitespace-nowrap px-2.5 sm:px-4 py-2 text-[11px] sm:text-xs font-medium uppercase transition-colors"
data-tab="model"
>
Model
</button>
)}
{componentsCode && (
<button
class="code-tab px-4 py-2 text-xs font-medium uppercase transition-colors"
class="code-tab shrink-0 whitespace-nowrap px-2.5 sm:px-4 py-2 text-[11px] sm:text-xs font-medium uppercase transition-colors"
data-tab="components"
>
Components
</button>
)}
{controllerCode && (
<button
class="code-tab px-4 py-2 text-xs font-medium uppercase transition-colors"
class="code-tab shrink-0 whitespace-nowrap px-2.5 sm:px-4 py-2 text-[11px] sm:text-xs font-medium uppercase transition-colors"
data-tab="controller"
>
Controller
</button>
)}
{importsCode && (
<button
class="code-tab px-4 py-2 text-xs font-medium uppercase transition-colors"
class="code-tab shrink-0 whitespace-nowrap px-2.5 sm:px-4 py-2 text-[11px] sm:text-xs font-medium uppercase transition-colors"
data-tab="imports"
>
Imports
</button>
)}
</div>
)}
{stackblitzProject && (
<button
class="ml-auto stackblitz-btn px-3 py-2 text-xs font-medium transition-colors hover:text-white flex items-center gap-1.5 border-l border-[hsl(var(--code-border))] cursor-pointer"
class="ml-auto shrink-0 stackblitz-btn px-2.5 sm:px-3 py-2 text-xs font-medium transition-colors hover:text-white flex items-center gap-1.5 border-l border-[hsl(var(--code-border))] cursor-pointer"
data-project={stackblitzProjectData}
style="color: rgba(255, 255, 255, 0.5);"
title="Open in StackBlitz"
Expand Down Expand Up @@ -472,6 +439,7 @@ const stackblitzProjectData = stackblitzProject && JSON.stringify(stackblitzProj
)
}

<div class="code-scroll-area relative">
<div class="code-content-wrapper max-h-96 overflow-y-auto">
<div class="code-content" data-content="code">
<Code code={displayCode} lang="tsx" theme="github-dark-dimmed" />
Expand Down Expand Up @@ -513,6 +481,10 @@ const stackblitzProjectData = stackblitzProject && JSON.stringify(stackblitzProj
)
}
</div>
<!-- Scroll hint, shown while the visible code continues below the bottom edge -->
<div class="code-scroll-fade" aria-hidden="true"></div>
<div class="code-scroll-more" aria-hidden="true"></div>
</div>
</div>

<!-- Preview - positioned to the right on xl+ screens -->
Expand Down Expand Up @@ -578,6 +550,51 @@ const stackblitzProjectData = stackblitzProject && JSON.stringify(stackblitzProj
color: rgba(255, 255, 255, 0.5);
}

/* On narrow screens the tabs scroll sideways, without a visible scrollbar */
.code-tab-list {
scrollbar-width: none;
}

.code-tab-list::-webkit-scrollbar {
display: none;
}

/* Scroll hint: a fade along the bottom edge and a count of the lines below it. Both are overlays, so showing or
hiding them does not change the layout. */
.code-scroll-fade,
.code-scroll-more {
position: absolute;
pointer-events: none;
opacity: 0;
transition: opacity 0.15s ease;
}

.code-scroll-fade {
left: 0;
right: 0;
bottom: 0;
height: 3rem;
background: linear-gradient(to bottom, transparent, hsl(var(--code-bg)));
}

.code-scroll-more {
right: 0.75rem;
bottom: 0.5rem;
padding: 0.125rem 0.5rem;
border-radius: 9999px;
font-size: 11px;
line-height: 1.5;
font-weight: 500;
color: rgba(255, 255, 255, 0.75);
background: hsl(var(--code-bg) / 0.85);
border: 1px solid hsl(var(--code-border));
}

.code-scroll-area[data-more] .code-scroll-fade,
.code-scroll-area[data-more] .code-scroll-more {
opacity: 1;
}

.code-tab:hover {
color: rgba(255, 255, 255, 0.8);
}
Expand Down Expand Up @@ -647,6 +664,62 @@ const stackblitzProjectData = stackblitzProject && JSON.stringify(stackblitzProj

initCodeExampleTabs();
document.addEventListener("astro:page-load", initCodeExampleTabs);

// Scroll hint: while the visible tab continues below the bottom edge of the code block, show a fade and the number
// of lines that are cut off or hidden.
function initCodeScrollHints() {
document.querySelectorAll(".code-example .code-scroll-area").forEach(function (area) {
if (area.dataset.scrollHint) return;
area.dataset.scrollHint = "1";

var wrapper = area.querySelector(".code-content-wrapper");
var fade = area.querySelector(".code-scroll-fade");
var label = area.querySelector(".code-scroll-more");
if (!wrapper || !fade || !label) return;

function update() {
var bottom = wrapper.getBoundingClientRect().bottom;
var hidden = 0;
wrapper.querySelectorAll(".code-content:not(.hidden) .line").forEach(function (line) {
if (line.getBoundingClientRect().bottom > bottom + 1) hidden++;
});

if (hidden > 0) {
// keep the fade off the vertical scrollbar
var scrollbar = wrapper.offsetWidth - wrapper.clientWidth;
fade.style.right = scrollbar + "px";
label.style.right = 12 + scrollbar + "px";
label.textContent = "↓ " + hidden + (hidden === 1 ? " more line" : " more lines");
area.setAttribute("data-more", "");
} else {
area.removeAttribute("data-more");
}
}

wrapper.addEventListener("scroll", update, { passive: true });

var example = area.closest(".code-example");
example.querySelectorAll(".code-tab").forEach(function (tab) {
tab.addEventListener("click", function () {
requestAnimationFrame(update);
});
});

// size changes: viewport width, font loading, code wrapping
if (window.ResizeObserver) {
var observer = new ResizeObserver(update);
observer.observe(wrapper);
wrapper.querySelectorAll(".code-content").forEach(function (content) {
observer.observe(content);
});
}

update();
});
}

initCodeScrollHints();
document.addEventListener("astro:page-load", initCodeScrollHints);
</script>

<script>
Expand Down
111 changes: 103 additions & 8 deletions homedocs/src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ const currentCategory = getCurrentCategory(pathname);
</svg>
</button>

<!-- Logo -->
<a href="/" class="flex items-center gap-2 mr-6">
<img src="/favicon.svg" alt="CxJS" class="h-8 w-8" />
<span class="hidden font-semibold text-foreground sm:inline-block">
CxJS
</span>
</a>
<!-- Logo: CxJS goes to the homepage; Docs is a label showing that this is the documentation -->
<div class="flex items-center mr-6 shrink-0">
<a
href="/"
class="group flex items-center gap-2"
title="CxJS home"
>
<img src="/favicon.svg" alt="CxJS" class="h-9 w-9 transition-transform group-hover:scale-110" />
<span class="hidden text-xl font-semibold text-foreground sm:inline-block">CxJS</span>
</a>
<span class="ml-1.5 text-xl font-normal text-muted-foreground select-none">Docs</span>
</div>

<!-- Category dropdown (md to xl) -->
<CategoryDropdown class="hidden md:block xl:hidden" />
Expand All @@ -52,13 +57,28 @@ const currentCategory = getCurrentCategory(pathname);
<!-- Right side -->
<div class="ml-auto flex items-center gap-2">
<!-- Search -->
<div class="hidden sm:block relative">
<div id="desktop-search-slot" class="hidden sm:block relative">
<Search id="search" className="pagefind-ui" uiOptions={{ showImages: false, showSubResults: false, excerptLength: 15 }} />
<kbd class="search-kbd absolute right-3 top-1/2 -translate-y-1/2 pointer-events-none px-2 py-0.5 text-xs font-medium text-muted-foreground bg-secondary border border-border rounded opacity-60">
⌘K
</kbd>
</div>

<!-- Mobile search (below sm, where the search box above is hidden) -->
<button
id="mobile-search-btn"
type="button"
class="sm:hidden inline-flex items-center justify-center h-9 w-9 rounded-md text-muted-foreground hover:text-foreground hover:bg-secondary transition-colors"
aria-label="Search"
aria-expanded="false"
aria-controls="mobile-search-panel"
>
<svg class="h-5 w-5" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<circle cx="11" cy="11" r="8"></circle>
<path d="m21 21-4.3-4.3"></path>
</svg>
</button>

<!-- Theme toggle -->
<ThemeToggle />

Expand All @@ -76,6 +96,13 @@ const currentCategory = getCurrentCategory(pathname);
</a>
</div>
</div>

<!-- Mobile search panel: the single Pagefind instance is moved here while the panel is open -->
<div id="mobile-search-backdrop" class="hidden absolute left-0 right-0 top-full h-[calc(100dvh-3.5rem)] bg-background/80 backdrop-blur-sm"></div>
<div
id="mobile-search-panel"
class="hidden absolute left-0 right-0 top-full max-h-[calc(100dvh-3.5rem)] overflow-y-auto border-b border-border bg-background px-4 py-3 shadow-lg"
></div>
</header>

<script is:inline>
Expand All @@ -102,6 +129,43 @@ const currentCategory = getCurrentCategory(pathname);
closeIcon?.classList.remove('hidden');
}

// Mobile search: the Pagefind element is moved from the header into the panel while it's open, so there is
// only one instance and one input (Ctrl/Cmd+K keeps working on the same input).
function isMobileSearchOpen() {
return !document.getElementById('mobile-search-panel')?.classList.contains('hidden');
}

function openMobileSearch() {
const panel = document.getElementById('mobile-search-panel');
const backdrop = document.getElementById('mobile-search-backdrop');
const search = document.getElementById('search');
if (!panel || !search) return;

panel.appendChild(search);
panel.classList.remove('hidden');
backdrop?.classList.remove('hidden');
document.getElementById('mobile-search-btn')?.setAttribute('aria-expanded', 'true');

// Focus synchronously within the tap, so that phones open the keyboard
search.querySelector('.pagefind-ui__search-input')?.focus();
}

function closeMobileSearch() {
const panel = document.getElementById('mobile-search-panel');
const backdrop = document.getElementById('mobile-search-backdrop');
const slot = document.getElementById('desktop-search-slot');
const search = document.getElementById('search');
if (!panel || panel.classList.contains('hidden')) return;

if (slot && search && search.parentElement !== slot) {
slot.insertBefore(search, slot.firstChild);
}
search?.querySelector('.pagefind-ui__search-input')?.blur();
panel.classList.add('hidden');
backdrop?.classList.add('hidden');
document.getElementById('mobile-search-btn')?.setAttribute('aria-expanded', 'false');
}

// Only add listeners once
if (!window._mobileMenuInitialized) {
window._mobileMenuInitialized = true;
Expand All @@ -115,11 +179,42 @@ const currentCategory = getCurrentCategory(pathname);
if (isOpen) {
closeMobileMenu();
} else {
closeMobileSearch();
openMobileMenu();
}
return;
}

if (e.target.closest('#mobile-search-btn')) {
if (isMobileSearchOpen()) {
closeMobileSearch();
} else {
closeMobileMenu();
openMobileSearch();
}
return;
}

if (e.target.closest('#mobile-search-backdrop')) {
closeMobileSearch();
}
});

// Escape closes the mobile search
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && isMobileSearchOpen()) {
closeMobileSearch();
}
});

// Back at sm and wider the panel is hidden, so put the search back into the header
window.matchMedia('(min-width: 640px)').addEventListener('change', (e) => {
if (e.matches) closeMobileSearch();
});

// Close the search on navigation, e.g. after a result is clicked
document.addEventListener('astro:before-preparation', closeMobileSearch);

// Close menu on navigation
document.addEventListener('astro:before-preparation', closeMobileMenu);
}
Expand Down
2 changes: 2 additions & 0 deletions homedocs/src/components/HoneycombBackground.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2237,6 +2237,8 @@
var GLOW_RADIUS = 150;

function initHoneycomb() {
// The glow that follows the mouse is decorative motion; leave it out when reduced motion is requested
if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
var svg = document.getElementById("honeycomb-svg");
if (!svg) return;
var edgeEls = svg.querySelectorAll(".hc-edge");
Expand Down
Loading
Loading