Skip to content

Commit ad72de4

Browse files
committed
Add ArrayInputBase story
1 parent ff63ccb commit ad72de4

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as React from 'react';
2+
import fakeRestDataProvider from 'ra-data-fakerest';
3+
import { TestMemoryRouter } from '../../routing';
4+
import { EditBase } from '../edit';
5+
import {
6+
Admin,
7+
DataTable,
8+
TextInput,
9+
SimpleFormIterator,
10+
SimpleForm,
11+
} from '../../test-ui';
12+
import { ListBase } from '../list';
13+
import { Resource } from '../../core';
14+
import { ArrayInputBase } from './ArrayInputBase';
15+
16+
export default { title: 'ra-core/controller/input/ArrayInputBase' };
17+
18+
export const Basic = () => (
19+
<TestMemoryRouter initialEntries={['/posts/1']}>
20+
<Admin
21+
dataProvider={fakeRestDataProvider({
22+
posts: [
23+
{
24+
id: 1,
25+
title: 'Post 1',
26+
tags: [
27+
{ name: 'Tag 1', color: 'red' },
28+
{ name: 'Tag 2', color: 'blue' },
29+
],
30+
},
31+
{ id: 2, title: 'Post 2' },
32+
],
33+
})}
34+
>
35+
<Resource
36+
name="posts"
37+
list={
38+
<ListBase>
39+
<DataTable>
40+
<DataTable.Col source="title" />
41+
<DataTable.Col
42+
label="Tags"
43+
render={record =>
44+
record.tags
45+
? record.tags
46+
.map(tag => tag.name)
47+
.join(', ')
48+
: ''
49+
}
50+
/>
51+
</DataTable>
52+
</ListBase>
53+
}
54+
edit={
55+
<EditBase>
56+
<SimpleForm>
57+
<TextInput source="title" />
58+
<div>
59+
<div>Tags:</div>
60+
<ArrayInputBase source="tags">
61+
<SimpleFormIterator>
62+
<TextInput source="name" />
63+
<TextInput source="color" />
64+
</SimpleFormIterator>
65+
</ArrayInputBase>
66+
</div>
67+
</SimpleForm>
68+
</EditBase>
69+
}
70+
/>
71+
</Admin>
72+
</TestMemoryRouter>
73+
);

0 commit comments

Comments
 (0)