@@ -41,6 +41,7 @@ export function CopyMarkdownButton({pathname}: CopyMarkdownButtonProps) {
4141 }
4242 } ;
4343
44+ // Set mounted state and close dropdown on outside click
4445 useEffect ( ( ) => {
4546 setIsMounted ( true ) ;
4647
@@ -72,9 +73,12 @@ export function CopyMarkdownButton({pathname}: CopyMarkdownButtonProps) {
7273 } ;
7374 } ;
7475
75- const buttonClass = "inline-flex items-center h-full text-gray-700 bg-transparent border-none cursor-pointer transition-colors duration-150 hover:bg-gray-50 active:bg-gray-100 focus:bg-gray-50 outline-none" ;
76- const dropdownItemClass = "flex items-center gap-3 w-full p-2 px-3 text-left bg-transparent rounded-md transition-colors hover:bg-gray-100 font-sans text-gray-900" ;
77- const iconContainerClass = "flex items-center justify-center w-7 h-7 bg-gray-100 rounded shrink-0" ;
76+ const buttonClass =
77+ 'inline-flex items-center h-full text-gray-700 bg-transparent border-none cursor-pointer transition-colors duration-150 hover:bg-gray-50 active:bg-gray-100 focus:bg-gray-50 outline-none' ;
78+ const dropdownItemClass =
79+ 'flex items-center gap-3 w-full p-2 px-3 text-left bg-transparent rounded-md transition-colors hover:bg-gray-100 font-sans text-gray-900' ;
80+ const iconContainerClass =
81+ 'flex items-center justify-center w-7 h-7 bg-gray-100 rounded shrink-0' ;
7882
7983 return (
8084 < Fragment >
@@ -107,49 +111,59 @@ export function CopyMarkdownButton({pathname}: CopyMarkdownButtonProps) {
107111 </ div >
108112 </ div >
109113
110- { isMounted && isOpen && createPortal (
111- < div
112- ref = { dropdownRef }
113- className = "fixed w-80 bg-white rounded-xl shadow-lg overflow-hidden z-[9999]"
114- style = { { ...getDropdownPosition ( ) , border : '1px solid #d1d5db' } }
115- >
116- < div className = "p-1" >
117- < button
118- onClick = { ( ) => {
119- copyMarkdownToClipboard ( ) ;
120- setIsOpen ( false ) ;
121- } }
122- className = { `${ dropdownItemClass } border-none cursor-pointer disabled:opacity-50` }
123- disabled = { isLoading }
124- >
125- < div className = { iconContainerClass } >
126- < Clipboard size = { 14 } />
127- </ div >
128- < div className = "flex-1" >
129- < div className = "font-medium text-gray-900 text-sm leading-5" > Copy page</ div >
130- < div className = "text-xs text-gray-500 leading-4" > Copy page as Markdown for LLMs</ div >
131- </ div >
132- </ button >
133-
134- < Link
135- href = { `/${ pathname } .md` }
136- target = "_blank"
137- rel = "noopener noreferrer"
138- className = { `${ dropdownItemClass } no-underline` }
139- onClick = { ( ) => setIsOpen ( false ) }
140- >
141- < div className = { iconContainerClass } >
142- < Markdown width = { 14 } height = { 14 } />
143- </ div >
144- < div className = "flex-1" >
145- < div className = "font-medium text-gray-900 text-sm leading-5" > View as Markdown</ div >
146- < div className = "text-xs text-gray-500 leading-4" > View this page as plain text</ div >
147- </ div >
148- </ Link >
149- </ div >
150- </ div > ,
151- document . body
152- ) }
114+ { isMounted &&
115+ isOpen &&
116+ createPortal (
117+ < div
118+ ref = { dropdownRef }
119+ className = "fixed w-80 bg-white rounded-xl shadow-lg overflow-hidden z-[9999]"
120+ style = { { ...getDropdownPosition ( ) , border : '1px solid #d1d5db' } }
121+ >
122+ < div className = "p-1" >
123+ < button
124+ onClick = { ( ) => {
125+ copyMarkdownToClipboard ( ) ;
126+ setIsOpen ( false ) ;
127+ } }
128+ className = { `${ dropdownItemClass } border-none cursor-pointer disabled:opacity-50` }
129+ disabled = { isLoading }
130+ >
131+ < div className = { iconContainerClass } >
132+ < Clipboard size = { 14 } />
133+ </ div >
134+ < div className = "flex-1" >
135+ < div className = "font-medium text-gray-900 text-sm leading-5" >
136+ Copy page
137+ </ div >
138+ < div className = "text-xs text-gray-500 leading-4" >
139+ Copy page as Markdown for LLMs
140+ </ div >
141+ </ div >
142+ </ button >
143+
144+ < Link
145+ href = { `/${ pathname } .md` }
146+ target = "_blank"
147+ rel = "noopener noreferrer"
148+ className = { `${ dropdownItemClass } no-underline` }
149+ onClick = { ( ) => setIsOpen ( false ) }
150+ >
151+ < div className = { iconContainerClass } >
152+ < Markdown width = { 14 } height = { 14 } />
153+ </ div >
154+ < div className = "flex-1" >
155+ < div className = "font-medium text-gray-900 text-sm leading-5" >
156+ View as Markdown
157+ </ div >
158+ < div className = "text-xs text-gray-500 leading-4" >
159+ View this page as plain text
160+ </ div >
161+ </ div >
162+ </ Link >
163+ </ div >
164+ </ div > ,
165+ document . body
166+ ) }
153167 </ Fragment >
154168 ) ;
155169}
0 commit comments