Alert
페이지나 작업에 대한 메시지를 info, success, warning, critical 네 가지 톤 중 하나로 보여 줍니다. 각 톤은 alert.<tone> contract 토큰을 거쳐 color.status.<tone> 토큰에서 색을 가져오며, 토큰을 빌드할 때 각 색 쌍이 APCA 검사를 통과합니다. info는 Todae의 다른 부분처럼 중립적인 잉크이며, 회사 테마에서 색조를 줄 수 있습니다.
이 페이지의 내용
import { Alert, Button, Stack } from '@tounsoo/todae';
import { CircleCheck, CircleX, Info, TriangleAlert } from 'lucide-react';
// Todae ships no icons. These come from Lucide; any icon library works.
export default function AlertTones() {
return (
<Stack.Root>
<Alert.Root tone="info" role="none">
<Alert.Icon>
<Info />
</Alert.Icon>
<Alert.Title>Scheduled maintenance</Alert.Title>
<Alert.Description>Sign-in pauses for ten minutes on Sunday at 02:00 UTC.</Alert.Description>
</Alert.Root>
<Alert.Root tone="success" role="none">
<Alert.Icon>
<CircleCheck />
</Alert.Icon>
<Alert.Title>Invoice paid</Alert.Title>
</Alert.Root>
<Alert.Root tone="warning" role="none">
<Alert.Icon>
<TriangleAlert />
</Alert.Icon>
<Alert.Title>Storage almost full</Alert.Title>
<Alert.Description>You have used 92% of your plan.</Alert.Description>
</Alert.Root>
<Alert.Root tone="critical" role="none">
<Alert.Icon>
<CircleX />
</Alert.Icon>
<Alert.Title>Payment failed</Alert.Title>
<Alert.Description>Update your card to keep your plan.</Alert.Description>
<Alert.Actions>
<Button.Root variant="secondary">Update card</Button.Root>
</Alert.Actions>
</Alert.Root>
</Stack.Root>
);
}
Scheduled maintenance
Invoice paid
Storage almost full
Payment failed
Todae는 아이콘을 제공하지 않습니다. Alert.Icon은 슬롯입니다. 직접 사용하는 아이콘 세트의 아이콘을 넣으면 텍스트 앞에 놓이고, 보조 기술에서는 숨겨집니다. 열은 렌더링한 파트에 맞춰지므로, 아이콘이나 닫기 버튼이 없는 Alert에는 빈 공간이 남지 않습니다.
알림 읽기
Alert.Root는 기본적으로 라이브 영역입니다. info와 success는 role="status"로, 읽던 내용이 멈출 때를 기다립니다. warning과 critical은 role="alert"로, 바로 끼어듭니다. 스크린 리더는 라이브 영역의 내용이 바뀔 때 읽어 주므로, 어떤 동작 뒤에 나타나는 메시지라면 영역은 페이지에 그대로 두고 안의 내용만 바꾸세요. 처음부터 페이지에 있어 읽어 줄 필요가 없는 배너에는 위 예시처럼 role="none"을 전달합니다.
Alert는 나타날 때 alert.motion.duration.enter와 alert.motion.easing.enter로 서서히 나타나며, 동작 줄이기에서도 그렇고, 사라질 때는 바로 사라집니다. 텍스트와 role은 첫 프레임부터 있으므로 페이드가 읽어 주기를 늦추지 않고, 제자리에서 텍스트만 바뀌는 Alert는 다시 페이드하지 않습니다.
Alert.Close는 ghost Button.Root입니다. "Got it"처럼 자체 텍스트가 이름이 되지 않으면 이름은 "Dismiss"입니다. 이 기본값은 StringsProvider의 dismiss 문자열이며, 설정하지 않으면 영어입니다. 비어 있지 않은 aria-label이 여전히 우선합니다. Alert에는 열림 상태가 없으므로 onClick에서 제거하세요.
import { Alert, Button, Stack } from '@tounsoo/todae';
import { useRef, useState } from 'react';
export default function AlertDismissible() {
const [shown, setShown] = useState(false);
const saveRef = useRef<HTMLButtonElement>(null);
return (
<Stack.Root>
<Button.Root ref={saveRef} variant="secondary" onClick={() => setShown(true)}>
Save changes
</Button.Root>
{/* The status region stays on the page; only its content changes, so it is announced. */}
<div role="status">
{shown ? (
<Alert.Root tone="success" role="none">
<Alert.Title>Changes saved</Alert.Title>
<Alert.Close
onClick={() => {
// The button is about to go away: give focus somewhere first.
saveRef.current?.focus();
setShown(false);
}}
/>
</Alert.Root>
) : null}
</div>
</Stack.Root>
);
}
아이콘
Alert.Icon 안에 바로 들어간 svg나 img는 alert.icon.size 토큰의 크기를 따릅니다. 내용이 없는 Alert.Close는 close 글리프를 보여 줍니다. GlyphsProvider가 정하지 않으면 X 모양입니다. 닫기 버튼 하나에만 다른 아이콘을 쓰려면 Button.Icon에 넣으세요.
import { TriangleAlert, X } from 'lucide-react';
<Alert.Root tone="warning">
<Alert.Icon>
<TriangleAlert />
</Alert.Icon>
<Alert.Title>Storage almost full</Alert.Title>
<Alert.Close onClick={hide}>
<Button.Icon>
<X />
</Button.Icon>
</Alert.Close>
</Alert.Root>
접근성을 지키는 조합
Todae가 맡는 것: Alert.Root는 위에서 설명한 대로 톤에 따라 role="status"나 role="alert"를 설정하고, 전달한 role은 그대로 둡니다. Alert.Icon은 aria-hidden입니다. Alert.Close는 이름이 있는 네이티브 버튼입니다. 이름은 버튼 자체의 텍스트, 비어 있지 않은 aria-label, 또는 dismiss 문자열입니다. Todae는 Alert가 나타날 때도 사라질 때도 포커스를 옮기지 않습니다.
직접 제공할 것: 메시지를 Alert.Title과 Alert.Description에 텍스트로 넣으세요. 톤은 색과 숨겨진 아이콘으로만 보이므로, 중요하다면 "Payment failed"처럼 말로도 적으세요. 어떤 동작 뒤에 나오는 메시지라면 톤에 맞는 라이브 role(status 또는 alert)을 가진 래퍼를 마운트한 채로 두고, 그 안에 role="none"인 Alert.Root를 렌더링하세요. 닫기 버튼이 Alert를 없앤다면, 메시지가 가리키던 컨트롤처럼 알맞은 곳으로 포커스를 옮기세요.
주의할 점: 라이브 영역을 메시지와 함께 새로 마운트하는 것. 스크린 리더가 읽지 않을 수 있습니다. role이나 나머지 props를 버리는 래퍼. 그러면 role="none"이 루트에 닿지 않습니다. 자체 닫기 버튼으로 Alert를 없애면서 포커스를 옮기지 않는 것. 포커스가 페이지 body로 떨어집니다.
언제 쓰나요
언제: 해결되거나 닫을 때까지 남아 있는, 페이지나 마지막 동작에 대한 메시지. 결제 실패, 점검 시간 안내, 폼 옆의 저장 완료 확인.
쓰지 않을 때: 필드 자체의 오류 → ErrorMessage. 작업을 막는 선택 → Dialog. 항목의 개수나 라벨 → Chip. 호버 도움말 → Tooltip.
Props
| 이름 | 타입 | 설명 |
|---|---|---|
tone | "info"| "success"| "warning"| "critical" | alert 계약 토큰을 거쳐 color.status.<tone>의 색을 씁니다. 기본 role도 정합니다. 기본값: "info" |
role | React.AriaRole | 라이브 영역 role. 처음부터 페이지에 있는 배너에는 role="none"을 전달합니다. 기본값: "status" for info and success, "alert" for warning and critical |
children | React.ReactNode | Alert 파트 또는 아무 콘텐츠. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 직접 사용하는 아이콘 세트의 아이콘 그래픽. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 제목 텍스트. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 본문 내용. |
| 이름 | 타입 | 설명 |
|---|---|---|
children | React.ReactNode | 버튼이나 링크. |
| 이름 | 타입 | 설명 |
|---|---|---|
aria-label | string | 접근 가능한 이름. "Got it"처럼 글자나 숫자가 두 개 이상인 텍스트가 있으면 그 텍스트가 버튼의 이름이 됩니다. 그렇지 않으면 StringsProvider의 dismiss 문자열이 이름이 되며, 영어로는 Dismiss입니다. 기본값: "Dismiss" when its text, not counting aria-hidden or SVG parts, has fewer than two letters or digits |
onClick | React.MouseEventHandler<HTMLButtonElement> | 여기서 알림을 숨깁니다. |