Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert Sticky Header to use ScrollablePane #764

Merged
merged 1 commit into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions src/controls/listView/ListView.stickyHeader.module.scss

This file was deleted.

116 changes: 83 additions & 33 deletions src/controls/listView/ListView.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import * as React from 'react';
import styles from './ListView.DragDrop.module.scss';
import stickyHeaderstyles from './ListView.stickyHeader.module.scss';
import { DetailsList, DetailsListLayoutMode, Selection, SelectionMode, IGroup } from 'office-ui-fabric-react/lib/DetailsList';
import { ScrollablePane, ScrollbarVisibility } from 'office-ui-fabric-react/lib/ScrollablePane';
import { Sticky, StickyPositionType } from 'office-ui-fabric-react/lib/Sticky';
import { IRenderFunction } from 'office-ui-fabric-react/lib/Utilities';
import { mergeStyleSets } from 'office-ui-fabric-react/lib/Styling';
import { DetailsList, DetailsListLayoutMode, Selection, SelectionMode, IGroup, IDetailsHeaderProps } from 'office-ui-fabric-react/lib/DetailsList';
import { IListViewProps, IListViewState, IViewField, IGrouping, GroupOrder } from './IListView';
import { IColumn, IGroupRenderProps } from 'office-ui-fabric-react/lib/components/DetailsList';
import { findIndex, has, sortBy, isEqual, cloneDeep } from '@microsoft/sp-lodash-subset';
Expand All @@ -15,6 +18,35 @@ import filter from 'lodash/filter';
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox';
import { Guid } from '@microsoft/sp-core-library';

const classNames = mergeStyleSets({
wrapper: {
height: '50vh',
position: 'relative'
}
});

/**
* Wrap the listview in a scrollable pane if sticky header = true
*/
const ListViewWrapper = ({ stickyHeader, children }) => (stickyHeader ?
<div className={classNames.wrapper} >
<ScrollablePane scrollbarVisibility={ScrollbarVisibility.auto}>
{children}
</ScrollablePane>
</div>
: children
);

/**
* Lock the searchbox when scrolling if sticky header = true
*/
const SearchBoxWrapper = ({ stickyHeader, children }) => (stickyHeader ?
<Sticky stickyPosition={StickyPositionType.Header}>
{children}
</Sticky>
: children
);


/**
* File type icon component
Expand Down Expand Up @@ -564,6 +596,23 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
this.dragCounter = 0;
}
}
/**
* Custom render of header
* @param props
* @param defaultRender
*/
private _onRenderDetailsHeader: IRenderFunction<IDetailsHeaderProps> = (props, defaultRender) => {
if (!props) {
return null;
}
return (
<Sticky stickyPosition={StickyPositionType.Header} isScrollSynced>
{defaultRender!({
...props,
})}
</Sticky>
);
}
/**
* Default React component render method
*/
Expand All @@ -585,38 +634,39 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
}

return (
<div className={styles.DragDropArea}
ref={this.dropRef}>
{(dragStatus && dragDropFiles) &&
<div className={styles.DragDropAreaBorder}>
<div className={styles.DragDropAreaZone}>
<Icon iconName="Download" className="ms-IconExample" />
<div>{strings.UploadFileHeader}</div>
<ListViewWrapper stickyHeader={!!this.props.stickyHeader}>
<div className={styles.DragDropArea}
ref={this.dropRef}>
{(dragStatus && dragDropFiles) &&
<div className={styles.DragDropAreaBorder}>
<div className={styles.DragDropAreaZone}>
<Icon iconName="Download" className="ms-IconExample" />
<div>{strings.UploadFileHeader}</div>
</div>
</div>
</div>
}
{
showFilter &&
<SearchBox placeholder={filterPlaceHolder || strings.ListViewFilterLabel} onSearch={this._updateFilterValue} onChange={this._updateFilterValue} value={filterValue} />
}
<DetailsList
key="ListViewControl"
items={items}
columns={columns}
groups={groups}
selectionMode={selectionMode || SelectionMode.none}
selectionPreservedOnEmptyClick={true}
selection={this._selection}
layoutMode={DetailsListLayoutMode.justified}
compact={compact}
setKey="ListViewControl"
groupProps={groupProps}
className={
stickyHeader &&
stickyHeaderstyles.StickyHeader
}
/>
</div>
}
{
showFilter &&
<SearchBoxWrapper stickyHeader={!!this.props.stickyHeader}>
<SearchBox placeholder={filterPlaceHolder || strings.ListViewFilterLabel} onSearch={this._updateFilterValue} onChange={this._updateFilterValue} value={filterValue} />
</SearchBoxWrapper>
}
<DetailsList
key="ListViewControl"
items={items}
columns={columns}
groups={groups}
selectionMode={selectionMode || SelectionMode.none}
selectionPreservedOnEmptyClick={true}
selection={this._selection}
layoutMode={DetailsListLayoutMode.justified}
compact={compact}
setKey="ListViewControl"
groupProps={groupProps}
onRenderDetailsHeader={this._onRenderDetailsHeader}
/>
</div>
</ListViewWrapper>
);
}
}