Skip to content

Import

import { Iterate } from '@dnb/eufemia/extensions/forms'
render(<Iterate.Toolbar />)

Description

Use Iterate.Toolbar to enhance each item in the array with additional functionality. It's particularly useful within components like Iterate.AnimatedContainer to incorporate a toolbar with extra tools.

The Toolbar is integrated into the Iterate.ViewContainer and the Iterate.EditContainer.

import { Iterate } from '@dnb/eufemia/extensions/forms'
render(
<Iterate.Array>
<Iterate.AnimatedContainer>
Item Content
<Iterate.Toolbar>
<Iterate.RemoveButton />
</Iterate.Toolbar>
</Iterate.AnimatedContainer>
</Iterate.Array>,
)

Customize the Toolbar

You can customize the toolbar by either passing a function as a child or as a JSX element:

import { Iterate } from '@dnb/eufemia/extensions/forms'
render(
<Iterate.Array>
<Iterate.ViewContainer>
Item view content
<Iterate.Toolbar>
<Iterate.ViewContainer.EditButton />
<Iterate.ViewContainer.RemoveButton />
</Iterate.Toolbar>
</Iterate.ViewContainer>
<Iterate.EditContainer>
Item edit content
<Iterate.Toolbar>
<Iterate.EditContainer.DoneButton />
<Iterate.EditContainer.CancelButton />
</Iterate.Toolbar>
</Iterate.EditContainer>
</Iterate.Array>,
)

You can also provide a function as a child. The function will provide the following parameters as an object:

  • index the index of the current item in the array.
  • value the value of the current item.
  • items the array of items.
import { Iterate } from '@dnb/eufemia/extensions/forms'
render(
<Iterate.Array>
<Iterate.ViewContainer>
Item Content
<Iterate.Toolbar>
{({ items, index, value }) => {
return items.length === 1 ? null : (
<>
<Iterate.ViewContainer.EditButton />
<Iterate.ViewContainer.RemoveButton />
</>
)
}}
</Iterate.Toolbar>
</Iterate.ViewContainer>
</Iterate.Array>,
)