verdnatura-chat/app/containers/markdown/List.js

47 lines
819 B
JavaScript
Raw Permalink Normal View History

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
}) => {
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, {
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
};
List.defaultProps = {
start: 1
};
export default List;