Add util for link static clicks

This commit is contained in:
Eric Bailey
2024-10-10 18:05:35 -05:00
parent e1a696bcbb
commit e5a4b8cb4d
2 changed files with 24 additions and 19 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.