diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-04-13 19:28:16 +0200 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-04-13 19:28:16 +0200 |
| commit | 47e35fcd7c2c346f4799630bf6521d6a4bf49e85 (patch) | |
| tree | 99228c523b6ced1d9c1e83a03a4dd9fc2468e4b0 /src/components/atoms/lists/description-list.tsx | |
| parent | 017d01680a933897df6ddd11d2e081730756250b (diff) | |
chore: add a Card component
Diffstat (limited to 'src/components/atoms/lists/description-list.tsx')
| -rw-r--r-- | src/components/atoms/lists/description-list.tsx | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/src/components/atoms/lists/description-list.tsx b/src/components/atoms/lists/description-list.tsx index a5ab1d5..0a92465 100644 --- a/src/components/atoms/lists/description-list.tsx +++ b/src/components/atoms/lists/description-list.tsx @@ -22,9 +22,29 @@ export type DescriptionListProps = { */ className?: string; /** + * Set additional classnames to the `dd` element. + */ + descriptionClassName?: string; + /** + * Set additional classnames to the `dt`/`dd` couple wrapper. + */ + groupClassName?: string; + /** * The list items. */ items: DescriptionListItem[]; + /** + * The list items layout. Default: column. + */ + layout?: 'inline' | 'column'; + /** + * Define if the layout should automatically create rows/columns. + */ + responsiveLayout?: boolean; + /** + * Set additional classnames to the `dt` element. + */ + termClassName?: string; }; /** @@ -34,8 +54,16 @@ export type DescriptionListProps = { */ const DescriptionList: VFC<DescriptionListProps> = ({ className = '', + descriptionClassName = '', + groupClassName = '', items, + layout = 'column', + responsiveLayout = false, + termClassName = '', }) => { + const layoutModifier = `list--${layout}`; + const responsiveModifier = responsiveLayout ? 'list--responsive' : ''; + /** * Retrieve the description list items wrapped in a div element. * @@ -45,10 +73,13 @@ const DescriptionList: VFC<DescriptionListProps> = ({ const getItems = (listItems: DescriptionListItem[]): JSX.Element[] => { return listItems.map(({ id, term, value }) => { return ( - <div key={id} className={styles.list__item}> - <dt className={styles.list__term}>{term}</dt> + <div key={id} className={`${styles.list__item} ${groupClassName}`}> + <dt className={`${styles.list__term} ${termClassName}`}>{term}</dt> {value.map((currentValue, index) => ( - <dd key={`${id}-${index}`} className={styles.list__description}> + <dd + key={`${id}-${index}`} + className={`${styles.list__description} ${descriptionClassName}`} + > {currentValue} </dd> ))} @@ -57,7 +88,13 @@ const DescriptionList: VFC<DescriptionListProps> = ({ }); }; - return <dl className={`${styles.list} ${className}`}>{getItems(items)}</dl>; + return ( + <dl + className={`${styles.list} ${styles[layoutModifier]} ${styles[responsiveModifier]} ${className}`} + > + {getItems(items)} + </dl> + ); }; export default DescriptionList; |
