@elastic/eui
Version:
Elastic UI Component Library
81 lines (80 loc) • 4.29 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "className", "listItems", "style", "bordered", "wrapText", "maxWidth", "showToolTips", "color", "ariaLabelledby"];
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import React, { useMemo } from 'react';
import classNames from 'classnames';
import { useEuiMemoizedStyles, cloneElementWithCss } from '../../services';
import { logicalStyle } from '../../global_styling';
import { EuiListGroupItem } from './list_group_item';
import { euiListGroupStyles } from './list_group.styles';
import { jsx as ___EmotionJSX } from "@emotion/react";
export var EuiListGroup = function EuiListGroup(_ref) {
var children = _ref.children,
className = _ref.className,
listItems = _ref.listItems,
style = _ref.style,
_ref$bordered = _ref.bordered,
bordered = _ref$bordered === void 0 ? false : _ref$bordered,
_ref$wrapText = _ref.wrapText,
wrapText = _ref$wrapText === void 0 ? false : _ref$wrapText,
_ref$maxWidth = _ref.maxWidth,
maxWidth = _ref$maxWidth === void 0 ? true : _ref$maxWidth,
_ref$showToolTips = _ref.showToolTips,
showToolTips = _ref$showToolTips === void 0 ? false : _ref$showToolTips,
_ref$color = _ref.color,
color = _ref$color === void 0 ? 'text' : _ref$color,
ariaLabelledby = _ref.ariaLabelledby,
rest = _objectWithoutProperties(_ref, _excluded);
var classes = classNames('euiListGroup', className);
var styles = useEuiMemoizedStyles(euiListGroupStyles);
var cssStyles = [styles.euiListGroup, bordered && styles.bordered, maxWidth === true && styles.maxWidthDefault];
var maxWidthStyle = useMemo(function () {
if (maxWidth && maxWidth !== true) {
return logicalStyle('max-width', maxWidth);
}
}, [maxWidth]);
var renderedListItems = useMemo(function () {
if (listItems && listItems.length) {
return listItems.map(function (item, index) {
return ___EmotionJSX(EuiListGroupItem, _extends({
key: "title-".concat(index),
showToolTip: showToolTips,
wrapText: wrapText
// we're passing the parent `color` and `size` down to the children
// so that they can inherit it if they don't have one
,
color: color
}, item));
});
}
}, [listItems, color, wrapText, showToolTips]);
var listItemsOrChildren = renderedListItems ||
// Note that there's no point in memoizing `children`, as JSX changes every rerender
React.Children.map(children, function (child) {
if ( /*#__PURE__*/React.isValidElement(child)) {
return cloneElementWithCss(child, _objectSpread(_objectSpread({
// we're passing the parent `color` and `size` down to the children
// so that they can inherit it if they don't have one
color: color
}, showToolTips && {
showToolTip: true
}), child.props));
}
});
return ___EmotionJSX("ul", _extends({
className: classes,
css: cssStyles,
style: _objectSpread(_objectSpread({}, style), maxWidthStyle),
"aria-labelledby": ariaLabelledby
}, rest), listItemsOrChildren);
};