@@ -24,7 +24,52 @@ import { DropzoneProvider } from '@genseki/react/v2'
2424
2525import { InformationCard , PlaygroundCard } from '~/src/components/card'
2626
27- function CustomDropzoneContent ( props : { removePreview : ( ) => void } ) {
27+ function FilePreviewItem ( props : { index : number ; removePreview : ( index ?: number ) => void } ) {
28+ const dropzoneCtx = useDropZone ( )
29+
30+ return (
31+ < FilePreview >
32+ < FilePreviewThumbnail />
33+ { /*
34+ * You can pass a preview as a children of FilePreviewThumbnail
35+ * <FilePreviewThumbnail className="size-50">
36+ * <img src="..." alt="..." />
37+ * </FilePreviewThumbnail>
38+ */ }
39+ < FilePreviewContent >
40+ < FilePreviewTitle > { dropzoneCtx . src ?. [ props . index ] . name } </ FilePreviewTitle >
41+ < FilePreviewStatus status = "COMPLETED" />
42+ < FilePreviewAddons >
43+ < DropZoneArea className = "hidden" aria-hidden />
44+ < button
45+ onClick = { ( ) => {
46+ dropzoneCtx . inputRef . current . click ( )
47+ } }
48+ className = "px-4 py-2 rounded-sm bg-surface-primary-hover text-text-secondary cursor-pointer"
49+ >
50+ < Typography type = "caption" weight = "medium" >
51+ Change
52+ </ Typography >
53+ </ button >
54+
55+ < button
56+ onClick = { ( ) => props . removePreview ( props . index ) }
57+ className = "px-4 py-2 rounded-sm bg-surface-incorrect text-text-incorrect-bold cursor-pointer"
58+ >
59+ < Typography type = "caption" weight = "medium" >
60+ Remove
61+ </ Typography >
62+ </ button >
63+ </ FilePreviewAddons >
64+ </ FilePreviewContent >
65+ </ FilePreview >
66+ )
67+ }
68+
69+ function CustomDropzoneContent ( props : {
70+ children ?: React . ReactNode
71+ removePreview : ( number ?: number ) => void
72+ } ) {
2873 const fullPreview = false // Try change this flag
2974 const dropzoneCtx = useDropZone ( )
3075 const router = useRouter ( )
@@ -53,41 +98,7 @@ function CustomDropzoneContent(props: { removePreview: () => void }) {
5398 if ( isValidPreview && ! fullPreview ) {
5499 return (
55100 // Handle more customization by yourselves here
56- < div className = "flex flex-col gap-y-4" >
57- { dropzoneCtx . previews . map ( ( preview ) => (
58- < FilePreview key = { preview . url } >
59- < FilePreviewThumbnail />
60- { /*
61- * You can pass a preview as a children of FilePreviewThumbnail
62- * <FilePreviewThumbnail className="size-50">
63- * <img src="..." alt="..." />
64- * </FilePreviewThumbnail>
65- */ }
66- < FilePreviewContent >
67- < FilePreviewTitle > PDF 2024-my-portfolioss.pdf</ FilePreviewTitle >
68- < FilePreviewStatus status = "COMPLETED" />
69- < FilePreviewAddons >
70- < button
71- onClick = { ( ) => props . removePreview ( ) }
72- className = "px-4 py-2 rounded-sm bg-surface-primary-hover text-text-secondary cursor-pointer"
73- >
74- < Typography type = "caption" weight = "medium" >
75- Change
76- </ Typography >
77- </ button >
78- < button
79- onClick = { ( ) => props . removePreview ( ) }
80- className = "px-4 py-2 rounded-sm bg-surface-incorrect text-text-incorrect-bold cursor-pointer"
81- >
82- < Typography type = "caption" weight = "medium" >
83- Remove
84- </ Typography >
85- </ button >
86- </ FilePreviewAddons >
87- </ FilePreviewContent >
88- </ FilePreview >
89- ) ) }
90- </ div >
101+ props . children
91102 )
92103 }
93104
@@ -150,7 +161,8 @@ function CustomDropzone() {
150161 console . log ( error )
151162 }
152163
153- const removePreview = ( ) => {
164+ const removePreview = ( imageId ?: number ) => {
165+ // You can use imageId or something to filter the remove preview
154166 setFiles ( [ ] )
155167 setPreviews ( [ ] )
156168 }
@@ -176,7 +188,13 @@ function CustomDropzone() {
176188 </ DropZoneEmptyContent >
177189 < DropZoneNonemptyContent >
178190 { /* These content will be displayed if there're available previewable item */ }
179- < CustomDropzoneContent removePreview = { removePreview } />
191+ < CustomDropzoneContent removePreview = { removePreview } >
192+ < div className = "flex flex-col gap-y-4" >
193+ { previews . map ( ( preview , index ) => (
194+ < FilePreviewItem key = { preview . url } index = { index } removePreview = { removePreview } />
195+ ) ) }
196+ </ div >
197+ </ CustomDropzoneContent >
180198 </ DropZoneNonemptyContent >
181199 </ DropzoneProvider >
182200 )
0 commit comments