From 4f768afe543bbf9e1857c41d03804f8e37ab3512 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 29 Sep 2023 21:29:45 +0200 Subject: refactor(components): rewrite List component * change `items` prop to children * replace `kind` prop with `isHierarchical`, `isOrdered` & `isInline` props * add `hideMarker` prop * add `spacing` prop to control item spacing * move lists styles to Sass placeholders to avoid repeats because of headless WordPress --- src/components/organisms/layout/cards-list.tsx | 71 ++++++++++++-------------- 1 file changed, 33 insertions(+), 38 deletions(-) (limited to 'src/components/organisms/layout/cards-list.tsx') diff --git a/src/components/organisms/layout/cards-list.tsx b/src/components/organisms/layout/cards-list.tsx index e3d1156..29add3b 100644 --- a/src/components/organisms/layout/cards-list.tsx +++ b/src/components/organisms/layout/cards-list.tsx @@ -1,5 +1,5 @@ -import { FC } from 'react'; -import { List, type ListItem, type ListProps } from '../../atoms'; +import type { FC } from 'react'; +import { List, ListItem } from '../../atoms'; import { Card, type CardProps } from '../../molecules'; import styles from './cards-list.module.scss'; @@ -10,17 +10,22 @@ export type CardsListItem = Omit & { id: string; }; -export type CardsListProps = Pick & - Pick & { - /** - * Set additional classnames to the list wrapper. - */ - className?: string; - /** - * The cards data. - */ - items: CardsListItem[]; - }; +export type CardsListProps = Pick & { + /** + * Set additional classnames to the list wrapper. + */ + className?: string; + /** + * Should the cards list be ordered? + * + * @default false + */ + isOrdered?: boolean; + /** + * The cards data. + */ + items: CardsListItem[]; +}; /** * CardsList component @@ -29,40 +34,30 @@ export type CardsListProps = Pick & */ export const CardsList: FC = ({ className = '', + isOrdered = false, items, - kind = 'unordered', titleLevel, }) => { - const kindModifier = `wrapper--${kind}`; + const kindModifier = `wrapper--${isOrdered ? 'ordered' : 'unordered'}`; - /** - * Format the cards data to be used by the List component. - * - * @param {CardsListItem[]} cards - An array of card data. - * @returns {ListItem[]} The formatted cards data. - */ - const getCards = (cards: CardsListItem[]): ListItem[] => { - return cards.map(({ id, ...card }) => { - return { - id, - value: ( + return ( + + {items.map(({ id, ...item }) => ( + - ), - }; - }); - }; - - return ( - + + ))} + ); }; -- cgit v1.2.3