From f4d4c44e20e98644bc3c21fdc3e6e2dc83f0aaaf Mon Sep 17 00:00:00 2001 From: Nishanth Shankar Date: Fri, 11 Feb 2022 13:37:56 +0530 Subject: [PATCH 1/3] Expose onMouse and onTouch functions --- src/lib/Trigger.js | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/src/lib/Trigger.js b/src/lib/Trigger.js index 4b25150..2696c7c 100644 --- a/src/lib/Trigger.js +++ b/src/lib/Trigger.js @@ -25,13 +25,38 @@ function Trigger(props){ }) }, []) - return( + const onMouseOver = () => { + setVisibility(true) + props.onMouseOver && props.onMouseOver() + } + + const onMouseOut = () => { + setVisibility(false) + props.onMouseOut && props.onMouseOut() + } + + const onMouseMove = e => { + getCursorPos(e) + props.onMouseMove && props.onMouseMove(e) + } + + const onTouchStart = () => { + setVisibility(true) + props.onTouchStart && props.onTouchStart() + } + + const onTouchEnd = () => { + setVisibility(false) + props.onTouchStart && props.onTouchStart() + } + + return (
setVisibility(true)} - onMouseOut={() => setVisibility(false)} - onMouseMove={(e) => getCursorPos(e)} - onTouchStart={() => setVisibility(true)} - onTouchEnd={() => setVisibility(false)} + onMouseOver={onMouseOver} + onMouseOut={onMouseOut} + onMouseMove={onMouseMove} + onTouchStart={onTouchStart} + onTouchEnd={onTouchEnd} ref={triggerContainerRef} style={styles} > @@ -42,4 +67,4 @@ function Trigger(props){ Trigger.propTypes = propTypes; -export default Trigger; \ No newline at end of file +export default Trigger; From 99958ade70e31ca3c57fc768e4dab1542e2fefd1 Mon Sep 17 00:00:00 2001 From: Nishanth Shankar Date: Thu, 17 Feb 2022 13:58:54 +0530 Subject: [PATCH 2/3] Change touchStart to touchEnd --- src/lib/Trigger.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/lib/Trigger.js b/src/lib/Trigger.js index 2696c7c..6135b57 100644 --- a/src/lib/Trigger.js +++ b/src/lib/Trigger.js @@ -9,9 +9,9 @@ const propTypes = { getCursorPos: PropTypes.func, } -function Trigger(props){ - const [styles, setStyles] = useState({}); - const { setVisibility, getCursorPos } = props.children.props; +function Trigger (props) { + const [styles, setStyles] = useState({}) + const { setVisibility, getCursorPos } = props.children.props const triggerContainerRef = useRef(null) useEffect(() => { @@ -21,7 +21,7 @@ function Trigger(props){ setStyles({ width: childStyles.getPropertyValue('width'), height: childStyles.getPropertyValue('height'), - margin: childStyles.getPropertyValue('margin') + margin: childStyles.getPropertyValue('margin'), }) }, []) @@ -47,7 +47,7 @@ function Trigger(props){ const onTouchEnd = () => { setVisibility(false) - props.onTouchStart && props.onTouchStart() + props.onTouchEnd && props.onTouchEnd() } return ( @@ -65,6 +65,6 @@ function Trigger(props){ ) } -Trigger.propTypes = propTypes; +Trigger.propTypes = propTypes -export default Trigger; +export default Trigger From f6f0fc38cc59f709743dc63fc9e9fa7a81d58371 Mon Sep 17 00:00:00 2001 From: Nishanth Shankar Date: Thu, 17 Feb 2022 14:00:45 +0530 Subject: [PATCH 3/3] Expose event for mouseEvents --- src/lib/Trigger.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/Trigger.js b/src/lib/Trigger.js index 6135b57..40fce7c 100644 --- a/src/lib/Trigger.js +++ b/src/lib/Trigger.js @@ -25,14 +25,14 @@ function Trigger (props) { }) }, []) - const onMouseOver = () => { + const onMouseOver = e => { setVisibility(true) - props.onMouseOver && props.onMouseOver() + props.onMouseOver && props.onMouseOver(e) } - const onMouseOut = () => { + const onMouseOut = e => { setVisibility(false) - props.onMouseOut && props.onMouseOut() + props.onMouseOut && props.onMouseOut(e) } const onMouseMove = e => { @@ -40,14 +40,14 @@ function Trigger (props) { props.onMouseMove && props.onMouseMove(e) } - const onTouchStart = () => { + const onTouchStart = e => { setVisibility(true) - props.onTouchStart && props.onTouchStart() + props.onTouchStart && props.onTouchStart(e) } - const onTouchEnd = () => { + const onTouchEnd = e => { setVisibility(false) - props.onTouchEnd && props.onTouchEnd() + props.onTouchEnd && props.onTouchEnd(e) } return (