Dialog
Critical confirmations and multi-style dialogs
Usage
Best Practices
- Use
TxBottomDialogfor mobile-style bottom confirmations and destructive flow checkpoints. - Keep at most one destructive row, drive it with
type: 'error', and word it unambiguously — the tile is additive to the label, never the carrier of the meaning. - Pass
iconas an icon class the host's icon pipeline generates statically (i-carbon-trash-can). A name assembled at runtime is never scanned into the stylesheet, so the row renders an empty box. - Use
TxBlowDialogsparingly for high-emphasis announcements; its background transform is intentionally dramatic. - Use
TxPopperDialogfor compact centered prompts that still need modal semantics. - Use
TxTouchTipfor touch-first guidance with multiple action buttons. - Keep
messageHtmlout of user-generated content paths unless a caller has explicitly sanitized and branded it as trusted.
API Reference
message is rendered as plain text and preserves line breaks through component styles. Use messageHtml only for trusted, sanitized internal content.
TxBottomDialog Props
| Name | Type | Default | Description |
|---|---|---|---|
title | string | '' | Dialog title |
message | string | '' | Dialog message |
stay | number | 0 | Reserved auto-close duration prop; current runtime does not start a timer from stay alone. |
close | () => void | required | Close callback |
btns | DialogButton[] | [] | Button configs |
icon | string | '' | Legacy icon class prop; not rendered by the current template. |
index | number | 0 | z-index offset |
DialogButton interface
interface DialogButton {
content: string
type?: 'info' | 'warning' | 'error' | 'success'
icon?: string
time?: number
onClick: () => Promise<boolean> | boolean
loading?: (done: () => void) => void
}
TxBlowDialog Props
| Name | Type | Default | Description |
|---|---|---|---|
title | string | '' | Dialog title |
message | string | '' | Plain-text message |
messageHtml | DialogMessageHtml | '' | Trusted HTML message for sanitized internal call sites |
confirmText | string | 'Confirm' | Confirm button text |
close | () => void | required | Close callback |
comp | Component | undefined | Custom component |
render | () => VNode | undefined | Render function |
TxPopperDialog Props
| Name | Type | Default | Description |
|---|---|---|---|
title | string | '' | Dialog title |
message | string | '' | Plain-text message |
messageHtml | DialogMessageHtml | '' | Trusted HTML message for sanitized internal call sites |
confirmText | string | 'Confirm' | Confirm button text |
close | () => void | required | Close callback |
comp | Component | undefined | Custom component |
render | () => VNode | undefined | Render function |
TxTouchTip Props
| Name | Type | Default | Description |
|---|---|---|---|
title | string | '' | Title |
message | string | '' | Message text |
messageHtml | DialogMessageHtml | '' | Trusted HTML message for sanitized internal call sites |
buttons | TouchTipButton[] | [] | Button configs |
close | () => void | required | Close callback |
Events
| Event | Payload | Description |
|---|---|---|
| - | - | Dialog variants do not emit Vue events; they close through the required close prop callback. |
Slots
| Slot | Props | Description |
|---|---|---|
| - | - | Dialog variants do not expose slots. Use comp or render for custom TxBlowDialog / TxPopperDialog content. |
BottomDialog
Bottom-aligned dialog with customizable buttons and motion.
BottomDialog
Bottom sheet confirmation dialog.
Loading demo...
Action rows and icons
Every button renders as a full-width row. An icon becomes its leading glyph, and type: 'error' is the only tone that repaints the row.
Loading demo...
Button types
type selects the row's tone, and only error repaints it. info, warning and success all render the neutral row, so the sheet carries a single destructive colour to read.
const btns = [
{ content: 'Neutral row', type: 'info', onClick: () => true },
{ content: 'Also neutral', type: 'success', onClick: () => true },
{ content: 'Destructive row', type: 'error', onClick: () => true },
]
Auto confirm timer
const btns = [
{
content: 'Auto confirm',
type: 'success',
time: 5,
onClick: () => true,
},
]
Loading state
const btns = [
{
content: 'Submit',
type: 'success',
onClick: async () => {
await saveData()
return true
},
},
]
BlowDialog
A centered dialog with dramatic animation.
BlowDialog
Focused, high-impact dialog.
Loading demo...
PopperDialog
PopperDialog
Lightweight popper-style prompt.
Loading demo...
TouchTip
TouchTip
Touch-friendly guidance prompt.
Loading demo...
Custom components
import CustomContent from './CustomContent.vue'
function showCustomDialog() {
return h(TxBlowDialog, {
comp: CustomContent,
close: () => {},
})
}
Render function
function showRenderDialog() {
return h(TxBlowDialog, {
render: () => h('div', [
h('h2', 'Dynamic content'),
h('p', 'Created with a render function'),
]),
close: () => {},
})
}
Overview
- All dialog variants teleport to
body, assign z-index through the shared z-index manager, and close through the requiredclose()callback. TxBottomDialogrenders a bottom-anchored sheet: an opaque--tx-bg-colorpanel with24pxcorners, a header holding the title and a circular close control, then one full-width action row per entry inbtns. The close control cancels — it callsclose()after the same leave animation Escape uses, and commits nothing.- Only
type: 'error'repaints a row (--tx-color-danger-light-9fill, the danger hue mixed 55% toward the primary ink). The measured label contrast is 5.10:1 in the light theme, 6.92:1 dark, 9.41:1 and 12.77:1 in the two high-contrast themes — every one clears the 4.5:1 that 14px text needs. Row glyphs and the close icon sit on--tx-text-color-regular, becausesecondarymeasures 2.75:1 on the row fill in the light theme, under the 3:1 an icon-only glyph needs. - A row's
loadingcallback — and the internal 200ms click window — disables that row and shows a spinner inside it, so a slowonClickcannot be submitted twice. - Escape closes the active dialog after its leave animation;
TxBottomDialog,TxBlowDialog,TxPopperDialog, andTxTouchTiprestore the previously focused element on unmount. TxBottomDialog,TxTouchTip, andTxBlowDialogall derive instance-level title/description ids viauseId();TxPopperDialoguses stable internal ids for its default title/content regions.- Plain
messagerenders as text and preserves line breaks. UsemessageHtmlonly withasTrustedDialogHtml()after sanitizing internal content. - Every variant's body sets
overflow-wrap: anywhere. A hash, an id or a URL offers no break opportunity, so a vertical scroll cannot rescue it — the token runs past the panel, which clips it.anywhererather thanbreak-wordbecause onlyanywherelets the token shrink the content's min-content width, so a long value stops widening the panel as well. - Every variant's body caps its own height and scrolls. The panels are
overflow: hidden, so a body without a cap of its own is cut rather than scrolled:TxBottomDialogcaps its message and its action list at46vheach and scrolls them independently, and caps the sheet itself at100vh - 48px, so a tall combination shrinks the two bodies instead of pushing the header off the top edge;TxTouchTipscrolls inside its fixed height, matching the300pxthatTxBlowDialogandTxPopperDialogalready used. DialogButton.onClick()/TouchTipButton.onClick()closes when it resolvestrueand keeps the dialog open when it resolvesfalse.
Technologies
- Sources:
packages/tuffex/packages/components/src/dialog/src/TxBottomDialog.vue,TxBlowDialog.vue,TxPopperDialog.vue, andTxTouchTip.vueconfirm teleport-to-body rendering, z-index allocation, Escape close behavior, focus restore, button return semantics, text-vs-trusted-HTML paths, and component/render content hooks. - Type contracts:
packages/tuffex/packages/components/src/dialog/src/types.tsdefines trusted HTML branding,asTrustedDialogHtml, button interfaces, dialog props, and exported instance types. - Verified coverage: Coverage:
packages/tuffex/packages/components/src/dialog/__tests__/dialog.test.tsverifies ARIA wiring, Escape close, focus restore, the close control cancelling without dispatching a row action, the destructive row tone, text-vs-trusted-HTML rendering, and button return semantics. - Export:
packages/tuffex/packages/components/src/dialog/index.tswraps each dialog withwithInstall, exports all variants, exportsasTrustedDialogHtml, and exposes public types.
查看源码
packages/tuffex/packages/components/src/dialog/index.ts