Use our Tailwind CSS Dialog
component to inform users about a task or important information that require decisions, or involves multiple tasks.
A Dialog
is a type of modal window with critical information which disable all app functionality when they appear and remains on screen until confirmed/dismissed.
See below our Dialog
example that you can use for your Tailwind CSS and React project.
import { Fragment, useState } from "react";
import {
Button,
Dialog,
DialogHeader,
DialogBody,
DialogFooter,
} from "@material-tailwind/react";
export default function Example() {
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(!open);
return (
<Fragment>
<Button onClick={handleOpen} variant="gradient">
Open Dialog
</Button>
<Dialog open={open} handler={handleOpen}>
<DialogHeader>Its a simple dialog.</DialogHeader>
<DialogBody divider>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Accusamus ad
reprehenderit omnis perspiciatis aut odit! Unde architecto
perspiciatis, dolorum dolorem iure quia saepe autem accusamus eum
praesentium magni corrupti explicabo!
</DialogBody>
<DialogFooter>
<Button
variant="text"
color="red"
onClick={handleOpen}
className="mr-1"
>
<span>Cancel</span>
</Button>
<Button variant="gradient" color="green" onClick={handleOpen}>
<span>Confirm</span>
</Button>
</DialogFooter>
</Dialog>
</Fragment>
);
}
The Dialog
component comes with 6 different sizes that you can change it using the size
prop.
import { Fragment, useState } from "react";
import {
Button,
Dialog,
DialogHeader,
DialogBody,
DialogFooter,
} from "@material-tailwind/react";
export default function Example() {
const [size, setSize] = useState(null);
const handleOpen = (value) => setSize(value);
return (
<Fragment>
<div className="mb-3 flex gap-3">
<Button onClick={() => handleOpen("xs")} variant="gradient">
Open Dialog XS
</Button>
<Button onClick={() => handleOpen("sm")} variant="gradient">
Open Dialog SM
</Button>
<Button onClick={() => handleOpen("md")} variant="gradient">
Open Dialog MD
</Button>
</div>
<div className="flex gap-3">
<Button onClick={() => handleOpen("lg")} variant="gradient">
Open Dialog LG
</Button>
<Button onClick={() => handleOpen("xl")} variant="gradient">
Open Dialog XL
</Button>
<Button onClick={() => handleOpen("xxl")} variant="gradient">
Open Dialog XXL
</Button>
</div>
<Dialog
open={
size === "xs" ||
size === "sm" ||
size === "md" ||
size === "lg" ||
size === "xl" ||
size === "xxl"
}
size={size || "md"}
handler={handleOpen}
>
<DialogHeader>Its a simple dialog.</DialogHeader>
<DialogBody divider>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Accusamus ad
reprehenderit omnis perspiciatis aut odit! Unde architecto
perspiciatis, dolorum dolorem iure quia saepe autem accusamus eum
praesentium magni corrupti explicabo!
</DialogBody>
<DialogFooter>
<Button
variant="text"
color="red"
onClick={() => handleOpen(null)}
className="mr-1"
>
<span>Cancel</span>
</Button>
<Button
variant="gradient"
color="green"
onClick={() => handleOpen(null)}
>
<span>Confirm</span>
</Button>
</DialogFooter>
</Dialog>
</Fragment>
);
}
You can modify the open/close state animation for Dialog
component using the animate
prop.
import { Fragment, useState } from "react";
import {
Button,
Dialog,
DialogHeader,
DialogBody,
DialogFooter,
} from "@material-tailwind/react";
export default function Example() {
const [open, setOpen] = useState(false);
const handleOpen = () => setOpen(!open);
return (
<Fragment>
<Button onClick={handleOpen} variant="gradient">
Open Dialog
</Button>
<Dialog
open={open}
handler={handleOpen}
animate={{
mount: { scale: 1, y: 0 },
unmount: { scale: 0.9, y: -100 },
}}
>
<DialogHeader>Its a simple dialog.</DialogHeader>
<DialogBody divider>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Accusamus ad
reprehenderit omnis perspiciatis aut odit! Unde architecto
perspiciatis, dolorum dolorem iure quia saepe autem accusamus eum
praesentium magni corrupti explicabo!
</DialogBody>
<DialogFooter>
<Button
variant="text"
color="red"
onClick={handleOpen}
className="mr-1"
>
<span>Cancel</span>
</Button>
<Button variant="gradient" color="green" onClick={handleOpen}>
<span>Confirm</span>
</Button>
</DialogFooter>
</Dialog>
</Fragment>
);
}