Bootstrap

API modal

createModal

function

createModal<Data>(config?): ModalWidget<Data>

Creates a new modal widget instance.

Type Parameters

Data

Parameters

config?: PropsConfig<ModalProps<Data>>

config of the modal, either as a store or as an object containing values or stores.

Returns

ModalWidget<Data>

a new modal widget instance


getModalDefaultConfig

function

getModalDefaultConfig(): ModalProps<any>

Retrieve a shallow copy of the default modal config

Returns

ModalProps<any>

the default modal config


ModalApi

interface

Interface representing the API for a modal component.

Type Parameters

Data

The type of data associated with the modal.

Properties
patch

patch: (parameters) => void

Method to change some modal properties.

Modify the parameter values, and recalculate the stores accordingly

Parameters

parameters: Partial<ModalProps<Data>>

Returns

void

Methods
close

close(result?): void

Closes the modal with the given result.

Parameters

result?: any

result of the modal, as passed in the result property of the event passed to the onBeforeClose event handler (and possibly changed by it) and resolved by the promise returned by the open method.

Returns

void


open

open(): Promise<any>

Opens the modal and returns a promise that is resolved when the modal is closed. The resolved value is the result passed to the close method and possibly changed by the onBeforeClose event handler

Returns

Promise<any>


ModalBeforeCloseEvent

interface

Type of the parameter of onBeforeClose.

Properties
cancel

cancel: boolean

Whether to cancel the close of the modal. It can be changed from the onBeforeClose event handler.


result

result: any

Result of the modal, which is the value passed to the close method and later resolved by the promise returned by the open method. If needed, it can be changed from the onBeforeClose event handler.


modalCloseButtonClick

constant

const modalCloseButtonClick: typeof modalCloseButtonClick

Value present in the result property of the onBeforeClose event and returned by the open method, when the modal is closed by a click on the close button.


ModalContext

interface

Represents the context for a modal component.

Type Parameters

Data

The type of data associated with the modal.

Properties
api

api: ModalApi<Data>

all the api functions to interact with the widget


directives

directives: ModalDirectives

directives to be used on html elements in the template of the widget or in the slots


state

state: ModalState<Data>

the state of the widget


ModalDirectives

interface

Directives of the modal widget.

Properties
backdropDirective

backdropDirective: Directive

Directive to put on the backdrop DOM element.


backdropPortalDirective

backdropPortalDirective: Directive

Portal directive to put on the backdrop DOM element.


closeButtonDirective

closeButtonDirective: Directive

Directive that adds all the necessary attributes to the close button


dialogDirective

dialogDirective: Directive

Directive to apply to the dialog element when using the native HTMLDialogElement


modalDirective

modalDirective: Directive

Directive to put on the modal DOM element.


modalPortalDirective

modalPortalDirective: Directive

Portal directive to put on the modal DOM element.


modalOutsideClick

constant

const modalOutsideClick: typeof modalOutsideClick

Value present in the result property of the onBeforeClose event and returned by the open method, when the modal is closed by a click inside the viewport but outside the modal.


ModalProps

interface

Interface representing the properties for a modal component.

Type Parameters

Data

The type of data that the modal will handle.

Properties
animated

animated: boolean

Whether the modal and its backdrop (if present) should be animated when shown or hidden.

Default Value

true


ariaCloseButtonLabel

ariaCloseButtonLabel: string

Value of the aria-label attribute to put on the close button.

Default Value

'Close'


backdrop

backdrop: boolean

Whether a backdrop should be created behind the modal.

Default Value

true


backdropClass

backdropClass: string

Classes to add on the backdrop DOM element.

Default Value

''


backdropTransition

backdropTransition: TransitionFn

The transition to use for the backdrop behind the modal (if present).

Default Value

fadeTransition


children

children: SlotContent<ModalContext<Data>>

Body of the modal.


className

className: string

CSS classes to be applied on the widget main container

Default Value

''


closeButton

closeButton: boolean

Whether to display the close button.

Default Value

true


closeOnOutsideClick

closeOnOutsideClick: boolean

Whether the modal should be closed when clicking on the viewport outside the modal.

Default Value

true


container

container: null | HTMLElement

Which element should contain the modal and backdrop DOM elements. If it is not null, the modal and backdrop DOM elements are moved to the specified container. Otherwise, they stay where the widget is located.

