Skip to Content
BBRICKSv0.7.4
PR PortalMessages

AudiencePicker

The composer's audience: the mode as a segmented control (the mock's cm-to), then the brand, group or tier select, or a searchable checklist of creators (photo, name, tier); under it the live count, announced politely as it changes. Controlled; the app counts (it knows the audience), the picker only shows the number.

import { AudiencePicker } from '@ergasti/bricks';

Examples

Who receives it

A choice of audience (everyone, a brand's creators, a group, a tier, hand-picked creators) with a live count; offer only the modes the sender may use.

Code
import { useState } from 'react';
import { AudiencePicker, type AudienceChoice } from '@ergasti/bricks';
import { brands, joinRequests } from './pr';

function Choose() {
  const [value, setValue] = useState<AudienceChoice>({ kind: 'all', picked: [] });
  const count = value.kind === 'all' ? 1240 : value.kind === 'brand' ? 86 : value.kind === 'tier' ? 127 : value.picked.length;
  return (
    <div style={{ maxWidth: 560 }}>
      <AudiencePicker
        value={value} onChange={setValue} modes={['all', 'brand', 'tier', 'picked']} recipients={count}
        brands={[{ ...brands.glow, creators: 86 }, { ...brands.mira, creators: 23 }]}
        tiers={[{ tier: 'rising', creators: 812 }, { tier: 'established', creators: 301 }, { tier: 'elite', creators: 127 }]}
        creators={joinRequests.map((j) => ({ id: j.id, name: j.creator.name, seed: j.creator.seed, tier: j.creator.tier }))}
      />
    </div>
  );
}

On behalf of one brand

fixedBrand makes the brand mode read "All Glow Lab creators" with no brand select; groups lists that brand's groups; counting says the count is on its way; note is a line under it.

Code
import { useState } from 'react';
import { AudiencePicker, type AudienceChoice } from '@ergasti/bricks';
import { brands } from './pr';

function ForBrand() {
  const [value, setValue] = useState<AudienceChoice>({ kind: 'brand', picked: [] });
  return (
    <div style={{ maxWidth: 560 }}>
      <AudiencePicker
        value={value} onChange={setValue} modes={['brand', 'group', 'tier']} fixedBrand={brands.glow}
        groups={[{ id: 'top', name: 'Top sellers', creators: 12 }, { id: 'new', name: 'New this month', creators: 31 }]}
        tiers={[{ tier: 'elite', creators: 9 }]}
        recipients={null} counting note="Only creators who joined Glow Lab can get it."
      />
    </div>
  );
}

Props

Prop

Type

Labels

Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key prAudiencePicker, or with the component's own prop where it has one. A {name} is a value the component fills in.

prAudiencePicker
KeyEnglishArabic
labelSend toابعت لـ
modes.allAll TRNDR creatorsكل صنّاع المحتوى على TRNDR
modes.brandA brandبراند
modes.groupA groupمجموعة
modes.tierA tierمستوى
modes.pickedPick creatorsاختار بنفسك
brandAllAll {b} creatorsكل صنّاع المحتوى بتوع {b}
brandBrandالبراند
groupGroupالمجموعة
tierTierالمستوى
joined{n} joined creators{n} صانع محتوى مشترك
members{n} creators{n} صانع محتوى
searchSearch creatorsدوّر على صانع محتوى
noneNo joined creators yet.مفيش صنّاع محتوى مشتركين لسه.
noMatchNo creator matches this search.مفيش صانع محتوى بالاسم ده.
picked{n} pickedاخترت {n}
pickPick {name}اختار {name}
will[object Object][object Object]
countingCounting creators…بنعدّ صنّاع المحتوى…
zeroNo creator matches this audience yet.مفيش صانع محتوى ينطبق عليه الاختيار ده لسه.

Design guidance

How the BRICKS design system uses AudiencePicker. Written in docs/content/components/AudiencePicker.md; the props above are read from the code, which wins where the two disagree.

The composer's "Send to": a mode switch (all creators, a brand, a group, a tier, or picked by hand), the select or searchable checklist the mode needs, and the live recipient count; use it in the message composer.

AudiencePicker is the mock's cm-to. It is controlled: the app holds the AudienceChoice and computes the count (it knows the audience); the picker shows the number and announces it politely as it changes. A brand sender passes fixedBrand, and the brand mode then reads "All Glow Lab creators" with no brand select.

Anatomy

  1. Mode switch: kit Segmented labelled "Send to" with the modes.
  2. Mode control: brand: select "Glow Lab · 86 joined creators"; group: "Beauty lovers · 40 creators"; tier: "Elite · 12 creators" (42px selects with a chevron); picked: a search box with "2 picked" and a checklist (checkbox, 28px photo, name, TierChip).
  3. Count: "86 creators will get this." / "Counting creators…" / "No creator matches this audience yet." (red), plus note.

Variants

value.kindControl
allnone
brandbrand select (none with fixedBrand)
groupgroup select
tiertier select
pickedsearch + checklist

States

StateTrigger
Countingcounting or recipients={null}
Zerorecipients={0}: zero line
No creatorspicked with creators=[]: "No joined creators yet."
No matchsearch with no result: "No creator matches this search."
Unset selectbrand / group / tier not chosen: a "—" first option

Types

AudienceChoice (value): { kind, brandId?, groupId?, tier?, picked: id[] }. PickableCreator (creators): { id, name, seed, src?, tier? }.

Usage

import { AudiencePicker } from '@ergasti/bricks';

<AudiencePicker
  value={audience}
  onChange={setAudience}
  modes={['all', 'brand', 'tier', 'picked']}
  brands={[{ id: 'glow', name: 'Glow Lab', color: '#C7325C', creators: 86 }, { id: 'mira', name: 'Mira Beauty', creators: 23 }]}
  tiers={[{ tier: 'elite', creators: 12 }, { tier: 'influential', creators: 31 }]}
  creators={creators}
  recipients={reach}
  counting={counting}
/>
// A brand sender: only its own creators
<AudiencePicker value={audience} onChange={setAudience} modes={['brand', 'tier', 'picked']}
  fixedBrand={{ id: 'glow', name: 'Glow Lab' }} tiers={tiers} creators={glowCreators} recipients={reach}
  note="Only creators who joined Glow Lab can get it." />

On behalf of one brand. fixedBrand makes the brand mode read "All Glow Lab creators" with no brand select; groups lists that brand's groups; counting says the count is on its way; note is a line under it. (docs example ForBrand)

import { useState } from 'react';
import { AudiencePicker, type AudienceChoice } from '@ergasti/bricks';
// brands, joinRequests: the docs' sample rows (docs/examples/_pr.ts), e.g. brands.glow = { id: 'glow', name: 'Glow Lab', color: '#C7325C' }

export function ForBrand() {
  const [value, setValue] = useState<AudienceChoice>({ kind: 'brand', picked: [] });
  return (
    <div style={{ maxWidth: 560 }}>
      <AudiencePicker
        value={value} onChange={setValue} modes={['brand', 'group', 'tier']} fixedBrand={brands.glow}
        groups={[{ id: 'top', name: 'Top sellers', creators: 12 }, { id: 'new', name: 'New this month', creators: 31 }]}
        tiers={[{ tier: 'elite', creators: 9 }]}
        recipients={null} counting note="Only creators who joined Glow Lab can get it."
      />
    </div>
  );
}

Where it appears

  • PR Portal › Messages › New message › Send to. Also suits the challenge's "Add creators" checklist (picked mode).

Guidelines

Do

  • Count on the server for exactly the choice shown.
  • Keep picked ids when switching modes back and forth (the value holds them).

Don't

  • Don't offer all or group to a brand sender.
  • Don't compute the count from the visible list.

RTL and Arabic

Mirrors; select chevrons move left. Arabic: "ابعت لـ", "كل صنّاع المحتوى على TRNDR", "اختار بنفسك", "86 صانع محتوى هيوصلهم الرسالة.".

Tokens

--line, --card, --radius-md, --radius-sm, --rasp, --soft, --bad, --ink, --kit-chevron.

Accessibility

Segmented radio buttons, labelled selects, a labelled search and checklist ("Pick Nour Hassan"); "2 picked" and the count are aria-live="polite".

Found in the source

  • ARIA attributes set: aria-label, aria-live.
  • Its tests cover: “modes as a segmented control; the live count is announced”.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

See also: Avatar · Segmented · TierChip · useBricks · useLanguage · ChannelPicker · MessageDrawer

Source

src/pr/AudiencePicker.tsx (line 91) on GitHub.

On this page