@clicoh/orion-library 1.1.0-beta.8 → 1.1.0-beta.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -6,6 +6,12 @@ type EachProps<T> = {
|
|
|
6
6
|
/**
|
|
7
7
|
* A utility component that iterates over an array and renders each item using the provided render function.
|
|
8
8
|
*
|
|
9
|
+
* Each rendered item is wrapped in a keyed `Fragment`, so consumers do not need
|
|
10
|
+
* to set a key themselves. When the render function does return an element with
|
|
11
|
+
* its own key, that key wins: a consumer that needs stable identity across
|
|
12
|
+
* reordering keeps it. The `Fragment` adds no DOM node, so the rendered items
|
|
13
|
+
* stay direct children of the parent and CSS grid or flex layouts are unaffected.
|
|
14
|
+
*
|
|
9
15
|
* @component
|
|
10
16
|
* @example
|
|
11
17
|
* // Example usage of Each component
|
|
@@ -16,6 +22,13 @@ type EachProps<T> = {
|
|
|
16
22
|
* )}
|
|
17
23
|
* />
|
|
18
24
|
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Providing a stable key for lists that reorder
|
|
27
|
+
* <Each
|
|
28
|
+
* of={fruits}
|
|
29
|
+
* render={(fruit) => <li key={fruit.id}>{fruit.name}</li>}
|
|
30
|
+
* />
|
|
31
|
+
*
|
|
19
32
|
* @param {Object} props - The properties of the Each component.
|
|
20
33
|
* @param {T[]} props.of - The array of items to iterate over and render.
|
|
21
34
|
* @param {(item: T, index: number) => ReactNode} props.render - A function that renders each item in the array.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Each.d.ts","sourceRoot":"","sources":["../../../../src/components/00-base/Each/Each.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"Each.d.ts","sourceRoot":"","sources":["../../../../src/components/00-base/Each/Each.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEjE,KAAK,SAAS,CAAC,CAAC,IAAI;IAClB,EAAE,EAAE,CAAC,EAAE,CAAC;IACR,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,SAAS,CAAC;CAC/C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,SAAS,CAO/D"}
|
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Fragment, isValidElement } from 'react';
|
|
2
2
|
/**
|
|
3
3
|
* A utility component that iterates over an array and renders each item using the provided render function.
|
|
4
4
|
*
|
|
5
|
+
* Each rendered item is wrapped in a keyed `Fragment`, so consumers do not need
|
|
6
|
+
* to set a key themselves. When the render function does return an element with
|
|
7
|
+
* its own key, that key wins: a consumer that needs stable identity across
|
|
8
|
+
* reordering keeps it. The `Fragment` adds no DOM node, so the rendered items
|
|
9
|
+
* stay direct children of the parent and CSS grid or flex layouts are unaffected.
|
|
10
|
+
*
|
|
5
11
|
* @component
|
|
6
12
|
* @example
|
|
7
13
|
* // Example usage of Each component
|
|
@@ -12,6 +18,13 @@ import { Children } from 'react';
|
|
|
12
18
|
* )}
|
|
13
19
|
* />
|
|
14
20
|
*
|
|
21
|
+
* @example
|
|
22
|
+
* // Providing a stable key for lists that reorder
|
|
23
|
+
* <Each
|
|
24
|
+
* of={fruits}
|
|
25
|
+
* render={(fruit) => <li key={fruit.id}>{fruit.name}</li>}
|
|
26
|
+
* />
|
|
27
|
+
*
|
|
15
28
|
* @param {Object} props - The properties of the Each component.
|
|
16
29
|
* @param {T[]} props.of - The array of items to iterate over and render.
|
|
17
30
|
* @param {(item: T, index: number) => ReactNode} props.render - A function that renders each item in the array.
|
|
@@ -19,6 +32,10 @@ import { Children } from 'react';
|
|
|
19
32
|
* @returns {ReactNode} The rendered Each component.
|
|
20
33
|
*/
|
|
21
34
|
export function Each({ of, render }) {
|
|
22
|
-
return
|
|
35
|
+
return of.map((item, index) => {
|
|
36
|
+
const rendered = render(item, index);
|
|
37
|
+
const key = isValidElement(rendered) && rendered.key ? rendered.key : index;
|
|
38
|
+
return <Fragment key={key}>{rendered}</Fragment>;
|
|
39
|
+
});
|
|
23
40
|
}
|
|
24
41
|
//# sourceMappingURL=Each.jsx.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Each.jsx","sourceRoot":"","sources":["../../../../src/components/00-base/Each/Each.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAkB,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Each.jsx","sourceRoot":"","sources":["../../../../src/components/00-base/Each/Each.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAkB,MAAM,OAAO,CAAC;AAOjE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,IAAI,CAAI,EAAE,EAAE,EAAE,MAAM,EAAgB;IAClD,OAAO,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;QAC5B,MAAM,QAAQ,GAAG,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACrC,MAAM,GAAG,GAAG,cAAc,CAAC,QAAQ,CAAC,IAAI,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;QAE5E,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC,CAAC;IACnD,CAAC,CAAC,CAAC;AACL,CAAC"}
|