changing color role and username in navbar while scroll
This commit is contained in:
@ -10,48 +10,63 @@ const HeaderTopbar = () => {
|
|||||||
const itemChatRef = useRef<any>(null);
|
const itemChatRef = useRef<any>(null);
|
||||||
const itemUserRef = useRef<any>(null);
|
const itemUserRef = useRef<any>(null);
|
||||||
const itemNotificationsRef = useRef<any>(null);
|
const itemNotificationsRef = useRef<any>(null);
|
||||||
|
|
||||||
const { isRTL } = useLanguage();
|
const { isRTL } = useLanguage();
|
||||||
|
|
||||||
|
const [isSticky, setIsSticky] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
const handleScroll = () => {
|
||||||
|
setIsSticky(window.scrollY > 100);
|
||||||
|
};
|
||||||
|
window.addEventListener('scroll', handleScroll);
|
||||||
|
return () => window.removeEventListener('scroll', handleScroll);
|
||||||
|
}, []);
|
||||||
|
|
||||||
const handleDropdownChatShow = () => {
|
const handleDropdownChatShow = () => {
|
||||||
window.dispatchEvent(new Event('resize'));
|
window.dispatchEvent(new Event('resize'));
|
||||||
};
|
};
|
||||||
// console.log(getAuth())
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center gap-4">
|
<div className="flex items-center gap-4">
|
||||||
<div className="hidden md:flex flex-col items-end mr-2 text-right">
|
<div className="hidden md:flex flex-col items-end mr-2 text-right">
|
||||||
<span className="font-semibold text-sm text-white leading-tight">{getAuth()?.user.username}</span>
|
<span
|
||||||
<span className="text-xs text-gray-400">{getAuth()?.role_name}</span>
|
className={`font-semibold text-sm leading-tight ${isSticky ? 'text-black' : 'text-white'}`}
|
||||||
</div>
|
>
|
||||||
|
{getAuth()?.user.username}
|
||||||
<Menu>
|
</span>
|
||||||
<MenuItem
|
<span className={`text-xs ${isSticky ? 'text-gray-700' : 'text-gray-400'}`}>
|
||||||
ref={itemUserRef}
|
{getAuth()?.role_name}
|
||||||
toggle="dropdown"
|
</span>
|
||||||
trigger="click"
|
</div>
|
||||||
dropdownProps={{
|
|
||||||
placement: isRTL() ? 'bottom-start' : 'bottom-end',
|
|
||||||
modifiers: [
|
|
||||||
{
|
|
||||||
name: 'offset',
|
|
||||||
options: {
|
|
||||||
offset: [20, 10],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<MenuToggle className="btn btn-icon rounded-full">
|
|
||||||
<img
|
|
||||||
className="w-9 h-9 rounded-full border border-gray-500 object-cover"
|
|
||||||
src={toAbsoluteUrl('/media/avatars/profile.png')}
|
|
||||||
alt="User avatar"
|
|
||||||
/>
|
|
||||||
</MenuToggle>
|
|
||||||
{DropdownUser({ menuItemRef: itemUserRef })}
|
|
||||||
</MenuItem>
|
|
||||||
</Menu>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
<Menu>
|
||||||
|
<MenuItem
|
||||||
|
ref={itemUserRef}
|
||||||
|
toggle="dropdown"
|
||||||
|
trigger="click"
|
||||||
|
dropdownProps={{
|
||||||
|
placement: isRTL() ? 'bottom-start' : 'bottom-end',
|
||||||
|
modifiers: [
|
||||||
|
{
|
||||||
|
name: 'offset',
|
||||||
|
options: {
|
||||||
|
offset: [20, 10]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<MenuToggle className="btn btn-icon rounded-full">
|
||||||
|
<img
|
||||||
|
className="w-9 h-9 rounded-full border border-gray-500 object-cover"
|
||||||
|
src={toAbsoluteUrl('/media/avatars/profile.png')}
|
||||||
|
alt="User avatar"
|
||||||
|
/>
|
||||||
|
</MenuToggle>
|
||||||
|
{DropdownUser({ menuItemRef: itemUserRef })}
|
||||||
|
</MenuItem>
|
||||||
|
</Menu>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user