Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ConnectionTraceId.tsx

55 lines1.6 KB

1import { useGT } from "gt-react-native";
2import { AppText as Text } from "../../components/ui/AppText";
3import { cn } from "../../lib/cn";
4import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic";
5​
6export function ConnectionTraceId({
7 traceId,
8 tone = "muted",
9 activation = "press",
10}: {
11 readonly traceId: string;
12 readonly tone?: "muted" | "danger";
13 readonly activation?: "press" | "longPress";
14}) {
15 const gt = useGT();
16 const copy = () => copyTextWithHaptic(traceId, { target: "connection-trace-id" });
17 return (
18 <>
19 {" "}
20 {gt("Trace ID:")}{" "}
21 <Text
22 accessibilityHint={
23 activation === "longPress"
24 ? gt("Long press to copy the trace ID")
25 : gt("Copies the trace ID")
26 }
27 accessibilityLabel={gt("Copy trace ID {traceId}", { traceId })}
28 accessibilityRole="button"
29 accessibilityActions={[{ name: "activate", label: gt("Copy trace ID") }]}
30 onAccessibilityAction={(event) => {
31 event.stopPropagation();
32 if (event.nativeEvent.actionName === "activate") copy();
33 }}
34 className={cn(
35 "underline decoration-dotted",
36 tone === "danger" ? "text-danger-foreground" : "text-foreground-muted",
37 )}
38 onLongPress={
39 activation === "longPress"
40 ? (event) => {
41 event.stopPropagation();
42 copy();
43 }
44 : undefined
45 }
46 onPress={(event) => {
47 event.stopPropagation();
48 if (activation === "press") copy();
49 }}
50 >
51 {traceId}
52 </Text>
53 </>
54 );