AgentCharacterSelector
先暂存、确认后才生效的 CharacterSelector。
已提交 hex、blue——写入 0 次
形状
配色
一次点击是一个提议
普通选择器是受控组件:每次点击都由宿主来应用。这在设置表单里没问题,但在对话框里不合适,因为对话框中的点击只是提议,取消必须真正生效。这个组件把提议保存在本地,确认时才提交一个值。这样宿主每个对话框只写一次存储,而不是每次点击写一次,页头的头像也不会在用户犹豫时来回切换五种形状。
确认时,onCommit 会收到暂存的 CharacterChoice;放弃时触发 onCancel,暂存的修改重置为 value。immediate 会关闭暂存,每次选择都立即提交,适用于设置表单,宿主不必更换组件。
图片与操作按钮
hasPicture 表示智能体有自己的照片。此时网格不显示选中环,因为屏幕上显示的是照片,而不是下面的角色;给一个看不见的六边形加高亮,会误导用户。选中状态仍会通知辅助技术。
actions={false} 会隐藏确认和放弃按钮,适合把按钮放在对话框底栏的宿主。要用自己的按钮提交时,保持 immediate 关闭,并把选择器放进由你控制提交的表单里。
API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
value* | CharacterChoice | — | The committed appearance. Staged edits start from here and reset to it on cancel. |
actions | boolean | true | Show the confirm and discard buttons. Off when a host supplies its own. |
className | string | — | — |
colors | readonly ColorId[] | — | — |
hasPicture | boolean | false | The agent has a picture of its own. The grid then shows no selection ring, because the character underneath is not what is on screen — highlighting a shape would claim the avatar is something it is not. Picking still stages a choice, so confirming swaps the picture out for the character. |
immediate | boolean | false | Commit on every pick instead of waiting for confirmation. |
layout | "grid" | "row" | 'grid' | — |
lineWeight | number | — | — |
onCancel | (() => void) | — | Called when the staged appearance is discarded. |
onCommit | ((choice: CharacterChoice) => void) | — | Called with the staged appearance when it is confirmed. |
shapes | readonly ShapeId[] | — | — |
style | CSSProperties | — | — |
接下来
- CompactCharacterSelector——注册表单用的精简版
- 角色设置——挑选智能体的外观