diff options
Diffstat (limited to 'src/components/Link.tsx')
-rw-r--r-- | src/components/Link.tsx | 19 |
1 files changed, 19 insertions, 0 deletions
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 @@ -330,6 +330,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. * @param displayText |