From 0b4dc64c63e7fecb82d2be6fe4cd9267c55ee444 Mon Sep 17 00:00:00 2001
From: Eric Bailey <git@esb.lol>
Date: Mon, 14 Oct 2024 10:44:04 -0500
Subject: Add util for link static clicks (#5683)

* Add util for link static clicks

* Format

* Update copy
---
 src/components/Link.tsx | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

(limited to 'src/components/Link.tsx')

diff --git a/src/components/Link.tsx b/src/components/Link.tsx
index fa8fa0cc3..010299dfb 100644
--- a/src/components/Link.tsx
+++ b/src/components/Link.tsx
@@ -329,6 +329,25 @@ export function InlineLinkText({
   )
 }
 
+/**
+ * Utility to create a static `onPress` handler for a `Link` that would otherwise link to a URI
+ *
+ * Example:
+ *   `<Link {...createStaticClick(e => {...})} />`
+ */
+export function createStaticClick(
+  onPressHandler: Exclude<BaseLinkProps['onPress'], undefined>,
+): Pick<BaseLinkProps, 'to' | 'onPress'> {
+  return {
+    to: '#',
+    onPress(e: GestureResponderEvent) {
+      e.preventDefault()
+      onPressHandler(e)
+      return false
+    },
+  }
+}
+
 /**
  * A Pressable that uses useLink to handle navigation. It is unstyled, so can be used in cases where the Button styles
  * in Link are not desired.
-- 
cgit 1.4.1

