Dialog
A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.
import Button from '@dinui/react/button'import Dialog from '@dinui/react/dialog'import Input from '@dinui/react/input'import Label from '@dinui/react/label'
export default function DialogDemo() { return ( <Dialog> <Dialog.Trigger asChild> <Button variant="outline">Edit Profile</Button> </Dialog.Trigger> <Dialog.Content className="sm:w-[32rem]"> <Dialog.Title>Edit profile</Dialog.Title> <Dialog.Description> Make changes to your profile here. Click save when you're done. </Dialog.Description>
<div className="grid gap-4 mt-4"> <div className="grid grid-cols-4 items-center gap-4"> <Label htmlFor="name" className="text-right"> Name </Label> <Input id="name" value="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" value="@peduarte" className="col-span-3" /> </div> </div>
<Dialog.Actions> <Dialog.Close asChild> <Button type="submit">Save changes</Button> </Dialog.Close> </Dialog.Actions> </Dialog.Content> </Dialog> )}Installation
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
All done
You now can start using this component in your project.
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
Run the following command in your project
Terminal window npx @dinui/cli@latest add dialogTerminal window yarn dlx @dinui/cli@latest add dialogTerminal window pnpm dlx @dinui/cli@latest add dialogTerminal window bunx @dinui/cli@latest add dialog -
Update the import paths to match your project setup
-
All done
You now can start using this component in your project.
-
Follow Installation Guide
To enable DinUI functionality in your project, you will need to properly set up Tailwind and install the necessary dependencies. -
Install dependencies
Terminal window npm install @radix-ui/react-dialog tailwind-variants type-festTerminal window yarn add @radix-ui/react-dialog tailwind-variants type-festTerminal window pnpm add @radix-ui/react-dialog tailwind-variants type-festTerminal window bun add @radix-ui/react-dialog tailwind-variants type-fest -
Copy and paste the following code into your project
'use client'import CloseButton from '@dinui/react/close-button'import * as DialogPrimitive from '@radix-ui/react-dialog'import { forwardRef } from 'react'import { tv } from 'tailwind-variants'import type { Merge } from 'type-fest'const dialog = tv({slots: {content: ['@container','z-50 fixed left-[50%] top-[50%] translate-x-[-50%] translate-y-[-50%]','w-full max-w-lg border bg-bg--contrast p-6 shadow-lg sm:rounded-lg','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%]',],overlay: ['fixed inset-0 z-50 bg-[#000]/80','data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0',],closeButton: 'absolute right-4 top-4',title: 'text-lg font-semibold leading-none tracking-tight text-center @md:text-left',description: 'text-sm text-fg-weaker mt-2 text-center @md:text-left',actions: 'mt-4 flex flex-col-reverse gap-2 @md:flex-row @md:justify-end',},})const DialogContent = forwardRef<React.ElementRef<typeof DialogPrimitive.Content>,Merge<React.ComponentPropsWithoutRef<typeof DialogPrimitive.Content>,{portalProps?: React.ComponentProps<typeof DialogPrimitive.DialogPortal>overlayProps?: React.ComponentProps<typeof DialogPrimitive.Overlay>closeButtonProps?: React.ComponentProps<typeof CloseButton>closeProps?: React.ComponentProps<typeof DialogPrimitive.Close>}>>(({ portalProps, overlayProps, closeProps, closeButtonProps, children, ...props }, ref) => {const { content, overlay, closeButton } = dialog()return (<DialogPrimitive.DialogPortal {...portalProps}><DialogPrimitive.Overlay{...overlayProps}className={overlay({ className: overlayProps?.className })}/><DialogPrimitive.Content{...props}ref={ref}className={content({ className: props.className })}>{children}<DialogPrimitive.Close {...closeProps} asChild><CloseButtonsize="sm"{...closeButtonProps}className={closeButton({ className: closeButtonProps?.className })}/></DialogPrimitive.Close></DialogPrimitive.Content></DialogPrimitive.DialogPortal>)})DialogContent.displayName = DialogPrimitive.Content.displayNameconst DialogActions = forwardRef<HTMLDivElement, React.ComponentPropsWithoutRef<'div'>>((props, ref) => {const { actions } = dialog()return <div {...props} ref={ref} className={actions({ className: props.className })} />},)DialogActions.displayName = 'DialogActions'const DialogTitle = forwardRef<React.ElementRef<typeof DialogPrimitive.Title>,React.ComponentPropsWithoutRef<typeof DialogPrimitive.Title>>((props, ref) => {const { title } = dialog()return (<DialogPrimitive.Title {...props} ref={ref} className={title({ className: props.className })} />)})DialogTitle.displayName = DialogPrimitive.Title.displayNameconst DialogDescription = forwardRef<React.ElementRef<typeof DialogPrimitive.Description>,React.ComponentPropsWithoutRef<typeof DialogPrimitive.Description>>((props, ref) => {const { description } = dialog()return (<DialogPrimitive.Description{...props}ref={ref}className={description({ className: props.className })}/>)})DialogDescription.displayName = DialogPrimitive.Description.displayNameconst Dialog = Object.assign(DialogPrimitive.Root, {Trigger: DialogPrimitive.Trigger,Content: DialogContent,Title: DialogTitle,Description: DialogDescription,Actions: DialogActions,Close: DialogPrimitive.Close,})export default Dialogexport { dialog, DialogPrimitive } -
Update the import paths to match your project setup
-
All done
You now can start using this component in your project.