1- import { useEffect , useState } from "react" ;
1+ import { useEffect , useRef , useState } from "react" ;
22import { type Resource } from "~/lib/resources.server" ;
33import { transformNpmCommand } from "~/lib/transformNpmCommand" ;
44import type { PackageManager } from "~/lib/transformNpmCommand" ;
55import { DetailsMenu , DetailsPopup } from "./details-menu" ;
66
7- import { Link , useSearchParams , useSubmit } from "@remix-run/react" ;
7+ import { Link , useSearchParams } from "@remix-run/react" ;
88import cx from "clsx" ;
99import iconsHref from "~/icons.svg" ;
1010
@@ -70,18 +70,12 @@ export function InitCodeblock({
7070 // Probably a more elegant solution, but this is what I've got
7171 let [ npxOrNpmMaybe , ...otherCode ] = initCommand . trim ( ) . split ( " " ) ;
7272 let [ copied , setCopied ] = useState ( false ) ;
73- const submit = useSubmit ( ) ;
7473
7574 function handleCopy ( packageManager : PackageManager ) {
7675 setCopied ( true ) ;
7776 navigator . clipboard . writeText (
7877 transformNpmCommand ( npxOrNpmMaybe , otherCode . join ( " " ) , packageManager ) ,
7978 ) ;
80- // This is a hack to close the details menu after clicking
81- submit ( null , {
82- preventScrollReset : true ,
83- replace : true ,
84- } ) ;
8579 }
8680
8781 // Reset copied state after 4 seconds
@@ -134,8 +128,14 @@ type CopyCodeBlockProps = {
134128} ;
135129
136130function CopyCodeBlock ( { copied, onCopy } : CopyCodeBlockProps ) {
131+ const detailsRef = useRef < HTMLDetailsElement > ( null ) ;
137132 return (
138- < DetailsMenu className = "absolute" data-copied = { copied } data-code-block-copy >
133+ < DetailsMenu
134+ className = "absolute"
135+ data-copied = { copied }
136+ data-code-block-copy
137+ ref = { detailsRef }
138+ >
139139 < summary
140140 className = "_no-triangle block outline-offset-2"
141141 data-copied = { copied }
@@ -155,18 +155,17 @@ function CopyCodeBlock({ copied, onCopy }: CopyCodeBlockProps) {
155155 < span className = "sr-only" > Copy code to clipboard</ span >
156156 </ span >
157157 </ summary >
158- < div className = "absolute left-auto right-0 top-10 w-[110px]" >
159- < DetailsPopup
160- // TODO: remove when we get the DetailsPopup figured out
161- className = "w-full" // ehhh, we'll see
162- >
158+ < div className = "absolute right-0 w-28" >
159+ < DetailsPopup >
163160 < div className = "flex flex-col" >
164161 { ( [ "npm" , "yarn" , "pnpm" , "bun" ] as const ) . map ( ( packageManager ) => (
165162 < button
166163 key = { packageManager }
167164 className = "rounded-md p-1.5 text-left text-sm text-gray-700 hover:bg-blue-200/50 hover:text-black dark:text-gray-400 dark:hover:bg-blue-800/50 dark:hover:text-gray-100"
168165 onClick = { ( ) => {
169166 onCopy ( packageManager ) ;
167+ // Close the details menu
168+ detailsRef . current ?. toggleAttribute ( "open" ) ;
170169 } }
171170 >
172171 { packageManager }
0 commit comments