@@ -73,6 +73,7 @@ function useCurrentFramework(frameworks: Framework[]) {
7373 const setFramework = React . useCallback (
7474 ( framework : string ) => {
7575 navigate ( {
76+ to : '.' ,
7677 params : ( prev ) => ( {
7778 ...prev ,
7879 framework,
@@ -142,6 +143,7 @@ function useCurrentVersion(versions: string[]) {
142143 const setVersion = React . useCallback (
143144 ( version : string ) => {
144145 navigate ( {
146+ to : '.' ,
145147 params : ( prev : Record < string , string > ) => ( {
146148 ...prev ,
147149 version,
@@ -300,6 +302,84 @@ const useVersionConfig = ({ versions }: { versions: string[] }) => {
300302 return versionConfig
301303}
302304
305+ const PrevNextButton = ( {
306+ item,
307+ direction,
308+ colorFrom,
309+ colorTo,
310+ textColor,
311+ libraryId,
312+ currentFramework,
313+ params,
314+ } : {
315+ item : { to : string ; label : React . ReactNode }
316+ direction : 'prev' | 'next'
317+ colorFrom : string
318+ colorTo : string
319+ textColor : string
320+ libraryId : string
321+ currentFramework : string
322+ params : Record < string , string >
323+ } ) => {
324+ const buttonContent = (
325+ < div className = "flex gap-2 items-center font-bold" >
326+ { direction === 'prev' ? (
327+ < >
328+ < FaArrowLeft />
329+ { item . label }
330+ </ >
331+ ) : (
332+ < >
333+ < span
334+ className = { `bg-gradient-to-r ${ colorFrom } ${ colorTo } bg-clip-text text-transparent` }
335+ >
336+ { item . label }
337+ </ span > { ' ' }
338+ < FaArrowRight className = { textColor } />
339+ </ >
340+ ) }
341+ </ div >
342+ )
343+
344+ const buttonClassName =
345+ 'py-1 px-2 bg-white/70 text-black dark:bg-gray-500/40 dark:text-white shadow-lg shadow-black/20 flex items-center justify-center backdrop-blur-sm z-20 rounded-lg overflow-hidden'
346+
347+ if ( item . to . startsWith ( 'http' ) ) {
348+ return (
349+ < a href = { item . to } className = { buttonClassName } >
350+ { buttonContent }
351+ </ a >
352+ )
353+ }
354+
355+ return (
356+ < Link
357+ to = {
358+ item . to . startsWith ( '/' )
359+ ? item . to
360+ : item . to . includes ( 'framework/' )
361+ ? '/$libraryId/$version/docs/framework/$framework/$'
362+ : '/$libraryId/$version/docs/$'
363+ }
364+ params = { {
365+ libraryId,
366+ version : params . version || 'latest' ,
367+ ...( item . to . includes ( 'framework/' )
368+ ? {
369+ framework : currentFramework ,
370+ _splat : item . to . split ( '/' ) . slice ( 2 ) . join ( '/' ) ,
371+ }
372+ : {
373+ _splat : item . to ,
374+ } ) ,
375+ } }
376+ className = { buttonClassName }
377+ >
378+ { buttonContent }
379+ </ Link >
380+ )
381+ }
382+
303383type DocsLayoutProps = {
304384 name : string
305385 version : string
@@ -327,8 +407,9 @@ export function DocsLayout({
327407} : DocsLayoutProps ) {
328408 const params = useParams ( { strict : false } )
329409 const libraryId = params . libraryId || ''
330-
331410 const { _splat } = params
411+
412+ const { framework : currentFramework } = useCurrentFramework ( frameworks )
332413 const frameworkConfig = useFrameworkConfig ( { frameworks } )
333414 const versionConfig = useVersionConfig ( { versions } )
334415 const menuConfig = useMenuConfig ( { config, frameworks, repo } )
@@ -580,34 +661,30 @@ export function DocsLayout({
580661 < div className = "sticky flex items-center flex-wrap bottom-2 z-10 right-0 text-xs md:text-sm px-1 print:hidden" >
581662 < div className = "w-1/2 px-1 flex justify-end flex-wrap" >
582663 { prevItem ? (
583- < Link
584- to = { prevItem . to }
585- params
586- className = "py-1 px-2 bg-white/70 text-black dark:bg-gray-500/40 dark:text-white shadow-lg shadow-black/20 flex items-center justify-center backdrop-blur-sm z-20 rounded-lg overflow-hidden"
587- >
588- < div className = "flex gap-2 items-center font-bold" >
589- < FaArrowLeft />
590- { prevItem . label }
591- </ div >
592- </ Link >
664+ < PrevNextButton
665+ item = { prevItem }
666+ direction = "prev"
667+ colorFrom = { colorFrom }
668+ colorTo = { colorTo }
669+ textColor = { textColor }
670+ libraryId = { libraryId }
671+ currentFramework = { currentFramework }
672+ params = { params }
673+ / >
593674 ) : null }
594675 </ div >
595676 < div className = "w-1/2 px-1 flex justify-start flex-wrap" >
596677 { nextItem ? (
597- < Link
598- to = { nextItem . to }
599- params
600- className = "py-1 px-2 bg-white/70 text-black dark:bg-gray-500/40 dark:text-white shadow-lg shadow-black/20 flex items-center justify-center backdrop-blur-sm z-20 rounded-lg overflow-hidden"
601- >
602- < div className = "flex gap-2 items-center font-bold" >
603- < span
604- className = { `bg-gradient-to-r ${ colorFrom } ${ colorTo } bg-clip-text text-transparent` }
605- >
606- { nextItem . label }
607- </ span > { ' ' }
608- < FaArrowRight className = { textColor } />
609- </ div >
610- </ Link >
678+ < PrevNextButton
679+ item = { nextItem }
680+ direction = "next"
681+ colorFrom = { colorFrom }
682+ colorTo = { colorTo }
683+ textColor = { textColor }
684+ libraryId = { libraryId }
685+ currentFramework = { currentFramework }
686+ params = { params }
687+ />
611688 ) : null }
612689 </ div >
613690 </ div >
0 commit comments