@zohodesk/components
Version:
Dot UI is a customizable React component library built to deliver a clean, accessible, and developer-friendly UI experience. It offers a growing set of reusable components designed to align with modern design systems and streamline application development
224 lines (189 loc) • 12.8 kB
JavaScript
"use strict";
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _Layout = require("../Layout");
var _icons = require("@zohodesk/icons");
var _ListContainer = _interopRequireDefault(require("./ListContainer"));
var _defaultProps = require("./props/defaultProps");
var _propTypes = require("./props/propTypes");
var _utils = require("@zohodesk/utils");
var _ListItemModule = _interopRequireDefault(require("./ListItem.module.css"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
var ListItemWithIcon = /*#__PURE__*/function (_React$Component) {
_inherits(ListItemWithIcon, _React$Component);
var _super = _createSuper(ListItemWithIcon);
function ListItemWithIcon(props) {
var _this;
_classCallCheck(this, ListItemWithIcon);
_this = _super.call(this, props);
_this.handleClick = _this.handleClick.bind(_assertThisInitialized(_this));
_this.getRef = _this.getRef.bind(_assertThisInitialized(_this));
_this.handleMouseEnter = _this.handleMouseEnter.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(ListItemWithIcon, [{
key: "getRef",
value: function getRef(ele) {
this.ele = ele;
var _this$props = this.props,
index = _this$props.index,
getRef = _this$props.getRef,
id = _this$props.id;
getRef && getRef(ele, index, id);
}
}, {
key: "handleClick",
value: function handleClick(e) {
var _this$props2 = this.props,
onClick = _this$props2.onClick,
id = _this$props2.id,
value = _this$props2.value,
index = _this$props2.index;
onClick && onClick(id, value, index, e);
}
}, {
key: "handleMouseEnter",
value: function handleMouseEnter(e) {
var _this$props3 = this.props,
onMouseEnter = _this$props3.onMouseEnter,
id = _this$props3.id,
value = _this$props3.value,
index = _this$props3.index;
onMouseEnter && onMouseEnter(id, value, index, e);
}
}, {
key: "render",
value: function render() {
var _this$props4 = this.props,
size = _this$props4.size,
active = _this$props4.active,
highlight = _this$props4.highlight,
value = _this$props4.value,
iconName = _this$props4.iconName,
iconSize = _this$props4.iconSize,
autoHover = _this$props4.autoHover,
palette = _this$props4.palette,
iconClass = _this$props4.iconClass,
dataId = _this$props4.dataId,
dataSelectorId = _this$props4.dataSelectorId,
title = _this$props4.title,
needTick = _this$props4.needTick,
isLink = _this$props4.isLink,
href = _this$props4.href,
target = _this$props4.target,
needBorder = _this$props4.needBorder,
isDisabled = _this$props4.isDisabled,
disableTitle = _this$props4.disableTitle,
a11y = _this$props4.a11y,
customClass = _this$props4.customClass,
customValueRightPlaceholderClass = _this$props4.customValueRightPlaceholderClass,
customProps = _this$props4.customProps,
needMultiLineText = _this$props4.needMultiLineText,
secondaryValue = _this$props4.secondaryValue,
renderValueRightPlaceholderNode = _this$props4.renderValueRightPlaceholderNode,
lhsAlignContent = _this$props4.lhsAlignContent,
lhsJustifyContent = _this$props4.lhsJustifyContent;
var _customProps$ListItem = customProps.ListItemProps,
ListItemProps = _customProps$ListItem === void 0 ? {} : _customProps$ListItem,
_customProps$Containe = customProps.ContainerProps,
ContainerProps = _customProps$Containe === void 0 ? {} : _customProps$Containe;
var listA11y = _objectSpread({
ariaHidden: true,
role: 'option'
}, a11y);
var ariaHidden = listA11y.ariaHidden;
var dataIdString = dataId ? "".concat(dataId.replace("'", '_')) : value.toLowerCase().replace("'", '_');
var iconBoxDataId = dataId ? "".concat(dataId, "_Icon") : "".concat(value.toLowerCase().replace("'", '_'), "_Icon");
return /*#__PURE__*/_react["default"].createElement(_ListContainer["default"], _extends({
a11y: listA11y,
size: size,
palette: palette,
highlight: highlight,
isDisabled: isDisabled,
active: active,
autoHover: autoHover,
needTick: needTick,
needBorder: needBorder,
customClass: customClass,
dataId: dataIdString,
dataSelectorId: dataSelectorId,
isLink: isLink,
href: href,
target: target,
onClick: this.handleClick,
onMouseOver: this.handleMouseEnter,
eleRef: this.getRef,
disableTitle: disableTitle,
title: null,
customProps: ListItemProps
}, ContainerProps), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: "".concat(_ListItemModule["default"].contentWrapper, " ").concat(!iconName && lhsAlignContent !== 'start' ? _ListItemModule["default"]["alignLhsBox_".concat(lhsAlignContent)] : '')
}, iconName && /*#__PURE__*/_react["default"].createElement("div", {
"aria-hidden": true,
className: "".concat(_ListItemModule["default"].iconBox, " ").concat(_ListItemModule["default"]["lhsJustifyContent_".concat(lhsJustifyContent)]),
"data-id": iconBoxDataId,
"data-test-id": iconBoxDataId
}, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
align: lhsAlignContent,
className: _ListItemModule["default"].iconWrapper
}, /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
iconClass: iconClass,
name: iconName,
size: iconSize
}))), iconClass && !iconName ? /*#__PURE__*/_react["default"].createElement("span", {
className: iconClass
}) : null, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true,
className: "".concat(_ListItemModule["default"].leftBox, " ").concat(_ListItemModule["default"].selfAlign_center)
}, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: _ListItemModule["default"].titleBox
}, value ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
shrink: true,
adjust: true,
className: needMultiLineText ? _ListItemModule["default"].multiLineValue : _ListItemModule["default"].value,
"data-title": isDisabled ? null : title,
dataId: "".concat(dataIdString, "_Text")
}, value) : null, (0, _utils.isRenderable)(renderValueRightPlaceholderNode) ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: customValueRightPlaceholderClass
}, (0, _utils.renderNode)(renderValueRightPlaceholderNode)) : null), secondaryValue ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
"data-title": isDisabled ? null : secondaryValue,
className: "".concat(_ListItemModule["default"].secondaryField, " ").concat(needMultiLineText ? _ListItemModule["default"].multiLine : _ListItemModule["default"].secondaryValue)
}, secondaryValue) : null), needTick && active ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
className: _ListItemModule["default"].tickIcon,
"aria-hidden": ariaHidden,
dataId: "".concat(dataIdString, "_tickIcon"),
dataSelectorId: "".concat(dataSelectorId, "_tickIcon")
}, /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
name: "ZD-ticknew",
size: "8"
})) : null));
}
}]);
return ListItemWithIcon;
}(_react["default"].Component);
exports["default"] = ListItemWithIcon;
ListItemWithIcon.defaultProps = _defaultProps.ListItemWithIconDefaultProps;
ListItemWithIcon.propTypes = _propTypes.ListItemWithIcon_Props; // if (__DOCS__) {
// ListItemWithIcon.docs = {
// componentGroup: 'Molecule',
// folderName: 'Style Guide'
// };
// }