Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 715258c

Browse files
committedFeb 15, 2024·
Adjust width override and fix submission hack for closing details
1 parent 8f2f1cc commit 715258c

File tree

4 files changed

+21
-30
lines changed

4 files changed

+21
-30
lines changed
 

‎app/routes/docs.$lang.$ref.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ function VersionSelect() {
268268
</svg>
269269
</summary>
270270
<DetailsPopup>
271-
<div className="flex flex-col gap-px">
271+
<div className="flex w-40 flex-col gap-px">
272272
<VersionsLabel label="Branches" />
273273
{branches.map((branch) => {
274274
return (
@@ -390,7 +390,7 @@ function ColorSchemeToggle() {
390390
replace
391391
action="/_actions/color-scheme"
392392
method="post"
393-
className="flex flex-col gap-px"
393+
className="flex w-40 flex-col gap-px"
394394
>
395395
<input
396396
type="hidden"
@@ -547,7 +547,7 @@ function HeaderMenuMobile({ className = "" }: { className: string }) {
547547
</svg>
548548
</summary>
549549
<DetailsPopup>
550-
<div className="flex flex-col">
550+
<div className="flex w-40 flex-col">
551551
<HeaderMenuLink to="/docs">Docs</HeaderMenuLink>
552552
<HeaderMenuLink to="/blog">Blog</HeaderMenuLink>
553553
<HeaderMenuLink to="/showcase">Showcase</HeaderMenuLink>

‎app/ui/details-menu.tsx

+4-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { forwardRef, useState, useRef, useEffect } from "react";
2-
import type { PropsWithChildren } from "react";
32
import { useLocation, useNavigation } from "@remix-run/react";
43
import cx from "clsx";
54

@@ -80,21 +79,14 @@ export const DetailsMenu = forwardRef<
8079
DetailsMenu.displayName = "DetailsMenu";
8180

8281
type DetailsPopupProps = {
82+
children: React.ReactNode;
8383
className?: string;
8484
};
8585

86-
export function DetailsPopup({
87-
children,
88-
className,
89-
}: PropsWithChildren<DetailsPopupProps>) {
86+
export function DetailsPopup({ children, className }: DetailsPopupProps) {
9087
return (
91-
// TODO: remove the width being defined here. Seems like it should be a min-width: fit-content or something, and anything more specific defined by the children passed in (or a className)
92-
<div className={cx("absolute right-0 z-20 w-40 md:left-0", className)}>
93-
<div
94-
className={
95-
"relative top-1 rounded-md border border-gray-100 bg-white p-1 shadow-sm dark:border-gray-800 dark:bg-gray-900"
96-
}
97-
>
88+
<div className={cx("absolute right-0 z-20 min-w-max md:left-0", className)}>
89+
<div className="relative top-1 rounded-md border border-gray-100 bg-white p-1 shadow-sm dark:border-gray-800 dark:bg-gray-900">
9890
{children}
9991
</div>
10092
</div>

‎app/ui/header.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ function HeaderMenuMobile({ className = "" }: { className: string }) {
6565
</svg>
6666
</summary>
6767
<DetailsPopup>
68-
<nav className="flex flex-col gap-2 px-2 py-2.5">
68+
<nav className="flex w-40 flex-col gap-2 px-2 py-2.5">
6969
<HeaderLink to="/docs/en/main">Docs</HeaderLink>
7070
<HeaderLink to="/blog">Blog</HeaderLink>
7171
<HeaderLink to="/showcase">Showcase</HeaderLink>

‎app/ui/resources.tsx

+13-14
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { useEffect, useState } from "react";
1+
import { useEffect, useRef, useState } from "react";
22
import { type Resource } from "~/lib/resources.server";
33
import { transformNpmCommand } from "~/lib/transformNpmCommand";
44
import type { PackageManager } from "~/lib/transformNpmCommand";
55
import { DetailsMenu, DetailsPopup } from "./details-menu";
66

7-
import { Link, useSearchParams, useSubmit } from "@remix-run/react";
7+
import { Link, useSearchParams } from "@remix-run/react";
88
import cx from "clsx";
99
import 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

136130
function 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

Comments
 (0)
Please sign in to comment.