AnnouncementComposer
The PR "New message" composer (the mock's compose()), as one presentational block: From (TRNDR or on behalf of a brand), channel (when channels are offered; in the modal layout, when there is a choice), audience with the live count, subject and message, a live preview beside them, then Cancel / Send. layout="modal" is the one-column form for a 480px Modal. Controlled: the app owns value and the recipient count. Send checks the fields first and says what is missing; changing the sender drops an audience mode that sender may not use.
import { AnnouncementComposer } from '@ergasti/bricks';Examples
New message
Sender, channel (an unavailable channel says why), audience with a recipient count, subject and body with a live preview. The composer is controlled: you own the ComposerValue.
Code
import { useState } from 'react';
import { AnnouncementComposer, Card, type ComposerValue } from '@ergasti/bricks';
import { brands, joinRequests } from './pr';
function Compose() {
const [value, setValue] = useState<ComposerValue>({ sender: null, channel: 'app', audience: { kind: 'all', picked: [] }, subject: 'New: TRNDR tiers are coming', body: '' });
const recipients = value.audience.kind === 'all' ? 1240 : value.audience.kind === 'brand' ? 86 : value.audience.kind === 'tier' ? 127 : value.audience.picked.length;
return (
<Card>
<AnnouncementComposer
value={value} onChange={setValue}
senders={[brands.glow, brands.mira, brands.kemet]}
channels={[{ channel: 'app' }, { channel: 'sms' }, { channel: 'whatsapp', unavailable: 'WhatsApp is not set up yet.' }]}
brands={[{ ...brands.glow, creators: 86 }, { ...brands.mira, creators: 23 }, { ...brands.kemet, creators: 57 }]}
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 }))}
recipients={recipients} onSend={() => {}} onCancel={() => {}}
/>
</Card>
);
}Groups, counting and a failed send
modes limits the audiences offered (here everyone or a group); groups lists the groups; counting shows the count is being worked out; sending locks the composer and error shows the server's message. Press Send to see it fail.
Code
import { useState } from 'react';
import { AnnouncementComposer, Card, type ComposerValue } from '@ergasti/bricks';
import { brands } from './pr';
function GroupsAndFailure() {
const [value, setValue] = useState<ComposerValue>({ sender: 'glow', channel: 'app', audience: { kind: 'group', groupId: 'top', picked: [] }, subject: 'Top sellers bonus', body: 'You are in the top sellers group: the bonus is on.' });
const [sending, setSending] = useState(false);
const [error, setError] = useState<string | null>(null);
return (
<Card>
<AnnouncementComposer
value={value} onChange={setValue} modes={['all', 'group']}
senders={[brands.glow]} channels={[{ channel: 'app' }, { channel: 'sms' }]}
groups={[{ id: 'top', name: 'Top sellers', creators: 12 }, { id: 'new', name: 'New this month', creators: 31 }]}
recipients={null} counting
sending={sending} error={error}
onSend={() => { setSending(true); setError(null); window.setTimeout(() => { setSending(false); setError('The message was not sent: the SMS provider is down.'); }, 1200); }}
onCancel={() => {}}
/>
</Card>
);
}In a modal
layout="modal" is one column for a 480px Modal, as the PR portal's New message: From, Send to (everyone, a brand, a tier, or a pick list), subject (80), message (500) with its counter, "N creators will get this" and Send. With a single channel (or none) there is no channel picker, and the modal layout has no preview (pass preview to add it back).
Code
import { useState } from 'react';
import { AnnouncementComposer, Button, Modal, type ComposerValue } from '@ergasti/bricks';
import { brands, joinRequests } from './pr';
function InAModal() {
const empty: ComposerValue = { sender: null, channel: 'app', audience: { kind: 'all', picked: [] }, subject: '', body: '' };
const [value, setValue] = useState<ComposerValue | null>(null);
const [sent, setSent] = useState<string | null>(null);
const recipients = !value ? null : value.audience.kind === 'all' ? 1240 : value.audience.kind === 'brand' ? 86 : value.audience.kind === 'tier' ? 398 : value.audience.picked.length;
return (
<div style={{ display: 'grid', gap: 10, justifyItems: 'start' }}>
<Button variant="ink" onClick={() => setValue(empty)}>New message</Button>
<small>{sent ? `Sent: ${sent}` : 'Nothing sent yet'}</small>
<Modal open={value !== null} onClose={() => setValue(null)} title="New message" hint="Creators get it in their TRNDR app notifications.">
{value && (
<AnnouncementComposer
layout="modal" value={value} onChange={setValue}
senders={[brands.glow, brands.mira, brands.kemet]}
brands={[{ ...brands.glow, creators: 86 }, { ...brands.mira, creators: 23 }, { ...brands.kemet, creators: 57 }]}
tiers={[{ tier: 'rising', creators: 640 }, { tier: 'established', creators: 398 }, { tier: 'elite', creators: 54 }]}
creators={joinRequests.map((j) => ({ id: j.id, name: j.creator.name, seed: j.creator.seed, tier: j.creator.tier }))}
recipients={recipients} onSend={(v) => { setSent(v.subject); setValue(null); }} onCancel={() => setValue(null)}
/>
)}
</Modal>
</div>
);
}No preview, no channel picker
preview={false} keeps the page layout's fields in one column; leaving channels out (or empty) hides the picker, while a single entry still shows it in the page layout.
Code (not run)
import { useState } from 'react';
import { AnnouncementComposer, Card, type ComposerValue } from '@ergasti/bricks';
import { brands } from './pr';
function FieldsOnly() {
const [value, setValue] = useState<ComposerValue>({ sender: 'glow', channel: 'app', audience: { kind: 'brand', brandId: 'glow', picked: [] }, subject: 'Winter top 10: 2 weeks left', body: 'Share your Glow Lab coupon this weekend.' });
return (
<Card>
<AnnouncementComposer value={value} onChange={setValue} preview={false} senders={[brands.glow]} recipients={86} onSend={() => {}} onCancel={() => {}} />
</Card>
);
}Props
Prop
Type
Labels
Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key prAnnouncementComposer, or with the component's own prop where it has one. A {name} is a value the component fills in.
| Key | English | Arabic |
|---|---|---|
channel | Channel | القناة |
to | Send to | ابعت لـ |
cancel | Cancel | إلغاء |
sending | Sending… | بنبعت… |
send | Send to {n} creators | ابعت لـ {n} صانع محتوى |
subjectReq | Add a subject. | اكتب عنوان. |
bodyReq | Write the message. | اكتب الرسالة. |
nobody | Pick at least one creator. | اختار صانع محتوى واحد على الأقل. |
onlyJoined | Only creators who joined {b} can get it. | بس صنّاع المحتوى اللي اشتركوا في {b} هيقدروا يستلموها. |
Design guidance
How the BRICKS design system uses AnnouncementComposer. Written in docs/content/components/AnnouncementComposer.md; the props above are read from the code, which wins where the two disagree.
The PR Portal's "New message" composer in one block: From, channel, audience with a live count, subject and message, a live preview, and Cancel / Send; use it on the Messages page when PR writes to creators.
AnnouncementComposer is the mock's compose(). It is controlled and presentational: the app owns the ComposerValue and counts the recipients for the current audience; the composer shows the number on the Send button ("Send to 86 creators"). Send checks the subject, the message and that someone will receive it, and says what is missing. Changing the sender drops audience modes that sender may not use: TRNDR reaches anyone, a brand only its own creators (senderModes).
Anatomy
- Grid: form column and a 300px preview column (one column at 760px and below); the preview is sticky.
- From:
SenderPicker(TRNDR or a brand) with its explanation. - Channel:
ChannelPickercards (app, SMS, WhatsApp; unavailable ones greyed). - Send to:
AudiencePicker: a modeSegmented, then a brand / group / tier select or a creator checklist, and the live count ("86 creators will get this."), plus "Only creators who joined Glow Lab can get it." for a brand sender. - Fields:
MessageFields: Subject (80) and Message (500) with counters; SMS segments on SMS. - Preview:
MessagePreview: an app notification card or an SMS / WhatsApp bubble. - Footer: an alert (send error, or "Pick at least one creator."), Cancel, and the raspberry Send ("Sending…").
Variants
| Situation | Value / props | Effect |
|---|---|---|
| TRNDR sender | sender: null | Modes all, brand, tier, picked (and group when offered) |
| Brand sender | sender: 'glow' | Modes brand, tier, picked; brand mode reads "All Glow Lab creators"; note under the count |
| App channel | channel: 'app' | Subject is the notification title; card preview |
| SMS / WhatsApp | channel: 'sms' | 'whatsapp' | Subject not sent (names the message in history); bubble preview; SMS counter |
modes | default ['all', 'brand', 'tier', 'picked'] | Which modes TRNDR is offered |
States
| State | Trigger |
|---|---|
| Counting | counting or recipients={null}: "Counting creators…", Send reads "Send" |
| No one | recipients={0}: "No creator matches this audience yet."; Send says "Pick at least one creator." |
| Missing fields | Send with an empty subject or body: "Add a subject." / "Write the message." on the fields |
| Sending | sending: Send disabled, "Sending…" |
| Error | error: alert in the footer |
Types
Also exported: senderModes(sender, offered).
ComposerValue (value): { sender, channel, audience: AudienceChoice, subject, body }; sender is a brand id or null (TRNDR).
Usage
import { AnnouncementComposer } from '@ergasti/bricks';
const [value, setValue] = useState<ComposerValue>({
sender: null, channel: 'app', audience: { kind: 'all', picked: [] }, subject: '', body: '',
});
const { count, counting } = useRecipientCount(value.sender, value.audience);
<AnnouncementComposer
value={value}
onChange={setValue}
senders={myBrands}
channels={[{ channel: 'app' }, { channel: 'sms' }, { channel: 'whatsapp', unavailable: 'WhatsApp is not set up yet.' }]}
brands={brandsWithCounts}
tiers={[{ tier: 'elite', creators: 12 }, { tier: 'influential', creators: 31 }]}
creators={pickable}
recipients={count}
counting={counting}
onSend={send}
onCancel={() => navigate('/messages')}
sending={sending}
error={sendError}
/>// Messages page: KPI strip, call to action, history; the composer opens in a wide modal
<KpiGrid columns={3}>
<KpiCard tone="lilac" icon={<PrIcon name="messages" />} label="Sent this month" value="14" />
<KpiCard tone="lime" icon={<PrIcon name="eye" />} label="Average opened" value="68%" />
<KpiCard tone="sky" icon={<PrIcon name="creators" />} label="Creators reached" value="1,240" />
</KpiGrid>
<CalloutCard tone="lilac" title="Message creators" sub="Send an update to every creator, a brand's creators, a tier or a few people.">
<Button variant="rasp" onClick={() => setComposing(true)}>New message</Button>
</CalloutCard>
<DataTable label="Sent messages" rows={messages} rowKey={(m) => m.id} columns={messageColumns('en')} />
<Modal open={composing} wide onClose={() => setComposing(false)} title="New message">
<AnnouncementComposer {...composerProps} onCancel={() => setComposing(false)} />
</Modal>Groups, counting and a failed send. modes limits the audiences offered (here everyone or a group); groups lists the groups; counting shows the count is being worked out; sending locks the composer and error shows the server's message. Press Send to see it fail. (docs example GroupsAndFailure)
import { useState } from 'react';
import { AnnouncementComposer, Card, type ComposerValue } 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 GroupsAndFailure() {
const [value, setValue] = useState<ComposerValue>({ sender: 'glow', channel: 'app', audience: { kind: 'group', groupId: 'top', picked: [] }, subject: 'Top sellers bonus', body: 'You are in the top sellers group: the bonus is on.' });
const [sending, setSending] = useState(false);
const [error, setError] = useState<string | null>(null);
return (
<Card>
<AnnouncementComposer
value={value} onChange={setValue} modes={['all', 'group']}
senders={[brands.glow]} channels={[{ channel: 'app' }, { channel: 'sms' }]}
groups={[{ id: 'top', name: 'Top sellers', creators: 12 }, { id: 'new', name: 'New this month', creators: 31 }]}
recipients={null} counting
sending={sending} error={error}
onSend={() => { setSending(true); setError(null); window.setTimeout(() => { setSending(false); setError('The message was not sent: the SMS provider is down.'); }, 1200); }}
onCancel={() => {}}
/>
</Card>
);
}Where it appears
- PR Portal › Messages › "New message" (the mock's composer; first priority of the PR build).
Guidelines
Do
- Recount on every audience change and pass
countingmeanwhile. - Keep the value in the app so a failed send keeps the draft.
- Offer the group mode only when groups exist.
Don't
- Don't let a brand sender reach all TRNDR creators (the composer prevents it; don't work around it).
- Don't send without a positive count.
- Don't close the composer on error.
RTL and Arabic
Mirrors; the preview follows each message's own direction (dir="auto"). SMS in Arabic uses UCS-2 (70 / 67 characters), so the counter shows more messages per creator. Arabic Send: "ابعت لـ 86 صانع محتوى".
Tokens
--line, --card, --radius-md, --rasp, --focus-ring, --kit-chevron, --soft, --r-xl, --radius-lg, --shadow-md, --ink-2, --ink-3.
Accessibility
- Each part keeps its own semantics: a labelled select, a radiogroup of channels, a segmented control, a checklist, labelled fields with errors.
- The count is
aria-live="polite"; errors arerole="alert". - The preview is a labelled
<figure>.
Found in the source
- Roles in the markup:
alert. - ARIA attributes set:
aria-hidden.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
SenderPicker,ChannelPicker,AudiencePicker,MessageFields,MessagePreview: its parts, usable alone.messageColumns,AudienceLabel,SenderCell,OpenRate: the history.
See also: Button · useLanguage · Card · Modal · MessageDrawer
Source
src/pr/AnnouncementComposer.tsx (line 86) on GitHub.