您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

BellNotification.tsx 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. 'use client'
  2. import {
  3. BellOutlined,
  4. } from '@ant-design/icons'
  5. import { Badge, Dropdown, Space, List, Typography } from 'antd'
  6. import type { MenuProps } from 'antd'
  7. const { Text } = Typography
  8. // Example Notification Data
  9. const notifications = [
  10. {
  11. id: '1',
  12. title: 'New Message',
  13. description: 'You have received a new message from John.',
  14. time: '2 min ago',
  15. },
  16. {
  17. id: '2',
  18. title: 'Server Update',
  19. description: 'Server will restart at 12:00 AM.',
  20. time: '10 min ago',
  21. },
  22. {
  23. id: '3',
  24. title: 'Payment Received',
  25. description: 'You have received a payment of $120.',
  26. time: '1 hour ago',
  27. },
  28. ]
  29. const NotificationList = () => (
  30. <div className="w-80 max-h-96 overflow-auto bg-white rounded p-2 border border-gray-200 absolute" style={{right:-16}}>
  31. <List
  32. itemLayout="horizontal"
  33. dataSource={notifications}
  34. renderItem={(item) => (
  35. <List.Item className="hover:bg-gray-50 px-3 py-2 cursor-pointer transition-all">
  36. <List.Item.Meta
  37. title={<Text strong>{item.title}</Text>}
  38. description={
  39. <div className="flex justify-between text-xs text-gray-500">
  40. <span>{item.description}</span>
  41. <span className="whitespace-nowrap">{item.time}</span>
  42. </div>
  43. }
  44. />
  45. </List.Item>
  46. )}
  47. />
  48. </div>
  49. )
  50. const BellNotification = () => {
  51. return (
  52. <Dropdown
  53. popupRender={() => <NotificationList />}
  54. placement="bottomRight"
  55. trigger={['click']}
  56. arrow
  57. >
  58. <Space className="cursor-pointer relative">
  59. <Badge count={notifications.length} size="small" offset={[-2, 2]}>
  60. <BellOutlined style={{ fontSize: 20, color: 'black' }} />
  61. </Badge>
  62. </Space>
  63. </Dropdown>
  64. )
  65. }
  66. export default BellNotification