@@ -10,13 +10,6 @@ import { IGridLayoutProps, IGridLayoutState } from './GridLayout.types';
10
10
11
11
import * as telemetry from '../../common/telemetry' ;
12
12
13
- // Get the constants from the SCSS so that we don't hard-code look and feel elements
14
- const ROWS_PER_PAGE : number = + styles . rowsPerPage ;
15
- const MAX_ROW_HEIGHT : number = + styles . maxWidth ;
16
- const PADDING : number = + styles . padding ;
17
- const MIN_WIDTH : number = + styles . minWidth ;
18
- const COMPACT_THRESHOLD : number = + styles . compactThreshold ;
19
-
20
13
/**
21
14
* Grid layout component
22
15
*/
@@ -31,6 +24,13 @@ export class GridLayout extends React.Component<IGridLayoutProps, IGridLayoutSta
31
24
telemetry . track ( 'ReactGridLayout' ) ;
32
25
}
33
26
27
+ //Get constants from SCSS if they are not passed in props
28
+ private ROWS_PER_PAGE : number = this . props . rowsPerPage ?? + styles . rowsPerPage ;
29
+ private MAX_WIDTH : number = this . props . itemMaxWidth ?? + styles . maxWidth ;
30
+ private MIN_WIDTH : number = this . props . itemMinWidth ?? + styles . minWidth ;
31
+ private PADDING : number = this . props . itemPadding ?? + styles . padding ;
32
+ private COMPACT_THRESHOLD : number = this . props . compactThreshold ?? + styles . compactThreshold ;
33
+
34
34
// Number of columns in a row
35
35
private _columnCount : number ;
36
36
@@ -49,17 +49,17 @@ export class GridLayout extends React.Component<IGridLayoutProps, IGridLayoutSta
49
49
public render ( ) : React . ReactElement < IGridLayoutProps > {
50
50
return (
51
51
< div className = { styles . gridLayout } role = "group" aria-label = { this . props . ariaLabel } >
52
- < FocusZone >
53
- < List
54
- role = "presentation"
55
- className = { styles . gridLayoutList }
56
- items = { this . props . items }
57
- getItemCountForPage = { this . _getItemCountForPage }
58
- getPageHeight = { this . _getPageHeight }
59
- onRenderCell = { this . _onRenderCell }
60
- { ...this . props . listProps }
61
- />
62
- </ FocusZone >
52
+ < FocusZone >
53
+ < List
54
+ role = "presentation"
55
+ className = { styles . gridLayoutList }
56
+ items = { this . props . items }
57
+ getItemCountForPage = { this . _getItemCountForPage }
58
+ getPageHeight = { this . _getPageHeight }
59
+ onRenderCell = { this . _onRenderCell }
60
+ { ...this . props . listProps }
61
+ />
62
+ </ FocusZone >
63
63
</ div >
64
64
) ;
65
65
}
@@ -69,19 +69,19 @@ export class GridLayout extends React.Component<IGridLayoutProps, IGridLayoutSta
69
69
*/
70
70
private _getItemCountForPage = ( itemIndex : number , surfaceRect : IRectangle ) : number => {
71
71
if ( itemIndex === 0 ) {
72
- this . _isCompact = surfaceRect . width < COMPACT_THRESHOLD ;
72
+ this . _isCompact = surfaceRect . width < this . COMPACT_THRESHOLD ;
73
73
if ( this . _isCompact ) {
74
74
this . _columnCount = 1 ;
75
75
this . _columnWidth = surfaceRect . width ;
76
76
return this . props . items . length ;
77
77
} else {
78
- this . _columnCount = Math . ceil ( surfaceRect . width / ( MAX_ROW_HEIGHT ) ) ;
79
- this . _columnWidth = Math . max ( MIN_WIDTH , Math . floor ( surfaceRect . width / this . _columnCount ) + Math . floor ( PADDING / this . _columnCount ) ) ;
78
+ this . _columnCount = Math . ceil ( surfaceRect . width / ( this . MAX_WIDTH ) ) ;
79
+ this . _columnWidth = Math . max ( this . MIN_WIDTH , Math . floor ( surfaceRect . width / this . _columnCount ) + Math . floor ( this . PADDING / this . _columnCount ) ) ;
80
80
this . _rowHeight = this . _columnWidth ;
81
81
}
82
82
}
83
83
84
- return this . _columnCount * ROWS_PER_PAGE ;
84
+ return this . _columnCount * this . ROWS_PER_PAGE ;
85
85
}
86
86
87
87
/**
@@ -91,17 +91,17 @@ export class GridLayout extends React.Component<IGridLayoutProps, IGridLayoutSta
91
91
if ( this . _isCompact ) {
92
92
return this . props . items . length * this . _rowHeight ;
93
93
}
94
- return this . _rowHeight * ROWS_PER_PAGE ;
94
+ return this . _rowHeight * this . ROWS_PER_PAGE ;
95
95
}
96
96
97
97
/**
98
98
* Calls the passed onRenderCell
99
99
*/
100
100
private _onRenderCell = ( item : any , index : number | undefined ) : JSX . Element => { // eslint-disable-line @typescript-eslint/no-explicit-any
101
101
const isCompact : boolean = this . _isCompact ;
102
- const cellPadding : number = index % this . _columnCount !== this . _columnCount - 1 && ! isCompact ? PADDING : 0 ;
102
+ const cellPadding : number = index % this . _columnCount !== this . _columnCount - 1 && ! isCompact ? this . PADDING : 0 ;
103
103
const finalSize : ISize = { width : this . _columnWidth , height : this . _rowHeight } ;
104
- const cellWidth : number = isCompact ? this . _columnWidth + PADDING : this . _columnWidth - PADDING ;
104
+ const cellWidth : number = isCompact ? this . _columnWidth + this . PADDING : this . _columnWidth - this . PADDING ;
105
105
return (
106
106
< div
107
107
style = { {
0 commit comments