Toast
일시적으로 표시되는 간결한 메시지입니다. 작업 후 피드백을 위해 자주 사용됩니다.
언제 사용하나요
- 성공, 경고, 오류 등의 피드백을 제공하기 위해.
- 복잡한 내용이 포함된 알림.
- 상단 중앙에 표시되며 자동으로 사라지는 메시지로, 방해되지 않는 가벼운 프롬프트로 작동합니다.
사용 예시
루트 레이아웃에 <Toast /> 컴포넌트를 한 번 포함합니다. 그런 다음 클라이언트 측 JavaScript 어디에서나 window.Toast.show()를 사용하여 토스트를 렌더링합니다.
Example.astro
---
import Toast from '@/components/feedback/Toast.astro';
---
<!-- Add this once in your layout -->
<Toast />
<!-- Use the JS API to show toasts -->
<script>
window.Toast.show({
title: 'Toast',
description: 'Friday, February 10, 2023 at 5:57 PM'
});
</script> 변형
토스트에는 적절한 아이콘과 색상을 자동으로 렌더링하는 의미론적 변형(`success`, `error`, `info`, `warning`)이 포함되어 있습니다.
script.js
window.Toast.show({
title: 'Toast',
description: 'Your changes have been saved.',
variant: 'success' // 'default' | 'success' | 'error' | 'info' | 'warning'
}); 위치
토스트는 화면의 다양한 위치에 렌더링될 수 있습니다. 기본값은 bottom-right입니다.
작업 및 옵션
토스트에 작업 버튼을 추가하거나 자동 닫기 시간을 조정하거나 닫기 버튼을 완전히 제거할 수 있습니다.
script.js
window.Toast.show({
title: 'Toast',
action: {
label: 'Try again',
onClick: () => console.log('Retrying...')
},
duration: 10000, // 10 seconds. Set to 0 to disable auto-close.
closable: false // Removes the 'x' close button
}); API 참조
| 속성 | 설명 | 타입 | 기본값 |
|---|---|---|---|
| title | 토스트의 기본 제목 텍스트. | string | - |
| description | 제목 아래의 보조 설명 텍스트. | string | - |
| variant | 아이콘과 색상을 결정하는 의미론적 변형 (success, error, info, warning). | 'default' | 'success' | 'error' | 'info' | 'warning' | 'default' |
| position | 토스트가 표시되는 화면 위치 (예: top-right, bottom-center). | 'top-left' | 'top-right' | 'top-center' | 'bottom-left' | 'bottom-right' | 'bottom-center' | 'bottom-right' |
| duration | 자동 닫기 전의 시간(ms) (0으로 설정하여 비활성화). | number | 5000 |
| closable | 닫기 버튼을 표시할지 여부. | boolean | true |
| action | 인라인 액션 버튼에 대한 구성. | ToastAction | - |