NoticeList.js 1.68 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,
afc163's avatar
afc163 committed
14
}) {
15 16 17
  if (data.length === 0) {
    return (
      <div className={styles.notFound}>
jim's avatar
jim committed
18
        {emptyImage ? <img src={emptyImage} alt="not found" /> : null}
afc163's avatar
afc163 committed
19
        <div>{emptyText || locale.emptyText}</div>
20 21 22 23 24
      </div>
    );
  }
  return (
    <div>
afc163's avatar
afc163 committed
25
      <List className={styles.list}>
26 27 28 29 30
        {data.map((item, i) => {
          const itemCls = classNames(styles.item, {
            [styles.read]: item.read,
          });
          return (
afc163's avatar
afc163 committed
31 32
            <List.Item className={itemCls} key={item.key || i} onClick={() => onClick(item)}>
              <List.Item.Meta
afc163's avatar
afc163 committed
33
                className={styles.meta}
afc163's avatar
afc163 committed
34 35
                avatar={item.avatar ? <Avatar className={styles.avatar} src={item.avatar} /> : null}
                title={
afc163's avatar
afc163 committed
36
                  <div className={styles.title}>
afc163's avatar
afc163 committed
37 38
                    {item.title}
                    <div className={styles.extra}>{item.extra}</div>
39
                  </div>
afc163's avatar
afc163 committed
40 41 42 43 44 45 46 47 48 49 50
                }
                description={
                  <div>
                    <div className={styles.description} title={item.description}>
                      {item.description}
                    </div>
                    <div className={styles.datetime}>{item.datetime}</div>
                  </div>
                }
              />
            </List.Item>
51 52
          );
        })}
afc163's avatar
afc163 committed
53
      </List>
54
      <div className={styles.clear} onClick={onClear}>
jim's avatar
jim committed
55 56
        {locale.clear}
        {title}
57 58 59 60
      </div>
    </div>
  );
}