@carbon/ibm-security
Version:
Carbon for Cloud & Cognitive IBM Security UI components
91 lines (89 loc) • 3.8 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import _extends from "@babel/runtime/helpers/extends";
var _excluded = ["children", "as", "href", "onClick"],
_excluded2 = ["className"];
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; }
/**
* @file List item module.
* @copyright IBM Security 2021
*/
import classnames from 'classnames';
import { elementType, func, string } from 'prop-types';
import React from 'react';
import LayoutModule, { layoutModuleNamespace } from '../LayoutModule';
var namespace = 'list-item';
function Column(props) {
return /*#__PURE__*/React.createElement(LayoutModule, _extends({
namespace: "".concat(namespace, "__column")
}, props));
}
/**
* The ListItem is a module designed for flexibility. It consists of optional pieces that can be used to design & build variants with universal consistency.
*/
var ListItemModule = function ListItemModule(_ref) {
var children = _ref.children,
as = _ref.as,
href = _ref.href,
onClick = _ref.onClick,
other = _objectWithoutProperties(_ref, _excluded);
var content = children({
Column: Column,
getLayoutProps: function getLayoutProps() {
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
className = _ref2.className,
rest = _objectWithoutProperties(_ref2, _excluded2);
var assignClassName = function assignClassName(type) {
return {
className: classnames(className, _defineProperty({}, "".concat(layoutModuleNamespace, "--").concat(namespace, "__").concat(type), type))
};
};
return _objectSpread({
avatar: assignClassName('avatar'),
component: assignClassName('component'),
description: assignClassName('description'),
farsidecolumn: assignClassName('farside-column'),
icon: assignClassName('icon'),
label: assignClassName('label'),
profileimage: assignClassName('profile-image'),
title: assignClassName('title')
}, rest);
}
});
var component = 'div';
if (as !== 'div') {
component = as;
} else if (href) {
component = 'a';
} else if (onClick) {
component = 'button';
}
return /*#__PURE__*/React.createElement(LayoutModule, _extends({
namespace: "".concat(namespace, " ").concat(layoutModuleNamespace, "--").concat(namespace, "--").concat(component),
as: component,
href: href,
onClick: onClick
}, other), content);
};
ListItemModule.propTypes = {
/** Provide a custom element to be rendered instead of the default */
as: elementType,
/** Provide the content for the `ListItemModule` */
children: func.isRequired,
/**
* Optionally specify an href for the ListItemModule to become an `<a>` element
*/
href: string,
/**
* Provide an optional function to be called when the ListItemModule
* is clicked, turning the ListItemModule into a `<button>` element
*/
onClick: func
};
ListItemModule.defaultProps = {
as: 'div',
href: null,
onClick: null
};
export default ListItemModule;