Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove hover function #4830

Merged
merged 13 commits into from
Feb 1, 2024
47 changes: 2 additions & 45 deletions website/src/components/detailsToggle/index.js
Original file line number Diff line number Diff line change
@@ -1,65 +1,22 @@
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import styles from './styles.module.css';

function detailsToggle({ children, alt_header = null }) {
const [isOn, setOn] = useState(false);
const [isScrolling, setIsScrolling] = useState(false); // New state to track scrolling
const [hoverTimeout, setHoverTimeout] = useState(null);

const handleToggleClick = () => {
setOn(current => !current); // Toggle the current state
setOn(current => !current);
};

const handleMouseEnter = () => {
if (isOn || isScrolling) return; // Ignore hover if already open or if scrolling
const timeout = setTimeout(() => {
if (!isScrolling) setOn(true);
}, 700); //
setHoverTimeout(timeout);
};

const handleMouseLeave = () => {
if (!isOn) {
clearTimeout(hoverTimeout);
setOn(false);
}
};

const handleScroll = () => {
setIsScrolling(true);
clearTimeout(hoverTimeout);
//setOn(false);


// Reset scrolling state after a delay
setTimeout(() => {
setIsScrolling(false);
}, 800);
};

useEffect(() => {
window.addEventListener('scroll', handleScroll);
return () => {
window.removeEventListener('scroll', handleScroll);
};
}, []);

useEffect(() => {
return () => clearTimeout(hoverTimeout);
}, [hoverTimeout]);

return (
<div className='detailsToggle'>
<span
className={styles.link}
onClick={handleToggleClick}
onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave}
>
<span className={`${styles.toggle} ${isOn ? null : styles.toggleUpsideDown}`}></span>&nbsp;
<span className={styles.headerText}>{alt_header}</span>
{/* Visual disclaimer */}
<small className={styles.disclaimer}>Hover to view</small>
</span>
<div
style={{ display: isOn ? 'block' : 'none' }}
Expand Down
32 changes: 3 additions & 29 deletions website/src/components/faqs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ function FAQ({ path, alt_header = null }) {
const [isOn, setOn] = useState(false);
const [filePath, setFilePath] = useState(path);
const [fileContent, setFileContent] = useState({});
const [hoverTimeout, setHoverTimeout] = useState(null);

// Get all faq file paths from plugin
const { faqFiles } = usePluginData('docusaurus-build-global-data-plugin');
Expand Down Expand Up @@ -37,40 +36,15 @@ function FAQ({ path, alt_header = null }) {
}
}, [filePath])

const handleMouseEnter = () => {
setHoverTimeout(setTimeout(() => {
setOn(true);
}, 500));
};

const handleMouseLeave = () => {
if (!isOn) {
clearTimeout(hoverTimeout);
setOn(false);
}
};

useEffect(() => {
return () => {
if (hoverTimeout) {
clearTimeout(hoverTimeout);
}
};
}, [hoverTimeout]);

const toggleOn = () => {
if (hoverTimeout) {
clearTimeout(hoverTimeout);
}
const toggleOn = function () {
setOn(!isOn);
};
}

return (
<div className={styles.faqs} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave}>
<div className={styles.faqs}>
<span className={styles.link} onClick={toggleOn}>
<span className={styles.toggle} style={{ transform: isOn ? 'rotateX(0deg)' : 'rotateX(180deg)' }}></span>
<span className={styles.headerText}>{alt_header || (fileContent?.meta && fileContent.meta.title)}</span>
<small className={styles.disclaimer}>Hover to view</small>
</span>
<div style={{ display: isOn ? 'block' : 'none' }} className={styles.body}>
{fileContent?.contents}
Expand Down
2 changes: 1 addition & 1 deletion website/src/components/lightbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function Lightbox({ src, collapsed = false, alignment = "center", alt = undefine
if (isHovered && !isScrolling) {
timeoutId = setTimeout(() => {
setExpandImage(true);
}, 300);
}, 200);
}
return () => clearTimeout(timeoutId);
}, [isHovered, isScrolling]);
Expand Down
Loading