({
className,
title,
allowCopy = true,
icon,
ref,
...props
}: PreProps)
| 42 | } |
| 43 | |
| 44 | export const PlainCode = ({ |
| 45 | className, |
| 46 | title, |
| 47 | allowCopy = true, |
| 48 | icon, |
| 49 | ref, |
| 50 | ...props |
| 51 | }: PreProps) => { |
| 52 | const areaRef = useRef<HTMLDivElement>(null) |
| 53 | const { copy, copied } = useClipboard() |
| 54 | const onCopy = useCallback(async () => { |
| 55 | const pre = areaRef.current?.getElementsByTagName('pre').item(0) |
| 56 | |
| 57 | if (!pre) return |
| 58 | |
| 59 | const clone = pre.cloneNode(true) as HTMLElement |
| 60 | for (const node of clone.querySelectorAll('.nd-copy-ignore')) { |
| 61 | node.remove() |
| 62 | } |
| 63 | window.aurelie?.track?.('copy', { |
| 64 | name: clone.textContent, |
| 65 | }) |
| 66 | await copy(clone.textContent ?? '') |
| 67 | }, [copy]) |
| 68 | return ( |
| 69 | <figure |
| 70 | ref={ref} |
| 71 | {...props} |
| 72 | className={twMerge( |
| 73 | 'not-prose group relative my-6 max-w-4xl overflow-hidden rounded-lg border bg-secondary/50 text-sm/6', |
| 74 | className |
| 75 | )} |
| 76 | > |
| 77 | {title ? ( |
| 78 | <div className="flex w-full flex-row items-center gap-2 border-b px-4 py-1.5"> |
| 79 | {icon ? ( |
| 80 | <div |
| 81 | className="text-muted-fg [&_svg]:size-3.5" |
| 82 | dangerouslySetInnerHTML={ |
| 83 | typeof icon === 'string' |
| 84 | ? { |
| 85 | __html: icon, |
| 86 | } |
| 87 | : undefined |
| 88 | } |
| 89 | > |
| 90 | {typeof icon !== 'string' ? icon : null} |
| 91 | </div> |
| 92 | ) : null} |
| 93 | <figcaption className="flex-1 truncate text-muted-fg">{title}</figcaption> |
| 94 | {allowCopy ? ( |
| 95 | <CopyButton |
| 96 | className="absolute top-1 right-1 z-2 grid size-10 place-content-center" |
| 97 | onPress={onCopy} |
| 98 | isCopied={copied} |
| 99 | /> |
| 100 | ) : null} |
| 101 | </div> |
nothing calls this directly
no test coverage detected