# ErrorBanner Floating banner component for displaying error, warning, info, or success messages with dismiss functionality. ## Features - ✅ 4 variants: error, warning, info, success - ✅ Auto-positioned at top of screen - ✅ Dismissable - ✅ Icon support - ✅ Custom colors - ✅ Shadow/elevation - ✅ TypeScript support ## Installation ```bash npx @memoro/ui add error-banner ``` Dependencies: `text`, `icon` ## Usage ### Error Banner ```tsx import { ErrorBanner } from '@/components/ui/ErrorBanner/ErrorBanner'; const [error, setError] = useState(null); { error && setError(null)} />; } ``` ### Success Banner ```tsx setSuccess(null)} /> ``` ### Warning Banner ```tsx setWarning(null)} /> ``` ### Info Banner ```tsx setInfo(null)} /> ``` ### Custom Colors ```tsx {}} /> ``` ### Custom Icon ```tsx {}} /> ``` ### Custom Position ```tsx {}} /> ``` ## Props | Prop | Type | Default | Description | | ------------------ | --------------------------------------------- | ----------- | ------------------------------------- | | `message` | `string` | - | **Required** - Message text | | `onDismiss` | `() => void` | - | **Required** - Dismiss callback | | `variant` | `'error' \| 'warning' \| 'info' \| 'success'` | `'error'` | Banner style variant | | `top` | `number` | `60` | Distance from top of screen | | `horizontalMargin` | `number` | `16` | Left/right margins | | `backgroundColor` | `string` | - | Custom background (overrides variant) | | `textColor` | `string` | `'#FFFFFF'` | Text and icon color | | `icon` | `string` | - | Custom icon (overrides variant) | | `style` | `ViewStyle` | - | Additional styles | ## Variants | Variant | Color | Default Icon | | --------- | --------------- | -------------------- | | `error` | Red (#EF4444) | `alert-circle` | | `warning` | Amber (#F59E0B) | `warning` | | `info` | Blue (#3B82F6) | `information-circle` | | `success` | Green (#10B981) | `checkmark-circle` | ## Examples ### Network Error ```tsx ``` ### Form Validation Error ```tsx setError(null)} /> ``` ### Save Success ```tsx setSuccess(null)} /> ``` ### Low Storage Warning ```tsx {}} /> ``` ### Auto-Dismiss Pattern ```tsx const [error, setError] = useState(null); useEffect(() => { if (error) { const timer = setTimeout(() => setError(null), 5000); return () => clearTimeout(timer); } }, [error]); return <>{error && setError(null)} />}; ``` ### Multiple Banners (Stacked) ```tsx { error && ( setError(null)} /> ); } { warning && ( setWarning(null)} /> ); } ``` ## Positioning - **Default:** Absolute position at `top: 60px` - **Z-Index:** 1000 (appears above most content) - **Horizontal:** 16px margins on left/right - **Width:** Automatically fills available width To position at bottom: ```tsx {}} /> ``` ## Animation Tip For smooth enter/exit animations, use a library like `react-native-reanimated`: ```tsx import Animated, { FadeInDown, FadeOutUp } from 'react-native-reanimated'; { error && ( setError(null)} /> ); } ``` ## Common Patterns ### API Error Handler ```tsx const handleApiError = (error: Error) => { setError(error.message || 'Something went wrong'); }; try { await api.call(); } catch (error) { handleApiError(error); } ``` ### Form Submission ```tsx const handleSubmit = async () => { try { await submitForm(); setSuccess('Form submitted successfully'); } catch (error) { setError('Failed to submit form'); } }; ``` ## Dependencies - `Text` component - `Icon` component ## Notes - Uses absolute positioning - ensure parent container has appropriate layout - Shadow works on both iOS and Android (shadowColor for iOS, elevation for Android) - Dismiss button has 8px hit slop for easier tapping - Banner is full-width with horizontal margins - Text auto-wraps if message is long - Close icon provides visual feedback on press (opacity change)