Claude Code के साथ Implement Toast Notifications कैसे करें
Claude Code का उपयोग करके implement toast notifications सीखें। Practical code examples और step-by-step guidance शामिल है।
トースト通知の設計
トースト通知は操作結果やシステムmessageを一時的にdisplayするUIpattern है।modalと違いuserの操作を妨げないため、フィードバックに最適 है।Claude Code का उपयोग करके、アクセシブルで美しいトースト通知システム build किया जा सकता है。
トーストmanagementシステムのimplementation
> グローバルに使えるトースト通知システムを作って。
> success, error, warning, infoの4種類にsupportして。
type ToastType = 'success' | 'error' | 'warning' | 'info';
interface Toast {
id: string;
type: ToastType;
message: string;
duration: number;
dismissible: boolean;
}
type ToastListener = (toasts: Toast[]) => void;
class ToastManager {
private toasts: Toast[] = [];
private listeners: Set<ToastListener> = new Set();
private counter = 0;
subscribe(listener: ToastListener) {
this.listeners.add(listener);
return () => this.listeners.delete(listener);
}
private notify() {
this.listeners.forEach((fn) => fn([...this.toasts]));
}
add(type: ToastType, message: string, options?: Partial<Pick<Toast, 'duration' | 'dismissible'>>) {
const id = `toast-${++this.counter}`;
const toast: Toast = {
id,
type,
message,
duration: options?.duration ?? 5000,
dismissible: options?.dismissible ?? true,
};
this.toasts = [...this.toasts, toast];
this.notify();
if (toast.duration > 0) {
setTimeout(() => this.remove(id), toast.duration);
}
return id;
}
remove(id: string) {
this.toasts = this.toasts.filter((t) => t.id !== id);
this.notify();
}
success(message: string) { return this.add('success', message); }
error(message: string) { return this.add('error', message, { duration: 8000 }); }
warning(message: string) { return this.add('warning', message); }
info(message: string) { return this.add('info', message); }
}
export const toast = new ToastManager();
Reactcomponent
import { useState, useEffect } from 'react';
const ICONS: Record<ToastType, string> = {
success: '✓',
error: '✕',
warning: '⚠',
info: 'ℹ',
};
const STYLES: Record<ToastType, string> = {
success: 'bg-green-50 border-green-200 text-green-800',
error: 'bg-red-50 border-red-200 text-red-800',
warning: 'bg-yellow-50 border-yellow-200 text-yellow-800',
info: 'bg-blue-50 border-blue-200 text-blue-800',
};
function ToastContainer() {
const [toasts, setToasts] = useState<Toast[]>([]);
useEffect(() => {
return toast.subscribe(setToasts);
}, []);
return (
<div
aria-live="polite"
aria-label="通知"
className="fixed top-4 right-4 z-50 flex flex-col gap-2 max-w-sm w-full"
>
{toasts.map((t) => (
<div
key={t.id}
role="status"
className={`flex items-start gap-3 p-4 rounded-lg border shadow-lg
animate-slideIn ${STYLES[t.type]}`}
>
<span className="text-lg font-bold flex-shrink-0">{ICONS[t.type]}</span>
<p className="flex-1 text-sm">{t.message}</p>
{t.dismissible && (
<button
onClick={() => toast.remove(t.id)}
aria-label="通知をClose"
className="text-gray-400 hover:text-gray-600"
>✕</button>
)}
</div>
))}
</div>
);
}
animation
@keyframes slideIn {
from {
transform: translateX(100%);
opacity: 0;
}
to {
transform: translateX(0);
opacity: 1;
}
}
@keyframes slideOut {
from {
transform: translateX(0);
opacity: 1;
}
to {
transform: translateX(100%);
opacity: 0;
}
}
.animate-slideIn {
animation: slideIn 0.3s ease-out;
}
.animate-slideOut {
animation: slideOut 0.3s ease-in forwards;
}
Reacthookでのutilization
export function useToast() {
return {
success: (msg: string) => toast.success(msg),
error: (msg: string) => toast.error(msg),
warning: (msg: string) => toast.warning(msg),
info: (msg: string) => toast.info(msg),
};
}
// Usage example
function SaveButton() {
const { success, error } = useToast();
const handleSave = async () => {
try {
await saveData();
success('保存しました');
} catch (e) {
error('保存に失敗し हुआ।もう一度お試し करें।');
}
};
return <button onClick={handleSave}>保存</button>;
}
Summary
Claude Code का उपयोग करके、型safeでアクセシブルなトースト通知システムをanimation付きで素早くbuild किया जा सकता है。modalとの使い分けはmodal・ダイアlog設計を、animation全般はanimationimplementationをदेखें。
WAI-ARIAのライブリージョンके बारे मेंはMDN Web Docs - aria-liveदेखें。
मुफ़्त PDF: 5 मिनट में Claude Code चीटशीट
बस अपना ईमेल दर्ज करें और हम तुरंत A4 एक-पृष्ठ चीटशीट PDF भेज देंगे।
हम आपकी व्यक्तिगत जानकारी की सुरक्षा करते हैं और स्पैम नहीं भेजते।
लेखक के बारे में
Masa
Claude Code का गहराई से उपयोग करने वाले इंजीनियर। claudecode-lab.com चलाते हैं, जो 10 भाषाओं में 2,000 से अधिक पेजों वाला टेक मीडिया है।
संबंधित लेख
Claude Code ke liye 7 CLAUDE.md templates jo aap real projects me copy kar sakte hain
Solo app, content site, API, team repo aur legacy codebase ke liye 7 practical CLAUDE.md templates, plus common failure cases.
Claude Code Approval aur Sandbox Guide | Roz ke kaam ke liye safe settings
Claude Code me allow, ask, deny aur sandbox ko kaise baantna chahiye - practical settings, hooks aur real workflow examples ke saath.
Claude Code की सम्पूर्ण शुरुआती गाइड 2026 | शून्य से प्रोफेशनल उपयोग तक 7 स्टेप्स में
पहली बार Claude Code उपयोग करने वालों के लिए पूरी गाइड। इंस्टॉलेशन से लेकर असली डेवलपमेंट वर्कफ्लो में शामिल करने तक — Masa के शुरुआती अनुभव के आधार पर।