MessageFields
The composer's subject (80) and message (500) with their counters (the mock's #ms / #mb and "0 / 500"). On SMS the counter also says how many messages each creator receives (GSM-7 160/153, UCS-2 70/67), since Arabic text costs more than twice as much. Errors come from the composer and are read with the field (FormField).
import { MessageFields } 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 prMessageFields, or with the component's own prop where it has one. A {name} is a value the component fills in.
| Key | English | Arabic |
|---|---|---|
subject | Subject | العنوان |
subjectPh | e.g. Last week of Winter top 10 | مثال: آخر أسبوع في توب 10 الشتا |
body | Message | الرسالة |
bodyPh | Keep it short and clear | خليها قصيرة وواضحة |
of | {n} / {max} | {n} / {max} |
sms | {chars} characters · {segments} SMS each · {enc} | {chars} حرف · {segments} رسالة لكل واحد · {enc} |
subjectNote | The title of the notification. | ده عنوان الإشعار. |
smsSubjectNote | Not sent by SMS: it names the message in the history. | مش بيتبعت في الـ SMS: ده اسم الرسالة في السجل. |
Design guidance
How the BRICKS design system uses MessageFields. Written in docs/content/components/MessageFields.md; the props above are read from the code, which wins where the two disagree.
The composer's Subject and Message fields with their character counters, and SMS segment counts on SMS; use it in the message composer.
MessageFields is the mock's #ms / #mb with "0 / 500". Subject is capped at 80 and the message at 500 (both adjustable). On SMS the message counter also says how many texts each creator receives, since Arabic switches the whole message to UCS-2 and costs more than twice as much (GSM-7 160 / 153 per part, UCS-2 70 / 67). Errors come from the composer and are read with their field.
Anatomy
- Subject:
FormField"Subject", placeholder "e.g. Last week of Winter top 10",maxLength; hint "The title of the notification." (SMS: "Not sent by SMS: it names the message in the history.") and "12 / 80". - Message:
FormField"Message", a 4-row textarea (min 96px, resizable), placeholder "Keep it short and clear"; hint "42 / 500", or on SMS "42 characters · 1 SMS each · GSM-7".
Variants
channel | Subject hint | Message hint |
|---|---|---|
app | Title of the notification | "n / 500" |
sms | Not sent by SMS | characters · SMS each · encoding |
whatsapp | Title of the notification | "n / 500" |
States
Default, focus (raspberry border + ring), errors (errors.subject, errors.body from the composer), at limit (maxLength stops typing).
Types
Also exported: smsCount(text) → { chars, segments, encoding: 'GSM-7' | 'UCS-2' }.
PrChannel (channel): 'app' | 'sms' | 'whatsapp'.
Usage
import { MessageFields } from '@ergasti/bricks';
<MessageFields channel="app" subject={subject} body={body} onSubject={setSubject} onBody={setBody} />// SMS with errors from a failed Send check, beside the preview
<MessageFields channel="sms" subject={subject} body={body} onSubject={setSubject} onBody={setBody}
errors={{ subject: subject ? undefined : 'Add a subject.', body: body ? undefined : 'Write the message.' }} />
<MessagePreview channel="sms" sender={null} subject={subject} body={body} />Errors and a shorter subject. errors marks the subject and the body with your messages; subjectMax sets the subject's counter (default 80). (docs example Invalid)
import { useState } from 'react';
import { MessageFields, MessagePreview, smsCount } from '@ergasti/bricks';
export 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>
);
}Where it appears
- PR Portal › Messages › New message › Subject and Message.
Guidelines
Do
- Keep subjects short: they are the notification's title.
- Warn PR when an Arabic SMS splits into several texts (the counter does it).
Don't
- Don't raise
bodyMaxfor SMS without a reason: every 67 Arabic characters is another text.
RTL and Arabic
Mirrors; counters stay left-to-right. Arabic: "العنوان", "الرسالة", "{n} حرف · {s} رسالة لكل واحد · UCS-2".
Tokens
--line, --card, --radius-md, --rasp, --focus-ring (composer field rules).
Accessibility
FormFields with real labels; hints and errors are tied to the fields; counters are text (dir="ltr").
Found in the source
- Its tests cover: “errors are read with the field; Arabic labels”.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
See also: FormField · useLanguage · AudienceLabel · AudiencePicker
Source
src/pr/MessageFields.tsx (line 32) on GitHub.