1
1
import * as React from 'react' ;
2
2
import styles from './ListView.DragDrop.module.scss' ;
3
- import stickyHeaderstyles from './ListView.stickyHeader.module.scss' ;
4
- import { DetailsList , DetailsListLayoutMode , Selection , SelectionMode , IGroup } from 'office-ui-fabric-react/lib/DetailsList' ;
3
+ import { ScrollablePane , ScrollbarVisibility } from 'office-ui-fabric-react/lib/ScrollablePane' ;
4
+ import { Sticky , StickyPositionType } from 'office-ui-fabric-react/lib/Sticky' ;
5
+ import { IRenderFunction } from 'office-ui-fabric-react/lib/Utilities' ;
6
+ import { mergeStyleSets } from 'office-ui-fabric-react/lib/Styling' ;
7
+ import { DetailsList , DetailsListLayoutMode , Selection , SelectionMode , IGroup , IDetailsHeaderProps } from 'office-ui-fabric-react/lib/DetailsList' ;
5
8
import { IListViewProps , IListViewState , IViewField , IGrouping , GroupOrder } from './IListView' ;
6
9
import { IColumn , IGroupRenderProps } from 'office-ui-fabric-react/lib/components/DetailsList' ;
7
10
import { findIndex , has , sortBy , isEqual , cloneDeep } from '@microsoft/sp-lodash-subset' ;
@@ -15,6 +18,35 @@ import filter from 'lodash/filter';
15
18
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox' ;
16
19
import { Guid } from '@microsoft/sp-core-library' ;
17
20
21
+ const classNames = mergeStyleSets ( {
22
+ wrapper : {
23
+ height : '50vh' ,
24
+ position : 'relative'
25
+ }
26
+ } ) ;
27
+
28
+ /**
29
+ * Wrap the listview in a scrollable pane if sticky header = true
30
+ */
31
+ const ListViewWrapper = ( { stickyHeader, children } ) => ( stickyHeader ?
32
+ < div className = { classNames . wrapper } >
33
+ < ScrollablePane scrollbarVisibility = { ScrollbarVisibility . auto } >
34
+ { children }
35
+ </ ScrollablePane >
36
+ </ div >
37
+ : children
38
+ ) ;
39
+
40
+ /**
41
+ * Lock the searchbox when scrolling if sticky header = true
42
+ */
43
+ const SearchBoxWrapper = ( { stickyHeader, children } ) => ( stickyHeader ?
44
+ < Sticky stickyPosition = { StickyPositionType . Header } >
45
+ { children }
46
+ </ Sticky >
47
+ : children
48
+ ) ;
49
+
18
50
19
51
/**
20
52
* File type icon component
@@ -564,6 +596,23 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
564
596
this . dragCounter = 0 ;
565
597
}
566
598
}
599
+ /**
600
+ * Custom render of header
601
+ * @param props
602
+ * @param defaultRender
603
+ */
604
+ private _onRenderDetailsHeader : IRenderFunction < IDetailsHeaderProps > = ( props , defaultRender ) => {
605
+ if ( ! props ) {
606
+ return null ;
607
+ }
608
+ return (
609
+ < Sticky stickyPosition = { StickyPositionType . Header } isScrollSynced >
610
+ { defaultRender ! ( {
611
+ ...props ,
612
+ } ) }
613
+ </ Sticky >
614
+ ) ;
615
+ }
567
616
/**
568
617
* Default React component render method
569
618
*/
@@ -585,38 +634,39 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
585
634
}
586
635
587
636
return (
588
- < div className = { styles . DragDropArea }
589
- ref = { this . dropRef } >
590
- { ( dragStatus && dragDropFiles ) &&
591
- < div className = { styles . DragDropAreaBorder } >
592
- < div className = { styles . DragDropAreaZone } >
593
- < Icon iconName = "Download" className = "ms-IconExample" />
594
- < div > { strings . UploadFileHeader } </ div >
637
+ < ListViewWrapper stickyHeader = { ! ! this . props . stickyHeader } >
638
+ < div className = { styles . DragDropArea }
639
+ ref = { this . dropRef } >
640
+ { ( dragStatus && dragDropFiles ) &&
641
+ < div className = { styles . DragDropAreaBorder } >
642
+ < div className = { styles . DragDropAreaZone } >
643
+ < Icon iconName = "Download" className = "ms-IconExample" />
644
+ < div > { strings . UploadFileHeader } </ div >
645
+ </ div >
595
646
</ div >
596
- </ div >
597
- }
598
- {
599
- showFilter &&
600
- < SearchBox placeholder = { filterPlaceHolder || strings . ListViewFilterLabel } onSearch = { this . _updateFilterValue } onChange = { this . _updateFilterValue } value = { filterValue } />
601
- }
602
- < DetailsList
603
- key = "ListViewControl"
604
- items = { items }
605
- columns = { columns }
606
- groups = { groups }
607
- selectionMode = { selectionMode || SelectionMode . none }
608
- selectionPreservedOnEmptyClick = { true }
609
- selection = { this . _selection }
610
- layoutMode = { DetailsListLayoutMode . justified }
611
- compact = { compact }
612
- setKey = "ListViewControl"
613
- groupProps = { groupProps }
614
- className = {
615
- stickyHeader &&
616
- stickyHeaderstyles . StickyHeader
617
- }
618
- />
619
- </ div >
647
+ }
648
+ {
649
+ showFilter &&
650
+ < SearchBoxWrapper stickyHeader = { ! ! this . props . stickyHeader } >
651
+ < SearchBox placeholder = { filterPlaceHolder || strings . ListViewFilterLabel } onSearch = { this . _updateFilterValue } onChange = { this . _updateFilterValue } value = { filterValue } />
652
+ </ SearchBoxWrapper >
653
+ }
654
+ < DetailsList
655
+ key = "ListViewControl"
656
+ items = { items }
657
+ columns = { columns }
658
+ groups = { groups }
659
+ selectionMode = { selectionMode || SelectionMode . none }
660
+ selectionPreservedOnEmptyClick = { true }
661
+ selection = { this . _selection }
662
+ layoutMode = { DetailsListLayoutMode . justified }
663
+ compact = { compact }
664
+ setKey = "ListViewControl"
665
+ groupProps = { groupProps }
666
+ onRenderDetailsHeader = { this . _onRenderDetailsHeader }
667
+ />
668
+ </ div >
669
+ </ ListViewWrapper >
620
670
) ;
621
671
}
622
672
}
0 commit comments