NoticeList.js 2 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
        {data.map((item, i) => {
          const itemCls = classNames(styles.item, {
            [styles.read]: item.read,
          });
31
          // eslint-disable-next-line no-nested-ternary
32 33 34 35 36 37 38 39
          const leftIcon = item.avatar ? (
            typeof item.avatar === 'string' ? (
              <Avatar className={styles.avatar} src={item.avatar} />
            ) : (
              item.avatar
            )
          ) : null;

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