make sidebar mobile responsive

This commit is contained in:
Philipinho
2023-08-29 22:16:36 +01:00
parent 5b6dbcc5bb
commit 1855e1e965
3 changed files with 64 additions and 24 deletions

View File

@ -0,0 +1,41 @@
import React from 'react';
import { useIsMobile } from '@/hooks/use-is-mobile';
import {
desktopSidebarAtom,
mobileSidebarAtom,
} from '@/components/sidebar/atoms/sidebar-atom';
import { useToggleSidebar } from './hooks/use-toggle-sidebar';
import ButtonWithIcon from '../ui/button-with-icon';
import {
IconLayoutSidebarLeftCollapse,
IconLayoutSidebarRightCollapse,
} from '@tabler/icons-react';
import { useAtom } from 'jotai';
import { cn } from '@/lib/utils';
interface SidebarToggleButtonProps {
className?: string;
}
export default function SidebarToggleButton({
className,
}: SidebarToggleButtonProps) {
const isMobile = useIsMobile();
const sidebarStateAtom = isMobile ? mobileSidebarAtom : desktopSidebarAtom;
const [isSidebarOpen] = useAtom(sidebarStateAtom);
const toggleSidebar = useToggleSidebar(sidebarStateAtom);
const SidebarIcon = isSidebarOpen
? IconLayoutSidebarLeftCollapse
: IconLayoutSidebarRightCollapse;
return (
<ButtonWithIcon
className={cn(className, 'z-[100]')}
icon={<SidebarIcon size={20} />}
variant={'ghost'}
onClick={toggleSidebar}
></ButtonWithIcon>
);
}