• 简体中文
  • CharacterPicker

    形状与墨色选择器。

    形状
    配色
    import { useState } from 'react';
    import { CharacterPicker, CharacterMark, type FaceStyle } from '@aora-bot/react';
    
    export default function Demo() {
      const [shape, setShape] = useState('blob' as const);
      const [color, setColor] = useState('blue' as const);
    
      return (
        <div className="site-demo">
          <CharacterMark shape={shape} color={color} state="happy" sizePx={120} />
          <CharacterPicker
            shape={shape}
            color={color}
            onSelectShape={setShape as never}
            onSelectColor={setColor as never}
          />
        </div>
      );
    }

    选中环跟随形状

    高亮用被选形状自己的轮廓画,而不是一个通用圆——六边形得到六边形环。它是由画出身体的同一函数生成的 CSS 蒙版,所以用 defineShape 注册的形状不需要额外工作就能得到正确的环。

    布局

    形状
    配色
    import { CharacterPicker } from '@aora-bot/react';
    
    export default function Demo() {
      return (
        <div className="site-demo site-demo--column">
          <CharacterPicker
            shape="hex"
            color="green"
            layout="row"
            shapes={['blob', 'hex', 'onigiri', 'cloud', 'leaf']}
          />
        </div>
      );
    }

    脸型与鼻子

    传入 face 会加上一个 cute | eyes | line 切换。选中线条脸时会跟着出现一行六种鼻子,而且每个形状预览都按所选脸型绘制,读者看到的就是将得到的。

    形状
    配色
    脸型
    鼻子
    import { useState } from 'react';
    import { CharacterPicker, CharacterMark, type FaceStyle } from '@aora-bot/react';
    
    export default function Demo() {
      const [shape, setShape] = useState('pear' as const);
      const [color, setColor] = useState('green' as const);
      const [face, setFace] = useState<FaceStyle>('line');
      const [nose, setNose] = useState('slant' as const);
    
      return (
        <div className="site-demo">
          <CharacterMark shape={shape} color={color} state="happy" sizePx={120} face={face} nose={nose} />
          <CharacterPicker
            shape={shape}
            color={color}
            face={face}
            nose={nose}
            shapes={['pear', 'blob', 'bun', 'ghost', 'egg', 'tofu']}
            colors={['green', 'blue', 'orange']}
            onSelectShape={setShape as never}
            onSelectColor={setColor as never}
            onSelectFace={setFace}
            onSelectNose={setNose as never}
          />
        </div>
      );
    }

    省略 face,选择器就仍然只是形状与墨色选择器。

    限制选项

    形状
    配色
    import { CharacterPicker } from '@aora-bot/react';
    
    export default function Demo() {
      return (
        <CharacterPicker
          shape="pill"
          color="magenta"
          shapes={['pill', 'tofu', 'ghost', 'bell']}
          colors={['magenta', 'violet', 'cyan']}
        />
      );
    }

    预览尺寸

    sizePx 设定每个形状预览的大小;脸型和鼻子预览随之缩放。默认是 PICKER_MARK_PX(36)。lineWeight 会传给预览,让选择器与它所编辑的角色一致。

    形状
    配色
    import { CharacterPicker } from '@aora-bot/react';
    
    export default function Demo() {
      return (
        <CharacterPicker
          shape="star"
          color="yellow"
          layout="row"
          sizePx={24}
          shapes={['star', 'hex', 'flower', 'flame', 'bell']}
          colors={['yellow', 'orange', 'red']}
        />
      );
    }

    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"——
    classNamestring——
    colorsreadonly ("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.
    lineWeightnumber—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)——
    shapesreadonly ("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_IDSRestrict the offered shapes.
    showSelectionbooleantrueHide the selection ring, for read-only displays. The selection is still announced.
    sizePxnumber—Size of each shape preview. Face and nose previews scale with it. Defaults to `PICKER_MARK_PX`.
    styleCSSProperties——

    接下来