Demos
Primitive elements
Code Editor
<Iterate.Arraylabel="Array label"value={['Iron Man', 'Captain America', 'The Hulk']}onChange={(value) => console.log('onChange', value)}><Field.String elementPath="/" /></Iterate.Array>
Object elements
Code Editor
<Iterate.Arraylabel="Accounts"value={[{accountName: 'Brukskonto',accountNumber: '90901134567',},{accountName: 'Sparekonto',accountNumber: '90901156789',},]}onChange={(value) => console.log('onChange', value)}><h3><Value.String elementPath="/nickname" /></h3><Layout.Row><Field.BankAccountNumber elementPath="/accountNumber" /><Field.String label="Account name" elementPath="/accountName" /></Layout.Row></Iterate.Array>
Render props with primitive elements
Code Editor
<Iterate.Arraylabel="Array label"value={['foo', 'bar', 'baz']}onChange={(value) => console.log('onChange', value)}>{(elementValue) => <Field.String value={elementValue} />}</Iterate.Array>
Render props with object elements
Code Editor
<Iterate.Arraylabel="Array label"value={[{num: 1,txt: 'One',},{num: 2,txt: 'Two',},{num: 3,txt: 'Three',},{num: 4,txt: 'Four',},]}onChange={(value) => console.log('onChange', value)}>{({ num, txt }) => (<Layout.Row width="large"><Field.Number value={num} width="small" /><Field.String value={txt} width={false} /></Layout.Row>)}</Iterate.Array>
With DataContext and add/remove buttons
elementPath
points to the root of each iterated element, while path
points to the root of the data source.
Avengers
Iron Man
Captain America
Code Editor
<DataContext.Providerdata={{avengers: [{nickname: 'Iron Man',firstName: 'Tony',lastName: 'Stark',bornYear: 1970,},{nickname: 'Captain America',firstName: 'Steve',lastName: 'Rogers',bornYear: 1918,},],alwaysThere: 'Nick Fury',}}onChange={(data) => console.log('Source onChange', data)}><Layout.MainHeading>Avengers</Layout.MainHeading><Iterate.Arraypath="/avengers"onChange={(value) => console.log('Iterate onChange', value)}><Layout.SubHeading><Value.String elementPath="/nickname" /></Layout.SubHeading><Layout.Row align="center"><Field.StringelementPath="/firstName"width="medium"label="First name"/><Field.StringelementPath="/lastName"width="medium"label="Last name"/><Field.NumberelementPath="/bornYear"label="Year of birth"width="small"/><Iterate.ArrayRemoveElementButton icon={TrashIcon} /></Layout.Row><Field.String path="/alwaysThere" top="x-small" /></Iterate.Array><Iterate.ArrayPushButtontop="small"text="Add another avenger"path="/avengers"pushValue={{}}/></DataContext.Provider>