@@ -6,15 +6,14 @@ export default { title: 'Usage' };
6
6
7
7
type BasicType = { forename : string ; surname : string ; email : string } ;
8
8
9
- const columns : ColumnsType < BasicType > = [
10
- { key : 'forename' , label : 'Forename' } ,
11
- { key : 'surname' , label : 'Surname' } ,
12
- { key : 'email' , label : 'Email' }
13
- ] ;
14
-
15
- const onChangeAction = action ( 'Parsed value has changed' ) ;
16
-
17
9
export const BasicUsage = ( ) => {
10
+ const columns : ColumnsType < BasicType > = [
11
+ { key : 'forename' , label : 'Forename' } ,
12
+ { key : 'surname' , label : 'Surname' } ,
13
+ { key : 'email' , label : 'Email' }
14
+ ] ;
15
+ const onChangeAction = action ( 'Parsed value has changed' ) ;
16
+
18
17
return (
19
18
< DSVImport < BasicType > columns = { columns } onChange = { onChangeAction } >
20
19
< DSVImport . TextareaInput />
@@ -25,6 +24,12 @@ export const BasicUsage = () => {
25
24
BasicUsage . story = { name : 'Basic usage' } ;
26
25
27
26
export const UsingCallbacks = ( ) => {
27
+ const columns : ColumnsType < BasicType > = [
28
+ { key : 'forename' , label : 'Forename' } ,
29
+ { key : 'surname' , label : 'Surname' } ,
30
+ { key : 'email' , label : 'Email' }
31
+ ] ;
32
+ const onChangeAction = action ( 'Parsed value has changed' ) ;
28
33
const [ state , setState ] = useState < BasicType [ ] > ( [ ] ) ;
29
34
30
35
const handleOnChange = ( value : BasicType [ ] ) => {
@@ -43,4 +48,20 @@ export const UsingCallbacks = () => {
43
48
</ >
44
49
) ;
45
50
} ;
46
- UsingCallbacks . story = { name : 'Using callbacks with states' } ;
51
+ UsingCallbacks . story = { name : 'Using callbacks a state' } ;
52
+
53
+ export const UsingValidation = ( ) => {
54
+ const columns : ColumnsType < BasicType > = [
55
+ { key : 'forename' , label : 'Forename' } ,
56
+ { key : 'surname' , label : 'Surname' } ,
57
+ { key : 'email' , label : 'Email' , rules : [ { constraint : { unique : true } , message : 'Must be unique' } ] }
58
+ ] ;
59
+ const onChangeAction = action ( 'Parsed value has changed' ) ;
60
+
61
+ return (
62
+ < DSVImport < BasicType > columns = { columns } onChange = { onChangeAction } >
63
+ < DSVImport . TextareaInput />
64
+ < DSVImport . TablePreview />
65
+ </ DSVImport >
66
+ ) ;
67
+ } ;
0 commit comments