headplane/app/components/Attribute.tsx

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-12-31 10:30:14 +05:30
import { CopyIcon } from '@primer/octicons-react';
import { toast } from './Toaster';
2024-03-26 09:28:52 -04:00
2024-05-15 21:52:19 -04:00
interface Props {
2024-12-31 10:30:14 +05:30
name: string;
value: string;
isCopyable?: boolean;
link?: string;
2024-03-26 09:28:52 -04:00
}
export default function Attribute({ name, value, link, isCopyable }: Props) {
2024-12-31 10:30:14 +05:30
const canCopy = isCopyable ?? false;
2024-03-26 09:28:52 -04:00
return (
2024-05-15 21:52:19 -04:00
<dl className="flex gap-1 text-sm w-full">
<dt className="w-1/2 shrink-0 min-w-0 truncate text-gray-700 dark:text-gray-300 py-1">
{link ? (
<a className="hover:underline" href={link}>
{name}
</a>
2024-12-31 10:30:14 +05:30
) : (
name
)}
2024-03-26 09:28:52 -04:00
</dt>
2024-12-31 10:30:14 +05:30
{canCopy ? (
<button
type="button"
className="focus:outline-none flex items-center gap-x-1 truncate hover:bg-zinc-100 dark:hover:bg-zinc-800 rounded-md"
onClick={async () => {
await navigator.clipboard.writeText(value);
toast(`Copied ${name}`);
}}
>
<dd className="min-w-0 truncate px-2 py-1">{value}</dd>
<CopyIcon className="text-gray-600 dark:text-gray-200 pr-2 w-max h-3" />
</button>
) : (
<dd className="min-w-0 truncate px-2 py-1">{value}</dd>
)}
2024-03-26 09:28:52 -04:00
</dl>
2024-12-31 10:30:14 +05:30
);
2024-03-26 09:28:52 -04:00
}