NoticeList.js 2.18 KB
Newer Older
1
import React from 'react';
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,
14
  onViewMore = null,
jim's avatar
jim committed
15
  showClear = true,
16
  showViewMore = false,
afc163's avatar
afc163 committed
17
}) {
18 19 20
  if (data.length === 0) {
    return (
      <div className={styles.notFound}>
jim's avatar
jim committed
21
        {emptyImage ? <img src={emptyImage} alt="not found" /> : null}
afc163's avatar
afc163 committed
22
        <div>{emptyText || locale.emptyText}</div>
23 24 25 26 27
      </div>
    );
  }
  return (
    <div>
28 29
      <List className={styles.list}>
        {data.map((item, i) => {
30 31 32
          const itemCls = classNames(styles.item, {
            [styles.read]: item.read,
          });
33
          // eslint-disable-next-line no-nested-ternary
34 35 36 37
          const leftIcon = item.avatar ? (
            typeof item.avatar === 'string' ? (
              <Avatar className={styles.avatar} src={item.avatar} />
            ) : (
何乐's avatar
何乐 committed
38
              <span className={styles.iconElement}>{item.avatar}</span>
39 40 41
            )
          ) : null;

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