semantic-ui-react
Version:
The official Semantic-UI-React integration.
168 lines (135 loc) • 5.83 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import _map from "lodash-es/map";
import _invoke from "lodash-es/invoke";
import cx from 'clsx';
import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { childrenUtils, customPropTypes, getElementType, getUnhandledProps, SUI, useKeyOnly, useKeyOrValueAndKey, useValueAndKey, useVerticalAlignProp } from '../../lib';
import ListContent from './ListContent';
import ListDescription from './ListDescription';
import ListHeader from './ListHeader';
import ListIcon from './ListIcon';
import ListItem from './ListItem';
import ListList from './ListList';
/**
* A list groups related content.
*/
var List = /*#__PURE__*/function (_Component) {
_inheritsLoose(List, _Component);
function List() {
var _this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
_this = _Component.call.apply(_Component, [this].concat(args)) || this;
_this.handleItemOverrides = function (predefinedProps) {
return {
onClick: function onClick(e, itemProps) {
_invoke(predefinedProps, 'onClick', e, itemProps);
_invoke(_this.props, 'onItemClick', e, itemProps);
}
};
};
return _this;
}
var _proto = List.prototype;
_proto.render = function render() {
var _this2 = this;
var _this$props = this.props,
animated = _this$props.animated,
bulleted = _this$props.bulleted,
celled = _this$props.celled,
children = _this$props.children,
className = _this$props.className,
content = _this$props.content,
divided = _this$props.divided,
floated = _this$props.floated,
horizontal = _this$props.horizontal,
inverted = _this$props.inverted,
items = _this$props.items,
link = _this$props.link,
ordered = _this$props.ordered,
relaxed = _this$props.relaxed,
selection = _this$props.selection,
size = _this$props.size,
verticalAlign = _this$props.verticalAlign;
var classes = cx('ui', size, useKeyOnly(animated, 'animated'), useKeyOnly(bulleted, 'bulleted'), useKeyOnly(celled, 'celled'), useKeyOnly(divided, 'divided'), useKeyOnly(horizontal, 'horizontal'), useKeyOnly(inverted, 'inverted'), useKeyOnly(link, 'link'), useKeyOnly(ordered, 'ordered'), useKeyOnly(selection, 'selection'), useKeyOrValueAndKey(relaxed, 'relaxed'), useValueAndKey(floated, 'floated'), useVerticalAlignProp(verticalAlign), 'list', className);
var rest = getUnhandledProps(List, this.props);
var ElementType = getElementType(List, this.props);
if (!childrenUtils.isNil(children)) {
return /*#__PURE__*/React.createElement(ElementType, _extends({
role: "list",
className: classes
}, rest), children);
}
if (!childrenUtils.isNil(content)) {
return /*#__PURE__*/React.createElement(ElementType, _extends({
role: "list",
className: classes
}, rest), content);
}
return /*#__PURE__*/React.createElement(ElementType, _extends({
role: "list",
className: classes
}, rest), _map(items, function (item) {
return ListItem.create(item, {
overrideProps: _this2.handleItemOverrides
});
}));
};
return List;
}(Component);
List.handledProps = ["animated", "as", "bulleted", "celled", "children", "className", "content", "divided", "floated", "horizontal", "inverted", "items", "link", "onItemClick", "ordered", "relaxed", "selection", "size", "verticalAlign"];
List.propTypes = process.env.NODE_ENV !== "production" ? {
/** An element type to render as (string or function). */
as: PropTypes.elementType,
/** A list can animate to set the current item apart from the list. */
animated: PropTypes.bool,
/** A list can mark items with a bullet. */
bulleted: PropTypes.bool,
/** A list can divide its items into cells. */
celled: PropTypes.bool,
/** Primary content. */
children: PropTypes.node,
/** Additional classes. */
className: PropTypes.string,
/** Shorthand for primary content. */
content: customPropTypes.contentShorthand,
/** A list can show divisions between content. */
divided: PropTypes.bool,
/** An list can be floated left or right. */
floated: PropTypes.oneOf(SUI.FLOATS),
/** A list can be formatted to have items appear horizontally. */
horizontal: PropTypes.bool,
/** A list can be inverted to appear on a dark background. */
inverted: PropTypes.bool,
/** Shorthand array of props for ListItem. */
items: customPropTypes.collectionShorthand,
/** A list can be specially formatted for navigation links. */
link: PropTypes.bool,
/**
* onClick handler for ListItem. Mutually exclusive with children.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All item props.
*/
onItemClick: customPropTypes.every([customPropTypes.disallow(['children']), PropTypes.func]),
/** A list can be ordered numerically. */
ordered: PropTypes.bool,
/** A list can relax its padding to provide more negative space. */
relaxed: PropTypes.oneOfType([PropTypes.bool, PropTypes.oneOf(['very'])]),
/** A selection list formats list items as possible choices. */
selection: PropTypes.bool,
/** A list can vary in size. */
size: PropTypes.oneOf(SUI.SIZES),
/** An element inside a list can be vertically aligned. */
verticalAlign: PropTypes.oneOf(SUI.VERTICAL_ALIGNMENTS)
} : {};
List.Content = ListContent;
List.Description = ListDescription;
List.Header = ListHeader;
List.Icon = ListIcon;
List.Item = ListItem;
List.List = ListList;
export default List;