-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30339 from software-mansion-labs/ts-migration/Hov…
…erable [TS migration] Migrate Hoverable
- Loading branch information
Showing
5 changed files
with
86 additions
and
108 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import {View} from 'react-native'; | ||
import HoverableProps from './types'; | ||
|
||
/** | ||
* On mobile, there is no concept of hovering, so we return a plain wrapper around the component's children, | ||
* where the hover state is always false. | ||
*/ | ||
function Hoverable({children}: HoverableProps) { | ||
const childrenWithHoverState = typeof children === 'function' ? children(false) : children; | ||
|
||
return <View>{childrenWithHoverState}</View>; | ||
} | ||
|
||
Hoverable.displayName = 'Hoverable'; | ||
|
||
export default Hoverable; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import {ReactElement} from 'react'; | ||
|
||
type HoverableProps = { | ||
/** Children to wrap with Hoverable. */ | ||
children: ((isHovered: boolean) => ReactElement) | ReactElement; | ||
|
||
/** Whether to disable the hover action */ | ||
disabled?: boolean; | ||
|
||
/** Function that executes when the mouse moves over the children. */ | ||
onHoverIn?: () => void; | ||
|
||
/** Function that executes when the mouse leaves the children. */ | ||
onHoverOut?: () => void; | ||
|
||
/** Direct pass-through of React's onMouseEnter event. */ | ||
onMouseEnter?: (event: MouseEvent) => void; | ||
|
||
/** Direct pass-through of React's onMouseLeave event. */ | ||
onMouseLeave?: (event: MouseEvent) => void; | ||
|
||
/** Decides whether to handle the scroll behaviour to show hover once the scroll ends */ | ||
shouldHandleScroll?: boolean; | ||
}; | ||
|
||
export default HoverableProps; |