NoticeList.js 1.95 KB
Newer Older
1
import React from 'react';
afc163's avatar
afc163 committed
2
import { Avatar, List } from 'antd';
3 4 5
import classNames from 'classnames';
import styles from './NoticeList.less';

afc163's avatar
afc163 committed
6
export default function NoticeList({
jim's avatar
jim committed
7 8 9 10 11 12 13
  data = [],
  onClick,
  onClear,
  title,
  locale,
  emptyText,
  emptyImage,
jim's avatar
jim committed
14
  showClear = true,
afc163's avatar
afc163 committed
15
}) {
16 17 18
  if (data.length === 0) {
    return (
      <div className={styles.notFound}>
jim's avatar
jim committed
19
        {emptyImage ? <img src={emptyImage} alt="not found" /> : null}
afc163's avatar
afc163 committed
20
        <div>{emptyText || locale.emptyText}</div>
21 22 23 24 25
      </div>
    );
  }
  return (
    <div>
afc163's avatar
afc163 committed
26
      <List className={styles.list}>
27 28 29 30
        {data.map((item, i) => {
          const itemCls = classNames(styles.item, {
            [styles.read]: item.read,
          });
31 32 33 34 35 36 37 38
          const leftIcon = item.avatar ? (
            typeof item.avatar === 'string' ? (
              <Avatar className={styles.avatar} src={item.avatar} />
            ) : (
              item.avatar
            )
          ) : null;

39
          return (
afc163's avatar
afc163 committed
40 41
            <List.Item className={itemCls} key={item.key || i} onClick={() => onClick(item)}>
              <List.Item.Meta
afc163's avatar
afc163 committed
42
                className={styles.meta}
43
                avatar={<span className={styles.iconElement}>{leftIcon}</span>}
afc163's avatar
afc163 committed
44
                title={
afc163's avatar
afc163 committed
45
                  <div className={styles.title}>
afc163's avatar
afc163 committed
46 47
                    {item.title}
                    <div className={styles.extra}>{item.extra}</div>
48
                  </div>
afc163's avatar
afc163 committed
49 50 51 52 53 54 55 56 57 58 59
                }
                description={
                  <div>
                    <div className={styles.description} title={item.description}>
                      {item.description}
                    </div>
                    <div className={styles.datetime}>{item.datetime}</div>
                  </div>
                }
              />
            </List.Item>
60 61
          );
        })}
afc163's avatar
afc163 committed
62
      </List>
jim's avatar
jim committed
63
      {showClear ? (
jim's avatar
jim committed
64 65 66 67
        <div className={styles.clear} onClick={onClear}>
          {locale.clear}
          {title}
        </div>
jim's avatar
jim committed
68
      ) : null}
69 70 71
    </div>
  );
}