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

Develop #815

Merged
merged 3 commits into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/app/layout/header/HeaderBlock.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const HeaderBlock = () => {
setIsPageDimmed(false);
setIsPopoverVisible(false);

}, 500);
}, 200);

}
}, [setIsPageDimmed, setIsPopoverVisible, off]);
Expand Down Expand Up @@ -143,15 +143,16 @@ const HeaderBlock = () => {
</div>
</div>
</div>
<div >
{windowSize.width <= 1024 && (
<div className={`searchContainerMobile ${(isInputActive ? 'active' : '')}`}>
<Popover
trigger="click"
open={isPopoverVisible}
arrow={false}
arrow={true}
overlayClassName="searchMobPopover"
content={(
<div className="headerPopupSkeleton">
<div >
<SearchBlock searchQuery={searchQuery} />
</div>
)}
Expand All @@ -176,6 +177,7 @@ const HeaderBlock = () => {
</Button>
</div>
)}
</div>
</div>
);
};
Expand Down
2 changes: 1 addition & 1 deletion src/app/layout/header/HeaderBlock.styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ $navbar-hidden-innerwidth: 400px;
@include mut.rem-padded(0, 15px, 15px, 15px);


position: absolute;
position: fixed;
z-index: 6;
background-color: c.$pure-white-color;
transform: translateY(f.pxToRem(-200px));
Expand Down
64 changes: 59 additions & 5 deletions src/app/layout/header/HeaderSkeleton/HeaderSkeleton.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,78 @@ import './HeaderSkeleton.styles.scss';

import MagnifyingGlass from '@images/header/Magnifying_glass.svg';

import { useState } from 'react';
import { useCallback, useEffect, useRef, useState } from 'react';
import SearchBlock from '@app/layout/header/SearchBlock/SearchBlock.component';

import { Input, Popover } from 'antd';

import useMobx, { useModalContext } from '@stores/root-store';
import useToggle from '@hooks/stateful/useToggle.hook';
import useOnClickOutside from '@/app/common/hooks/stateful/useClickOutside.hook';
import useWindowSize from '@/app/common/hooks/stateful/useWindowSize.hook';
import useEventListener from '@/app/common/hooks/external/useEventListener.hook';

const HeaderSkeleton = () => {
const [isHeaderHidden, setIsHeaderHidden] = useState(false);
const [searchQuery, setSearchQuery] = useState<string>('');
const [isPopoverVisible, setIsPopoverVisible] = useState<boolean>(false);

const { modalStore: { setModal, setIsPageDimmed, isPageDimmed } } = useModalContext();
const { toggleState: isInputActive, handlers: { off, toggle } } = useToggle();
const inputRef = useRef<HTMLInputElement>(null);
const searchButtonRef = useRef(null);
const dimWrapperRef = useRef(null);
const windowSize = useWindowSize();

const handlePopoverVisibleChange = (visible: boolean) => {
setIsPopoverVisible(visible);
};

const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const { value } = e.target;
setSearchQuery(value);
if (value.length > 0) {
if (value.length > 0 && windowSize.width > 1024) {
handlePopoverVisibleChange(true);
} else {
handlePopoverVisibleChange(false);
}
};


const onDimCancel = useCallback((e?: Event) => {
if (
(!searchButtonRef.current || !searchButtonRef.current.contains(e?.target)) &&
dimWrapperRef.current && !dimWrapperRef.current.contains(e?.target)
) {

setTimeout(() => {
off();
setIsPageDimmed(false);
setIsPopoverVisible(false);

}, 0);

}
}, [setIsPageDimmed, setIsPopoverVisible, off]);

useEventListener('scroll', () => {
setIsHeaderHidden(window.scrollY > 100);
});

useEffect(onDimCancel, [isHeaderHidden, onDimCancel]);
useOnClickOutside(inputRef, onDimCancel);

if (isInputActive && !isPageDimmed) {
setIsPageDimmed(true);
}

const onMagnifyingGlassClick = () => {
setIsPageDimmed();
toggle();
};

return (
<Popover
<div ref={dimWrapperRef}>
<Popover
trigger="click"
placement="bottomLeft"
open={isPopoverVisible}
Expand All @@ -40,10 +87,17 @@ const HeaderSkeleton = () => {
<Input
onChange={handleInputChange}
placeholder="Пошук..."
prefix={<MagnifyingGlass />}
prefix={
<MagnifyingGlass
viewBox="0 -2 24 24"
transform="scale(1.2)"
onClick={onMagnifyingGlassClick}
style={isPageDimmed ? { zIndex: '-1' } : undefined}
/>}
/>
</div>
</Popover>
</div>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@use "@sass/mixins/_utils.mixins.scss" as mut;

.headerPopupSkeleton {
width: f.pxToRem(915px);
width: auto;
@include mut.flexed($justify-content: flex-start);
transition: all 1s;
overflow-x: auto;
Expand Down