-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSidebarOpen.tsx
78 lines (76 loc) · 2.37 KB
/
SidebarOpen.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
'use client';
import { SidebarVisibilityContext } from '@/contexts/SidebarVisibilityContext';
import { setSidebarVisibility } from '@/data/user/ui';
import { cn } from '@/utils/cn';
import { useMutation } from '@tanstack/react-query';
import { Menu, PanelLeftOpen } from 'lucide-react';
import Image from 'next/image';
import darkLogo from 'public/logos/nextbase-dark-logo.png';
import lightLogo from 'public/logos/nextbase-light-logo.png';
import { useContext } from 'react';
import { toast } from 'sonner';
export function SidebarOpen() {
const { setVisibility: setVisibilityContextValue, isVisible } = useContext(
SidebarVisibilityContext,
);
const { mutate } = useMutation(setSidebarVisibility, {
onError: (error) => {
console.log(error);
toast.error('An error occurred.');
},
});
function openSidebar() {
mutate(true);
setVisibilityContextValue(true);
}
return (
<>
{/* lg+ */}
<div
className={cn(
'items-center ',
isVisible ? 'hidden ' : 'hidden lg:flex',
)}
>
<div className="flex items-center gap-2 ">
<div
className={cn(
'flex group cursor-pointer border items-center p-1.5 h-[30px] hover:bg-neutral-100 rounded-md',
)}
onClick={openSidebar}
>
<PanelLeftOpen className="h-4 w-4 text-neutral-500 group-hover:text-neutral-700" />
</div>
<Image
width={32}
src={lightLogo}
alt="Logo Login"
className={cn(
'rotate-0 transition-all cursor-pointer block',
)}
/>
<Image
width={32}
src={darkLogo}
alt="Logo Login"
className={cn(
'rotate-90 transition-all cursor-pointer hidden',
)}
/>
</div>
<div className="w-px h-5 ml-2 mr-4 bg-neutral-200" />
</div>
{/* xs to md */}
<div className="flex lg:hidden items-center w-fit">
<div className="flex items-center gap-2 w-20">
<div
className="group cursor-pointer border flex items-center p-1.5 h-[30px] hover:bg-neutral-100 rounded-md"
onClick={openSidebar}
>
<Menu className="h-4 w-4 text-neutral-500 group-hover:text-neutral-700" />
</div>
</div>
</div>
</>
);
}