-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathlist-item.tsx
More file actions
42 lines (38 loc) · 1.27 KB
/
list-item.tsx
File metadata and controls
42 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import React, { useContext } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
import { ListItemProps } from './types';
const ListItem = React.forwardRef<HTMLLIElement, ListItemProps>((props, ref) => {
const {
extra,
actions,
prefixCls: customisedCls,
className,
style,
children,
...otherProps
} = props;
const configContext = useContext(ConfigContext);
const prefixCls = getPrefixCls('list-item', configContext.prefixCls, customisedCls);
const cls = classNames(prefixCls, className);
return (
<li {...otherProps} ref={ref} className={cls} style={style}>
<div className={`${prefixCls}__main`}>
<div className={`${prefixCls}__content`}>{children}</div>
{actions && actions.length > 0 && (
<ul className={`${prefixCls}__actions`} aria-label="Actions">
{actions.map((action, i) => (
<li key={i} className={`${prefixCls}__action`}>
{action}
</li>
))}
</ul>
)}
</div>
{extra && <div className={`${prefixCls}__extra`}>{extra}</div>}
</li>
);
});
ListItem.displayName = 'ListItem';
export default ListItem;