# Animated toast notification

> A small notification that springs in from the corner or edge you pick, then quietly leaves after a few seconds.

- Category: [Toasts](https://library.aimran.es/components/toasts)
- Built with: React + Motion
- Live editor: https://library.aimran.es/blocks/toast
- Library: AIMRAN Library (https://library.aimran.es), free, no sign-up, by Aimran Oukham

## Where to use it

Use it for the quick “done” moments of an app: an invoice saved in a billing tool, a product updated in a shop's back office, a profile photo changed. This React toast notification slides in with a soft spring, and if you fire several in a row they line up instead of covering each other.

Pick the position to match your layout: bottom right on a desktop dashboard, top center on mobile, where thumbs cover the bottom of the screen. Three seconds is enough for a short message; go longer only if the text needs reading twice.

## Code

### React (Motion)

```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { CheckCircle2 } from "lucide-react";

const positionClasses = {
  "bottom-center": "bottom-4 left-1/2 -translate-x-1/2",
  "bottom-right": "bottom-4 right-4",
  "top-center": "top-4 left-1/2 -translate-x-1/2",
  "top-right": "top-4 right-4",
} as const;

interface ToastProps {
  position?: keyof typeof positionClasses;
  duration?: number;
  color?: string;
  title?: string;
  message?: string;
}

export default function Toast({
  position = "bottom-center",
  duration = 3,
  color = "#0071e3",
  title = "Saved successfully",
  message = "Your changes have been applied.",
}: ToastProps) {
  const [items, setItems] = useState<{ id: number }[]>([]);
  const fromTop = position.startsWith("top");

  const fire = () => {
    const id = Date.now();
    setItems((p) => [...p, { id }]);
    setTimeout(() => setItems((p) => p.filter((i) => i.id !== id)), duration * 1000);
  };

  return (
    <div className="relative flex h-72 w-full items-center justify-center">
      <button
        type="button"
        onClick={fire}
        className="rounded-full px-5 py-2.5 text-sm font-semibold text-white"
        style={{ backgroundColor: color }}
      >
        Show notification
      </button>
      <div
        className={`absolute z-10 flex w-64 max-w-[calc(100%-2rem)] flex-col gap-2 ${positionClasses[position]}`}
      >
        <AnimatePresence>
          {items.map((i) => (
            <motion.div
              key={i.id}
              role="status"
              initial={{ opacity: 0, y: fromTop ? -24 : 24, scale: 0.95 }}
              animate={{ opacity: 1, y: 0, scale: 1 }}
              exit={{ opacity: 0, y: fromTop ? -16 : 16, scale: 0.95 }}
              transition={{ type: "spring", stiffness: 380, damping: 28 }}
              className="flex w-full items-start gap-3 rounded-xl border border-black/10 bg-white p-3.5 text-[#1d1d1f] shadow-[0_4px_12px_rgba(0,0,0,0.04),0_24px_60px_rgba(0,0,0,0.1)] dark:border-white/10 dark:bg-[#1d1d1f] dark:text-[#f5f5f7]"
            >
              <CheckCircle2 className="mt-0.5 h-4 w-4 shrink-0" style={{ color }} />
              <div>
                <p className="text-sm font-medium">{title}</p>
                <p className="mt-0.5 text-xs text-[#86868b]">{message}</p>
              </div>
            </motion.div>
          ))}
        </AnimatePresence>
      </div>
    </div>
  );
}
```

## Prompt for AI assistants

Paste this into ChatGPT, Claude, Cursor, v0 or Lovable to adapt the block to your stack (Tailwind, Vue, Svelte…):

````text
I want to add the “Animated toast notification” block (Toasts) from AIMRAN Library to my project.

## What it is
A small notification that springs in from the corner or edge you pick, then quietly leaves after a few seconds.

## Chosen settings
- Position: Bottom center (other options: Bottom right, Top center, Top right)
- Duration: 3s (from 1 to 8s)
- Color: #0071e3

## What I need
1. Add it to my project with the same look and animation as the reference code: same sizes, colours, radii, shadows, timings and easing.
2. It is built with React + TypeScript, with framer-motion for the animation and lucide-react for the icons. If my project uses something else (Vue, Svelte, Astro, plain HTML…), translate it without losing any behaviour. If I use Tailwind, turn the styles into classes; if not, keep the CSS in its own file.
3. Expose the settings above as props (or CSS variables) with those values as defaults.
4. Make it work well on phones: nothing that depends only on hover, touch targets of at least 44 px and no overflow on 320 px screens.
5. Make it look right in light and dark mode.
6. Keep it accessible: semantic HTML, roles and aria-* where needed, visible focus and keyboard support.
7. Respect prefers-reduced-motion: with reduced motion, no big animations but the same end result.

## Reference code
```tsx
import { useState } from "react";
import { AnimatePresence, motion } from "framer-motion";
import { CheckCircle2 } from "lucide-react";

const positionClasses = {
  "bottom-center": "bottom-4 left-1/2 -translate-x-1/2",
  "bottom-right": "bottom-4 right-4",
  "top-center": "top-4 left-1/2 -translate-x-1/2",
  "top-right": "top-4 right-4",
} as const;

interface ToastProps {
  position?: keyof typeof positionClasses;
  duration?: number;
  color?: string;
  title?: string;
  message?: string;
}

export default function Toast({
  position = "bottom-center",
  duration = 3,
  color = "#0071e3",
  title = "Saved successfully",
  message = "Your changes have been applied.",
}: ToastProps) {
  const [items, setItems] = useState<{ id: number }[]>([]);
  const fromTop = position.startsWith("top");

  const fire = () => {
    const id = Date.now();
    setItems((p) => [...p, { id }]);
    setTimeout(() => setItems((p) => p.filter((i) => i.id !== id)), duration * 1000);
  };

  return (
    <div className="relative flex h-72 w-full items-center justify-center">
      <button
        type="button"
        onClick={fire}
        className="rounded-full px-5 py-2.5 text-sm font-semibold text-white"
        style={{ backgroundColor: color }}
      >
        Show notification
      </button>
      <div
        className={`absolute z-10 flex w-64 max-w-[calc(100%-2rem)] flex-col gap-2 ${positionClasses[position]}`}
      >
        <AnimatePresence>
          {items.map((i) => (
            <motion.div
              key={i.id}
              role="status"
              initial={{ opacity: 0, y: fromTop ? -24 : 24, scale: 0.95 }}
              animate={{ opacity: 1, y: 0, scale: 1 }}
              exit={{ opacity: 0, y: fromTop ? -16 : 16, scale: 0.95 }}
              transition={{ type: "spring", stiffness: 380, damping: 28 }}
              className="flex w-full items-start gap-3 rounded-xl border border-black/10 bg-white p-3.5 text-[#1d1d1f] shadow-[0_4px_12px_rgba(0,0,0,0.04),0_24px_60px_rgba(0,0,0,0.1)] dark:border-white/10 dark:bg-[#1d1d1f] dark:text-[#f5f5f7]"
            >
              <CheckCircle2 className="mt-0.5 h-4 w-4 shrink-0" style={{ color }} />
              <div>
                <p className="text-sm font-medium">{title}</p>
                <p className="mt-0.5 text-xs text-[#86868b]">{message}</p>
              </div>
            </motion.div>
          ))}
        </AnimatePresence>
      </div>
    </div>
  );
}
```

Give me the complete final code, ready to paste, and tell me in one line where to put it in my project.
````
