Dialog
Declarative modal dialog. Title + content + confirm / cancel buttons, with the scrim and the card rendered on separate layers.
Spec source:
lh-ui-core/specs/dialog.json· Golden cases:lh-ui-core/cases/dialog.json(12 cases, translated into hypium tests)
Declarative visibility
When visible is false, nothing is rendered. After confirm / cancel the component fires onClose, and the host sets visible back to false (isomorphic to react's open / onClose). The component must be mounted as the last child of the page's Stack; elevation is carried by the zIndex tokens.
Basic usage
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
LhDialog({
visible: this.dialogVisible,
title: 'Confirm deletion',
content: 'Deletion is irreversible. Are you sure you want to delete this record?',
type: LhDialogType.Warning,
closable: true,
onConfirm: () => {},
onCancel: () => {},
onClose: () => { this.dialogVisible = false },
})Types
type decides the semantic type of the confirm button (mapped to LhButtonType); the danger type's confirm button takes the danger color.
HTML mockup preview (HarmonyOS / ArkUI appearance) — not an on-device render
API
Props
| Prop | Description | Type | Default |
|---|---|---|---|
visible | Whether to show; nothing is rendered when false | boolean | false |
title | Title | string | '' |
content | Body content | string | '' |
type | Semantic type, decides the confirm button's type | LhDialogType | Default |
confirmText | Confirm button label | string | Language pack (@lh-i18n) |
cancelText | Cancel button label | string | Language pack (@lh-i18n) |
closable | Whether tapping the scrim area fires onClose | boolean | false |
onConfirm | Fired when the confirm button is tapped (onClose follows) | () => void | Empty function |
onCancel | Fired when the cancel button is tapped (onClose follows) | () => void | Empty function |
onClose | Fired after confirm / cancel / tapping the closable scrim | () => void | Empty function |
LhDialogType
| Value | Confirm button type |
|---|---|
Default | LhButtonType.Default |
Primary | LhButtonType.Primary |
Success | LhButtonType.Success |
Warning | LhButtonType.Warning |
Danger | LhButtonType.Danger |
Info | LhButtonType.Info |
Token reference
| Token | Purpose |
|---|---|
dialog.width | Content card width (320vp) |
dialog.paddingHorizontal / dialog.paddingVertical | Card paddings (20 / 20vp) |
dialog.titleFontSize / dialog.contentFontSize | Title / body font size (16 / 14) |
dialog.gap | Spacing between title and body, and between body and the button row (12vp) |
dialog.borderRadius | Card corner radius |
color.background.default / color.background.overlay | Card background / scrim color |
color.text.primary / color.text.regular | Title / body color |
shadow.base | Card shadow |
zIndex.modalBackdrop / zIndex.modal | Scrim / dialog elevation |
Golden case reference
How the 12 assertions in cases/dialog.json map onto hypium tests (entry/src/test/Dialog.test.ets):
| case id | Assertion | Local test |
|---|---|---|
confirm-emits-onconfirm | Confirm fires onConfirm | confirm_button_type_maps_from_dialog_type |
cancel-emits-oncancel | Cancel fires onCancel | type_variants_map_to_button_types |
confirm-also-emits-onclose | Confirm also fires onClose | type_variants_map_to_button_types |
closable-overlay-emits-onclose | A closable scrim tap fires onClose | overlay_and_zindex_use_tokens |
not-closable-blocks-overlay-close | A non-closable scrim swallows the tap | overlay_and_zindex_use_tokens |
hidden-not-rendered | Nothing is rendered while hidden | card_dimensions_use_tokens (visible gate) |
title-renders-text | The title consumes the font-size tokens | title_and_content_use_font_tokens |
danger-type-uses-danger-token | The danger type's confirm button takes the danger color | danger_type_uses_danger_token |
confirm-text-fallback-locale | 确认 label falls back to language pack when unset | dialog_confirm_falls_back_to_current_locale(Locale.test.ets) |
cancel-text-fallback-locale | 取消 label falls back to language pack when unset | dialog_confirm_falls_back_to_default_pack(Locale.test.ets) |
confirm-text-explicit-wins | Explicit 确认 text wins over the pack | dialog_explicit_text_wins_over_pack(Locale.test.ets) |
cancel-text-empty-hides-button | Empty string hides the 取消 button | dialog_empty_string_stays_empty(Locale.test.ets) |
Plus dark-mode specifics: dark_colors_come_from_dark_tokens / dimensions_are_identical_in_dark_mode. To run: in DevEco Studio, right-click entry/src/test → Run Tests.

