MessagePreview
What the creator receives, drawn as it lands: an app notification card (the sender's square, TRNDR · now, the subject in bold, the message), or a message bubble for SMS / WhatsApp (no subject: those channels have none). Empty fields show grey placeholders. A labelled figure; the text inside follows the message's own direction (dir="auto").
import { MessagePreview } from '@ergasti/bricks';Examples
Subject and body
A subject (not for SMS) and a body with character counters; for SMS the counter reports segments and the encoding (smsCount). Errors are yours to pass.
Code
import { useState } from 'react';
import { MessageFields, smsCount } from '@ergasti/bricks';
function Fields() {
const [subject, setSubject] = useState('Winter top 10');
const [body, setBody] = useState('Two weeks left. Share your Glow Lab coupon in stories this weekend.');
return (
<div style={{ display: 'grid', gap: 16, maxWidth: 560 }}>
<MessageFields channel="sms" subject={subject} body={body} onSubject={setSubject} onBody={setBody} bodyMax={480} />
<small>smsCount: {JSON.stringify(smsCount(body))}</small>
</div>
);
}Preview
What the creator sees on each channel, with the sender's name.
Code
import { MessagePreview } from '@ergasti/bricks';
import { brands } from './pr';
function Preview() {
return (
<div style={{ display: 'grid', gap: 16, gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))' }}>
<MessagePreview channel="app" sender={brands.glow} subject="Winter top 10" body="Two weeks left. Share your coupon in stories." />
<MessagePreview channel="sms" sender={null} subject="" body="TRNDR: two weeks left in Winter top 10." />
</div>
);
}Errors and a shorter subject
errors marks the subject and the body with your messages; subjectMax sets the subject's counter (default 80).
Code
import { useState } from 'react';
import { MessageFields } from '@ergasti/bricks';
function Invalid() {
const [subject, setSubject] = useState('');
const [body, setBody] = useState('Hi');
return (
<div style={{ maxWidth: 560 }}>
<MessageFields
channel="app" subject={subject} body={body} onSubject={setSubject} onBody={setBody} subjectMax={40}
errors={{ subject: subject ? undefined : 'Add a subject.', body: body.length < 10 ? 'Write at least 10 characters.' : undefined }}
/>
</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 prMessagePreview, or with the component's own prop where it has one. A {name} is a value the component fills in.
| Key | English | Arabic |
|---|---|---|
label | Preview | معاينة |
app | TRNDR | TRNDR |
now | now | دلوقتي |
subjectPh | Your subject | العنوان |
bodyPh | Your message shows here as creators will see it. | رسالتك هتظهر هنا زي ما صنّاع المحتوى هيشوفوها. |
sms | SMS from TRNDR | SMS من TRNDR |
whatsapp | WhatsApp · TRNDR | واتساب · TRNDR |
via | from {b} | من {b} |
Design guidance
How the BRICKS design system uses MessagePreview. Written in docs/content/components/MessagePreview.md; the props above are read from the code, which wins where the two disagree.
What the creator receives, drawn as it lands: an app notification card or an SMS / WhatsApp bubble; use it beside the composer's fields so PR sees the message before sending.
MessagePreview draws the sender's square, "TRNDR · now", the subject in bold and the message for the app channel; SMS and WhatsApp have no subject, so they show a header line ("SMS from TRNDR · from Glow Lab") and a chat bubble. Empty fields show grey placeholders. The preview is inferred (the mock has no preview panel).
Anatomy
- Figure:
<figure>on--soft, 16px padding, radius--r-xl, labelled by its caption. - Caption: "PREVIEW", 11px upper-case muted.
- App card (
app): white card with--shadow-md: 28px sender square; "TRNDR · now"; bold subject; message (13px, wraps anywhere). - Bubble (
sms,whatsapp): header "SMS from TRNDR" / "WhatsApp · TRNDR" (+ " · from Glow Lab"), then the body in a white bubble with a small corner at the start-end.
Variants
channel | Look |
|---|---|
app | Notification card with subject |
sms | Bubble, "SMS from TRNDR" |
whatsapp | Bubble, "WhatsApp · TRNDR" |
sender | Effect |
|---|---|
null | TRNDR ink square and name |
| brand | Brand square and name (app); "· from {brand}" (bubbles) |
States
Filled, or placeholders ("Your subject", "Your message shows here as creators will see it.") in grey when empty.
Usage
import { MessagePreview } from '@ergasti/bricks';
<MessagePreview channel="app" sender={{ id: 'glow', name: 'Glow Lab', color: '#C7325C' }}
subject="Winter top 10: 2 weeks left" body="Two weeks left to climb the board. Top 10 win EGP 2,000 each." />// Sticky preview column beside the fields
<div style={{ display: 'grid', gridTemplateColumns: 'minmax(0, 1fr) 300px', gap: 24 }}>
<MessageFields channel={channel} subject={subject} body={body} onSubject={setSubject} onBody={setBody} />
<MessagePreview channel={channel} sender={sender} subject={subject} body={body} />
</div>Preview. What the creator sees on each channel, with the sender's name. (docs example Preview)
import { MessageFields, MessagePreview, smsCount } from '@ergasti/bricks';
// brands: the docs' sample rows (docs/examples/_pr.ts), e.g. brands.glow = { id: 'glow', name: 'Glow Lab', color: '#C7325C' }
export function Preview() {
return (
<div style={{ display: 'grid', gap: 16, gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))' }}>
<MessagePreview channel="app" sender={brands.glow} subject="Winter top 10" body="Two weeks left. Share your coupon in stories." />
<MessagePreview channel="sms" sender={null} subject="" body="TRNDR: two weeks left in Winter top 10." />
</div>
);
}Where it appears
- Library-only (no v3 mock screen): the composer's preview column (inside
AnnouncementComposer); the v3 mock's PR Portal › Messages composer has no preview.
Guidelines
Do
- Update it on every keystroke; it is cheap.
- Show the real sender so PR sees what creators see.
Don't
- Don't treat it as a delivery guarantee: real devices may truncate.
RTL and Arabic
The card mirrors; text follows its own direction; the caption drops letter spacing in Arabic.
Tokens
--soft, --r-xl, --card, --radius-lg, --shadow-md, --ink-2, --ink-3.
Accessibility
A <figure> labelled "Preview"; the text inside uses dir="auto" so mixed Arabic and English read correctly.
Found in the source
- ARIA attributes set:
aria-labelledby.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
See also: BrandAvatar · useLanguage · AudienceLabel · AudiencePicker
Source
src/pr/MessagePreview.tsx (line 22) on GitHub.