diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Array/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Array/Examples.tsx index 5319b307398..0154e03209c 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Array/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Array/Examples.tsx @@ -378,52 +378,41 @@ export const InitialOpen = () => { - - {({ items }) => { - if (items.length === 1) { - return - } - return ( - <> - - - - ) - }} - - } - > + + + {({ items }) => + items.length === 1 ? ( + + ) : ( + <> + + + + ) + } + - - {({ items }) => { - if (items.length === 1) { - return null - } - - return ( - <> - - - - ) - }} - - } - > + + + {({ items }) => + items.length === 1 ? null : ( + <> + + + + ) + } + diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/EditContainer/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/EditContainer/info.mdx index a03c0799f39..362ac4bdcc0 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/EditContainer/info.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/EditContainer/info.mdx @@ -54,15 +54,12 @@ import { Iterate, Field } from '@dnb/eufemia/extensions/forms' render( - - - - - } - > + + + + + , ) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Toolbar/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Toolbar/info.mdx index 0e93c56243f..528c891b984 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Toolbar/info.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/Toolbar/info.mdx @@ -26,7 +26,25 @@ render( ## Customize the Toolbar -You can customize the toolbar by passing a function as a child to `Iterate.Toolbar`. The function receives the following parameters as an object: +You can customize the toolbar by either passing a function as a child or as a JSX element: + +```tsx +import { Iterate } from '@dnb/eufemia/extensions/forms' + +render( + + + Item Content + + + + + + , +) +``` + +The function receives the following parameters as an object: - `index` the index of the current item in the array. - `value` the value of the current item. @@ -37,25 +55,18 @@ import { Iterate } from '@dnb/eufemia/extensions/forms' render( - - {({ items, index, value }) => { - if (items.length === 1) { - return null - } - - return ( - <> - - - - ) - }} - - } - > + Item Content + + {({ items, index, value }) => { + return items.length === 1 ? null : ( + <> + + + + ) + }} + , ) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/ViewContainer/info.mdx b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/ViewContainer/info.mdx index 3692d4a4968..3002f328cd2 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/ViewContainer/info.mdx +++ b/packages/dnb-design-system-portal/src/docs/uilib/extensions/forms/Iterate/ViewContainer/info.mdx @@ -51,15 +51,13 @@ import { Iterate, Value } from '@dnb/eufemia/extensions/forms' render( - - - - - } - > + + + + + + , ) diff --git a/packages/dnb-eufemia/src/extensions/forms/Iterate/EditContainer/EditContainer.tsx b/packages/dnb-eufemia/src/extensions/forms/Iterate/EditContainer/EditContainer.tsx index f07cad7bab2..93444873b73 100644 --- a/packages/dnb-eufemia/src/extensions/forms/Iterate/EditContainer/EditContainer.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Iterate/EditContainer/EditContainer.tsx @@ -37,20 +37,30 @@ export type Props = { export type AllProps = Props & FlexContainerProps & ElementSectionProps export default function EditContainer(props: AllProps) { - const { toolbar, ...rest } = props + const { toolbar, children, ...rest } = props + + const hasToolbar = + !toolbar && + React.Children.toArray(children).some((child) => { + return child?.['type'] === Toolbar + }) return ( - - - - ) + hasToolbar + ? null + : toolbar ?? ( + + + + + ) } {...rest} - /> + > + {children} + ) } diff --git a/packages/dnb-eufemia/src/extensions/forms/Iterate/PushContainer/__tests__/PushContainer.test.tsx b/packages/dnb-eufemia/src/extensions/forms/Iterate/PushContainer/__tests__/PushContainer.test.tsx index 134f227692c..e05e8f4284f 100644 --- a/packages/dnb-eufemia/src/extensions/forms/Iterate/PushContainer/__tests__/PushContainer.test.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Iterate/PushContainer/__tests__/PushContainer.test.tsx @@ -384,8 +384,9 @@ describe('PushContainer', () => { ... - }> + + ) diff --git a/packages/dnb-eufemia/src/extensions/forms/Iterate/ViewContainer/ViewContainer.tsx b/packages/dnb-eufemia/src/extensions/forms/Iterate/ViewContainer/ViewContainer.tsx index 44872a55cb7..eb73c05ca7f 100644 --- a/packages/dnb-eufemia/src/extensions/forms/Iterate/ViewContainer/ViewContainer.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Iterate/ViewContainer/ViewContainer.tsx @@ -35,6 +35,12 @@ function ViewContainer(props: AllProps) { itemTitle = ariaLabel = ariaLabel.replace('{itemNr}', index + 1) } + const hasToolbar = + !toolbar && + React.Children.toArray(children).some((child) => { + return child?.['type'] === Toolbar + }) + return ( {itemTitle && {itemTitle}} {children} - {toolbar ?? ( - - - - - )} + {hasToolbar + ? null + : toolbar ?? ( + + + + + )} ) diff --git a/packages/dnb-eufemia/src/extensions/forms/Iterate/stories/Iterate.stories.tsx b/packages/dnb-eufemia/src/extensions/forms/Iterate/stories/Iterate.stories.tsx index eebd11c7344..fb62fd9046d 100644 --- a/packages/dnb-eufemia/src/extensions/forms/Iterate/stories/Iterate.stories.tsx +++ b/packages/dnb-eufemia/src/extensions/forms/Iterate/stories/Iterate.stories.tsx @@ -148,53 +148,49 @@ export const InitialOpen = () => { const MyEditItem = useCallback(() => { return ( - - {({ items }) => { - if (items.length === 1) { - return null - } - - return ( - <> - - - - ) - }} - - } - > + + + + {({ items }) => { + if (items.length === 1) { + return null + } + + return ( + <> + + + + ) + }} + ) }, [MyEditItemForm]) const MyViewItem = useCallback(() => { return ( - - {({ items }) => { - if (items.length === 1) { - return - } - - return ( - <> - - - - ) - }} - - } - > + + + + {({ items }) => { + if (items.length === 1) { + return + } + + return ( + <> + + + + ) + }} + ) }, [])