CharacterPicker
形状与墨色选择器。
形状
配色
选中环跟随形状
高亮用被选形状自己的轮廓画,而不是一个通用圆——六边形得到六边形环。它是由画出身体的同一函数生成的 CSS 蒙版,所以用 defineShape 注册的形状不需要额外工作就能得到正确的环。
布局
形状
配色
脸型与鼻子
传入 face 会加上一个 cute | eyes | line 切换。选中线条脸时会跟着出现一行六种鼻子,而且每个形状预览都按所选脸型绘制,读者看到的就是将得到的。
形状
配色
脸型
鼻子
省略 face,选择器就仍然只是形状与墨色选择器。
限制选项
形状
配色
预览尺寸
sizePx 设定每个形状预览的大小;脸型和鼻子预览随之缩放。默认是 PICKER_MARK_PX(36)。lineWeight 会传给预览,让选择器与它所编辑的角色一致。
形状
配色
onSelectColor
墨色回调是 onSelectColor,拼写与 color prop 和它交回的 ColorId 类型一致。
另外两个选择器
AgentCharacterPicker 把修改暂存到确认时才生效,给点击只是提议、取消必须有意义的对话框用。CompactCharacterPicker 只留一小撮形状和墨色,放在注册表单旁边。
键盘与辅助技术
每一行一个单选组——形状、墨色,以及启用时的脸型和鼻子——各有可访问名称。每个选项都有 role="radio" 和 aria-checked,焦点可见。Tab 在组之间移动,方向键在组内移动,这正是单选组应有的行为。
API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
color* | "black" | "brown" | "red" | "orange" | "yellow" | "green" | "cyan" | "blue" | "violet" | "magenta" | "pink" | "gray" | — | — |
shape* | "mochi" | "circle" | "blob" | "pebble" | "egg" | "bun" | "tofu" | "pill" | "hex" | "onigiri" | "gem" | "cloud" | "drop" | "leaf" | "flower" | "clover" | "sprout" | "mushroom" | "acorn" | "cactus" | "pear" | "apple" | "strawberry" | "cherry" | "star" | "heart" | "flame" | "bell" | "ghost" | "bot" | "crescent" | "boba" | "fish" | "octopus" | "cat" | "bunny" | "bear" | "chick" | "penguin" | "pig" | "fox" | "bob" | "topknot" | "spiky" | "curly" | "twinbuns" | — | — |
className | string | — | — |
colors | readonly ("black" | "brown" | "red" | "orange" | "yellow" | "green" | "cyan" | "blue" | "violet" | "magenta" | "pink" | "gray")[] | — | Restrict the offered colours. |
face | "cute" | "eyes" | "line" | — | Face style. Passing this shows the face toggle; in line mode a row of noses follows. Omit it to keep the picker to shape and colour. |
layout | "grid" | "row" | 'grid' | `grid` stacks shapes over colours in fixed columns; `row` keeps both groups on one line. |
lineWeight | number | — | Line weight for the previews, so a picker matches the character it edits. |
nose | "slant" | "angular" | "hook" | "long" | "curve" | "bow" | null | — | Nose for the line face. Defaults to the first nose while `face` is `line`. `null` — the same "no nose" every other surface takes — also lands on the first nose, because the picker has to highlight one of the offered options and "none" is not one of them. |
onSelectColor | ((color: "black" | "brown" | "red" | "orange" | "yellow" | "green" | "cyan" | "blue" | "violet" | "magenta" | "pink" | "gray") => void) | — | — |
onSelectFace | ((face: "cute" | "eyes" | "line") => void) | — | — |
onSelectNose | ((nose: "slant" | "angular" | "hook" | "long" | "curve" | "bow") => void) | — | — |
onSelectShape | ((shape: "mochi" | "circle" | "blob" | "pebble" | "egg" | "bun" | "tofu" | "pill" | "hex" | "onigiri" | "gem" | "cloud" | "drop" | "leaf" | "flower" | "clover" | "sprout" | "mushroom" | "acorn" | "cactus" | "pear" | "apple" | "strawberry" | "cherry" | "star" | "heart" | "flame" | "bell" | "ghost" | "bot" | "crescent" | "boba" | "fish" | "octopus" | "cat" | "bunny" | "bear" | "chick" | "penguin" | "pig" | "fox" | "bob" | "topknot" | "spiky" | "curly" | "twinbuns") => void) | — | — |
shapes | readonly ("mochi" | "circle" | "blob" | "pebble" | "egg" | "bun" | "tofu" | "pill" | "hex" | "onigiri" | "gem" | "cloud" | "drop" | "leaf" | "flower" | "clover" | "sprout" | "mushroom" | "acorn" | "cactus" | "pear" | "apple" | "strawberry" | "cherry" | "star" | "heart" | "flame" | "bell" | "ghost" | "bot" | "crescent" | "boba" | "fish" | "octopus" | "cat" | "bunny" | "bear" | "chick" | "penguin" | "pig" | "fox" | "bob" | "topknot" | "spiky" | "curly" | "twinbuns")[] | SHAPE_IDS | Restrict the offered shapes. |
showSelection | boolean | true | Hide the selection ring, for read-only displays. The selection is still announced. |
sizePx | number | — | Size of each shape preview. Face and nose previews scale with it. Defaults to `PICKER_MARK_PX`. |
style | CSSProperties | — | — |
接下来
- AgentCharacterPicker——修改暂存到确认才生效
- AvatarEditor——角色、生成、上传三个标签页
- 角色设置——挑选智能体的外观