UNPKG

@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

212 lines (177 loc) • 12 kB
"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 _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 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, needBorder = _this$props4.needBorder, 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, 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({ 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, _customClass$customVa = customClass.customValueRightPlaceholder, customValueRightPlaceholder = _customClass$customVa === void 0 ? '' : _customClass$customVa; var iconBoxDataId = "".concat(dataId, "_radio"); return /*#__PURE__*/_react["default"].createElement(_ListContainer["default"], _extends({ a11y: listA11y, size: size, palette: palette, highlight: highlight, isDisabled: isDisabled, active: active, autoHover: autoHover, needBorder: needBorder, 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, { className: _ListItemModule["default"].contentWrapper }, /*#__PURE__*/_react["default"].createElement("div", { 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: lhsAlignContent !== 'center' ? _ListItemModule["default"].lhsBoxInner : '' }, /*#__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, 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, "data-title": disableTitle ? null : title, className: needMultiLineText ? _ListItemModule["default"].multiLineValue : _ListItemModule["default"].value }, value) : null, (0, _utils.isRenderable)(renderValueRightPlaceholderNode) ? /*#__PURE__*/_react["default"].createElement(_Layout.Box, { className: customValueRightPlaceholder }, (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))); } }]); 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' // }; // }