1
- import { useEffect , useState } from "react" ;
1
+ import { useEffect , useRef , useState } from "react" ;
2
2
import { type Resource } from "~/lib/resources.server" ;
3
3
import { transformNpmCommand } from "~/lib/transformNpmCommand" ;
4
4
import type { PackageManager } from "~/lib/transformNpmCommand" ;
5
5
import { DetailsMenu , DetailsPopup } from "./details-menu" ;
6
6
7
- import { Link , useSearchParams , useSubmit } from "@remix-run/react" ;
7
+ import { Link , useSearchParams } from "@remix-run/react" ;
8
8
import cx from "clsx" ;
9
9
import iconsHref from "~/icons.svg" ;
10
10
@@ -70,18 +70,12 @@ export function InitCodeblock({
70
70
// Probably a more elegant solution, but this is what I've got
71
71
let [ npxOrNpmMaybe , ...otherCode ] = initCommand . trim ( ) . split ( " " ) ;
72
72
let [ copied , setCopied ] = useState ( false ) ;
73
- const submit = useSubmit ( ) ;
74
73
75
74
function handleCopy ( packageManager : PackageManager ) {
76
75
setCopied ( true ) ;
77
76
navigator . clipboard . writeText (
78
77
transformNpmCommand ( npxOrNpmMaybe , otherCode . join ( " " ) , packageManager ) ,
79
78
) ;
80
- // This is a hack to close the details menu after clicking
81
- submit ( null , {
82
- preventScrollReset : true ,
83
- replace : true ,
84
- } ) ;
85
79
}
86
80
87
81
// Reset copied state after 4 seconds
@@ -134,8 +128,14 @@ type CopyCodeBlockProps = {
134
128
} ;
135
129
136
130
function CopyCodeBlock ( { copied, onCopy } : CopyCodeBlockProps ) {
131
+ const detailsRef = useRef < HTMLDetailsElement > ( null ) ;
137
132
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
+ >
139
139
< summary
140
140
className = "_no-triangle block outline-offset-2"
141
141
data-copied = { copied }
@@ -155,18 +155,17 @@ function CopyCodeBlock({ copied, onCopy }: CopyCodeBlockProps) {
155
155
< span className = "sr-only" > Copy code to clipboard</ span >
156
156
</ span >
157
157
</ 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 >
163
160
< div className = "flex flex-col" >
164
161
{ ( [ "npm" , "yarn" , "pnpm" , "bun" ] as const ) . map ( ( packageManager ) => (
165
162
< button
166
163
key = { packageManager }
167
164
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"
168
165
onClick = { ( ) => {
169
166
onCopy ( packageManager ) ;
167
+ // Close the details menu
168
+ detailsRef . current ?. toggleAttribute ( "open" ) ;
170
169
} }
171
170
>
172
171
{ packageManager }
0 commit comments