web/islands/Code.tsx
2025-11-01 23:46:32 -03:00

29 lines
544 B
TypeScript

/**
* Copyright (c) 2025 xwra
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import { ComponentChildren } from "preact";
interface CodeProps {
children: ComponentChildren;
[key: string]: any;
}
export default function Code({ children, ...props }: CodeProps) {
const handleClick = () => {
if (typeof children === "string") {
navigator.clipboard.writeText(children);
}
};
return (
<button
class="inline-code"
onClick={handleClick}
title="Click to copy"
{...props}
>
<span>{children}</span>
</button>
);
}