Prompts 提示词
AI 对话组件。公开入口:Prompts、Prompt。
在线演示
本页复用官方 Go gallery 的真实示例。下方可以切换场景、主题和深浅色;长页面支持滚动,复杂布局可以横向滚动或在独立页面打开。
示例代码
以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。
API
签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。
入口函数
ui.Prompts
func Prompts(c *Context, items []PromptItem) *PromptsWPrompts adds prompt cards for items.
if k, ok := ui.Prompts(c, prompts).Title("试试这样问").Wrap().Clicked(); ok { ask(k) }
返回 *PromptsW,可链式调用的方法见 PromptsW 方法。
ui.Prompt
func Prompt(c *Context, o ConfirmOptions) *ConfirmRefPrompt opens a dialog with a text input; read the value in OnOk with d.Value().
返回 *ConfirmRef,可链式调用的方法见 ConfirmRef 方法。
PromptsW 方法
ui.PromptsW:PromptsW is a group of clickable prompt suggestion cards (the empty state of a chat, follow-up questions under an answer). Not to be confused with Prompt, the input dialog.
| 方法 | 说明 | 签名 |
|---|---|---|
CardWidth | CardWidth sets the minimum card width when wrapping (default 200). | CardWidth(px float32) *PromptsW |
Clicked | Clicked returns the key of the card activated this frame. | Clicked() (string, bool) |
Layout | Layout applies layout options to the group. | Layout(opts ...layout.Option) *PromptsW |
Title | Title shows a heading above the cards (also the accessible name). | Title(s string) *PromptsW |
Vertical | Vertical stacks the cards in a column. | Vertical() *PromptsW |
Wrap | Wrap lets the cards wrap onto more rows instead of shrinking. | Wrap() *PromptsW |
ConfirmRef 方法
ui.ConfirmRef:ConfirmRef is a handle to an open dialog.
| 方法 | 说明 | 签名 |
|---|---|---|
Action | Action reports how the dialog was closed by the user ("" while open or after Close). | Action() ConfirmAction |
Close | Close closes the dialog without calling any callback. | Close() |
IsOpen | IsOpen reports whether the dialog is still shown. | IsOpen() bool |
Loading | Loading shows (or clears) the spinner on the OK button. | Loading(on bool) |
Value | Value returns the Prompt input. | Value() string |
PromptItem 参数类型
ui.PromptItem:PromptItem is one suggestion card of Prompts.
| 字段 | 说明 | 类型 |
|---|---|---|
Key | string | |
Label | string | |
Description | string | |
Icon | *icon.Icon | |
Disabled | bool |
ConfirmOptions 参数类型
ui.ConfirmOptions:ConfirmOptions configure Confirm, MessageBox and Prompt.
| 字段 | 说明 | 类型 |
|---|---|---|
Title | string | |
Content | string | |
Status | Status picks the leading icon: "info", "success", "warning", "error" or "none". | string |
OkText | default "确定" ("知道了" for Ant MessageBox) | string |
CancelText | default "取消" | string |
Danger | red OK button (destructive actions) | bool |
Width | float32 | |
MaskClosable | MaskClosable closes the dialog (as a cancel) on a mask click. | bool |
OnOk | OnOk runs on the UI thread when OK is activated. | func(d *ConfirmRef) |
OnCancel | OnCancel runs on Cancel, the close button, Escape or a mask click. | func() |
DistinguishCancelAndClose | DistinguishCancelAndClose tells the close button, Escape and a mask click apart from Cancel: they run OnClose (not OnCancel) and ConfirmRef.Action reports ConfirmActionClose. | bool |
OnClose | OnClose runs when the dialog is closed without Cancel or OK (close button, Escape, mask) and DistinguishCancelAndClose is set. | func() |
Center | Center centers the icon, title, content and buttons. | bool |
Draggable | Draggable lets the user move the dialog by dragging its title. | bool |
Icon | Icon replaces the status icon; it is drawn in the status color (the primary color for Status "none"). | *icon.Icon |
AutoFocusButton | AutoFocusButton picks the button focused when the dialog opens: "" or "ok" (default), "cancel", or "none" (antd autoFocusButton, null for none). | string |
NoKeyboard | NoKeyboard keeps Escape from closing the dialog (antd keyboard false, Element close-on-press-escape false). | bool |
InputValue | Prompt only. | string |
InputPlaceholder | string | |
Validate | Validate returns an error message ("" = valid); OK is refused while it fails. | func(v string) string |
相关链接
本页由完整组件表、实际 gallery 注册信息和 Go 源码(site/tools/compdoc)生成;新增组件未接入演示时,文档构建会报错。场景中的表单、表格、图表和移动端屏幕使用示例数据。