Default Value
typeof window !== 'undefined' ? document.body : null

contentData

contentData: Data

Data to use in content slots


footer: SlotContent<ModalContext<Data>>

Footer of the modal.


fullscreen

fullscreen: boolean

Option to create a fullscreen modal, according to the bootstrap documentation.

Default Value

false


header

header: SlotContent<ModalContext<Data>>

Header of the modal. The default header includes title.


modalTransition

modalTransition: TransitionFn

The transition to use for the modal.

Default Value

fadeTransition


onBeforeClose

onBeforeClose: (event) => void

Event to be triggered when the modal is about to be closed (i.e. the close method was called).

Parameters

event: ModalBeforeCloseEvent

event giving access to the argument given to the close method and allowing to cancel the close process.

Returns

void

Default Value
() => {}

onHidden

onHidden: () => void

Event to be triggered when the transition is completed and the modal is not visible.

Returns

void

Default Value
() => {}

onShown

onShown: () => void

Event to be triggered when the transition is completed and the modal is visible.

Returns

void

Default Value
() => {}

onVisibleChange

onVisibleChange: (visible) => void

Event to be triggered when the visible property changes.

Parameters

visible: boolean

new value of the visible propery

Returns

void

Default Value
() => {}

structure

structure: SlotContent<ModalContext<Data>>

Structure of the modal. The default structure uses header, children and footer.


title

title: SlotContent<ModalContext<Data>>

Title of the modal.


visible

visible: boolean

Whether the modal should be visible when the transition is completed.

Default Value

false


ModalState

interface

Represents the state of a modal component.

Type Parameters

Data

The type of the data associated with the modal.

Properties
ariaCloseButtonLabel

ariaCloseButtonLabel: string

Value of the aria-label attribute to put on the close button.

Default Value

'Close'


backdropClass

backdropClass: string

Classes to add on the backdrop DOM element.

Default Value

''


backdropHidden

backdropHidden: boolean

Whether the backdrop is fully hidden. This can be true either because backdrop is false or because visible is false and there is no current transition.


children

children: SlotContent<ModalContext<Data>>

Body of the modal.


className

className: string

CSS classes to be applied on the widget main container

Default Value

''


closeButton

closeButton: boolean

Whether to display the close button.

Default Value

true


container

container: null | HTMLElement

Which element should contain the modal and backdrop DOM elements. If it is not null, the modal and backdrop DOM elements are moved to the specified container. Otherwise, they stay where the widget is located.

Default Value
typeof window !== 'undefined' ? document.body : null

contentData

contentData: Data

Data to use in content slots


footer: SlotContent<ModalContext<Data>>

Footer of the modal.


fullscreen

fullscreen: boolean

Option to create a fullscreen modal, according to the bootstrap documentation.

Default Value

false


header

header: SlotContent<ModalContext<Data>>

Header of the modal. The default header includes title.


hidden

hidden: boolean

Whether the modal is fully hidden.


modalElement

modalElement: null | HTMLElement

DOM element of the modal.


structure

structure: SlotContent<ModalContext<Data>>

Structure of the modal. The default structure uses header, children and footer.


title

title: SlotContent<ModalContext<Data>>

Title of the modal.


transitioning

transitioning: boolean

Whether there is an active transition to either display or hide the modal.


visible

visible: boolean

Whether the modal should be visible when the transition is completed.

Default Value

false


ModalWidget

type alias

ModalWidget<Data>: Widget<ModalProps<Data>, ModalState<Data>, ModalApi<Data>, ModalDirectives>

Represents a modal widget with specific data type.

Type Parameters

Data

The type of data that the modal widget will handle.


openModal

function

openModal<Data>(options, context?): Promise<any>

Opens a modal dialog with the specified options.

Type Parameters

Data

The type of data that the modal will handle.

Parameters

options: Partial<ModalProps<Data>>

The options to configure the modal.

context? = {}

Optional context to pass to the modal.

context.context?: Map<any, any>

A map of context values to pass to the modal.

Returns

Promise<any>

A promise that resolves when the modal is closed.

Example
const result = await openModal<MyDataType>({
  title: 'My Modal Title',
  content: 'This is the content of the modal.'
});
console.log(result);