mirror of
https://github.com/wassname/talk.git
synced 2026-06-30 07:21:41 +08:00
33 lines
814 B
JavaScript
33 lines
814 B
JavaScript
import React, {Component} from 'react';
|
|
import styles from './List.css';
|
|
|
|
export default class List extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.handleClickItem = this.handleClickItem.bind(this);
|
|
}
|
|
|
|
handleClickItem(itemId) {
|
|
if (this.props.onChange) {
|
|
this.props.onChange(itemId);
|
|
}
|
|
}
|
|
|
|
render() {
|
|
const {children, activeItem, className = ''} = this.props;
|
|
return (
|
|
<ul className={`${styles.base} ${className}`}>
|
|
{React.Children.toArray(children)
|
|
.filter((child) => !child.props.restricted)
|
|
.map((child, i) =>
|
|
React.cloneElement(child, {
|
|
i,
|
|
active: child.props.itemId === activeItem,
|
|
onItemClick: this.handleClickItem,
|
|
})
|
|
)}
|
|
</ul>
|
|
);
|
|
}
|
|
}
|