| 1 | import { AppText as Text } from "../../components/AppText"; |
| 2 | import { cn } from "../../lib/cn"; |
| 3 | import { copyTextWithHaptic } from "../../lib/copyTextWithHaptic"; |
| 4 | |
| 5 | /** Inline trace control; disclosure rows reserve ordinary taps for their own navigation. */ |
| 6 | export 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 copy = () => copyTextWithHaptic(traceId, { target: "connection-trace-id" }); |
| 16 | return ( |
| 17 | <> |
| 18 | {" Trace ID: "} |
| 19 | <Text |
| 20 | accessibilityHint={ |
| 21 | activation === "longPress" ? "Long press to copy the trace ID" : "Copies the trace ID" |
| 22 | } |
| 23 | accessibilityLabel={`Copy trace ID ${traceId}`} |
| 24 | accessibilityRole="button" |
| 25 | accessibilityActions={[{ name: "activate", label: "Copy trace ID" }]} |
| 26 | onAccessibilityAction={(event) => { |
| 27 | event.stopPropagation(); |
| 28 | if (event.nativeEvent.actionName === "activate") copy(); |
| 29 | }} |
| 30 | className={cn( |
| 31 | "underline decoration-dotted", |
| 32 | tone === "danger" ? "text-danger-foreground" : "text-foreground-muted", |
| 33 | )} |
| 34 | onLongPress={ |
| 35 | activation === "longPress" |
| 36 | ? (event) => { |
| 37 | event.stopPropagation(); |
| 38 | copy(); |
| 39 | } |
| 40 | : undefined |
| 41 | } |
| 42 | onPress={(event) => { |
| 43 | event.stopPropagation(); |
| 44 | if (activation === "press") copy(); |
| 45 | }} |
| 46 | > |
| 47 | {traceId} |
| 48 | </Text> |
| 49 | </> |
| 50 | ); |
| 51 | } |