Skip to content

Commit 6286b50

Browse files
committed
feat: add TopNavEnd layout export
1 parent 68e6e5e commit 6286b50

File tree

6 files changed

+21
-3
lines changed

6 files changed

+21
-3
lines changed

.changeset/curly-schools-film.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"vocs": patch
3+
---
4+
5+
Added `TopNavEnd` layout export to `layout.tsx`.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export default function Layout({ children }: { children: React.ReactNode }) {
22
return <div className="custom_fullwidth">{children}</div>
33
}
4+
5+
export function TopNavEnd() {
6+
return <div>TopNavEnd</div>
7+
}

src/app/components/DesktopTopNav.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TopNavEnd } from 'virtual:consumer-components'
12
import clsx from 'clsx'
23
import { useLocation } from 'react-router'
34

@@ -88,6 +89,7 @@ function Navigation() {
8889
)
8990
return null
9091
})}
92+
<TopNavEnd />
9193
</NavigationMenu.List>
9294
</NavigationMenu.Root>
9395
)

src/app/components/MobileTopNav.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TopNavEnd } from 'virtual:consumer-components'
12
import * as Accordion from '@radix-ui/react-accordion'
23
import { assignInlineVars } from '@vanilla-extract/dynamic'
34
import clsx from 'clsx'
@@ -89,6 +90,7 @@ function Navigation({ items }: { items: Config.ParsedTopNavItem[] }) {
8990
</NavigationMenu.Item>
9091
)
9192
})}
93+
<TopNavEnd />
9294
</NavigationMenu.List>
9395
</NavigationMenu.Root>
9496
)
@@ -183,6 +185,7 @@ function CompactNavigation({ items }: { items: Config.ParsedTopNavItem[] }) {
183185
</Accordion.Item>
184186
)
185187
})}
188+
<TopNavEnd />
186189
</Accordion.Root>
187190
<div className={styles.topNavPopoverFooter}>
188191
<Socials />

src/app/vite-env.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ declare module 'virtual:routes' {
1515
declare module 'virtual:consumer-components' {
1616
export const Layout: import('react').ElementType
1717
export const Footer: import('react').ElementType
18+
export const TopNavEnd: import('react').ElementType
1819
}
1920

2021
declare module 'virtual:searchIndex' {

src/vite/plugins/virtual-consumer-components.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { existsSync } from 'node:fs'
1+
import { existsSync, readFileSync } from 'node:fs'
22
import { resolve } from 'node:path'
33
import type { PluginOption } from 'vite'
44

@@ -22,12 +22,15 @@ export function virtualConsumerComponents(): PluginOption {
2222
return `
2323
${exportComponent(resolve(rootDir, 'layout.tsx'), 'Layout')}
2424
${exportComponent(resolve(rootDir, 'footer.tsx'), 'Footer')}
25+
${exportComponent(resolve(rootDir, 'layout.tsx'), 'TopNavEnd', { named: true })}
2526
`
2627
},
2728
}
2829
}
2930

30-
function exportComponent(path: string, name: string) {
31-
if (existsSync(path)) return `export { default as ${name} } from "${path}";`
31+
function exportComponent(path: string, name: string, { named = false }: { named?: boolean } = {}) {
32+
const exists =
33+
existsSync(path) && new RegExp(`export(.*)${name}`).test(readFileSync(path, 'utf-8'))
34+
if (exists) return `export { ${!named ? `default as ${name}` : name} } from "${path}";`
3235
return `export const ${name} = ({ children }) => children;`
3336
}

0 commit comments

Comments
 (0)