2019-08-27 12:25:38 +00:00
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
const List = React.memo(({
|
2019-10-02 12:41:51 +00:00
|
|
|
children, ordered, start, tight, numberOfLines = 0
|
2019-08-27 12:25:38 +00:00
|
|
|
}) => {
|
|
|
|
let bulletWidth = 15;
|
|
|
|
|
|
|
|
if (ordered) {
|
|
|
|
const lastNumber = (start + children.length) - 1;
|
|
|
|
bulletWidth = (9 * lastNumber.toString().length) + 7;
|
|
|
|
}
|
|
|
|
|
2019-10-02 12:41:51 +00:00
|
|
|
let items = React.Children.toArray(children);
|
|
|
|
|
|
|
|
if (numberOfLines) {
|
|
|
|
items = items.slice(0, numberOfLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
const _children = items.map((child, index) => React.cloneElement(child, {
|
2019-08-27 12:25:38 +00:00
|
|
|
bulletWidth,
|
|
|
|
ordered,
|
|
|
|
tight,
|
|
|
|
index: start + index
|
|
|
|
}));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{_children}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
List.propTypes = {
|
|
|
|
children: PropTypes.node,
|
|
|
|
ordered: PropTypes.bool,
|
|
|
|
start: PropTypes.number,
|
2019-10-02 12:41:51 +00:00
|
|
|
tight: PropTypes.bool,
|
|
|
|
numberOfLines: PropTypes.number
|
2019-08-27 12:25:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
List.defaultProps = {
|
|
|
|
start: 1
|
|
|
|
};
|
|
|
|
|
|
|
|
export default List;
|