2019-08-27 12:25:38 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
2021-07-21 15:15:13 +00:00
|
|
|
interface IList {
|
|
|
|
children: JSX.Element;
|
|
|
|
ordered: boolean;
|
|
|
|
start: number;
|
|
|
|
tight: boolean;
|
|
|
|
numberOfLines: number;
|
|
|
|
}
|
|
|
|
|
2021-08-02 22:17:29 +00:00
|
|
|
const List = React.memo(({ children, ordered, tight, start = 1, numberOfLines = 0 }: IList) => {
|
2019-08-27 12:25:38 +00:00
|
|
|
let bulletWidth = 15;
|
|
|
|
|
|
|
|
if (ordered) {
|
2021-07-21 15:15:13 +00:00
|
|
|
// @ts-ignore
|
2019-08-27 12:25:38 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-07-21 15:15:13 +00:00
|
|
|
const _children = items.map((child: any, index: number) => React.cloneElement(child, {
|
2019-08-27 12:25:38 +00:00
|
|
|
bulletWidth,
|
|
|
|
ordered,
|
|
|
|
tight,
|
|
|
|
index: start + index
|
|
|
|
}));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{_children}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
export default List;
|