跳转到内容

SusChoiceDialog

SusChoiceDialog

N-button choice card for modal dialogs — buttons render in order, awaitable ShowAsync resolves to the chosen index (or -1 on dismiss).

SusKit · Molecules(商业)

在 Playground 中打开

SusKit · Molecules

属性

名称类型默认值
TitleProp<string>"Choose"
MessageProp<string>""v-model
ButtonsProp<string[]>Array.Empty<string>()
ButtonIdsProp<string[]>Array.Empty<string>()

插槽

没有插槽。

事件

名称字段载荷
ChooseOnChooseint
ChooseIdOnChooseIdstring

样式钩子

USS 类契约 — 无需改 C# 即可覆盖外观。状态通过这些类切换:

  • sus-choice-dialog
  • sus-choice-dialog__btn
  • sus-choice-dialog__buttons

用法

xml
<template>
  <sus:SusChoiceDialog Title="Delete item?"
                       Message="This cannot be undone."
                       :Buttons="Options.Value"
                       @choose="OnChoose" />
</template>

<script>
public Prop<string[]> Options = new(new[] { "Cancel", "Delete" });
void OnChoose(int index) { /* index == Options.Value.Length - 1 → confirmed */ }
</script>
csharp
// Awaitable helper — hosts the card inside a SusModal and resolves when it closes.
int index = await SusChoiceDialog.ShowAsync(
    "Delete item?", "This cannot be undone.", "Cancel", "Delete");
if (index == 1) { /* confirmed */ }

说明

  • Buttons 中的最后一项渲染为主操作(elevated / primary 色);其余项渲染为 outlined / secondary — 把确认选项放在最后。
  • OnChoose(int) 以点击索引触发。ButtonIds 是与 Buttons 平行的可选数组 — 当被点击按钮有匹配 id 时,会同时触发 OnChooseId(string),调用方可按稳定 id 而非位置键控。
  • 静态 ShowAsync 辅助通过 SusModalService 将卡片包进 SusModal 宿主;若通过模态 scrim 关闭且未点击按钮,则解析为 -1