modal
caution
All props/parameters are optional unless they are marked with an asterisk ( * ).
tip
It is highly recommended to use this module together with the Modal
component.
Example
import { common } from "replugged";
const { modal } = common;
modal.confirm({}).then((confirmed) => {
if (confirmed) console.log("Confirmed!");
else console.log("Cancelled!");
});
The confirm function has title, cancelText, onConfirm, onCancel and onCloseCallback with
a default value. Whether the confirm button is pressed determines the return value of the promise.
Enums
info
The following enums are a shortcut to the Flex component enums.
| Enum | Description |
|---|---|
modal.Align | Flexbox alignments START | END | CENTER | STRETCH | BASELINE |
modal.Direction | Flexbox directions VERTICAL | HORIZONTAL | HORIZONTAL_REVERSE |
modal.Justify | Flexbox justifies START | END | CENTER | BETWEEN | AROUND |
modal.Wrap | Flexbox wraps NO_WRAP | WRAP | WRAP_REVERSE |
Functions
| Name | Parameters | Return Type | Description |
|---|---|---|---|
alert | * props: AlertProps | void | Brings up a modal useful for a quick response |
closeModal | * modalKey: string contextKey: string | void | Closes a specific modal by its key |
confirm | * props: AlertProps | Promise<boolean | null> | Brings up an alert modal useful for asking the user for a quick confirmation |
openModal | * render: (props: ModalProps) => ReactNode options: ModalOptions contextKey: string | string | Opens a specific modal and returns its key |
Types
AlertProps
| Name | Type | Default | Description |
|---|---|---|---|
body | string | ReactElement | Modal content | |
cancelText | string | Text for the cancel button | |
className | string | Component class name | |
confirmColor | Button.Colors | Button.Colors.BRAND | Primary button color |
confirmText | string | Okay | Text for the cancel button |
onCancel | () => void | Function ran on modal cancel | |
onCloseCallback | () => void | Function ran on modal close | |
onConfirm | () => void | Function ran when the primary button is used | |
onConfirmSecondary | () => void | Function ran when the secondary button is used | |
secondaryConfirmText | string | Text for the secondary button | |
title | string | Modal title | |
titleClassName | string | Title element class name |
ModalOptions
| Name | Type | Default | Description |
|---|---|---|---|
modalKey | string | Modal key | |
onCloseCallback | () => void | Function ran when the modal gets closed | |
onCloseRequest | () => void | Function ran when clicking outside the modal |
ModalProps
| Name | Type | Default | Description |
|---|---|---|---|
onClose | (): Promise<void> | Function ran when the modal gets closed | |
transitionState | string | Modal state |