Notice
An inline message with its icon, a title and the words, in one of five tones.
import { Notice, type NoticeTone } from '@nyxon/nasim';
// What a settings page says about the shop's payment gateway, in each tone.
const notices: { tone: NoticeTone; title: string; body: string }[] = [
{
tone: 'info',
title: 'درگاه در حالت آزمایشی است',
body: 'پرداختها ثبت میشوند، اما پولی جابهجا نمیشود.',
},
{
tone: 'success',
title: 'درگاه وصل شد',
body: 'از این لحظه مشتریها میتوانند آنلاین پرداخت کنند.',
},
{
tone: 'warning',
title: 'گواهی درگاه تا ۵ روز دیگر تمام میشود',
body: 'پیش از آن گواهی تازه را بارگذاری کنید.',
},
{
tone: 'danger',
title: 'اتصال به درگاه قطع است',
body: 'سفارشهای تازه تا وصل شدن دوباره منتظر میمانند.',
},
{
tone: 'neutral',
title: 'درگاه دوم تعریف نشده است',
body: 'اگر درگاه اول قطع شود، پرداختی ممکن نیست.',
},
];
export default function Tones() {
return (
<div className="flex flex-col gap-3">
{notices.map(({ tone, title, body }) => (
<Notice key={tone} tone={tone} title={title}>
{body}
</Notice>
))}
</div>
);
}Import
import { Notice } from '@nyxon/nasim';Usage
HeroUI's alert with its icon, a title and the words as children. tone is "info" (the default),
"success", "warning", "danger" or "neutral". It is a client component; a Server Component
renders it with plain props.
<Notice tone="warning" title={t.limits.title}>
{t.limits.body}
</Notice>Examples
Tones
Shown above: what a settings page says about a payment gateway, in each tone.
After an action
A failure that appears in answer to a press gets role="alert", so it is read out the moment it appears.
Good news that appears that way gets role="status".
'use client';
import { Button, Notice } from '@nyxon/nasim';
import { useState } from 'react';
const copy = {
save: 'ذخیرهٔ شماره کارت',
failed: 'ذخیره نشد',
why: 'شماره کارت ۱۶ رقم است؛ این شماره ۱۵ رقم دارد.',
};
// A failure that appears in answer to a press is role="alert": it is read out the moment it appears.
export default function AfterAction() {
const [failed, setFailed] = useState(false);
return (
<div className="flex flex-col items-start gap-3">
<Button onPress={() => setFailed(true)}>{copy.save}</Button>
{failed ? (
<Notice tone="danger" title={copy.failed} role="alert">
{copy.why}
</Notice>
) : null}
</div>
);
}Rules
- The title says what happened, the body what to do next. Never colour alone: the icon and the words carry the tone.
- A notice that is on the page from the start takes no
role: it is read in order with the page.
Accessibility
Without role it is plain content. role="alert" is announced at once and interrupts; keep it for a
failure the person caused just now. role="status" is announced politely, after what is being read.
API
| Prop | Type | Default | Description |
|---|---|---|---|
tone | "danger" | "info" | "neutral" | "success" | "warning" | — | |
title | ReactNode | — | |
children | ReactNode | — | |
role | "alert" | "status" | — | "alert" for a failure that appears in answer to an action, "status" for good news. |
className | string | — |
NoticeTone is exported too.
Related
StatusChip (a status in a word or two), MessageBar and ErrorState (a whole view that failed to
load).