diff --git a/app/components/Attribute.tsx b/app/components/Attribute.tsx index de35830..91bf246 100644 --- a/app/components/Attribute.tsx +++ b/app/components/Attribute.tsx @@ -1,18 +1,23 @@ -import { CopyIcon } from '@primer/octicons-react'; +import { Check, Copy } from 'lucide-react'; +import cn from '~/utils/cn'; import toast from '~/utils/toast'; -interface Props { +export interface AttributeProps { name: string; value: string; isCopyable?: boolean; link?: string; } -export default function Attribute({ name, value, link, isCopyable }: Props) { - const canCopy = isCopyable ?? false; +export default function Attribute({ + name, + value, + link, + isCopyable, +}: AttributeProps) { return ( -
- {props.children}
-
- {props.isCopyable ? (
+
+ {isCopyable ? (
{
- if (!props.children) {
- throw new Error('Made copyable without children');
+ className="inline-flex items-center gap-x-1"
+ onClick={async (event) => {
+ const text = Array.isArray(children)
+ ? children.join(' ')
+ : children;
+
+ const svgs = event.currentTarget.querySelectorAll('svg');
+ for (const svg of svgs) {
+ svg.toggleAttribute('data-copied', true);
}
- navigator.clipboard.writeText(props.children.join(''));
+ await navigator.clipboard.writeText(text);
toast('Copied to clipboard');
- setIsCopied(true);
- setTimeout(() => setIsCopied(false), 1000);
+
+ setTimeout(() => {
+ for (const svg of svgs) {
+ svg.toggleAttribute('data-copied', false);
+ }
+ }, 1000);
}}
>
- {isCopied ? (
-
- ) : (
-
- )}
+ {children}
+
+
- ) : undefined}
- >
+ ) : (
+ children
+ )}
+
);
}