Skip to content

Dialog API

Methods

MethodSignatureDescription
openModal(options: SoDialogModalOptions)Open a modal dialog.
openOffcanvas(options: Omit<SoDialogOffcanvasOptions, 'kind'>)Open an offcanvas panel dialog.
confirmModal(options?: SoDialogConfirmOptions)Open a confirm dialog and return Promise<boolean>.
promptModal(options?: SoDialogPromptOptions)Open a prompt dialog and return `Promise<string
formModal(options: SoDialogFormOptions)Open a dynamic form dialog and return submitted values.
SoDialog.open(options: SoDialogOptions)Open modal or offcanvas by kind.

Core Options (SoDialogBaseOptions)

NameTypeRequiredDefaultDescription
titlestringYes-Dialog title text.
contentstring | NodeYes-Dialog content.
confirmTextstringNo确认Confirm button text.
cancelTextstringNo取消Cancel button text.
confirmAction'hide' | 'destroy'NohideConfirm click close strategy.
closeOnEscbooleanNotrueAllow Esc to close the dialog.
closeOnBackdropbooleanNotrueAllow backdrop click close.
hideFooterbooleanNofalseHide default footer buttons.
footerAlign'start' | 'center' | 'end' | 'between'NoendFooter layout alignment.
footerButtonsSoDialogFooterButton[]Nobuilt-in confirm/cancelCustom footer buttons.
traceIdstringNo-Diagnostic trace identifier.
onLayoutStable(ctx) => voidNo-Triggered when layout is stable.
onAction(ctx) => voidNo-Triggered on footer actions.
onLifecycle/onBeforeOpen/...SoLifecycleHookNo-Dialog lifecycle hooks.
NameTypeDefaultDescription
idstringauto idReuse an existing modal instance by id.
position'center' | 'top' | 'bottom'centerModal position.
animation'slide' | 'fade' | 'zoom'fadeModal animation.
useModalbooleantrueUse native showModal() behavior.
draggablebooleanfalseEnable drag interactions.
dragHandleSoModalDragHandleheaderDrag handle selector target(s).
autoFitSizebooleantrueAuto fit panel to content changes.
scrollMode'body' | 'viewport' | 'none' | 'hybrid'autoAuto-fit scroll strategy.

Offcanvas-only Options (SoDialogOffcanvasOptions)

NameTypeDefaultDescription
placement'start' | 'end' | 'top' | 'bottom'endPanel placement.
animation'slide' | 'fade' | 'zoom'slideOffcanvas animation.

Return Handle (SoDialogHandle)

openModal and openOffcanvas return a SoDialogHandle which can be used to close, update, or inspect state.

FieldTypeDescription
dialogHTMLDialogElementNative dialog element.
close() => voidClose dialog.
refit() => voidTrigger layout refit manually.
setFooterButtons(buttons) => voidReplace footer button set.
updateFooterButton(id, updates) => booleanPatch one button by id.
onAction(listener) => () => voidSubscribe footer actions and return unsubscribe.

Usage Example

ts
import { openModal } from 'sodialog'

const handle = openModal({
  title: 'Delete item',
  content: '<p>Do you want to continue?</p>',
  confirmText: 'Delete',
  cancelText: 'Cancel',
})

handle.close()

Released under the MIT License.