Skip to content

Commit 3775590

Browse files
committed
Describe API within the readme
1 parent 5733260 commit 3775590

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,39 @@ const columns = [
5151
</DSVImport>
5252
```
5353

54+
## API
55+
The `<DSVImport<T>>` components has the following API:
56+
57+
| Property | Type | Description |
58+
|:---------------|:-------------------------------|:-----------------------------------------------------------|
59+
| `columns` | [ColumnType](#columntype) | Description of the expected columns |
60+
| `transformers?`| [Transformer](#transformer)`[]`| Globally applied transformers |
61+
| `onChange?` | `(value: T[]) => void` | Callback which is called after parsing the input |
62+
| `onValidation?`| `(errors: Error<T>[]) => void` | Callback which is called if there are validation errors |
63+
64+
### Types
65+
Within this section additional types are explained.
66+
67+
#### ColumnType
68+
| Property | Type | Description |
69+
|:----------------|:-----------------------------|:------------------------------------------------------------|
70+
| `key` | `string` | Key of the current column |
71+
| `label` | `string` | Label of the current column, which can be shown to the user |
72+
| `rules?` | [Rule](#rule)`[]` | Validation rules which are applied to this column |
73+
| `transformers?` | [Transformer](#transformer)`[]`| Transformers which are applied to this column |
74+
75+
#### Rule
76+
| Property | Type | Description |
77+
|:----------------|:-----------------------------|:------------------------------------------------------------|
78+
| `message` | `string` | Error message |
79+
| `contraint` | `{ unique: boolean } | { constraint: `[Constraint](#constraint)`}` | Constraint for this rule |
80+
81+
#### Constraint
82+
`(value: string) => boolean`
83+
84+
#### Transformer
85+
`(value: string) => string`
86+
5487
## Project
5588
This section describes the status of the project.
5689

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|API' };
6+
export default { title: 'Usage|Examples' };
77

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

src/DSVImport.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const EventListener = <T extends { [key: string]: string }>(props: EventListener
3333
};
3434

3535
export interface Props<T> {
36+
columns: ColumnsType<T>;
3637
onChange?: (value: T[]) => void;
3738
onValidation?: (errors: ValidationError<T>[]) => void;
3839
transformers?: Transformer[];
39-
columns: ColumnsType<T>;
4040
}
4141

4242
export const DSVImport = <T extends { [key: string]: string }>(props: PropsWithChildren<Props<T>>) => {

0 commit comments

Comments
 (0)