1
1
import { boolean , number } from '@storybook/addon-knobs' ;
2
- import React , { FC , useCallback , useEffect , useState , useRef } from 'react' ;
2
+ import React , { FC , useCallback , useEffect , useRef , useState } from 'react' ;
3
+ import { FixedSizeGrid } from 'react-window' ;
3
4
import { useManagedFiles } from '../../hooks' ;
4
5
import { action } from '../../storybook-helpers/action/action' ;
5
6
import { createFile , FakeFile } from '../../storybook-helpers/data/files' ;
6
7
import { forwardAction } from '../../storybook-helpers/knobs/forwardAction' ;
7
8
import { integer } from '../../storybook-helpers/knobs/integer' ;
9
+ import { Button } from '../Button' ;
8
10
import { FileOrganizer , FileOrganizerProps } from '../FileOrganizer' ;
9
11
import { Icon } from '../Icon' ;
10
12
import { Thumbnail } from '../Thumbnail' ;
11
13
import { ThumbnailDragLayer } from '../ThumbnailDragLayer' ;
12
14
import readme from './README.md' ;
13
- import { FixedSizeGrid } from 'react-window' ;
14
- import { Button } from '../Button' ;
15
15
16
16
export default {
17
17
title : 'Components/FileOrganizer' ,
@@ -24,9 +24,16 @@ interface TemplateProps {
24
24
numFiles ?: number ;
25
25
editable ?: boolean ;
26
26
scrollToTop ?: boolean ;
27
+ customSizedThumbnail ?: boolean ;
27
28
}
28
29
29
- const Template : FC < TemplateProps > = ( { onRenderDragLayer, numFiles = 2 , editable, scrollToTop } ) => {
30
+ const Template : FC < TemplateProps > = ( {
31
+ onRenderDragLayer,
32
+ numFiles = 2 ,
33
+ editable,
34
+ scrollToTop,
35
+ customSizedThumbnail,
36
+ } ) => {
30
37
// This is the index organizing function.
31
38
const [ files , setFiles ] = useState < FakeFile [ ] > ( [ ] ) ;
32
39
const handleOnMove = useCallback < NonNullable < FileOrganizerProps < FakeFile > [ 'onMove' ] > > ( ( fromIndex , toIndex ) => {
@@ -45,6 +52,10 @@ const Template: FC<TemplateProps> = ({ onRenderDragLayer, numFiles = 2, editable
45
52
gridRef . current ?. scrollTo ( { scrollTop : 0 , scrollLeft : 0 } ) ;
46
53
} ;
47
54
55
+ const [ largerSize , setLargerSize ] = useState ( false ) ;
56
+ const changeSize = ( ) => setLargerSize ( ( prev ) => ! prev ) ;
57
+ const size = largerSize ? { width : 200 , height : 250 } : { width : 150 , height : 200 } ;
58
+
48
59
// This is just a helper for adding or removing files.
49
60
useEffect ( ( ) => {
50
61
setFiles ( ( prev ) => {
@@ -75,26 +86,43 @@ const Template: FC<TemplateProps> = ({ onRenderDragLayer, numFiles = 2, editable
75
86
onDragChange = { action ( 'onDragChange' ) }
76
87
onDeselectAll = { action ( 'onDeselectAll' ) }
77
88
onSelectAll = { action ( 'onSelectAll' ) }
89
+ thumbnailSize = { customSizedThumbnail ? size : undefined }
78
90
onRenderDragLayer = { onRenderDragLayer ? ( ) => < ThumbnailDragLayer /> : undefined }
79
- onRenderThumbnail = { ( { onRenderThumbnailProps } ) => (
80
- < Thumbnail
81
- { ...onRenderThumbnailProps }
82
- onRename = { editable ? ( ) => { } : undefined }
83
- buttonProps = {
84
- editable
85
- ? [
86
- {
87
- children : < Icon icon = "Close" /> ,
88
- onClick : ( ) => { } ,
89
- key : 0 ,
90
- } ,
91
- ]
92
- : undefined
93
- }
94
- />
95
- ) }
91
+ onRenderThumbnail = { ( { onRenderThumbnailProps, index } ) =>
92
+ customSizedThumbnail ? (
93
+ < div
94
+ style = { {
95
+ ...size ,
96
+ display : 'flex' ,
97
+ justifyContent : 'center' ,
98
+ alignItems : 'center' ,
99
+ background : 'lightblue' ,
100
+ border : '1px solid orange' ,
101
+ } }
102
+ >
103
+ Thumbnail { index + 1 }
104
+ </ div >
105
+ ) : (
106
+ < Thumbnail
107
+ { ...onRenderThumbnailProps }
108
+ onRename = { editable ? ( ) => { } : undefined }
109
+ buttonProps = {
110
+ editable
111
+ ? [
112
+ {
113
+ children : < Icon icon = "Close" /> ,
114
+ onClick : ( ) => { } ,
115
+ key : 0 ,
116
+ } ,
117
+ ]
118
+ : undefined
119
+ }
120
+ />
121
+ )
122
+ }
96
123
/>
97
124
{ scrollToTop && < Button onClick = { onScrollToTop } > Scroll to top</ Button > }
125
+ { customSizedThumbnail && < Button onClick = { changeSize } > Change thumbnail size</ Button > }
98
126
</ >
99
127
) ;
100
128
} ;
@@ -111,6 +139,10 @@ export const WithCustomDragLayer = () => {
111
139
const numFiles = number ( 'number of files' , 2 , { min : 0 , max : 16 , step : 1 , range : true } ) ;
112
140
return < Template numFiles = { numFiles } onRenderDragLayer /> ;
113
141
} ;
142
+ export const DifferentThumbnailSize = ( ) => {
143
+ const numFiles = number ( 'number of files' , 2 , { min : 0 , max : 16 , step : 1 , range : true } ) ;
144
+ return < Template numFiles = { numFiles } customSizedThumbnail /> ;
145
+ } ;
114
146
export const WithGridRef = ( ) => {
115
147
return < Template numFiles = { 100 } scrollToTop /> ;
116
148
} ;
0 commit comments