NoticeList.js 1.51 KB
Newer Older
1
import React from 'react';
afc163's avatar
afc163 committed
2
import { Avatar, Icon, List } from 'antd';
3 4 5 6 7 8 9 10 11 12 13 14 15 16
import classNames from 'classnames';
import styles from './NoticeList.less';

export default function NoticeList({ data = [], onClick, onClear, title, locale }) {
  if (data.length === 0) {
    return (
      <div className={styles.notFound}>
        <Icon type="frown-o" />
        {locale.emptyText}
      </div>
    );
  }
  return (
    <div>
afc163's avatar
afc163 committed
17
      <List className={styles.list}>
18 19 20 21 22
        {data.map((item, i) => {
          const itemCls = classNames(styles.item, {
            [styles.read]: item.read,
          });
          return (
afc163's avatar
afc163 committed
23 24 25 26 27 28 29
            <List.Item className={itemCls} key={item.key || i} onClick={() => onClick(item)}>
              <List.Item.Meta
                avatar={item.avatar ? <Avatar className={styles.avatar} src={item.avatar} /> : null}
                title={
                  <div>
                    {item.title}
                    <div className={styles.extra}>{item.extra}</div>
30
                  </div>
afc163's avatar
afc163 committed
31 32 33 34 35 36 37 38 39 40 41
                }
                description={
                  <div>
                    <div className={styles.description} title={item.description}>
                      {item.description}
                    </div>
                    <div className={styles.datetime}>{item.datetime}</div>
                  </div>
                }
              />
            </List.Item>
42 43
          );
        })}
afc163's avatar
afc163 committed
44
      </List>
45 46 47 48 49 50
      <div className={styles.clear} onClick={onClear}>
        {locale.clear}{title}
      </div>
    </div>
  );
}