Add util for link static clicks (#5683)

* Add util for link static clicks

* Format

* Update copy
This commit is contained in:
Eric Bailey
2024-10-14 10:44:04 -05:00
committed by GitHub
parent a445489b53
commit 0b4dc64c63
2 changed files with 26 additions and 21 deletions
+19
View File
@@ -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.