26
26
* - Tweaked styles for Uppy's Dashboard use case
27
27
*/
28
28
29
- import { h , Component } from 'preact'
30
- import type { HTMLAttributes } from 'preact/compat'
29
+ import { h , Component } from 'preact'
31
30
32
31
const STYLE_INNER = {
33
32
position : 'relative' ,
@@ -52,21 +51,8 @@ const STYLE_CONTENT = {
52
51
overflow : 'visible' ,
53
52
}
54
53
55
- type Props < T > = Omit < HTMLAttributes < HTMLDivElement > , 'data' > & {
56
- data : T [ ]
57
- rowHeight : number
58
- renderRow : ( item : T ) => h . JSX . Element
59
- // eslint-disable-next-line react/require-default-props
60
- overscanCount ?: number | undefined
61
- }
62
-
63
- class VirtualList < T > extends Component <
64
- Props < T > ,
65
- { offset : number ; height : number }
66
- > {
67
- focusElement : HTMLElement | null
68
-
69
- constructor ( props : Props < T > ) {
54
+ class VirtualList extends Component {
55
+ constructor ( props ) {
70
56
super ( props )
71
57
72
58
// The currently focused node, used to retain focus when the visible rows change.
@@ -79,61 +65,58 @@ class VirtualList<T> extends Component<
79
65
}
80
66
}
81
67
82
- componentDidMount ( ) : void {
68
+ componentDidMount ( ) {
83
69
this . resize ( )
84
70
window . addEventListener ( 'resize' , this . handleResize )
85
71
}
86
72
87
73
// TODO: refactor to stable lifecycle method
88
74
// eslint-disable-next-line
89
- componentWillUpdate ( ) {
90
- if ( this . base ! . contains ( document . activeElement ) ) {
91
- this . focusElement = document . activeElement as HTMLElement
75
+ componentWillUpdate ( ) {
76
+ if ( this . base . contains ( document . activeElement ) ) {
77
+ this . focusElement = document . activeElement
92
78
}
93
79
}
94
80
95
- componentDidUpdate ( ) : void {
81
+ componentDidUpdate ( ) {
96
82
// Maintain focus when rows are added and removed.
97
- if (
98
- this . focusElement &&
99
- this . focusElement . parentNode &&
100
- document . activeElement !== this . focusElement
101
- ) {
102
- this . focusElement ! . focus ( )
83
+ if ( this . focusElement && this . focusElement . parentNode
84
+ && document . activeElement !== this . focusElement ) {
85
+ this . focusElement . focus ( )
103
86
}
104
87
this . focusElement = null
105
88
this . resize ( )
106
89
}
107
90
108
- componentWillUnmount ( ) : void {
91
+ componentWillUnmount ( ) {
109
92
window . removeEventListener ( 'resize' , this . handleResize )
110
93
}
111
94
112
- handleScroll = ( ) : void => {
113
- this . setState ( { offset : ( this . base ! as HTMLElement ) . scrollTop } )
95
+ handleScroll = ( ) => {
96
+ this . setState ( { offset : this . base . scrollTop } )
114
97
}
115
98
116
- handleResize = ( ) : void => {
99
+ handleResize = ( ) => {
117
100
this . resize ( )
118
101
}
119
102
120
- resize ( ) : void {
103
+ resize ( ) {
121
104
const { height } = this . state
122
105
123
- if ( height !== ( this . base ! as HTMLElement ) . offsetHeight ) {
106
+ if ( height !== this . base . offsetHeight ) {
124
107
this . setState ( {
125
- height : ( this . base ! as HTMLElement ) . offsetHeight ,
108
+ height : this . base . offsetHeight ,
126
109
} )
127
110
}
128
111
}
129
112
130
- render ( {
113
+ render ( {
131
114
data,
132
115
rowHeight,
133
116
renderRow,
134
117
overscanCount = 10 ,
135
118
...props
136
- } : Props < T > ) : h . JSX . Element {
119
+ } ) {
137
120
const { offset, height } = this . state
138
121
// first visible row index
139
122
let start = Math . floor ( offset / rowHeight )
0 commit comments