ModalComponentProp
Note: ModalComponentProp reuses the same types as ModalProp and only adds 4 more on top of them. Starting with v3.5.0, ModalProps is a simplified way of usingModalComponentProp.
export type ModalComponentProp<
P extends ModalfyParams,
Props = unknown,
M = keyof P
> = Props & {
modal: UsableModalComponentProp<P, M>
}
export type ModalProps<
N extends keyof ModalfyParams = keyof ModalfyParams,
P = void
> = ModalComponentProp<
ModalfyParams,
P,
N
>
// ------------------ INTERNAL TYPES ------------------ //
type ModalfyParams = { [key: string]: any }
interface UsableModalComponentProp<
P extends ModalfyParams,
M extends keyof P
> extends<UsableModalProp<P>> {
addListener: ModalListener
getParam: <N extends keyof P[M], D extends P[M][N]>(
paramName: N,
defaultValue?: D,
) => D extends P[M][N] ? P[M][N] : undefined
params?: P[M]
removeAllListeners: () => void
setModalOptions: (modalOptions: ModalOptions) => void
}
type ModalListener = (
eventName: ModalEventName,
callback: ModalEventCallback,
) => ModalEventListener
type ModalOnAnimateEventCallback = (value?: number) => void
type ModalOnCloseEventCallback = (closingAction: {
type: ModalClosingActionName
origin: ModalClosingActionOrigin
}) => void
type ModalClosingActionName = 'closeModal' | 'closeModals' | 'closeAllModals'
type ModalClosingActionOrigin = 'default' | 'fling' | 'backdrop'
type ModalEventCallback = ModalOnAnimateEventCallback | ModalOnCloseEventCallback
type ModalEventListener = { remove: () => boolean }Unexpected error with integration github-files: Integration is not installed on this space
API reference
addListener
addListener Function that allows you to hook a listener to the modal component you're in. Right now, only 2 listener types are supported: 'onAnimate' and 'onClose'.
Example:
getParam
getParam Function that looks inside params and returns you the value of the key corresponding to paramName. Returns the provided defaultValue if nothing was found.
Example:
params
params Optional params you provided when opening the modal you're in.
Example:
removeAllListeners
removeAllListeners Removes all the listeners connected to the modal component you're in.
Example:
setModalOptions
setModalOptions Allows you to dynamically change the modal options of to the modal component you're in.
This is an alternative to the static approach: MyModal.modalOptions = { ... }.
You can learn more about it here.
Example:
Last updated
Was this helpful?