• English
  • CharacterSelector

    Shape and ink chooser.

    Shape
    Colour
    import { useState } from 'react';
    import { CharacterSelector, 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} />
          <CharacterSelector
            shape={shape}
            color={color}
            onSelectShape={setShape as never}
            onSelectColor={setColor as never}
          />
        </div>
      );
    }

    The selection ring follows the shape

    The highlight is drawn in the selected shape's own outline, not as a generic circle — a hexagon gets a hexagonal ring. It is a CSS mask generated by the same function that draws the body, so a shape registered with defineShape gets a correct ring without any extra work.

    Layouts

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

    Face style and nose

    Pass face to add a cute | eyes | line toggle. While the line face is selected, a row of the six noses appears. Every shape preview is drawn in the chosen style, so what you see is what you get.

    Shape
    Colour
    Face
    Nose
    import { useState } from 'react';
    import { CharacterSelector, 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} />
          <CharacterSelector
            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>
      );
    }

    Omit face and the picker stays a shape and ink chooser.

    Restricting the options

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

    Preview size

    sizePx sets the size of each shape preview; face and nose previews scale with it. The default is SELECTOR_MARK_PX (36). lineWeight is passed to the previews so a picker matches the character it edits.

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

    Colour chips

    Each colour chip shows the colour the body takes on the current page (getInkColorCss), so the black chip is white in dark mode. A chip that almost matches the page background gets the same hairline edge as the body (--aora-rim). See Palette.

    onSelectColor

    The colour callback is onSelectColor, spelt like the color prop and the ColorId type it hands back.

    Two more pickers

    AgentCharacterSelector holds its edits until they are confirmed, for a dialog where a click is only a proposal and Cancel must discard it. CompactCharacterSelector is cut down to a handful of shapes and inks, for the space beside a sign-up form.

    Keyboard and assistive technology

    One radio group per row — shapes, inks, and when enabled face style and nose — each with an accessible name. Every option has role="radio" and aria-checked, and focus is visible. Tab moves between the groups and arrow keys move within one, which is what a radio group is expected to do.

    API

    PropTypeDefaultDescription
    color*"cream" | "ivory" | "black" | "brown" | "red" | "orange" | "yellow" | "green" | "cyan" | "blue" | "violet" | "magenta" | "pink" | "gray" | "sage" | "clay" | "navy" | "mauve" | "night" | "cocoa" | "sky" | "blush" | "lilac" | "butter" | "meadow" | "peach" | "pine" | "crimson" | "snow" | "indigo" | "crust" | "jade" | "peel" | "mint" | "carrot" | "caramel" | "lagoon" | "lemon" | "aqua" | "sand" | "grass" | "wine" | "plum"——
    shape*"circle" | "mochi" | "blob" | "pebble" | "egg" | "bun" | "tofu" | "pill" | "hex" | "onigiri" | "gem" | "cloud" | "drop" | "leaf" | "flower" | "clover" | "sprout" | "mushroom" | "acorn" | "cactus" | "eggplant" | "pear" | "apple" | "strawberry" | "cherry" | "avocado" | "melon" | "pudding" | "toast" | "icecream" | "cupcake" | "fries" | "candy" | "burger" | "star" | "heart" | "flame" | "bell" | "ghost" | "bot" | "crescent" | "boba" | "planet" | "cottage" | "chat" | "gift" | "bulb" | "fish" | "octopus" | "seal" | "puffer" | "cat" | "bunny" | "bear" | "chick" | "penguin" | "pig" | "fox" | "lion" | "hamster" | "hedgehog" | "koala" | "bat" | "bob" | "topknot" | "spiky" | "curly" | "twinbuns" | "chunk" | "lump" | "fluff" | "spook" | "pumpkin" | "nightcat" | "batling" | "cauldron" | "witch" | "toffee" | "manor" | "wisp" | "deadtree" | "scarecrow" | "tombstone" | "candycorn" | "mummy" | "skull" | "spider" | "owl" | "pail" | "candle" | "vampire" | "witchmochi" | "lanterncat" | "nightcapmoon" | "xm-tree" | "xm-snowman" | "xm-ginger" | "xm-deer" | "xm-stocking" | "xm-cane" | "xm-globe" | "xm-santa" | "xm-cocoa" | "xm-bauble" | "xm-mochi-hat" | "xm-chirp-hat" | "xm-waddle-scarf" | "xm-miso-antlers" | "xm-kiki-muffs" | "xm-pokey-mittens" | "xm-pud-holly" | "xm-chime-holly" | "sf-tangyuan" | "sf-hongbao" | "sf-firecracker" | "sf-fu" | "sf-nian" | "sf-knot" | "sf-orange" | "sf-goat" | "sf-koi" | "sf-ingot" | "sf-kiki-tiger" | "sf-waddle-scarf" | "sf-hop-lantern" | "sf-maru-collar" | "sf-mochi-fu" | "sf-lulu-crackers" | "sf-nook-couplets" | "sf-chirp-lion" | "ma-mooncake" | "ma-rabbit" | "ma-lantern" | "ma-osmanthus" | "ma-moon" | "ma-pomelo" | "ma-skylantern" | "ma-crab" | "ma-mochi-ears" | "ma-hop-cake" | "ma-chirp-cake" | "ma-lulu-pin" | "ma-kiki-pin" | "ma-miso-lamp" | "ma-waddle-lamp" | "ma-bao-hat" | "ma-pip-hat" | "ea-dapple" | "ea-wicker" | "ea-cocoa" | "ea-crunchy" | "ea-posy" | "ea-breezy" | "ea-peeky" | "ea-hop-crown" | "ea-chirp-shell" | "ea-mochi-ears" | "ea-momo-ears" | "ea-waddle-shell" | "ea-kiki-crown" | "ea-lulu-bow" | "ea-hammy-basket" | "sm-popsicle" | "sm-coconut" | "sm-ring" | "sm-castle" | "sm-fan" | "sm-ice" | "sm-pineapple" | "sm-shell" | "sm-cicada" | "sm-miso-shades" | "sm-waddle-goggles" | "sm-chirp-hat" | "sm-hop-hat" | "sm-bruno-melon" | "sm-koko-lei" | "sm-leo-sunscreen" | "sm-scoop-shades" | "vl-bonbon" | "vl-rose" | "vl-cherub" | "vl-ring" | "vl-dove" | "vl-dipped" | "vl-mochi-stickers" | "vl-miso-bowtie" | "vl-waddle-bowtie" | "vl-bruno-rose" | "vl-hop-glasses" | "vl-oink-stickers" | "vl-kiki-letter" | "vl-chirp-headband"——
    classNamestring——
    colorsreadonly ColorId[]—Restrict the offered colours.
    face"symbol" | "capsule" | "cute" | "eyes" | "line" | "brow" | "glossy" | "sparkle" | "button" | "shades" | "droopy" | "bigmouth" | "pie" | "screen" | "teardrop" | "specs"—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: ColorId) => void)——
    onSelectFace((face: "symbol" | "capsule" | "cute" | "eyes" | "line" | "brow" | "glossy" | "sparkle" | "button" | "shades" | "droopy" | "bigmouth" | "pie" | "screen" | "teardrop" | "specs") => void)——
    onSelectNose((nose: "slant" | "angular" | "hook" | "long" | "curve" | "bow") => void)——
    onSelectShape((shape: ShapeId) => void)——
    shapesreadonly ShapeId[]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 `SELECTOR_MARK_PX`.
    styleCSSProperties——

    Next