@zohodesk/components
Version:
In this Package, we Provide Some Basic Components to Build Web App
198 lines (164 loc) • 11.1 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 _Radio = _interopRequireDefault(require("../Radio/Radio"));
var _Layout = require("../Layout");
var _ListContainer = _interopRequireDefault(require("./ListContainer"));
var _defaultProps = require("./props/defaultProps");
var _propTypes = require("./props/propTypes");
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 ListItemWithRadio = /*#__PURE__*/function (_React$Component) {
_inherits(ListItemWithRadio, _React$Component);
var _super = _createSuper(ListItemWithRadio);
function ListItemWithRadio(props) {
var _this;
_classCallCheck(this, ListItemWithRadio);
_this = _super.call(this, props);
_this.onClick = _this.onClick.bind(_assertThisInitialized(_this));
_this.getRef = _this.getRef.bind(_assertThisInitialized(_this));
_this.onHover = _this.onHover.bind(_assertThisInitialized(_this));
return _this;
}
_createClass(ListItemWithRadio, [{
key: "getRef",
value: function getRef(ele) {
this.ele = ele;
var _this$props = this.props,
index = _this$props.index,
getRef = _this$props.getRef;
getRef && getRef(ele, index);
}
}, {
key: "onClick",
value: function onClick(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: "onHover",
value: function onHover(e) {
var _this$props3 = this.props,
onHover = _this$props3.onHover,
id = _this$props3.id,
value = _this$props3.value,
index = _this$props3.index;
onHover && onHover(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,
checked = _this$props4.checked,
autoHover = _this$props4.autoHover,
palette = _this$props4.palette,
id = _this$props4.id,
dataId = _this$props4.dataId,
dataSelectorId = _this$props4.dataSelectorId,
title = _this$props4.title,
isDisabled = _this$props4.isDisabled,
disableTitle = _this$props4.disableTitle,
a11y = _this$props4.a11y,
customClass = _this$props4.customClass,
customProps = _this$props4.customProps,
needMultiLineText = _this$props4.needMultiLineText,
secondaryValue = _this$props4.secondaryValue,
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({
role: 'option'
}, a11y);
var _customClass$customLi = customClass.customListItem,
customListItem = _customClass$customLi === void 0 ? '' : _customClass$customLi,
_customClass$customRa = customClass.customRadio,
customRadio = _customClass$customRa === void 0 ? '' : _customClass$customRa,
_customClass$customRa2 = customClass.customRadioWrap,
customRadioWrap = _customClass$customRa2 === void 0 ? '' : _customClass$customRa2;
return /*#__PURE__*/_react["default"].createElement(_ListContainer["default"], _extends({
a11y: listA11y,
size: size,
palette: palette,
highlight: highlight,
isDisabled: isDisabled,
active: active,
autoHover: autoHover,
customClass: customListItem,
dataId: dataId,
dataSelectorId: dataSelectorId,
onClick: this.onClick,
onMouseOver: this.onHover,
eleRef: this.getRef,
disableTitle: disableTitle,
title: null,
customProps: ListItemProps
}, ContainerProps), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
align: lhsAlignContent,
className: "".concat(_ListItemModule["default"].iconBox, " ").concat(_ListItemModule["default"].lhsBox, " ").concat(_ListItemModule["default"]["lhsJustifyContent_".concat(lhsJustifyContent)]),
dataId: "".concat(dataId, "_radio")
}, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
align: lhsAlignContent,
className: lhsAlignContent !== 'center' ? _ListItemModule["default"]["lhsBox_".concat(size)] : ''
}, /*#__PURE__*/_react["default"].createElement(_Radio["default"], {
checked: checked,
id: id,
a11y: {
ariaHidden: true
},
customClass: {
customRadio: customRadio,
customRadioWrap: customRadioWrap
}
}))), /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
flexible: true,
shrink: true
}, /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
alignBox: "column"
}, value ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
"data-title": disableTitle ? null : title,
className: needMultiLineText ? _ListItemModule["default"].multiLineValue : _ListItemModule["default"].value
}, value) : 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)));
}
}]);
return ListItemWithRadio;
}(_react["default"].Component);
exports["default"] = ListItemWithRadio;
ListItemWithRadio.defaultProps = _defaultProps.ListItemWithRadioDefaultProps;
ListItemWithRadio.propTypes = _propTypes.ListItemWithRadio_Props; // if (__DOCS__) {
// ListItemWithRadio.docs = {
// componentGroup: 'Molecule',
// folderName: 'Style Guide'
// };
// }