Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | 2x 2x 2x 2x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 17x 16x 2x 2x 7x | import React from "react";
import { ListProps } from "./List.types";
import styled from "styled-components";
import Text from "../Text/Text";
import { ListItemProps } from "./ListItem/ListItem.types";
interface ListStyleProps {
$variant: ListProps["variant"];
}
const List = ({
title,
children,
variant = "ordered",
size,
containerStyle,
color,
style,
className,
"data-testid": dataTestId,
...props
}: ListProps) => {
return (
<div style={containerStyle} data-testid={dataTestId} {...props}>
{
typeof title === "string" ?
<Text color={color} variant="paragraph" size={size}>
{title}
</Text> :
title
}
<StyledList $variant={variant} style={style} className={className}>
{React.Children.map(children, (child) => {
if(!child || !React.isValidElement(child)) return child;
return React.cloneElement(child, {
...(!child.props.size && {size: size}),
...(!child.props.color && {color: color}),
} as ListItemProps);
})}
</StyledList>
</div>
);
};
export default List;
const StyledList = styled.ul<ListStyleProps>`
display: flex;
flex-direction: column;
gap: 0.5rem;
margin: 0.75rem 0 0 0;
padding: 0 0 0 2rem;
font-family: "Lato", sans-serif;
list-style-type: ${(props) =>
props.$variant === "ordered"
? "decimal"
: props.$variant === "unordered"
? "disc"
: "none"};
`; |