Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions apps/web/src/components/copyable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@ import { CheckIcon, CopyIcon } from "@phosphor-icons/react";
import { useState } from "react";

import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";

/** A shell command to run by hand, or a value to paste elsewhere, with a copy button that confirms. */
export function CopyCommand({ command, label = "Copy command" }: { command: string; label?: string }) {
const [copied, setCopied] = useState(false);
return (
<span className="flex min-w-0 items-center gap-1 rounded-lg border border-edge bg-ink/3 py-1 pr-1 pl-3">
<code className="min-w-0 flex-1 truncate font-mono text-xs" title={command}>
{command}
</code>
<Button
size="icon-xs"
variant="ghost"
aria-label={label}
title="Copy"
onClick={() =>
void navigator.clipboard.writeText(command).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
})
}
>
{copied ? <CheckIcon /> : <CopyIcon />}
</Button>
<CopyButton value={command} label={label} />
</span>
);
}

/** Copies a value, and shows a check for a moment once it has. */
export function CopyButton({ value, label, className }: { value: string; label: string; className?: string }) {
const [copied, setCopied] = useState(false);
return (
<Button
// Inside a form it would otherwise submit it.
type="button"
size="icon-xs"
variant="ghost"
aria-label={label}
title="Copy"
className={cn("relative before:absolute before:-inset-2 before:content-['']", className)}
onClick={() =>
void navigator.clipboard.writeText(value).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
})
}
>
{copied ? <CheckIcon /> : <CopyIcon />}
</Button>
);
}
4 changes: 2 additions & 2 deletions apps/web/src/components/ui/alert-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function AlertDialogFooter({ className, ...props }: React.ComponentProps<"div">)
<div
data-slot="alert-dialog-footer"
className={cn(
"flex flex-col-reverse gap-2 rounded-b-2xl border-t border-edge bg-ink/4 px-6 py-4 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
"flex flex-col-reverse gap-2 px-6 pb-6 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
className,
)}
{...props}
Expand Down Expand Up @@ -133,7 +133,7 @@ function AlertDialogAction({

function AlertDialogCancel({
className,
variant = "outline",
variant = "ghost",
size = "default",
...props
}: React.ComponentProps<typeof AlertDialogPrimitive.Cancel> &
Expand Down
9 changes: 7 additions & 2 deletions apps/web/src/settings/blocks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,17 +120,22 @@ export function DialogRow({
title,
description,
htmlFor,
top = false,
children,
}: {
title: ReactNode;
description: ReactNode;
/** The field the title labels. */
htmlFor?: string | undefined;
/** Title and field share their top line, for a field with a message line under it. */
top?: boolean;
children: ReactNode;
}) {
return (
<div className="grid items-center gap-x-6 gap-y-2 px-5 py-4 sm:grid-cols-[1fr_16rem]">
<span className="flex flex-col gap-1">
<div
className={`grid gap-x-6 gap-y-2 px-5 py-4 sm:grid-cols-[1fr_16rem] ${top ? "items-start" : "items-center"}`}
>
<span className={`flex flex-col gap-1 ${top ? "sm:pt-1" : ""}`}>
{htmlFor === undefined ? (
<span className="font-medium">{title}</span>
) : (
Expand Down
13 changes: 10 additions & 3 deletions apps/web/src/settings/machines/machine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,14 @@ function Detail({
<Sub
title={server.name}
description={
<span className="flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1">
<span className="flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-xs">
<Status server={server} />
{workspace !== undefined && <span className="text-xs">{linkText(membership, workspace)}</span>}
{workspace !== undefined && linkText(membership, workspace) !== undefined && (
<>
<span aria-hidden>·</span>
<span>{linkText(membership, workspace)}</span>
</>
)}
</span>
}
>
Expand Down Expand Up @@ -213,7 +218,9 @@ function Detail({
</Row>
{server.paired && server.fingerprint !== null && (
<Row title="Machine Key" description="Printed by codework service pair">
<CopyCommand command={server.fingerprint} label="Copy Machine Key" />
<div className="w-full min-w-0 shrink-0 @min-[560px]:w-64">
<CopyCommand command={server.fingerprint} label="Copy Machine Key" />
</div>
</Row>
)}
<Row title="Version">
Expand Down
Loading