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