29 lines
547 B
TypeScript
29 lines
547 B
TypeScript
/**
|
|
* Copyright (c) 2025 misties
|
|
* 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>
|
|
);
|
|
}
|