Modal
A fully-managed renderless Modal component. When requiring users to interact with the application, but without jumping to a new page and interrupting the user's workflow, you can use Modal to create a new floating layer over the current page to get user feedback or display information.
'use client';
import { Modal } from 'rizzui/modal';
Default
A simple sigun up modal example.
'use client';
import { useState } from 'react';
import {
Modal,
Button,
Title,
Text,
ActionIcon,
Input,
Password,
Checkbox,
} from 'rizzui';
import { XMarkIcon } from '@heroicons/react/20/solid';
export default function App() {
const [modalState, setModalState] = useState(false);
return (
<>
<Button onClick={() => setModalState(true)}>Open Modal</Button>
<Modal isOpen={modalState} onClose={() => setModalState(false)}>
<div className="m-auto px-7 pt-6 pb-8">
<div className="mb-7 flex items-center justify-between">
<Title as="h3">Welcome to RizzUi</Title>
<ActionIcon
size="sm"
variant="text"
onClick={() => setModalState(false)}
>
<XMarkIcon className="h-auto w-6" strokeWidth={1.8} />
</ActionIcon>
</div>
<div className="grid grid-cols-2 gap-y-6 gap-x-5 [&_label>span]:font-medium">
<Input label="First Name *" inputClassName="border-2" size="lg" />
<Input label="Last Name *" inputClassName="border-2" size="lg" />
<Input
label="Email *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Confirm Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Checkbox
size="lg"
inputClassName="border-2"
className="col-span-2"
label={
<Text className="text-sm">
I agree to RizzUI‘s{' '}
<a className="underline">Terms of Service</a> and{' '}
<a className="underline">Privacy Policy</a>
</Text>
}
/>
<Button
type="submit"
size="lg"
className="col-span-2 mt-2"
onClick={() => setModalState(false)}
>
Create an Account
</Button>
</div>
</div>
</Modal>
</>
);
}
Sizes
You can change the size of Modal using size property.
'use client';
import { useState } from 'react';
import {
Modal,
Button,
Text,
Title,
ActionIcon,
Input,
Password,
Checkbox,
} from 'rizzui';
import { XMarkIcon } from '@heroicons/react/20/solid';
export default function App() {
const [modalState, setModalState] = useState({
isOpen: false,
size: 'md',
});
return (
<>
<div className="flex items-center justify-around gap-2 flex-wrap">
<Button
variant="outline"
onClick={() =>
setModalState((prevState) => ({
...prevState,
isOpen: true,
size: 'sm',
}))
}
>
sm
</Button>
<Button
variant="outline"
onClick={() =>
setModalState((prevState) => ({
...prevState,
isOpen: true,
size: 'md',
}))
}
>
Default
</Button>
<Button
variant="outline"
onClick={() =>
setModalState((prevState) => ({
...prevState,
isOpen: true,
size: 'lg',
}))
}
>
lg
</Button>
<Button
variant="outline"
onClick={() =>
setModalState((prevState) => ({
...prevState,
isOpen: true,
size: 'full',
}))
}
>
full
</Button>
</div>
<Modal
isOpen={modalState.isOpen}
size={modalState.size}
onClose={() =>
setModalState((prevState) => ({ ...prevState, isOpen: false }))
}
>
<div className="m-auto px-7 pt-6 pb-8">
<div className="mb-7 flex items-center justify-between">
<Title as="h3">Welcome to RizzUI</Title>
<ActionIcon
size="sm"
variant="text"
onClick={() =>
setModalState((prevState) => ({ ...prevState, isOpen: false }))
}
>
<XMarkIcon className="h-auto w-6" strokeWidth={1.8} />
</ActionIcon>
</div>
<div className="grid grid-cols-2 gap-y-6 gap-x-5 [&_label>span]:font-medium">
<Input label="First Name *" inputClassName="border-2" size="lg" />
<Input label="Last Name *" inputClassName="border-2" size="lg" />
<Input
label="Email *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Confirm Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Checkbox
size="lg"
inputClassName="border-2"
className="col-span-2"
label={
<Text className="text-sm">
I agree to RizzUI‘s{' '}
<a className="underline">Terms of Service</a> and{' '}
<a className="underline">Privacy Policy</a>
</Text>
}
/>
<Button
type="submit"
size="lg"
className="col-span-2 mt-2"
onClick={() =>
setModalState((prevState) => ({ ...prevState, isOpen: false }))
}
>
Create an Account
</Button>
</div>
</div>
</Modal>
</>
);
}
With Custom Size
You can use change the Modal size style using customSize property.
'use client';
import { useState } from 'react';
import {
Modal,
Button,
Title,
Text,
ActionIcon,
Input,
Password,
Checkbox,
} from 'rizzui';
import { XMarkIcon } from '@heroicons/react/20/solid';
export default function App() {
const [modalState, setModalState] = useState(false);
return (
<>
<Button onClick={() => setModalState(true)}>Custom Size Modal</Button>
<Modal
isOpen={modalState}
onClose={() => setModalState(false)}
customSize={1080}
>
<div className="m-auto px-7 pt-6 pb-8">
<div className="mb-7 flex items-center justify-between">
<Title as="h3">Welcome to RizzUI</Title>
<ActionIcon
size="sm"
variant="text"
onClick={() => setModalState(false)}
>
<XMarkIcon className="h-auto w-6" strokeWidth={1.8} />
</ActionIcon>
</div>
<div className="grid grid-cols-2 gap-y-6 gap-x-5 [&_label>span]:font-medium">
<Input label="First Name *" inputClassName="border-2" size="lg" />
<Input label="Last Name *" inputClassName="border-2" size="lg" />
<Input
label="Email *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Confirm Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Checkbox
size="lg"
inputClassName="border-2"
className="col-span-2"
label={
<Text className="text-sm">
I agree to RizzUI‘s{' '}
<a className="underline">Terms of Service</a> and{' '}
<a className="underline">Privacy Policy</a>
</Text>
}
/>
<Button
type="submit"
size="lg"
className="col-span-2 mt-2"
onClick={() => setModalState(false)}
>
Create an Account
</Button>
</div>
</div>
</Modal>
</>
);
}
With Custom Style
The customization options are limitless, You can customize as per your preference.
'use client';
import { useState } from 'react';
import {
Modal,
Button,
Title,
Text,
ActionIcon,
Input,
Password,
Checkbox,
} from 'rizzui';
import { XMarkIcon } from '@heroicons/react/20/solid';
export default function App() {
const [modalState, setModalState] = useState(false);
return (
<>
<Button onClick={() => setModalState(true)}>Custom Style Modal</Button>
<Modal
isOpen={modalState}
onClose={() => setModalState(false)}
overlayClassName="backdrop-blur"
containerClassName="!max-w-4xl !shadow-2xl"
>
<div className="m-auto px-7 pt-6 pb-8">
<div className="mb-7 flex items-center justify-between">
<Title as="h3">Welcome to RizzUI</Title>
<ActionIcon
size="sm"
variant="text"
onClick={() => setModalState(false)}
>
<XMarkIcon className="h-auto w-6" strokeWidth={1.8} />
</ActionIcon>
</div>
<div className="grid grid-cols-2 gap-y-6 gap-x-5 [&_label>span]:font-medium">
<Input label="First Name *" inputClassName="border-2" size="lg" />
<Input label="Last Name *" inputClassName="border-2" size="lg" />
<Input
label="Email *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Password
label="Confirm Password *"
inputClassName="border-2"
size="lg"
className="col-span-2"
/>
<Checkbox
size="lg"
inputClassName="border-2"
className="col-span-2"
label={
<Text className="text-sm">
I agree to RizzUI‘s{' '}
<a className="underline">Terms of Service</a> and{' '}
<a className="underline">Privacy Policy</a>
</Text>
}
/>
<Button
type="submit"
size="lg"
className="col-span-2 mt-2"
onClick={() => setModalState(false)}
>
Create an Account
</Button>
</div>
</div>
</Modal>
</>
);
}
API Reference
Modal Props
Here is the API documentation of the Modal component.
| Props | Type | Description | Default |
|---|---|---|---|
| isOpen | boolean | Whether the Modal is open or not | __ |
| onClose | () => void | Called when modal is closed (Escape key and click outside, depending on options) | __ |
| size | ModalSizes | Preset size of modal is sm, md, lg, xl, full | "md" |
| customSize | number | Size prop will not work when you are using customSize prop. Here is the example of using this prop -> customSize={500} | __ |
| noGutter | boolean | This prop will remove extra padding spacing from screen | __ |
| overlayClassName | string | Override default CSS style of Modal's overlay | __ |
| containerClassName | string | Set custom style classes for the Modal container, where you can set custom Modal size and padding and background color | __ |
| className | string | Set custom style classes for the Modal root element | __ |
Modal Sizes
type ModalSizes = 'sm' | 'md' | 'lg' | 'full';