fix(GlobalCarousel)

- reduce header and controls animation duration to 0.25s

- Use the same hover trigger for both header and controls
This commit is contained in:
Aminejv 2021-11-01 07:51:13 +01:00
parent ab510a492c
commit bc58d0362e

View File

@ -88,7 +88,12 @@ function CarouselHeader({
current, current,
total, total,
onAction, onAction,
onClose, onClose,
enableNextSlide,
enablePreviousSlide,
onNextSlide,
onPreviousSlide,
...props ...props
}) { }) {
const [isHeaderVisible, setHeaderVisibility] = React.useState(true); const [isHeaderVisible, setHeaderVisibility] = React.useState(true);
@ -176,10 +181,22 @@ function CarouselHeader({
/> />
</ModalPortal> </ModalPortal>
<CarouselControls
enableNextSlide={enableNextSlide}
enablePreviousSlide={enablePreviousSlide}
onNextSlide={onNextSlide}
onPreviousSlide={onPreviousSlide}
showControls={isHeaderVisible || isJumperOpen}
onClose={onClose}
onMouseEnter={showHeader}
onMouseLeave={hideHeader}
/>
<motion.nav <motion.nav
css={STYLES_HEADER_WRAPPER} css={STYLES_HEADER_WRAPPER}
initial={{ opacity: 0 }} initial={{ opacity: 0 }}
animate={{ opacity: isHeaderVisible || isJumperOpen ? 1 : 0 }} animate={{ opacity: isHeaderVisible || isJumperOpen ? 1 : 0 }}
transition={{ ease: "easeInOut", duration: 0.25 }}
onMouseEnter={showHeader} onMouseEnter={showHeader}
onMouseLeave={hideHeader} onMouseLeave={hideHeader}
{...props} {...props}
@ -492,7 +509,10 @@ function CarouselControls({
enablePreviousSlide, enablePreviousSlide,
onNextSlide, onNextSlide,
onPreviousSlide, onPreviousSlide,
showControls,
onClose, onClose,
...props
}) { }) {
useCarouselKeyCommands({ useCarouselKeyCommands({
handleNext: onNextSlide, handleNext: onNextSlide,
@ -500,38 +520,19 @@ function CarouselControls({
handleClose: onClose, handleClose: onClose,
}); });
const [areControlsVisible, setControlsVisibility] = React.useState(true);
const timeoutRef = React.useRef();
const showControls = () => {
clearTimeout(timeoutRef.current);
setControlsVisibility(true);
};
const hideControls = () => {
timeoutRef.current = setTimeout(() => {
setControlsVisibility(false);
}, 500);
};
React.useEffect(() => {
timeoutRef.current = setTimeout(hideControls, 3000);
return () => clearTimeout(timeoutRef.current);
}, []);
return ( return (
<> <>
<div <div
onMouseEnter={showControls}
onMouseLeave={hideControls}
css={STYLES_CONTROLS_WRAPPER} css={STYLES_CONTROLS_WRAPPER}
style={{ left: 0, justifyContent: "flex-start" }} style={{ left: 0, justifyContent: "flex-start" }}
{...props}
> >
{enablePreviousSlide ? ( {enablePreviousSlide ? (
<motion.button <motion.button
onClick={onPreviousSlide} onClick={onPreviousSlide}
initial={{ opacity: 0 }} initial={{ opacity: 0 }}
animate={{ opacity: areControlsVisible ? 1 : 0 }} animate={{ opacity: showControls ? 1 : 0 }}
transition={{ ease: "easeInOut", duration: 0.25 }}
css={STYLES_CONTROLS_BUTTON} css={STYLES_CONTROLS_BUTTON}
> >
<SVG.ChevronLeft width={16} /> <SVG.ChevronLeft width={16} />
@ -539,16 +540,15 @@ function CarouselControls({
) : null} ) : null}
</div> </div>
<div <div
onMouseEnter={showControls}
onMouseLeave={hideControls}
css={STYLES_CONTROLS_WRAPPER} css={STYLES_CONTROLS_WRAPPER}
style={{ right: 0, justifyContent: "flex-end" }} style={{ right: 0, justifyContent: "flex-end" }}
{...props}
> >
{enableNextSlide ? ( {enableNextSlide ? (
<motion.button <motion.button
onClick={onNextSlide} onClick={onNextSlide}
initial={{ opacity: 0 }} initial={{ opacity: 0 }}
animate={{ opacity: areControlsVisible ? 1 : 0 }} animate={{ opacity: showControls ? 1 : 0 }}
css={STYLES_CONTROLS_BUTTON} css={STYLES_CONTROLS_BUTTON}
> >
<SVG.ChevronRight width={16} /> <SVG.ChevronRight width={16} />
@ -783,16 +783,6 @@ export function GlobalCarousel({
return ( return (
<div css={STYLES_ROOT}> <div css={STYLES_ROOT}>
{!isMobile ? (
<CarouselControls
enableNextSlide={index < objects.length - 1}
enablePreviousSlide={index > 0}
onNextSlide={handleNext}
onPreviousSlide={handlePrevious}
onClose={handleClose}
/>
) : null}
{isMobile ? ( {isMobile ? (
<CarouselHeaderMobile <CarouselHeaderMobile
current={index + 1} current={index + 1}
@ -811,6 +801,10 @@ export function GlobalCarousel({
current={index + 1} current={index + 1}
total={objects.length} total={objects.length}
onAction={onAction} onAction={onAction}
enableNextSlide={index < objects.length - 1}
enablePreviousSlide={index > 0}
onNextSlide={handleNext}
onPreviousSlide={handlePrevious}
onClose={handleClose} onClose={handleClose}
/> />
)} )}