File size: 1,025 Bytes
c9767fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import { AnimatePresence } from 'framer-motion';
import AlertCard from './AlertCard';

const containerPositions = {
  'top-left': 'fixed top-6 left-6 z-[9999]',
  'top-center': 'fixed top-6 left-1/2 -translate-x-1/2 z-[9999]',
  'top-right': 'fixed top-6 right-6 z-[9999]',
  'bottom-left': 'fixed bottom-6 left-6 z-[9999]',
  'bottom-center': 'fixed bottom-6 left-1/2 -translate-x-1/2 z-[9999]',
  'bottom-right': 'fixed bottom-6 right-6 z-[9999]',
  'center': 'fixed top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 z-[9999]',
};

export default function AlertContainer({ alerts, position, onDismiss }) {
  return (
    <div className={`${containerPositions[position] || containerPositions['top-right']} flex flex-col gap-3 w-full max-w-sm`}>
      <AnimatePresence mode="popLayout">
        {alerts.map((alert) => (
          <AlertCard
            key={alert.id}
            {...alert}
            position={position}
            onDismiss={onDismiss}
          />
        ))}
      </AnimatePresence>
    </div>
  );
}