Modal

Modals provide important prompts in a user flow.

import {
Modal,
ModalHeader,
ModalHeading,
ModalDescription,
trapFocus,
useModal
} from '@cerberus/react'

Usage

Basic Usage

some-page.tsx
import { Model } from '@cerberus/icons'
import {
Modal,
ModalHeader,
ModalHeading,
ModalDescription,
Portal,
useModal,
trapFocus,
Button,
} from '@cerberus/react'
import { hstack } from 'styled-system/patterns'
function OverviewPreview() {
const { modalRef, show, close } = useModal()
const handleKeyDown = trapFocus(modalRef)
return (
<div>
<Button onClick={show}>Open Modal</Button>
<Portal>
<Modal onKeyDown={handleKeyDown} ref={modalRef}>
<ModalHeader>
<ModalHeading>This is a custom modal</ModalHeading>
</ModalHeader>
<ModalDescription>
This is a custom modal that is can be whatever you need.
</ModalDescription>
<div
className={hstack({
color: 'info.text.100',
mb: '10',
})}
>
<Model size="5rem" />
<Model size="5rem" />
<Model size="5rem" />
</div>
<Button usage="outlined" onClick={close}>
Close
</Button>
</Modal>
</Portal>
</div>
)
}

Customization

You can customize each Modal component like you would any other component.

some-page.tsx
import { Model } from '@cerberus/icons'
import {
Modal,
ModalHeader,
ModalHeading,
ModalDescription,
Portal,
useModal,
trapFocus,
Button,
} from '@cerberus/react'
import { css } from 'styled-system/css'
function CustomPreview() {
const { modalRef, show, close } = useModal()
const handleKeyDown = trapFocus(modalRef)
return (
<div>
<Button
className={css({
bgColor: 'black',
color: 'yellow',
_hover: {
bgColor: 'yellow',
color: 'black',
},
})}
onClick={show}
>
Enter the Wu
</Button>
<Portal>
<Modal
className={css({
bgColor: 'black',
})}
onKeyDown={handleKeyDown}
ref={modalRef}
>
<ModalHeader>
<ModalHeading
className={css({
color: 'yellow !important',
})}
>
Inspectah Deck
</ModalHeading>
<ModalDescription>
Swingin' through your town like your neighborhood Spider-man!
</ModalDescription>
</ModalHeader>
<Button
className={css({
borderColor: 'yellow',
color: 'yellow',
_hover: {
borderColor: 'yellow',
color: 'yellow',
},
})}
usage="outlined"
onClick={close}
>
Close
</Button>
</Modal>
</Portal>
</div>
)
}

API

define function Modal(props: HTMLAttributes<HTMLDialogElement>): ReactNode
define function ModalHeader(props: HTMLAttributes<HTMLDivElement>): ReactNode
define function ModalHeading(props: HTMLAttributes<HTMLParagraphElement>): ReactNode
define function ModalDescription(props: HTMLAttributes<HTMLParagraphElement>): ReactNode