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

ConnectionTraceId.tsx

53 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" ? gt`Long press to copy the trace ID` : gt`Copies the trace ID`
24 }
25 accessibilityLabel={gt`Copy trace ID ${{ traceId }}`}
26 accessibilityRole="button"
27 accessibilityActions={[{ name: "activate", label: gt`Copy trace ID` }]}
28 onAccessibilityAction={(event) => {
29 event.stopPropagation();
30 if (event.nativeEvent.actionName === "activate") copy();
31 }}
32 className={cn(
33 "underline decoration-dotted",
34 tone === "danger" ? "text-danger-foreground" : "text-foreground-muted",
35 )}
36 onLongPress={
37 activation === "longPress"
38 ? (event) => {
39 event.stopPropagation();
40 copy();
41 }
42 : undefined
43 }
44 onPress={(event) => {
45 event.stopPropagation();
46 if (activation === "press") copy();
47 }}
48 >
49 {traceId}
50 </Text>
51 </>
52 );