about summary refs log tree commit diff
path: root/src/view/com/util/PressableWithHover.tsx
diff options
context:
space:
mode:
authorOllie Hsieh <renahlee@outlook.com>2023-04-19 18:05:10 -0700
committerGitHub <noreply@github.com>2023-04-19 20:05:10 -0500
commitb24ba3adc93cf940eb936309ae73a2c205eaef24 (patch)
tree373337a5f364fd1d83010c33bae3d878437d4ca7 /src/view/com/util/PressableWithHover.tsx
parent1472bd4f173a483e5f1a91514244fecaec23808f (diff)
downloadvoidsky-b24ba3adc93cf940eb936309ae73a2c205eaef24.tar.zst
Add cursor to clickable elements (#491)
* Add cursor to clickable elements

* Add cursor to clickable elements

* Update per comments

* Fix word wrap in notifications

* Center the web login-load screen

* Add hover states on web

* Fix lint

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/view/com/util/PressableWithHover.tsx')
-rw-r--r--src/view/com/util/PressableWithHover.tsx45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/view/com/util/PressableWithHover.tsx b/src/view/com/util/PressableWithHover.tsx
new file mode 100644
index 000000000..09ccb6a2d
--- /dev/null
+++ b/src/view/com/util/PressableWithHover.tsx
@@ -0,0 +1,45 @@
+import React, {
+  useState,
+  useCallback,
+  PropsWithChildren,
+  forwardRef,
+  Ref,
+} from 'react'
+import {Pressable, PressableProps, StyleProp, ViewStyle} from 'react-native'
+import {addStyle} from 'lib/styles'
+
+interface PressableWithHover extends PressableProps {
+  hoverStyle: StyleProp<ViewStyle>
+}
+
+export const PressableWithHover = forwardRef(
+  (
+    {
+      children,
+      style,
+      hoverStyle,
+      ...props
+    }: PropsWithChildren<PressableWithHover>,
+    ref: Ref<any>,
+  ) => {
+    const [isHovering, setIsHovering] = useState(false)
+
+    const onHoverIn = useCallback(() => setIsHovering(true), [setIsHovering])
+    const onHoverOut = useCallback(() => setIsHovering(false), [setIsHovering])
+    style =
+      typeof style !== 'function' && isHovering
+        ? addStyle(style, hoverStyle)
+        : style
+
+    return (
+      <Pressable
+        {...props}
+        style={style}
+        onHoverIn={onHoverIn}
+        onHoverOut={onHoverOut}
+        ref={ref}>
+        {children}
+      </Pressable>
+    )
+  },
+)