mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-22 19:19:52 +02:00
feat: CopyableCode styles and remove DEV name fallback
This commit is contained in:
1 parent
4cdb712013
commit
5b9ff7acb3
3 files changed
+40
-16
No files matched your search
@@ -1,29 +1,37 @@
|
||||
import { Code, Tooltip } from "@radix-ui/themes";
|
||||
import { useState, type ReactNode } from "react";
|
||||
import { Code, Tooltip, type CodeProps } from "@radix-ui/themes";
|
||||
import { useState } from "react";
|
||||
import { useLocale } from "../hooks/useLocale";
|
||||
|
||||
interface CopyableCodeProps {
|
||||
export interface CopyableCodeProps extends CodeProps {
|
||||
copy?: string;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export function CopyableCode({ copy, children }: CopyableCodeProps) {
|
||||
export function CopyableCode({
|
||||
copy,
|
||||
onClick,
|
||||
onPointerLeave,
|
||||
style,
|
||||
children,
|
||||
...props
|
||||
}: CopyableCodeProps) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const { strings } = useLocale();
|
||||
|
||||
return (
|
||||
<Tooltip open={copied} content={strings.website.common.copy_button.copied}>
|
||||
<Code
|
||||
variant="soft"
|
||||
highContrast
|
||||
color="gray"
|
||||
style={{ cursor: copy ? "copy" : "default" }}
|
||||
onClick={() => {
|
||||
{...props}
|
||||
style={{ ...(copy ? { cursor: "copy" } : {}), ...style }}
|
||||
onClick={(event) => {
|
||||
onClick?.(event);
|
||||
if (!copy) return;
|
||||
navigator.clipboard.writeText(copy);
|
||||
setCopied(true);
|
||||
}}
|
||||
onPointerLeave={() => setCopied(false)}
|
||||
onPointerLeave={(event) => {
|
||||
onPointerLeave?.(event);
|
||||
setCopied(false);
|
||||
}}
|
||||
>
|
||||
{children}
|
||||
</Code>
|
||||
|
||||
Reference in new issue
Block a user