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

165 lines (156 loc) 5.08 kB
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); } /**** Libraries ****/ import React from 'react'; import { Box } from "../Layout"; import ListContainer from "./ListContainer"; import { ListItemDefaultProps } from "./props/defaultProps"; import { ListItem_Props } from "./props/propTypes"; /**** Components ****/ import { Icon } from '@zohodesk/icons'; /*** Utils ****/ import { renderNode, isRenderable } from '@zohodesk/utils'; /**** CSS ****/ import style from "./ListItem.module.css"; export default class ListItem extends React.Component { constructor(props) { super(props); this.handleClick = this.handleClick.bind(this); this.getRef = this.getRef.bind(this); this.handleMouseEnter = this.handleMouseEnter.bind(this); } getRef(ele) { this.ele = ele; let { index, getRef, id } = this.props; getRef && getRef(ele, index, id); } handleClick(e) { let { onClick, id, value, index } = this.props; onClick && onClick(id, value, index, e); } handleMouseEnter(e) { let { onMouseEnter, id, value, index } = this.props; onMouseEnter && onMouseEnter(id, value, index, e); } render() { let { size, active, highlight, value, autoHover, palette, title, disableTitle, needTick, isLink, href, target, needBorder, isDisabled, children, dataId, dataSelectorId, a11y, customClass, customProps, needMultiLineText, secondaryValue, renderBeforeChildren, renderValueRightPlaceholderNode, lhsAlignContent } = this.props; let { ListItemProps = {}, ContainerProps = {} } = customProps; let { customListItem = '', customTickIcon = '', customValueRightPlaceholder = '', customTitleBox = '' } = customClass; const listA11y = { ariaHidden: true, role: 'option', ...a11y }; let { ariaHidden } = listA11y; let tickIconPalette = style[`${palette}Tick`] ? style[`${palette}Tick`] : ''; let dataIdString = dataId ? dataId : value ? String(value).replace("'", '_') : 'listItem'; return /*#__PURE__*/React.createElement(ListContainer, _extends({ a11y: listA11y, size: size, palette: palette, highlight: highlight, isDisabled: isDisabled, active: active, autoHover: autoHover, needTick: needTick, needBorder: needBorder, customClass: customListItem, dataId: dataIdString, dataSelectorId: `${dataSelectorId}`, isLink: isLink, href: href, target: target, disableTitle: disableTitle, title: title, onClick: this.handleClick, onMouseEnter: this.handleMouseEnter, eleRef: this.getRef, customProps: ListItemProps }, ContainerProps), /*#__PURE__*/React.createElement(Box, { flexible: true, className: style.leftBox }, /*#__PURE__*/React.createElement(Box, { className: `${style.titleBox} ${lhsAlignContent !== 'start' ? `${style[`alignLhsBox_${lhsAlignContent}`]}` : ''} ${customTitleBox}` }, isRenderable(renderBeforeChildren) ? /*#__PURE__*/React.createElement(Box, { adjust: true, className: style.beforeChild }, renderNode(renderBeforeChildren)) : null, value ? /*#__PURE__*/React.createElement(Box, { shrink: true, adjust: true, className: `${style.selfAlign_center} ${needMultiLineText ? style.multiLineValue : style.value}` }, value) : null, isRenderable(renderValueRightPlaceholderNode) ? /*#__PURE__*/React.createElement(Box, { className: customValueRightPlaceholder }, renderNode(renderValueRightPlaceholderNode)) : null, children ? /*#__PURE__*/React.createElement(Box, { shrink: true, adjust: true, className: style.children }, children) : null), secondaryValue ? /*#__PURE__*/React.createElement(Box, { "data-title": isDisabled ? null : secondaryValue, className: `${style.secondaryField} ${needMultiLineText ? style.multiLine : style.secondaryValue}` }, secondaryValue) : null), needTick && active ? /*#__PURE__*/React.createElement(Box, { className: `${style.tickIcon} ${tickIconPalette} ${customTickIcon}`, "aria-hidden": ariaHidden, dataId: `${dataIdString}_tickIcon`, dataSelectorId: `${dataSelectorId}_tickIcon` }, /*#__PURE__*/React.createElement(Icon, { name: "ZD-ticknew", size: "8" })) : null); } } ListItem.defaultProps = ListItemDefaultProps; ListItem.propTypes = ListItem_Props; // if (__DOCS__) { // ListItem.docs = { // componentGroup: 'Molecule', // folderName: 'Style Guide' // }; // }