2025-03-01 04:03:06 +08:00
|
|
|
import React, { useEffect } from 'react';
|
2025-03-01 08:34:56 +08:00
|
|
|
import SvgIcon from './SvgIcon';
|
2025-03-01 04:03:06 +08:00
|
|
|
|
|
|
|
const Snackbar = ({ type = 'primary', message, duration = 3000, onClose }) => {
|
|
|
|
if (!message) return null;
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (message) {
|
|
|
|
const timer = setTimeout(() => {
|
|
|
|
if (onClose) onClose();
|
|
|
|
}, duration);
|
|
|
|
return () => clearTimeout(timer);
|
|
|
|
}
|
|
|
|
}, [duration, onClose]);
|
|
|
|
|
|
|
|
const icons = {
|
|
|
|
success: 'check-circle-fill',
|
|
|
|
primary: 'info-fill',
|
|
|
|
warning: 'exclamation-triangle-fill',
|
|
|
|
danger: 'exclamation-triangle-fill',
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div
|
2025-03-04 03:38:50 +08:00
|
|
|
className={`snackbar alert alert-${type} d-flex align-items-center justify-content-between position-fixed top-10 start-50 translate-middle w-50 alert-dismissible z-2 gap-2`}
|
2025-03-01 04:03:06 +08:00
|
|
|
role='alert'
|
|
|
|
>
|
2025-03-01 08:34:56 +08:00
|
|
|
<SvgIcon className={icons[type]} />
|
2025-03-01 04:03:06 +08:00
|
|
|
<div className='flex-fill'>{message}</div>
|
|
|
|
<button
|
|
|
|
type='button'
|
|
|
|
className='btn-close flex-end'
|
|
|
|
data-bs-dismiss='alert'
|
|
|
|
aria-label='Close'
|
|
|
|
></button>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Snackbar;
|