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 --- .../organisms/widgets/links-list-widget.tsx | 67 +++++++++++++--------- 1 file changed, 39 insertions(+), 28 deletions(-) (limited to 'src/components/organisms/widgets/links-list-widget.tsx') diff --git a/src/components/organisms/widgets/links-list-widget.tsx b/src/components/organisms/widgets/links-list-widget.tsx index df8430d..8f71efd 100644 --- a/src/components/organisms/widgets/links-list-widget.tsx +++ b/src/components/organisms/widgets/links-list-widget.tsx @@ -1,6 +1,6 @@ -import { FC } from 'react'; +import type { FC } from 'react'; import { slugify } from '../../../utils/helpers'; -import { Link, List, type ListItem, type ListProps } from '../../atoms'; +import { Link, List, ListItem } from '../../atoms'; import { Widget, type WidgetProps } from '../../molecules'; import styles from './links-list-widget.module.scss'; @@ -19,13 +19,19 @@ export type LinksListItems = { url: string; }; -export type LinksListWidgetProps = Pick & - Pick & { - /** - * An array of name/url couple. - */ - items: LinksListItems[]; - }; +export type LinksListWidgetProps = Pick & { + className?: string; + /** + * Should the links be ordered? + * + * @default false + */ + isOrdered?: boolean; + /** + * An array of name/url couple. + */ + items: LinksListItems[]; +}; /** * LinksListWidget component @@ -34,11 +40,11 @@ export type LinksListWidgetProps = Pick & */ export const LinksListWidget: FC = ({ className = '', + isOrdered = false, items, - kind = 'unordered', ...props }) => { - const listKindClass = `list--${kind}`; + const listKindClass = `list--${isOrdered ? 'ordered' : 'unordered'}`; /** * Format the widget data to be used as List items. @@ -46,19 +52,23 @@ export const LinksListWidget: FC = ({ * @param {LinksListItems[]} data - The widget data. * @returns {ListItem[]} The list items data. */ - const getListItems = (data: LinksListItems[]): ListItem[] => { - return data.map((item) => { - return { - id: slugify(item.name), - child: item.child && getListItems(item.child), - value: ( - - {item.name} - - ), - }; - }); - }; + const getListItems = (data: LinksListItems[]) => + data.map((item) => ( + + + {item.name} + + {item.child?.length ? ( + + {getListItems(item.child)} + + ) : null} + + )); return ( = ({ > + hideMarker + isOrdered={isOrdered} + > + {getListItems(items)} + ); }; -- cgit v1.2.3