-
Notifications
You must be signed in to change notification settings - Fork 462
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
de82521
commit 5e57c2c
Showing
7 changed files
with
171 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
"use client"; | ||
|
||
import { cn } from "lib/cssUtils"; | ||
import { | ||
type ComponentProps, | ||
type ComponentPropsWithoutRef, | ||
type ElementRef, | ||
type HTMLAttributes, | ||
forwardRef, | ||
} from "react"; | ||
import { Drawer as DrawerPrimitive } from "vaul"; | ||
|
||
const Drawer = ({ | ||
shouldScaleBackground = true, | ||
...props | ||
}: 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 = forwardRef< | ||
ElementRef<typeof DrawerPrimitive.Overlay>, | ||
ComponentPropsWithoutRef<typeof DrawerPrimitive.Overlay> | ||
>(({ className, ...props }, ref) => ( | ||
<DrawerPrimitive.Overlay | ||
ref={ref} | ||
className={cn("fixed inset-0 z-50 bg-black/50 backdrop-blur-sm", className)} | ||
{...props} | ||
/> | ||
)); | ||
DrawerOverlay.displayName = DrawerPrimitive.Overlay.displayName; | ||
|
||
const DrawerContent = forwardRef< | ||
ElementRef<typeof DrawerPrimitive.Content>, | ||
ComponentPropsWithoutRef<typeof DrawerPrimitive.Content> | ||
>(({ className, children, ...props }, ref) => ( | ||
<DrawerPortal> | ||
<DrawerOverlay /> | ||
<DrawerPrimitive.Content | ||
ref={ref} | ||
className={cn( | ||
"fixed inset-x-0 bottom-0 z-50 mt-24 flex h-auto flex-col rounded-t-xl bg-background", | ||
className, | ||
)} | ||
{...props} | ||
> | ||
<div className="mx-auto mt-4 h-2 w-[100px] rounded-full bg-drawer-handle" /> | ||
{children} | ||
</DrawerPrimitive.Content> | ||
</DrawerPortal> | ||
)); | ||
DrawerContent.displayName = "DrawerContent"; | ||
|
||
const DrawerHeader = ({ | ||
className, | ||
...props | ||
}: 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 | ||
}: HTMLAttributes<HTMLDivElement>) => ( | ||
<div | ||
className={cn("mt-auto flex flex-col gap-2 p-4", className)} | ||
{...props} | ||
/> | ||
); | ||
DrawerFooter.displayName = "DrawerFooter"; | ||
|
||
const DrawerTitle = forwardRef< | ||
ElementRef<typeof DrawerPrimitive.Title>, | ||
ComponentPropsWithoutRef<typeof DrawerPrimitive.Title> | ||
>(({ className, ...props }, ref) => ( | ||
<DrawerPrimitive.Title | ||
ref={ref} | ||
className={cn( | ||
"font-display font-extrabold text-lg leading-none tracking-tight", | ||
className, | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
DrawerTitle.displayName = DrawerPrimitive.Title.displayName; | ||
|
||
export { | ||
Drawer, | ||
DrawerPortal, | ||
DrawerOverlay, | ||
DrawerTrigger, | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerHeader, | ||
DrawerFooter, | ||
DrawerTitle, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { Button } from "app/components/ui/Button"; | ||
import { | ||
Drawer, | ||
DrawerClose, | ||
DrawerContent, | ||
DrawerFooter, | ||
DrawerHeader, | ||
DrawerTitle, | ||
DrawerTrigger, | ||
} from "app/components/ui/Drawer"; | ||
|
||
const DrawerExample = () => ( | ||
<Drawer> | ||
<DrawerTrigger>Open</DrawerTrigger> | ||
<DrawerContent> | ||
<DrawerHeader> | ||
<DrawerTitle>Are you absolutely sure?</DrawerTitle> | ||
</DrawerHeader> | ||
<DrawerFooter> | ||
<Button colorScheme="primary">Submit</Button> | ||
<DrawerClose asChild> | ||
<Button variant="subtle">Cancel</Button> | ||
</DrawerClose> | ||
</DrawerFooter> | ||
</DrawerContent> | ||
</Drawer> | ||
); | ||
|
||
const meta: Meta<typeof DrawerExample> = { | ||
title: "Design system/Drawer", | ||
component: DrawerExample, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof DrawerExample>; | ||
|
||
export const Default: Story = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters