Skip to content

Dialog ​

A modal overlay for important confirmations or content that needs the user's focus. The window-level layering is hosted by the Compose Dialog.

Spec source: lh-ui-core/specs/dialog.json · Golden cases: cases/dialog.json (12 cases: token mappings translated into JVM unit tests, interaction and label semantics into Compose UI Test)

Types ​

type determines the confirm button's color (mapped 1:1 to LhButtonType); the rest of the layout stays the same.

9:41Dialog
Title
This is body text that explains the impact of the current action.

HTML mock preview (Android / Compose look), not an on-device render

kotlin
var visible by remember { mutableStateOf(false) }
LhDialog(
  visible = visible,
  onConfirm = { /* confirm logic */ },
  onCancel = {},
  onClose = { visible = false },
  title = "删除确认",
  content = "删除后不可恢复,确定删除吗?",
  type = LhDialogType.danger,
)

Semantic type and overlay ​

When type is danger, the confirm button takes the danger color; closable controls whether tapping the overlay or pressing the back button triggers onClose.

9:41Dialog danger
Confirm deletion
This action cannot be undone. Delete anyway?

HTML mock preview (Android / Compose look), not an on-device render

When the confirm / cancel button is tapped, the business callback fires first, then onClose — the host uses this to set visible to false.

API ​

Props ​

PropDescriptionTypeDefault
visibleWhether the dialog is shown; when false, nothing is renderedBoolean—
onConfirmTriggered when the confirm button is tapped() -> Unit—
onCancelTriggered when the cancel button is tapped() -> Unit—
onCloseTriggered after confirm / cancel, or (when closable) when the overlay is tapped() -> Unit—
titleTitleString?null
contentBody contentString?null
typeSemantic type; determines the confirm button's type (color)LhDialogTypedefault
confirmTextConfirm button text; falls back to the locale pack when omitted, hidden when emptyString@lh-i18n
cancelTextCancel button text; falls back to the locale pack when omitted, hidden when emptyString@lh-i18n
closableWhether tapping the overlay or pressing back triggers onCloseBooleanfalse
titleContentTitle content (overrides title; the spec's title slot)@Composable (() -> Unit)?null
contentContentBody content (overrides content; the spec's default slot)@Composable (() -> Unit)?null
footerBottom button area (overrides the default buttons; the spec's footer slot)@Composable (() -> Unit)?null
modifierModifier (applied to the content card)ModifierModifier

LhDialogType ​

ValueConfirm button type
default / primary / success / warning / danger / infoThe LhButtonType of the same name, taking the corresponding semantic color

Token reference ​

TokenUsage
dialog.widthContent card width (320dp)
dialog.borderRadiusCard corner radius (follows radius.base)
dialog.paddingHorizontal / dialog.paddingVerticalCard padding (follows spacing.lg)
dialog.titleFontSize / dialog.contentFontSizeTitle / body font sizes
dialog.gapSpacing between the title, body, and button area
zIndex.modal / zIndex.modalBackdropLayering semantics alignment (the Compose Dialog hosts the window-level layering)
color.background.overlayOverlay color
color.background.defaultCard background color
color.text.primary / color.text.regularTitle / body color
shadow.baseCard shadow (Compose has no spread; the blur radius is used as elevation)

Golden case reference ​

case idAssertionLocal test
confirm-emits-onconfirmConfirm triggers onConfirm + onCloseLhDialogTest.confirm_emits_onConfirm_and_onClose (Compose UI Test)
confirm-also-emits-oncloseConfirm also triggers onClosesame as above
cancel-emits-oncancelCancel triggers onCancel + onCloseLhDialogTest.cancel_emits_onCancel_and_onClose
closable-overlay-emits-oncloseWhen closable, tapping the overlay triggers onCloseLhDialogTest.closable_overlay_emits_onClose
not-closable-blocks-overlay-closeWhen not closable, the overlay tap is swallowedLhDialogTest.not_closable_blocks_overlay_close
hidden-not-renderedWhen hidden, nothing is renderedLhDialogTest.hidden_is_not_rendered
title-renders-textThe title renders textLhDialogTest.title_renders_text
danger-type-uses-danger-tokenThe danger type's confirm button takes the danger colorLhDialogDefaultsTest.danger_type_maps_to_danger_button
confirm-text-fallback-localeAn omitted confirm label falls back to the locale pack (default "Confirm")LhDialogTest.confirm_text_falls_back_to_locale
cancel-text-fallback-localeAn omitted cancel label falls back to the locale pack (default "Cancel")LhDialogTest.cancel_text_falls_back_to_locale
confirm-text-explicit-winsAn explicit confirm label takes precedence over the locale packLhDialogTest.confirm_text_explicit_wins
cancel-text-empty-hides-buttonAn empty cancel label hides the button (no locale fallback)LhDialogTest.cancel_text_empty_hides_button
bash
./gradlew :components:dialog:test                             # JVM part
./gradlew :components:dialog:connectedAndroidTest             # Interaction part (requires a device)

lh-ui native bloodline · Android (Kotlin + Compose)