import * as React from 'react' import cls from 'classnames' import { Icon, TouchFeedback } from 'rcm-mobile' import './style/index.scss' // 偷懒了~~,extra API被移除,改用children,配合表单的children查询 /** * @author tongxiaokang * @version 0.0.1 * * 实现了 [TouchFeedback](#/Components/TouchFeedback) 组件的所有API。 */ export default class ListItem extends React.PureComponent { static defaultProps = { wrap: false, arrow: '', disabled: false, prefixCls: 'x-list-item', activeClassName: 'x-active' } constructor(props: ListItemProps) { super(props) this.state = { rotate: Icon.getRotate(props.arrow) } } render() { const { className, activeStyle, activeClassName, wrap, disabled, title, children, thumb, arrow, onClick, prefixCls, ...restProps } = this.props return ( {thumb ? (
{typeof thumb === 'string' ? : thumb}
) : null}
{title ?
{title}
: null} {children !== undefined &&
{children}
} {arrow && (
)}
) } static getDerivedStateFromProps(nextProps: ListItemProps, prevState: any) { if (nextProps.arrow !== prevState.arrow) { return { rotate: Icon.getRotate(nextProps.arrow) } } return null } /** * 辅助说明 * */ static Brief(props?: any) { const prefixCls = ListItem.defaultProps.prefixCls if (!props.children) return null return
{props.children}
} handleClick = (e: React.MouseEvent) => { const { onClick, disabled } = this.props if (!disabled && onClick) { onClick(e) } } } // @ts-ignore export interface ListItemProps extends React.HTMLAttributes<{}> { /** * 样式前缀 * @ignore */ prefixCls?: string; /** * 是否禁用 * @default false */ disabled?: boolean; /** * 左侧内容,可以是icon地址 */ thumb?: React.ReactNode; /** * 标题内容 */ title?: React.ReactNode; /** * 右侧-箭头 * @default right */ arrow?: 'left' | 'right' | 'top' | 'bottom' | null; /** * 是否换行 * @default false */ wrap?: boolean; /** * 点击反馈的自定义类名 * @default "x-active" * */ activeClassName?: string /** * 点击反馈的自定义样式 */ activeStyle?: any }