feat: CopyableCode styles and remove DEV name fallback

This commit is contained in:
GonnaHetzMe committed 2026-03-25 17:25:52 +01:00
1 parent 4cdb712013
commit 5b9ff7acb3
3 files changed
+40 -16

No files matched your search

@@ -61,7 +61,12 @@ export function ArmorPlateDisplay() {
<> <>
<Text mt="2" color="gray" size="2"> <Text mt="2" color="gray" size="2">
<b>DEV:</b>{" "} <b>DEV:</b>{" "}
<CopyableCode copy={highlightArmor.name}> <CopyableCode
copy={highlightArmor.name}
variant="soft"
highContrast
color="gray"
>
{highlightArmor.name} {highlightArmor.name}
</CopyableCode> </CopyableCode>
</Text> </Text>
@@ -1,29 +1,37 @@
import { Code, Tooltip } from "@radix-ui/themes"; import { Code, Tooltip, type CodeProps } from "@radix-ui/themes";
import { useState, type ReactNode } from "react"; import { useState } from "react";
import { useLocale } from "../hooks/useLocale"; import { useLocale } from "../hooks/useLocale";
interface CopyableCodeProps { export interface CopyableCodeProps extends CodeProps {
copy?: string; 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 [copied, setCopied] = useState(false);
const { strings } = useLocale(); const { strings } = useLocale();
return ( return (
<Tooltip open={copied} content={strings.website.common.copy_button.copied}> <Tooltip open={copied} content={strings.website.common.copy_button.copied}>
<Code <Code
variant="soft" {...props}
highContrast style={{ ...(copy ? { cursor: "copy" } : {}), ...style }}
color="gray" onClick={(event) => {
style={{ cursor: copy ? "copy" : "default" }} onClick?.(event);
onClick={() => {
if (!copy) return; if (!copy) return;
navigator.clipboard.writeText(copy); navigator.clipboard.writeText(copy);
setCopied(true); setCopied(true);
}} }}
onPointerLeave={() => setCopied(false)} onPointerLeave={(event) => {
onPointerLeave?.(event);
setCopied(false);
}}
> >
{children} {children}
</Code> </Code>
@@ -24,6 +24,7 @@ export function MetaSection() {
const protagonist = Duel.use((state) => state.protagonist.tank); const protagonist = Duel.use((state) => state.protagonist.tank);
const ClassIcon = classIcons[protagonist.class]; const ClassIcon = classIcons[protagonist.class];
const { locale, strings } = useLocale(); const { locale, strings } = useLocale();
const devName = (protagonist as { dev_name?: string }).dev_name;
return ( return (
<Flex justify="center" mt="-9"> <Flex justify="center" mt="-9">
@@ -102,17 +103,27 @@ export function MetaSection() {
<Listing <Listing
label={strings.website.tools.tankopedia.meta.dev_id} label={strings.website.tools.tankopedia.meta.dev_id}
> >
<CopyableCode copy={`${protagonist.id}`}> <CopyableCode
copy={`${protagonist.id}`}
variant="soft"
highContrast
color="gray"
>
{protagonist.id} {protagonist.id}
</CopyableCode> </CopyableCode>
</Listing> </Listing>
)} )}
{developerMode && ( {developerMode && devName && (
<Listing <Listing
label={strings.website.tools.tankopedia.meta.dev_name} label={strings.website.tools.tankopedia.meta.dev_name}
> >
<CopyableCode copy={protagonist.dev_name}> <CopyableCode
{protagonist.dev_name ?? '-'} copy={devName}
variant="soft"
highContrast
color="gray"
>
{devName}
</CopyableCode> </CopyableCode>
</Listing> </Listing>
)} )}