AgentPortrait
放进列表里直接使用的头像。
Ada
Grace
Alan
头像的选择顺序
按以下顺序选择:
- 照片:设置了
pictureUrl时 - 群组头像:
members非空时 - 角色:由
id推导
因此应用可以把手头有的数据直接传进来,得到合理的结果,不必在每个调用处写分支。
无需存储的身份
未显式指定时,形状和墨色由 id 哈希得出,所以每个用户都对应一个固定的角色,无需存储任何数据。不同的客户端、不同的会话以及服务端渲染,得到的结果都一致。
在 agent 上传入 shape 或 color 可以单独覆盖形状或颜色。
脸型
在 agent 上加 face: 'line' 即可使用线条脸。鼻子和形状、墨色一样从 id 哈希而来,所以同样稳定;设置 nose 可以指定鼻子,设为 null 则不画。
阵容 preset 也可以带脸型和鼻子;agent 上的显式值优先于预设,预设优先于哈希。
尺寸
xs, 16px
sm, 24px
md, 32px
lg, 40px
xl, 80px
静止与光晕
still 渲染静态图片而不是动画,适合长列表。halo 会加一层柔和的底色,颜色由角色自身的色相推导而来。
填充
fillPx 设定圆内角色的大小。圆本身的尺寸不变,变的只是里面绘制的内容:比圆小会留出边距,比圆大则会被裁掉。默认正好填满圆。它通过自定义属性设置,而不是设置子元素的宽度,因为三种渲染方式中有两种的子元素是 img,样式表已经为它们设定了尺寸。
fillPx 44
fillPx 64
fillPx 80
形状正在改变时
isMorphingShape 表示形状此刻正在被替换,例如编辑器打开着,用户正在网格里逐个点选。为 true 时,头像在落定窗口(SETTLE_MS,通过 useMarkSettle)内保持上一次落定的状态,这样一次变形只算一次变化,而不是两次。如果角色在同一帧里同时改变形状和表情,看起来不像同一个角色换了轮廓,而像换成了另一个角色。
无障碍
头像默认是 aria-hidden,只有带名称的照片除外。如果头像单独出现、旁边没有文字,请自行为它设置名称,详见无障碍。
API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
agent* | AgentLike | — | — |
className | string | — | — |
emotionId | string | — | Protocol id, for hosts that speak the wire format. Ignored when `state` is given. |
face | "symbol" | "capsule" | "cute" | "eyes" | "line" | "brow" | "glossy" | "sparkle" | "button" | "shades" | "droopy" | "bigmouth" | "pie" | "screen" | "teardrop" | "specs" | — | Face style, overriding whatever the agent identity resolves to. |
fillPx | number | — | Size of the character inside the circle. Smaller than the circle leaves a margin; larger crops it. Defaults to filling the circle exactly. |
halo | boolean | false | Soft colour wash behind the character. |
isMorphingShape | boolean | false | The shape is being changed under the character right now. Holds the last settled state for the settle window, so a morph is one change rather than two. A body that changes shape and expression in the same frame does not read as the same character having a new outline; it reads as a different character appearing. |
lineWeight | number | — | Stroke width multiplier. Not part of an identity, so always explicit. |
nose | "slant" | "angular" | "hook" | "long" | "curve" | "bow" | null | — | Nose, overriding the identity. `null` draws no nose. |
size | "xs" | "sm" | "md" | "lg" | "xl" | 'md' | — |
sizePx | number | — | Exact pixel size, overriding `size`. |
state | "idle" | "sleeping" | "drowsy" | "bored" | "waking" | "powering-down" | "listening" | "thinking" | "searching" | "reading" | "writing" | "working" | "loading" | "progress" | "radar" | "orbit" | "dictating" | "uploading" | "sending" | "receiving" | "messaging" | "waiting" | "spawning" | "composing" | "dragging" | "happy" | "excited" | "laughing" | "playful" | "proud" | "celebrate" | "bouncing" | "shy" | "sad" | "angry" | "confused" | "suspicious" | "surprised" | "scared" | "curious" | "humming" | "alerting" | "notifying" | "refusing" | — | — |
still | boolean | false | Render a still image instead of an animation. |
style | CSSProperties | — | — |
接下来
- AvatarGroup——重叠的群组头像
- 徽标与状态——未读数与状态点
- 智能体名册——侧边栏里的二十张脸