diff options
author | Eric Bailey <git@esb.lol> | 2024-10-14 10:44:04 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-14 10:44:04 -0500 |
commit | 0b4dc64c63e7fecb82d2be6fe4cd9267c55ee444 (patch) | |
tree | 20a0d6ed824e48352fc66197006ee67c67609cfd /src/components/Link.tsx | |
parent | a445489b53725f3c87f6fa43b904015e910dbfea (diff) | |
download | voidsky-0b4dc64c63e7fecb82d2be6fe4cd9267c55ee444.tar.zst |
Add util for link static clicks (#5683)
* Add util for link static clicks * Format * Update copy
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 |