Skip to content

Commit

Permalink
add drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
anamontiaga committed Feb 15, 2024
1 parent d42d499 commit 1d5f261
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 12 deletions.
1 change: 1 addition & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"tailwindcss": "3.3.2",
"tailwindcss-animate": "^1.0.6",
"typescript": "5.1.3",
"vaul": "^0.9.0",
"zod": "^3.21.4"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions client/src/app/projects/[slug]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const metadata: Metadata = {
};

import Panel from '@/containers/panel';
import ProjectDashboard from '@/containers/projects/detail/dashboard';
import ProjectDetailPanel from '@/containers/projects/detail/panel';

export default function ProjectDetailPage() {
Expand All @@ -15,7 +14,6 @@ export default function ProjectDetailPage() {
<Panel>
<ProjectDetailPanel />
</Panel>
<ProjectDashboard />
</>
);
}
99 changes: 99 additions & 0 deletions client/src/components/ui/drawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
'use client';

import * as React from 'react';

import { Drawer as DrawerPrimitive } from 'vaul';

import { cn } from '@/lib/classnames';

const Drawer = ({
shouldScaleBackground = true,
...props
}: React.ComponentProps<typeof DrawerPrimitive.Root>) => (
<DrawerPrimitive.Root shouldScaleBackground={shouldScaleBackground} {...props} />
);
Drawer.displayName = 'Drawer';

const DrawerTrigger = DrawerPrimitive.Trigger;

const DrawerPortal = DrawerPrimitive.Portal;

const DrawerClose = DrawerPrimitive.Close;

const DrawerOverlay = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Overlay
ref={ref}
className={cn('fixed inset-0 z-50 bg-black/80', className)}
{...props}
/>
));
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName;

const DrawerContent = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Content>
>(({ className, children, ...props }, ref) => (
<DrawerPortal>
<DrawerPrimitive.Content
ref={ref}
className={cn(
'fixed inset-x-0 bottom-0 left-[580px] top-0 z-10 flex h-auto w-3/5 flex-col rounded-t-[10px]',
className
)}
{...props}
>
{children}
</DrawerPrimitive.Content>
</DrawerPortal>
));
DrawerContent.displayName = 'DrawerContent';

const DrawerHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('grid gap-1.5 p-4 text-center sm:text-left', className)} {...props} />
);
DrawerHeader.displayName = 'DrawerHeader';

const DrawerFooter = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('mt-auto flex flex-col gap-2 p-4', className)} {...props} />
);
DrawerFooter.displayName = 'DrawerFooter';

const DrawerTitle = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Title>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Title
ref={ref}
className={cn('text-lg font-semibold leading-none tracking-tight', className)}
{...props}
/>
));
DrawerTitle.displayName = DrawerPrimitive.Title.displayName;

const DrawerDescription = React.forwardRef<
React.ElementRef<typeof DrawerPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof DrawerPrimitive.Description>
>(({ className, ...props }, ref) => (
<DrawerPrimitive.Description
ref={ref}
className={cn('text-muted-foreground text-sm', className)}
{...props}
/>
));
DrawerDescription.displayName = DrawerPrimitive.Description.displayName;

export {
Drawer,
DrawerPortal,
DrawerOverlay,
DrawerTrigger,
DrawerClose,
DrawerContent,
DrawerHeader,
DrawerFooter,
DrawerTitle,
DrawerDescription,
};
29 changes: 19 additions & 10 deletions client/src/containers/projects/detail/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import { dashboardAtom } from '@/store';
import { PANEL_OVERVIEW_ITEMS } from '@/containers/projects/detail/constants';

import { Button } from '@/components/ui/button';
import { Drawer, DrawerContent, DrawerTrigger } from '@/components/ui/drawer';

import ProjectDashboard from './dashboard';

export default function ProjectDetailPanel() {
const [dashboard, setDashboard] = useAtom(dashboardAtom);
Expand Down Expand Up @@ -103,16 +106,22 @@ export default function ProjectDetailPanel() {
</p>
</div>
</div>

<Button
variant="primary"
className="group fixed bottom-6 right-6 space-x-2"
size="base"
onClick={() => setDashboard(!dashboard)}
>
<p className="w-36">{dashboard ? 'Hide dashboard' : 'Show dashboard'}</p>
<ChevronRight className="h-4 w-4 text-yellow-900 group-hover:text-yellow-50" />
</Button>
<Drawer>
<DrawerTrigger asChild>
<Button
variant="primary"
className="group fixed bottom-6 right-6 z-50 space-x-2"
size="base"
onClick={() => setDashboard(!dashboard)}
>
<p className="w-36">{dashboard ? 'Hide dashboard' : 'Show dashboard'}</p>
<ChevronRight className="h-4 w-4 text-yellow-900 group-hover:text-yellow-50" />
</Button>
</DrawerTrigger>
<DrawerContent>
<ProjectDashboard />
</DrawerContent>
</Drawer>
</div>
);
}

0 comments on commit 1d5f261

Please sign in to comment.