-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: dialog components * refactor: delete X comment from components * build: lock file --------- Co-authored-by: boomchanotai <[email protected]>
- Loading branch information
1 parent
0d2eb6b
commit 1d2c359
Showing
4 changed files
with
193 additions
and
0 deletions.
There are no files selected for viewing
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,72 @@ | ||
import { Meta, StoryObj } from '@storybook/react' | ||
|
||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogDescription, | ||
DialogFooter, | ||
DialogHeader, | ||
DialogTitle, | ||
DialogTrigger, | ||
} from '.' | ||
import { Button } from '..' | ||
import { Input } from '..' | ||
import { Label } from '..' | ||
|
||
const meta: Meta<typeof Dialog> = { | ||
title: 'Components/Dialog', | ||
component: Dialog, | ||
tags: ['autodocs'], | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
} | ||
|
||
export default meta | ||
type Story = StoryObj<typeof Dialog> | ||
|
||
export const Default: Story = { | ||
args: {}, | ||
render: (args) => { | ||
return ( | ||
<Dialog {...args}> | ||
<DialogTrigger asChild> | ||
<Button variant='outline'>Edit Profile</Button> | ||
</DialogTrigger> | ||
<DialogContent className='sm:max-w-[425px]'> | ||
<DialogHeader> | ||
<DialogTitle>Edit profile</DialogTitle> | ||
<DialogDescription> | ||
Make changes to your profile here. Click save when you're done. | ||
</DialogDescription> | ||
</DialogHeader> | ||
<div className='grid gap-4 py-4'> | ||
<div className='grid grid-cols-4 items-center gap-4'> | ||
<Label htmlFor='name' className='text-right'> | ||
Name | ||
</Label> | ||
<Input | ||
id='name' | ||
defaultValue='Pedro Duarte' | ||
className='col-span-3' | ||
/> | ||
</div> | ||
<div className='grid grid-cols-4 items-center gap-4'> | ||
<Label htmlFor='username' className='text-right'> | ||
Username | ||
</Label> | ||
<Input | ||
id='username' | ||
defaultValue='@peduarte' | ||
className='col-span-3' | ||
/> | ||
</div> | ||
</div> | ||
<DialogFooter> | ||
<Button type='submit'>Save changes</Button> | ||
</DialogFooter> | ||
</DialogContent> | ||
</Dialog> | ||
) | ||
}, | ||
} |
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,117 @@ | ||
'use client' | ||
|
||
import * as DialogPrimitive from '@radix-ui/react-dialog' | ||
import * as React from 'react' | ||
|
||
import { cn } from '@/utils' | ||
|
||
const Dialog = DialogPrimitive.Root | ||
|
||
const DialogTrigger = DialogPrimitive.Trigger | ||
|
||
const DialogPortal = DialogPrimitive.Portal | ||
|
||
const DialogClose = DialogPrimitive.Close | ||
|
||
const DialogOverlay = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Overlay>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Overlay> | ||
>(({ className, ...props }, ref) => ( | ||
<DialogPrimitive.Overlay | ||
ref={ref} | ||
className={cn( | ||
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 fixed inset-0 z-50 bg-black/80', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
DialogOverlay.displayName = DialogPrimitive.Overlay.displayName | ||
|
||
const DialogContent = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Content>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content> | ||
>(({ className, children, ...props }, ref) => ( | ||
<DialogPortal> | ||
<DialogOverlay /> | ||
<DialogPrimitive.Content | ||
ref={ref} | ||
className={cn( | ||
'data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-neutral-300 bg-white p-6 shadow-lg duration-200 sm:rounded-lg', | ||
className | ||
)} | ||
{...props} | ||
> | ||
{children} | ||
</DialogPrimitive.Content> | ||
</DialogPortal> | ||
)) | ||
DialogContent.displayName = DialogPrimitive.Content.displayName | ||
|
||
const DialogHeader = ({ | ||
className, | ||
...props | ||
}: React.HTMLAttributes<HTMLDivElement>) => ( | ||
<div | ||
className={cn( | ||
'flex flex-col space-y-1.5 text-center sm:text-left', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
) | ||
DialogHeader.displayName = 'DialogHeader' | ||
|
||
const DialogFooter = ({ | ||
className, | ||
...props | ||
}: React.HTMLAttributes<HTMLDivElement>) => ( | ||
<div | ||
className={cn( | ||
'flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
) | ||
DialogFooter.displayName = 'DialogFooter' | ||
|
||
const DialogTitle = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Title>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title> | ||
>(({ className, ...props }, ref) => ( | ||
<DialogPrimitive.Title | ||
ref={ref} | ||
className={cn( | ||
'text-lg font-semibold leading-none tracking-tight', | ||
className | ||
)} | ||
{...props} | ||
/> | ||
)) | ||
DialogTitle.displayName = DialogPrimitive.Title.displayName | ||
|
||
const DialogDescription = React.forwardRef< | ||
React.ElementRef<typeof DialogPrimitive.Description>, | ||
React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description> | ||
>(({ className, ...props }, ref) => ( | ||
<DialogPrimitive.Description | ||
ref={ref} | ||
className={cn('text-sm text-neutral-500', className)} | ||
{...props} | ||
/> | ||
)) | ||
DialogDescription.displayName = DialogPrimitive.Description.displayName | ||
|
||
export { | ||
Dialog, | ||
DialogPortal, | ||
DialogOverlay, | ||
DialogClose, | ||
DialogTrigger, | ||
DialogContent, | ||
DialogHeader, | ||
DialogFooter, | ||
DialogTitle, | ||
DialogDescription, | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.