For the complete documentation index, see llms.txt. This page is also available as Markdown.

ModalComponentProp

Interface of the modal prop exposed by the library specifically to modal components.

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

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

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

Optional params you provided when opening the modal you're in.

Example:

removeAllListeners

Removes all the listeners connected to the modal component you're in.

Example:

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