1
- import { AutocompleteElement , FormContainer } from 'react-hook-form-mui'
1
+ import { AutocompleteElement , FormContainer } from 'react-hook-form-mui/src '
2
2
import { FC , PropsWithChildren } from 'react'
3
3
import { ComponentMeta , ComponentStory } from '@storybook/react'
4
4
import { action } from '@storybook/addon-actions'
5
5
import { Box , Button } from '@mui/material'
6
6
import LocationIcon from '@mui/icons-material/LocationOn'
7
7
8
8
export default {
9
- title : 'Autocomplete' ,
10
- component : AutocompleteElement
9
+ title : 'Autocomplete' ,
10
+ component : AutocompleteElement
11
11
} as ComponentMeta < typeof AutocompleteElement >
12
12
13
13
const FormWrap : FC < PropsWithChildren > = ( { children} ) => (
14
- < FormContainer onSuccess = { action ( 'form-submit' ) }
15
- defaultValues = { {
16
- preselect : { id : 2 , label : 'Second' } ,
17
- 'multi-preselect' : [ { id : 2 , label : 'Second' } ] ,
18
- 'match-id' : 2 ,
19
- 'match-id-multi' : [ 2 , 3 ] ,
20
- } } >
21
- { children }
22
- < Box marginTop = { 2 } >
23
- < Button type = { 'submit' } > Submit</ Button >
24
- </ Box >
25
- </ FormContainer >
14
+ < FormContainer onSuccess = { action ( 'form-submit' ) }
15
+ defaultValues = { {
16
+ preselect : { id : 2 , label : 'Second' } ,
17
+ 'multi-preselect' : [ { id : 2 , label : 'Second' } ] ,
18
+ 'match-id' : 2 ,
19
+ 'match-id-multi' : [ 2 , 3 ] ,
20
+ } } >
21
+ { children }
22
+ < Box marginTop = { 2 } >
23
+ < Button type = { 'submit' } > Submit</ Button >
24
+ </ Box >
25
+ </ FormContainer >
26
26
)
27
27
28
28
const Template : ComponentStory < typeof AutocompleteElement > = ( args ) => {
29
- return (
30
- < FormWrap >
31
- < AutocompleteElement { ...args } />
32
- </ FormWrap >
33
- )
29
+ return (
30
+ < FormWrap >
31
+ < AutocompleteElement { ...args } />
32
+ </ FormWrap >
33
+ )
34
34
}
35
35
36
36
const options = [ { label : 'First' , id : 1 } , { label : 'Second' , id : 2 } , { label : 'Third' , id : 3 } , {
37
- label : 'Four' ,
38
- id : 4
37
+ label : 'Four' ,
38
+ id : 4
39
39
} ]
40
40
41
41
export const Basic = Template . bind ( { } )
42
42
43
43
Basic . args = {
44
- name : 'basic' ,
45
- options
44
+ name : 'basic' ,
45
+ options
46
46
}
47
47
48
48
export const BasicPreSelect = Template . bind ( { } )
49
49
BasicPreSelect . args = {
50
- name : 'preselect' ,
51
- options
50
+ name : 'preselect' ,
51
+ options
52
52
}
53
53
54
54
export const MultiSelect = Template . bind ( { } )
55
55
MultiSelect . args = {
56
- name : 'multi' ,
57
- options,
58
- multiple : true
56
+ name : 'multi' ,
57
+ options,
58
+ multiple : true
59
59
}
60
60
61
61
export const MultiSelectRequired = Template . bind ( { } )
62
62
MultiSelectRequired . args = {
63
- label : 'Multiple Required' ,
64
- name : 'multi-required' ,
65
- options,
66
- multiple : true ,
67
- required : true
63
+ label : 'Multiple Required' ,
64
+ name : 'multi-required' ,
65
+ options,
66
+ multiple : true ,
67
+ required : true
68
68
}
69
69
70
70
export const MultiSelectRequiredCustom = Template . bind ( { } )
71
71
MultiSelectRequiredCustom . args = {
72
- label : 'Multiple Required Custom' ,
73
- name : 'multi-required-custom' ,
74
- options,
75
- multiple : true ,
76
- rules : {
77
- required : 'Please fill out.'
78
- }
72
+ label : 'Multiple Required Custom' ,
73
+ name : 'multi-required-custom' ,
74
+ options,
75
+ multiple : true ,
76
+ rules : {
77
+ required : 'Please fill out.'
78
+ }
79
79
}
80
80
81
81
export const MultiSelectPredefined = Template . bind ( { } )
82
82
MultiSelectPredefined . args = {
83
- name : 'multi-preselect' ,
84
- options,
85
- multiple : true
83
+ name : 'multi-preselect' ,
84
+ options,
85
+ multiple : true
86
86
}
87
87
88
88
export const MultiSelectCheckbox = Template . bind ( { } )
89
89
MultiSelectCheckbox . args = {
90
- name : 'multicheck' ,
91
- options,
92
- multiple : true ,
93
- showCheckbox : true
90
+ name : 'multicheck' ,
91
+ options,
92
+ multiple : true ,
93
+ showCheckbox : true
94
94
}
95
95
96
96
export const Loading = Template . bind ( { } )
97
97
Loading . args = {
98
- label : 'Loading State' ,
99
- name : 'loading' ,
100
- options : [ ] ,
101
- multiple : true ,
102
- showCheckbox : true ,
103
- loading : true
98
+ label : 'Loading State' ,
99
+ name : 'loading' ,
100
+ options : [ ] ,
101
+ multiple : true ,
102
+ showCheckbox : true ,
103
+ loading : true
104
104
}
105
105
106
106
export const MatchId = Template . bind ( { } )
107
107
MatchId . args = {
108
- label : 'Match ID' ,
109
- name : 'match-id' ,
110
- options,
111
- matchId : true
108
+ label : 'Match ID' ,
109
+ name : 'match-id' ,
110
+ options,
111
+ matchId : true
112
112
}
113
113
114
114
export const MatchIdMulti = Template . bind ( { } )
115
115
MatchIdMulti . args = {
116
- label : 'Match ID' ,
117
- name : 'match-id-multi' ,
118
- options,
119
- multiple : true ,
120
- matchId : true
116
+ label : 'Match ID' ,
117
+ name : 'match-id-multi' ,
118
+ options,
119
+ multiple : true ,
120
+ matchId : true
121
121
}
122
122
123
123
export const CustomInput = Template . bind ( { } )
124
124
CustomInput . args = {
125
- name : 'custom-input' ,
126
- options,
127
- textFieldProps : {
128
- placeholder : 'Some placeholder' ,
129
- InputProps : { startAdornment : < LocationIcon /> , endAdornment : null } ,
130
- }
125
+ name : 'custom-input' ,
126
+ options,
127
+ textFieldProps : {
128
+ placeholder : 'Some placeholder' ,
129
+ InputProps : { startAdornment : < LocationIcon /> , endAdornment : null } ,
130
+ }
131
131
}
0 commit comments