UNPKG

5.03 kBJavaScriptView Raw
1"use strict";
2/*
3 * Copyright 2015 Palantir Technologies, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17Object.defineProperty(exports, "__esModule", { value: true });
18exports.CollapsibleList = void 0;
19var tslib_1 = require("tslib");
20/**
21 * @fileoverview This component is DEPRECATED, and the code is frozen.
22 * All changes & bugfixes should be made to OverflowList instead.
23 */
24/* eslint-disable deprecation/deprecation */
25var classnames_1 = tslib_1.__importDefault(require("classnames"));
26var React = tslib_1.__importStar(require("react"));
27var boundary_1 = require("../../common/boundary");
28var Classes = tslib_1.__importStar(require("../../common/classes"));
29var Errors = tslib_1.__importStar(require("../../common/errors"));
30var position_1 = require("../../common/position");
31var props_1 = require("../../common/props");
32var utils_1 = require("../../common/utils");
33var menu_1 = require("../menu/menu");
34var menuItem_1 = require("../menu/menuItem");
35var popover_1 = require("../popover/popover");
36/**
37 * CollapsibleList component.
38 *
39 * @see https://blueprintjs.com/docs/#core/components/collapsible-list
40 * @deprecated use `<OverflowList>` for automatic overflow based on available space.
41 */
42var CollapsibleList = /** @class */ (function (_super) {
43 tslib_1.__extends(CollapsibleList, _super);
44 function CollapsibleList() {
45 return _super !== null && _super.apply(this, arguments) || this;
46 }
47 CollapsibleList.prototype.render = function () {
48 var _this = this;
49 var collapseFrom = this.props.collapseFrom;
50 var childrenLength = React.Children.count(this.props.children);
51 var _a = this.partitionChildren(), visibleChildren = _a[0], collapsedChildren = _a[1];
52 var visibleItems = visibleChildren.map(function (child, index) {
53 var absoluteIndex = collapseFrom === boundary_1.Boundary.START ? childrenLength - 1 - index : index;
54 return (React.createElement("li", { className: _this.props.visibleItemClassName, key: absoluteIndex }, _this.props.visibleItemRenderer(child.props, absoluteIndex)));
55 });
56 if (collapseFrom === boundary_1.Boundary.START) {
57 // reverse START list so separators appear before items
58 visibleItems.reverse();
59 }
60 // construct dropdown menu for collapsed items
61 var collapsedPopover;
62 if (collapsedChildren.length > 0) {
63 var position = collapseFrom === boundary_1.Boundary.END ? position_1.Position.BOTTOM_RIGHT : position_1.Position.BOTTOM_LEFT;
64 collapsedPopover = (React.createElement("li", { className: this.props.visibleItemClassName },
65 React.createElement(popover_1.Popover, tslib_1.__assign({ content: React.createElement(menu_1.Menu, null, collapsedChildren), position: position }, this.props.dropdownProps), this.props.dropdownTarget)));
66 }
67 return (React.createElement("ul", { className: (0, classnames_1.default)(Classes.COLLAPSIBLE_LIST, this.props.className) },
68 collapseFrom === boundary_1.Boundary.START ? collapsedPopover : null,
69 visibleItems,
70 collapseFrom === boundary_1.Boundary.END ? collapsedPopover : null));
71 };
72 // splits the list of children into two arrays: visible and collapsed
73 CollapsibleList.prototype.partitionChildren = function () {
74 var childrenArray = React.Children.map(this.props.children, function (child, index) {
75 if (!(0, utils_1.isElementOfType)(child, menuItem_1.MenuItem)) {
76 throw new Error(Errors.COLLAPSIBLE_LIST_INVALID_CHILD);
77 }
78 return React.cloneElement(child, { key: "visible-".concat(index) });
79 });
80 if (childrenArray == null) {
81 return [[], []];
82 }
83 if (this.props.collapseFrom === boundary_1.Boundary.START) {
84 // reverse START list so we can always slice visible items from the front of the list
85 childrenArray.reverse();
86 }
87 var visibleItemCount = this.props.visibleItemCount;
88 return [childrenArray.slice(0, visibleItemCount), childrenArray.slice(visibleItemCount)];
89 };
90 CollapsibleList.displayName = "".concat(props_1.DISPLAYNAME_PREFIX, ".CollapsibleList");
91 CollapsibleList.defaultProps = {
92 collapseFrom: boundary_1.Boundary.START,
93 visibleItemCount: 3,
94 };
95 return CollapsibleList;
96}(React.Component));
97exports.CollapsibleList = CollapsibleList;
98//# sourceMappingURL=collapsibleList.js.map
\No newline at end of file