From 31ac25d51048284585f2579cfd4f8da4535fb3e7 Mon Sep 17 00:00:00 2001 From: Aarnav Tale Date: Sat, 1 Feb 2025 18:11:33 -0500 Subject: [PATCH] feat: redesign code and attribute --- app/components/Attribute.tsx | 67 +++++++++++++++++++++++----------- app/components/Code.tsx | 71 ++++++++++++++++++------------------ 2 files changed, 82 insertions(+), 56 deletions(-) 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 ( -
-
+
+
{link ? ( {name} @@ -21,22 +26,42 @@ export default function Attribute({ name, value, link, isCopyable }: Props) { name )}
+
+ {isCopyable ? ( + - ) : ( -
{value}
- )} + await navigator.clipboard.writeText(value); + toast('Copied to clipboard'); + + setTimeout(() => { + for (const svg of svgs) { + svg.toggleAttribute('data-copied', false); + } + }, 1000); + }} + > + {value} + + + + ) : ( + value + )} +
); } diff --git a/app/components/Code.tsx b/app/components/Code.tsx index b8dfad9..25be774 100644 --- a/app/components/Code.tsx +++ b/app/components/Code.tsx @@ -1,52 +1,53 @@ -import { CheckIcon, CopyIcon } from '@primer/octicons-react'; -import { HTMLProps, useState } from 'react'; +import { Check, Copy } from 'lucide-react'; +import { HTMLProps } from 'react'; import cn from '~/utils/cn'; import toast from '~/utils/toast'; -interface Props extends HTMLProps { +export interface CodeProps extends HTMLProps { isCopyable?: boolean; + children: string | string[]; } -export default function Code(props: Props) { - const [isCopied, setIsCopied] = useState(false); - +export default function Code({ isCopyable, children, className }: CodeProps) { return ( - <> - - {props.children} - - {props.isCopyable ? ( + + {isCopyable ? ( - ) : undefined} - + ) : ( + children + )} + ); }