UNPKG

office-ui-fabric-react

Version:

Reusable React components for building experiences for Office 365.

151 lines 6.88 kB
import * as tslib_1 from "tslib"; import * as React from 'react'; import { TextField } from 'office-ui-fabric-react/lib/TextField'; import { DetailsList, DetailsListLayoutMode, Selection, ConstrainMode, DetailsRow } from 'office-ui-fabric-react/lib/DetailsList'; import { createRef } from 'office-ui-fabric-react/lib/Utilities'; import { TooltipHost } from 'office-ui-fabric-react/lib/Tooltip'; import { ScrollablePane } from 'office-ui-fabric-react/lib/ScrollablePane'; import { Sticky, StickyPositionType } from 'office-ui-fabric-react/lib/Sticky'; import { MarqueeSelection } from 'office-ui-fabric-react/lib/MarqueeSelection'; import { lorem } from 'office-ui-fabric-react/lib/utilities/exampleData'; import { SelectionMode } from 'office-ui-fabric-react/lib/utilities/selection/index'; var _columns = [ { key: 'column1', name: 'Test 1', fieldName: 'test1', minWidth: 100, maxWidth: 200, isResizable: true, ariaLabel: 'Operations for name' }, { key: 'column2', name: 'Test 2', fieldName: 'test2', minWidth: 100, maxWidth: 200, isResizable: true, ariaLabel: 'Operations for value' }, { key: 'column3', name: 'Test 3', fieldName: 'test3', minWidth: 100, maxWidth: 200, isResizable: true, ariaLabel: 'Operations for value' }, { key: 'column4', name: 'Test 4', fieldName: 'test4', minWidth: 100, maxWidth: 200, isResizable: true, ariaLabel: 'Operations for value' }, { key: 'column5', name: 'Test 4', fieldName: 'test5', minWidth: 100, maxWidth: 200, isResizable: true, ariaLabel: 'Operations for value' }, { key: 'column6', name: 'Test 6', fieldName: 'test6', minWidth: 100, maxWidth: 200, isResizable: true, ariaLabel: 'Operations for value' } ]; var ScrollablePaneDetailsListExample = /** @class */ (function (_super) { tslib_1.__extends(ScrollablePaneDetailsListExample, _super); function ScrollablePaneDetailsListExample(props) { var _this = _super.call(this, props) || this; _this._scrollablePane = createRef(); var items = []; // Populate with items for demos. for (var i = 0; i < 200; i++) { items.push({ key: i, test1: lorem(2), test2: lorem(2), test3: lorem(2), test4: lorem(2), test5: lorem(2), test6: lorem(2) }); } _this._items = items; _this._selection = new Selection({ onSelectionChanged: function () { return _this.setState({ selectionDetails: _this._getSelectionDetails() }); } }); _this.state = { items: items, selectionDetails: _this._getSelectionDetails() }; return _this; } ScrollablePaneDetailsListExample.prototype.render = function () { var _this = this; var _a = this.state, items = _a.items, selectionDetails = _a.selectionDetails; return (React.createElement("div", { style: { height: '80vh', position: 'relative' } }, React.createElement(ScrollablePane, { componentRef: this._scrollablePane, scrollbarVisibility: "always" /* always */ }, React.createElement(Sticky, { stickyPosition: StickyPositionType.Header }, selectionDetails), React.createElement(TextField, { label: "Filter by name:", // tslint:disable-next-line:jsx-no-lambda onChange: function (ev, text) { return _this.setState({ items: text ? _this._items.filter(function (item) { return hasText(item, text); }) : _this._items }); } }), React.createElement(Sticky, { stickyPosition: StickyPositionType.Header }, React.createElement("h1", { style: { margin: '0px' } }, "Item List")), React.createElement(MarqueeSelection, { selection: this._selection }, React.createElement(DetailsList, { items: items, columns: _columns, setKey: "set", layoutMode: DetailsListLayoutMode.fixedColumns, constrainMode: ConstrainMode.unconstrained, onRenderDetailsHeader: onRenderDetailsHeader, onRenderDetailsFooter: onRenderDetailsFooter, selection: this._selection, selectionPreservedOnEmptyClick: true, ariaLabelForSelectionColumn: "Toggle selection", ariaLabelForSelectAllCheckbox: "Toggle selection for all items", // tslint:disable-next-line:jsx-no-lambda onItemInvoked: function (item) { return alert("Item invoked: " + item.name); } }))))); }; ScrollablePaneDetailsListExample.prototype._getSelectionDetails = function () { var selectionCount = this._selection.getSelectedCount(); switch (selectionCount) { case 0: return 'No items selected'; case 1: return '1 item selected: ' + this._selection.getSelection()[0].name; default: return selectionCount + " items selected"; } }; return ScrollablePaneDetailsListExample; }(React.Component)); export { ScrollablePaneDetailsListExample }; function onRenderDetailsHeader(props, defaultRender) { return (React.createElement(Sticky, { stickyPosition: StickyPositionType.Header, isScrollSynced: true }, defaultRender(tslib_1.__assign({}, props, { onRenderColumnHeaderTooltip: function (tooltipHostProps) { return React.createElement(TooltipHost, tslib_1.__assign({}, tooltipHostProps)); } })))); } function onRenderDetailsFooter(props, defaultRender) { return (React.createElement(Sticky, { stickyPosition: StickyPositionType.Footer, isScrollSynced: true }, React.createElement(DetailsRow, { columns: props.columns, item: { key: 'footer', test1: 'Total 1', test2: 'Total 2', test3: 'Total 3', test4: 'Total 4', test5: 'Total 5', test6: 'Total 6' }, itemIndex: -1, selection: props.selection, selectionMode: (props.selection && props.selection.mode) || SelectionMode.none }))); } function hasText(item, text) { return (item.test1 + "|" + item.test2 + "|" + item.test3 + "|" + item.test4 + "|" + item.test5 + "|" + item.test6).indexOf(text) > -1; } //# sourceMappingURL=ScrollablePane.DetailsList.Example.js.map