aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/meta-list/meta-list.tsx
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2023-11-20 11:02:20 +0100
committerArmand Philippot <git@armandphilippot.com>2023-11-20 19:20:21 +0100
commitd5ade2359539648845a5854ed353b29367961d74 (patch)
tree45a49d90090408887135a971a7fd79c45d9dcd94 /src/components/molecules/meta-list/meta-list.tsx
parent6ab9635a22d69186c8a24181ad5df7736e288577 (diff)
refactor(components): extract MetaItem from MetaList
* replace `items` prop on MetaList with `children` prop: it was too restrictive and the global options was not really useful. It is better too give control to the consumers.
Diffstat (limited to 'src/components/molecules/meta-list/meta-list.tsx')
-rw-r--r--src/components/molecules/meta-list/meta-list.tsx72
1 files changed, 20 insertions, 52 deletions
diff --git a/src/components/molecules/meta-list/meta-list.tsx b/src/components/molecules/meta-list/meta-list.tsx
index 288fd9a..c19f0fd 100644
--- a/src/components/molecules/meta-list/meta-list.tsx
+++ b/src/components/molecules/meta-list/meta-list.tsx
@@ -1,54 +1,32 @@
-import { type ForwardRefRenderFunction, forwardRef } from 'react';
+import {
+ type ForwardRefRenderFunction,
+ forwardRef,
+ type ReactNode,
+} from 'react';
import { DescriptionList, type DescriptionListProps } from '../../atoms';
-import { MetaItem, type MetaItemProps } from './meta-item';
import styles from './meta-list.module.scss';
-export type MetaItemData = Pick<
- MetaItemProps,
- | 'hasBorderedValues'
- | 'hasInlinedValues'
- | 'isCentered'
- | 'isInline'
- | 'label'
- | 'value'
+export type MetaListProps = Omit<
+ DescriptionListProps,
+ 'children' | 'spacing'
> & {
- id: string;
+ /**
+ * The meta items.
+ */
+ children: ReactNode;
+ /**
+ * Should the meta be centered?
+ *
+ * @default false
+ */
+ isCentered?: boolean;
};
-export type MetaListProps = Omit<DescriptionListProps, 'children' | 'spacing'> &
- Pick<MetaItemProps, 'hasBorderedValues' | 'hasInlinedValues'> & {
- /**
- * Should the items be inlined?
- *
- * @default false
- */
- hasInlinedItems?: boolean;
- /**
- * Should the meta be centered?
- *
- * @default false
- */
- isCentered?: boolean;
- /**
- * The meta items.
- */
- items: MetaItemData[];
- };
-
const MetaListWithRef: ForwardRefRenderFunction<
HTMLDListElement,
MetaListProps
> = (
- {
- className = '',
- hasBorderedValues = false,
- hasInlinedItems = false,
- hasInlinedValues = false,
- isCentered = false,
- isInline = false,
- items,
- ...props
- },
+ { children, className = '', isCentered = false, isInline = false, ...props },
ref
) => {
const listClass = [
@@ -60,17 +38,7 @@ const MetaListWithRef: ForwardRefRenderFunction<
return (
<DescriptionList {...props} className={listClass} ref={ref}>
- {items.map(({ id, ...item }) => (
- <MetaItem
- hasBorderedValues={hasBorderedValues}
- hasInlinedValues={hasInlinedValues}
- isCentered={isCentered}
- isInline={hasInlinedItems}
- // Each item should be able to override the global settings.
- {...item}
- key={id}
- />
- ))}
+ {children}
</DescriptionList>
);
};