1
1
import { MultiUpload } from '../../src/multiUpload/MultiUpload' ;
2
2
/**
3
- * In this section we're using the button component providing the **GovUk style** passing the relative `className.
3
+ * In this section we're using the button component providing the **GovUk style** passing the relative `className.
4
4
* Feel free to use your own css to style the formInput as you prefer.
5
5
*/
6
6
export default {
@@ -11,93 +11,110 @@ export default {
11
11
showPanel : true ,
12
12
} ,
13
13
} ,
14
- tags : [ 'autodocs' ]
14
+ tags : [ 'autodocs' ] ,
15
15
} ;
16
16
17
17
export const Basic = {
18
18
name : 'Basic' ,
19
- render : function ( { onChange, ...args } ) {
20
- const handleChange = file => {
21
- onChange ( file ) ;
22
- alert ( `${ file . name } was uploaded, it was last modified at ${ new Date ( file . lastModified ) . toLocaleDateString ( "en-us" ) } ` ) ;
23
- }
24
- return ( < MultiUpload { ...args } onChange = { handleChange } /> ) ;
19
+ render : function ( { onChange, ...args } ) {
20
+ const handleChange = ( files ) => {
21
+ onChange ( files ) ;
22
+ Array . from ( files ) . forEach ( ( file ) => {
23
+ const date = new Date ( file . lastModified ) . toLocaleDateString ( 'en-us' ) ;
24
+ console . log (
25
+ file . name + 'was uploaded, it was last modified at ' + date
26
+ ) ;
27
+ } ) ;
28
+ } ;
29
+
30
+ return < MultiUpload { ...args } onChange = { handleChange } /> ;
25
31
} ,
26
32
args : {
27
- name :" file-upload-1" ,
28
- label :" Upload a file" ,
29
- id :" file-upload-1" ,
30
- className :" govuk-form-group" ,
31
- inputProperties :{
33
+ name : ' file-upload-1' ,
34
+ label : ' Upload a file' ,
35
+ id : ' file-upload-1' ,
36
+ className : ' govuk-form-group' ,
37
+ inputProperties : {
32
38
className : 'govuk-file-upload' ,
33
39
} ,
34
- labelProperties :{
40
+ labelProperties : {
35
41
className : 'govuk-label' ,
36
- }
42
+ } ,
37
43
} ,
38
44
argTypes : { onChange : { action : 'onChange' } } ,
39
45
} ;
40
46
41
47
export const Hint = {
42
48
name : 'Hint' ,
43
- render : function ( { onChange, ...args } ) {
44
- const handleChange = file => {
45
- onChange ( file ) ;
46
- alert ( `${ file . name } was uploaded, it was last modified at ${ new Date ( file . lastModified ) . toLocaleDateString ( "en-us" ) } ` ) ;
47
- }
48
- return ( < MultiUpload { ...args } onChange = { handleChange } /> ) ;
49
+ render : function ( { onChange, ...args } ) {
50
+ const handleChange = ( files ) => {
51
+ onChange ( files ) ;
52
+ Array . from ( files ) . forEach ( ( file ) => {
53
+ const date = new Date ( file . lastModified ) . toLocaleDateString ( 'en-us' ) ;
54
+ console . log (
55
+ file . name + 'was uploaded, it was last modified at ' + date
56
+ ) ;
57
+ } ) ;
58
+ } ;
59
+
60
+ return < MultiUpload { ...args } onChange = { handleChange } /> ;
49
61
} ,
50
62
args : {
51
- name :" file-upload-2" ,
52
- label :" Upload a file" ,
53
- id :" file-upload-2" ,
54
- className :" govuk-form-group" ,
55
- hint :{
63
+ name : ' file-upload-2' ,
64
+ label : ' Upload a file' ,
65
+ id : ' file-upload-2' ,
66
+ className : ' govuk-form-group' ,
67
+ hint : {
56
68
text : 'This can be in either JPG or PNG format' ,
57
69
className : 'govuk-hint' ,
58
70
} ,
59
- inputProperties :{
71
+ inputProperties : {
60
72
className : 'govuk-file-upload' ,
61
73
} ,
62
- labelProperties :{
74
+ labelProperties : {
63
75
className : 'govuk-label' ,
64
- }
76
+ } ,
65
77
} ,
66
78
argTypes : { onChange : { action : 'onChange' } } ,
67
79
} ;
68
80
69
81
export const Error = {
70
82
name : 'Error' ,
71
- render : function ( { onChange, ...args } ) {
72
- const handleChange = file => {
73
- onChange ( file ) ;
74
- alert ( `${ file . name } was uploaded, it was last modified at ${ new Date ( file . lastModified ) . toLocaleDateString ( "en-us" ) } ` ) ;
75
- }
76
- return ( < MultiUpload { ...args } onChange = { handleChange } /> ) ;
83
+ render : function ( { onChange, ...args } ) {
84
+ const handleChange = ( files ) => {
85
+ onChange ( files ) ;
86
+ Array . from ( files ) . forEach ( ( file ) => {
87
+ const date = new Date ( file . lastModified ) . toLocaleDateString ( 'en-us' ) ;
88
+ console . log (
89
+ file . name + 'was uploaded, it was last modified at ' + date
90
+ ) ;
91
+ } ) ;
92
+ } ;
93
+
94
+ return < MultiUpload { ...args } onChange = { handleChange } /> ;
77
95
} ,
78
96
args : {
79
- name :" file-upload-3" ,
80
- label :" Upload a file" ,
81
- id :" file-upload-3" ,
82
- className :" govuk-form-group govuk-form-group--error" ,
83
- acceptedFormats :" .jpg, .png" ,
84
- inputProperties :{
97
+ name : ' file-upload-3' ,
98
+ label : ' Upload a file' ,
99
+ id : ' file-upload-3' ,
100
+ className : ' govuk-form-group govuk-form-group--error' ,
101
+ acceptedFormats : ' .jpg, .png' ,
102
+ inputProperties : {
85
103
className : 'govuk-file-upload govuk-file-upload--error' ,
86
104
'aria-describedby' : 'govuk-file-upload govuk-file-upload--error' ,
87
105
} ,
88
- label :"Upload a file" ,
89
- labelProperties :{
106
+ labelProperties : {
90
107
className : 'govuk-label' ,
91
108
} ,
92
- error :{
109
+ error : {
93
110
text : 'The CSV must be smaller than 2MB' ,
94
111
className : 'govuk-error-message' ,
95
112
id : 'file-upload-1-error' ,
96
113
visuallyHiddenText : {
97
114
text : 'Error:' ,
98
115
className : 'govuk-visually-hidden' ,
99
116
} ,
100
- }
117
+ } ,
101
118
} ,
102
119
argTypes : { onChange : { action : 'onChange' } } ,
103
- } ;
120
+ } ;
0 commit comments