NoticeList.js 1.74 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 31
        {data.map((item, i) => {
          const itemCls = classNames(styles.item, {
            [styles.read]: item.read,
          });
          return (
afc163's avatar
afc163 committed
32 33
            <List.Item className={itemCls} key={item.key || i} onClick={() => onClick(item)}>
              <List.Item.Meta
afc163's avatar
afc163 committed
34
                className={styles.meta}
afc163's avatar
afc163 committed
35 36
                avatar={item.avatar ? <Avatar className={styles.avatar} src={item.avatar} /> : null}
                title={
afc163's avatar
afc163 committed
37
                  <div className={styles.title}>
afc163's avatar
afc163 committed
38 39
                    {item.title}
                    <div className={styles.extra}>{item.extra}</div>
40
                  </div>
afc163's avatar
afc163 committed
41 42 43 44 45 46 47 48 49 50 51
                }
                description={
                  <div>
                    <div className={styles.description} title={item.description}>
                      {item.description}
                    </div>
                    <div className={styles.datetime}>{item.datetime}</div>
                  </div>
                }
              />
            </List.Item>
52 53
          );
        })}
afc163's avatar
afc163 committed
54
      </List>
jim's avatar
jim committed
55
      {showClear ? (
jim's avatar
jim committed
56 57 58 59
        <div className={styles.clear} onClick={onClear}>
          {locale.clear}
          {title}
        </div>
jim's avatar
jim committed
60
      ) : null}
61 62 63
    </div>
  );
}