2021-09-13 20:41:05 +00:00
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
interface IList {
|
2022-03-25 17:20:09 +00:00
|
|
|
children: React.ReactElement[] | null;
|
2021-09-13 20:41:05 +00:00
|
|
|
ordered: boolean;
|
|
|
|
start: number;
|
|
|
|
tight: boolean;
|
2022-02-17 15:27:01 +00:00
|
|
|
numberOfLines?: number;
|
2021-09-13 20:41:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const List = React.memo(({ children, ordered, tight, start = 1, numberOfLines = 0 }: IList) => {
|
|
|
|
let bulletWidth = 15;
|
|
|
|
|
2022-03-25 17:20:09 +00:00
|
|
|
if (ordered && children) {
|
|
|
|
const lastNumber = start + children?.length - 1;
|
2021-09-13 20:41:05 +00:00
|
|
|
bulletWidth = 9 * lastNumber.toString().length + 7;
|
|
|
|
}
|
|
|
|
|
|
|
|
let items = React.Children.toArray(children);
|
|
|
|
|
|
|
|
if (numberOfLines) {
|
|
|
|
items = items.slice(0, numberOfLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
const _children = items.map((child: any, index: number) =>
|
|
|
|
React.cloneElement(child, {
|
|
|
|
bulletWidth,
|
|
|
|
ordered,
|
|
|
|
tight,
|
|
|
|
index: start + index
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
return <>{_children}</>;
|
|
|
|
});
|
|
|
|
|
|
|
|
export default List;
|