Skip to content

Commit 754dac3

Browse files
committed
fix mobile
1 parent 68a080e commit 754dac3

File tree

9 files changed

+109
-25
lines changed

9 files changed

+109
-25
lines changed

src/components/DocsNavigation/DocsNavigationMobile/DocsPickerMobile.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export function ProductNavigation({ path }: Props) {
5858
label: page.label,
5959
href: page.href,
6060
sdkLang: page.sdkLang,
61+
chainTypes: page.chainTypes,
6162
highlightAsCurrent: page.highlightAsCurrent,
6263
children: page.children ? page.children.map(mapPageWithChildren) : [],
6364
})

src/components/DocsNavigation/DocsNavigationMobile/SubProductContent.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React, { useEffect, useRef } from "react"
22
import { useStore } from "@nanostores/react"
33
import { selectedLanguage } from "~/lib/languageStore.js"
4+
import { selectedChainType } from "~/stores/chainType.js"
5+
import { applyChainTypeFilter } from "~/utils/chainType.js"
46
import { BackArrowIcon } from "./BackArrowIcon.js"
57
import { Page } from "../../Header/Nav/config.js"
68
import styles from "./subProductContent.module.css"
@@ -42,8 +44,17 @@ const PageLink = ({ page, currentPath, level }: { page: Page; currentPath: strin
4244
fontWeight: isActive ? "500" : "normal",
4345
}
4446

47+
// Format chainTypes as data attribute (matching desktop sidebar)
48+
const chainAttr = page.chainTypes ? page.chainTypes.join(",") : "universal"
49+
4550
return (
46-
<a ref={linkRef} style={linkStyle} className={`${styles.link} subproduct-link level-${level}`} href={adjustedHref}>
51+
<a
52+
ref={linkRef}
53+
style={linkStyle}
54+
className={`${styles.link} subproduct-link level-${level}`}
55+
href={adjustedHref}
56+
data-chain-types={chainAttr}
57+
>
4758
{page.label}
4859
</a>
4960
)
@@ -52,7 +63,7 @@ const PageLink = ({ page, currentPath, level }: { page: Page; currentPath: strin
5263
const renderPages = (pages: Page[], currentPath: string, currentLang: string, level = 0): React.ReactNode[] => {
5364
return pages
5465
.filter((page) => {
55-
// If page has sdkLang, only show if it matches current language
66+
// Filter by sdkLang (for CRE language switching)
5667
if (page.sdkLang) {
5768
return page.sdkLang === currentLang
5869
}
@@ -71,6 +82,12 @@ const renderPages = (pages: Page[], currentPath: string, currentLang: string, le
7182

7283
export const SubProductContent = ({ subProducts, onSubproductClick, currentPath }: Props) => {
7384
const currentLang = useStore(selectedLanguage)
85+
const currentChain = useStore(selectedChainType)
86+
87+
// Apply chain type filtering using shared utility (same as desktop sidebar)
88+
useEffect(() => {
89+
applyChainTypeFilter(currentChain)
90+
}, [currentChain])
7491

7592
if (!subProducts) {
7693
return null

src/components/Header/Nav/config.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { ChainType } from "~/config/types.js"
2+
13
type LinksConfig = {
24
docs?: boolean
35
githubUrl?: string
@@ -8,6 +10,7 @@ export type Page = {
810
label: string
911
href: string
1012
sdkLang?: string
13+
chainTypes?: ChainType[]
1114
highlightAsCurrent?: string[]
1215
children?: Page[]
1316
}

src/components/Header/getNavigationProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ import generalLogo from "../../assets/product-logos/general-logo.svg"
1212
import nodesLogo from "../../assets/product-logos/node-logo.svg"
1313
import quickstartLogo from "../../assets/product-logos/quickstart-logo.svg"
1414
import { SIDEBAR as sidebar } from "../../config/sidebar.ts"
15+
import type { ChainType } from "../../config/types.js"
1516

1617
interface Page {
1718
label: string
1819
href: string
1920
sdkLang?: string
21+
chainTypes?: ChainType[]
2022
children?: Page[]
2123
}
2224

2325
interface SidebarContent {
2426
title?: string
2527
url?: string
2628
highlightAsCurrent?: string[]
29+
chainTypes?: ChainType[]
2730
children?: SidebarContent[]
2831
}
2932

@@ -37,6 +40,7 @@ const mapContents = (contents: SidebarContent[], pageSdkLangMap: Map<string, str
3740
label,
3841
href,
3942
...(sdkLang && { sdkLang }),
43+
...(page.chainTypes && { chainTypes: page.chainTypes }),
4044
...(page.highlightAsCurrent && { highlightAsCurrent: page.highlightAsCurrent }),
4145
}
4246

src/components/LeftSidebar/LeftSidebar.astro

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -161,32 +161,14 @@ const sidebarSections = getSidebarSections(section)
161161

162162
<script>
163163
import { selectedChainType } from "~/stores/chainType"
164+
import { applyChainTypeFilter } from "~/utils/chainType.js"
164165

165166
/**
166167
* Filters sidebar items based on selected chain type
167-
* - Shows items with matching chainTypes or universal items
168-
* - Hides items that don't match the selected chain
168+
* Uses shared utility function for consistency with mobile drawer
169169
*/
170170
function filterSidebarByChainType() {
171-
const currentChain = selectedChainType.get()
172-
const sidebarItems = document.querySelectorAll<HTMLElement>("[data-chain-types]")
173-
174-
sidebarItems.forEach((item) => {
175-
const chainTypesAttr = item.getAttribute("data-chain-types")
176-
177-
if (chainTypesAttr === "universal") {
178-
item.style.display = ""
179-
} else if (chainTypesAttr) {
180-
const itemChains = chainTypesAttr.split(",")
181-
if (itemChains.includes(currentChain)) {
182-
item.style.display = ""
183-
} else {
184-
item.style.display = "none"
185-
}
186-
} else {
187-
item.style.display = ""
188-
}
189-
})
171+
applyChainTypeFilter(selectedChainType.get())
190172
}
191173

192174
// Run on initial load

src/content/ccip/getting-started/aptos.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
section: ccip
33
date: Last Modified
4-
title: "Getting Started with Chainlink CCIP on Aptos"
4+
title: "Getting Started (Aptos)"
55
metadata:
66
description: "Get started with Chainlink CCIP on Aptos: essential guides and resources to integrate cross‑chain messaging and token transfers with Aptos using the Move language."
77
excerpt: "Chainlink CCIP, Cross-chain interoperability, Getting started, Aptos, Move language, Blockchain integration, Cross-chain dApps, Token bridges, Cross-chain messaging, Fungible Assets"

src/content/ccip/getting-started/svm.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
section: ccip
33
date: Last Modified
4-
title: "Getting Started with Chainlink CCIP on Solana (SVM)"
4+
title: "Getting Started (Solana)"
55
metadata:
66
description: "Get started with Chainlink CCIP on Solana: essential guides and resources to integrate cross‑chain messaging and token transfers with SVM chains."
77
excerpt: "Chainlink CCIP, Cross-chain interoperability, Getting started, SVM chains, Solana, Blockchain integration, Cross-chain dApps, Token bridges, Cross-chain messaging, SPL Tokens, Token-2022"

src/layouts/DocsLayout.astro

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import DocsNavigation from "~/components/DocsNavigation"
1212
import { VersionSelector } from "~/components/VersionSelector/index.js"
1313
import { detectApiReference } from "@components/VersionSelector/utils/versions"
1414
import { LanguageSwitcherDropdown } from "~/components/LanguageSwitcherDropdown"
15+
import { ChainTypeSelector } from "~/components/ChainSelector"
16+
import { isChainAwareSection } from "~/config/chainTypes"
1517
1618
interface Props {
1719
frontmatter: BaseFrontmatter
@@ -48,6 +50,9 @@ const includeLinkToWalletScript = !!Astro.props.frontmatter.metadata?.linkToWall
4850
// Detect if this is an API reference page and get the product
4951
const { isApiReference, product, isVersioned } = detectApiReference(currentPage)
5052
53+
// Check if this section supports chain type filtering
54+
const showChainSelector = isChainAwareSection(frontmatter.section)
55+
5156
// Derive HowTo steps from headings (H2/H3)
5257
const howToSteps = initialHeadings
5358
.filter((h) => h.depth === 2 || h.depth === 3)
@@ -77,6 +82,13 @@ const howToSteps = initialHeadings
7782
</div>
7883
)
7984
}
85+
{
86+
showChainSelector && (
87+
<div class="chain-selector-mobile">
88+
<ChainTypeSelector client:only="react" />
89+
</div>
90+
)
91+
}
8092
{isApiReference && product && isVersioned && <VersionSelector product={product} currentPath={currentPage} />}
8193
<PageContent {titleHeading}>
8294
<slot />
@@ -190,6 +202,19 @@ const howToSteps = initialHeadings
190202
display: none;
191203
}
192204
}
205+
206+
/* Chain Selector - Mobile (< 800px) */
207+
.chain-selector-mobile {
208+
display: block;
209+
margin-bottom: var(--space-6x);
210+
}
211+
212+
/* Hide mobile chain selector on tablet+ (left sidebar version visible) */
213+
@media (min-width: 50em) {
214+
.chain-selector-mobile {
215+
display: none;
216+
}
217+
}
193218
</style>
194219

195220
<script define:vars={{ includeLinkToWalletScript }}>

src/utils/chainType.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,55 @@ export function filterContentByChainType(contents: SectionContent[], selectedCha
5454
})
5555
.filter((item): item is SectionContent => item !== null)
5656
}
57+
58+
/**
59+
* Filters sidebar DOM elements by chain type using show/hide approach
60+
*
61+
* This function is used by both desktop sidebar and mobile drawer to
62+
* filter navigation items based on the selected chain type.
63+
*
64+
* Filtering rules:
65+
* - data-chain-types="universal": Always visible (no chain restriction)
66+
* - data-chain-types includes selected chain: Visible
67+
* - data-chain-types doesn't include selected chain: Hidden (display: none)
68+
* - No data-chain-types attribute: Always visible (legacy/universal content)
69+
*
70+
* Performance: Operates on DOM after initial render for instant switching
71+
*
72+
* @param currentChain - Currently selected chain type from store
73+
*
74+
* @example
75+
* // In Astro script tag
76+
* import { applyChainTypeFilter } from "~/utils/chainType.js"
77+
* applyChainTypeFilter(selectedChainType.get())
78+
*
79+
* @example
80+
* // In React component
81+
* import { applyChainTypeFilter } from "~/utils/chainType.js"
82+
* useEffect(() => {
83+
* applyChainTypeFilter(currentChain)
84+
* }, [currentChain])
85+
*/
86+
export function applyChainTypeFilter(currentChain: ChainType): void {
87+
const sidebarItems = document.querySelectorAll<HTMLElement>("[data-chain-types]")
88+
89+
sidebarItems.forEach((item) => {
90+
const chainTypesAttr = item.getAttribute("data-chain-types")
91+
92+
if (chainTypesAttr === "universal") {
93+
// Always show universal content
94+
item.style.display = ""
95+
} else if (chainTypesAttr) {
96+
// Check if item's chains include the current selection
97+
const itemChains = chainTypesAttr.split(",")
98+
if (itemChains.includes(currentChain)) {
99+
item.style.display = ""
100+
} else {
101+
item.style.display = "none"
102+
}
103+
} else {
104+
// No chain types attribute means universal/legacy content
105+
item.style.display = ""
106+
}
107+
})
108+
}

0 commit comments

Comments
 (0)