Skip to content

Dialog ​

A declarative modal dialog. @Binding var visible controls visibility; it renders a backdrop plus a centered panel, and its buttons reuse LhButton.

Spec source: lh-ui-core/specs/dialog.json · Golden cases: lh-ui-core/cases/dialog.json (8 entries, translated into XCTest, runnable on the macOS host)

Types ​

Six types determine the semantic color of the confirm button (buttonType(for:) maps to LhButtonType).

9:41Dialog types
Confirm deletion
This action will permanently delete the item. Continue?

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

swift
@State private var visible = false

LhDialog(
  visible: $visible,
  title: "Confirm deletion",
  content: "This action will permanently delete the item. Continue?",
  type: .danger,
  confirmText: "Confirm",
  cancelText: "Cancel"
)

Visibility and callbacks ​

  • visible = true renders the backdrop and the panel; visible = false emits no draw commands at all (golden case hidden-not-rendered).
  • Tapping "Confirm" fires onConfirm and then onClose in order (confirm-also-emits-onclose).
  • Tapping "Cancel" fires onCancel; onClose is responsible for setting visible back to false inside the component (wrapped in withAnimation).
  • When closable = true, tapping the backdrop also fires onClose (closable-overlay-emits-onclose); by default it does not close (not-closable-blocks-overlay-close).
9:41Dialog backdrop closable
Notice
Tap the backdrop to close

HTML mock preview (iOS / SwiftUI appearance), not an on-device render

API ​

Props ​

PropDescriptionTypeDefault
visibleWhether visible (controlled two-way binding)Bool—
titleTitleString""
contentBody contentString""
typeDialog type, determines the confirm button's semantic colorLhDialogType.default
confirmTextConfirm button text; nil (default) uses the language pack, "" hides the buttonString?Language pack (Simplified Chinese "确认")
cancelTextCancel button text; nil (default) uses the language pack, "" hides the buttonString?Language pack (Simplified Chinese "取消")
closableWhether a backdrop tap can close itBoolfalse
onConfirmConfirm callback(() -> Void)?nil
onCancelCancel callback(() -> Void)?nil
onCloseClose callback (fired by a backdrop tap, the Cancel button, and the Confirm button)(() -> Void)?nil

LhDialogType ​

ValueConfirm button typeBackground
.default.defaultcolor.background.default + border
.primary.primarycolor.primary.default
.success.successcolor.success.default
.warning.warningcolor.warning.default
.danger.dangercolor.danger.default
.info.infocolor.info.default

Token Reference ​

TokenPurpose
dialog.widthPanel width (320pt)
dialog.paddingHorizontal / dialog.paddingVerticalPanel padding
dialog.borderRadiusPanel corner radius
dialog.titleFontSize / dialog.contentFontSizeTitle and body font sizes
dialog.gapVertical gap between sections
color.background.overlayBackdrop color
color.background.defaultPanel background
color.text.{primary,regular}Title and body colors
shadow.basePanel shadow (LhShadow carrier)
zIndex.{modalBackdrop,modal}Backdrop and panel stacking order

Golden Case Mapping ​

case idAssertionLocal test
confirm-emits-onconfirmConfirming fires onConfirmtestConfirmUsesTypeColor
cancel-emits-oncancelCanceling fires onCanceltestCancelUsesNeutralColor
confirm-also-emits-oncloseConfirming also fires onClosetestConfirmUsesTypeColor
closable-overlay-emits-oncloseA backdrop tap fires onClosetestClosableFlagIsExposed
not-closable-blocks-overlay-closeBy default the backdrop does not close ittestNotClosableBlocksOverlay
hidden-not-renderedWhen hidden, nothing is renderedtestHiddenNotRendered
title-renders-textThe title renders correctlytestTitleUsesTitleTokens
danger-type-uses-danger-tokenThe danger type consumes the danger tokentestDangerTypeUsesDangerToken

Plus dedicated tests: testVisibleRendersAppearance / testLayoutUsesDialogTokens / testDarkColorsComeFromDarkTokens / testDimensionsAreIdenticalInDarkMode / testDialogViewInitAcceptsConstant.

bash
swift test --filter LhDialogTests    # Runs on the macOS host, no simulator required

lh-ui native bloodline · iOS (Swift + SwiftUI)