Skip to content

Commit 8b18589

Browse files
committed
Describe antd integration
1 parent 95bbf34 commit 8b18589

File tree

6 files changed

+97
-5
lines changed

6 files changed

+97
-5
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ The most important features of this component are:
6262
- ✅ Fully compositable
6363
- ✅ Automatic testing with >90% coverage
6464
- ✅ Input validation
65+
-[Ant Design](https://ant.design/) integration (see storybook)
6566
- ❌ Input transformation
66-
-[Material UI](https://material-ui.com/) integration
67-
-[ant.design](https://ant.design/) integration
67+
-[Material UI](https://material-ui.com/) integration (see storybook)
6868

6969
✅ means the feature is implemented and released. ❌ indicates that a feature is planned.
7070

docs/antd-integration.stories.mdx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import { Meta, Description, Source } from '@storybook/addon-docs/blocks';
2+
import Readme from '../README.md';
3+
4+
<Meta title="Usage|Integrations/Ant Design" />
5+
6+
# Ant Design integration
7+
This page shows how an input and a preview component with Ant Design (`>= 4`) can be built and connected to this component.
8+
9+
First the imports need to be declared.
10+
11+
<Source language='tsx' code={`
12+
import * as React from 'react';
13+
import { DSVImport as Import, ColumnsType, useDSVImport } from 'react-dsv-import';
14+
import { Form, Input, Table } from 'antd';
15+
`} />
16+
17+
## Input component
18+
<Source language='tsx' code={`
19+
const TextareaInput: React.FC = () => {
20+
const [, dispatch] = useDSVImport();
21+
22+
const handleChange = (event: React.ChangeEvent<HTMLTextAreaElement>) => {
23+
dispatch({ type: 'setRaw', raw: event.target.value });
24+
};
25+
26+
return <Input.TextArea rows={15} onChange={handleChange} />;
27+
};
28+
`} />
29+
30+
## Preview component
31+
<Source language='tsx' code={`
32+
const TablePreview: React.FC = () => {
33+
const [context] = useDSVImport();
34+
35+
const getRowKey = (record: { [key: string]: string }) => {
36+
return context.parsed.indexOf(record);
37+
};
38+
39+
return (
40+
<Table pagination={false} dataSource={context.parsed} rowKey={getRowKey}>
41+
{context.columns.map((r) => {
42+
return <Table.Column key={r.key} dataIndex={r.key} title={r.label ? r.label : r.key} />;
43+
})}
44+
</Table>
45+
);
46+
};
47+
`} />
48+
49+
## Create context
50+
51+
<Source language='tsx' code={`
52+
export interface Props<T> {
53+
onChange?: (value: T[]) => void;
54+
columns: ColumnsType<T>;
55+
}
56+
57+
export const DSVImport = <T extends { [key: string]: string }>(props: Props<T>) => {
58+
const intl = useIntl();
59+
60+
return (
61+
<Form layout='vertical'>
62+
<Import<T> columns={props.columns} onChange={props.onChange}>
63+
<Form.Item label='Input'>
64+
<TextareaInput />
65+
</Form.Item>
66+
<Form.Item label='Preview'>
67+
<TablePreview />
68+
</Form.Item>
69+
</Import>
70+
</Form>
71+
);
72+
};
73+
`} />

docs/input.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log('asdsa');

docs/material-integration.stories.mdx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Meta, Description, Source } from '@storybook/addon-docs/blocks';
2+
3+
<Meta title="Usage|Integrations/Material UI" />
4+
5+
# Material UI integration
6+
This page shows how an input and a preview component with Material UI can be built and connected to this component. It's possible to put everything into one file.
7+
8+
First the imports need to be declared.
9+
10+
<Source language='tsx' code={`
11+
import * as React from 'react';
12+
import { DSVImport as Import, ColumnsType, useDSVImport } from 'react-dsv-import';
13+
`} />
14+
15+
## Input component
16+
17+
## Preview component
18+
19+
## Create context

docs/start.stories.mdx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Meta, Description } from '@storybook/addon-docs/blocks';
22
import Readme from '../README.md';
33

4-
5-
<Meta title="Start" />
4+
<Meta title="Start|Readme" />
65

76
<Description markdown={Readme} />

src/DSVImport.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { DSVImport, ColumnsType } from './';
33
import { action } from '@storybook/addon-actions';
44
import styled from '@emotion/styled';
55

6-
export default { title: 'Usage' };
6+
export default { title: 'Usage|API' };
77

88
type BasicType = { forename: string; surname: string; email: string };
99

0 commit comments

Comments
 (0)