@zohodesk/components
Version:
In this Package, we Provide Some Basic Components to Build Web App
142 lines (135 loc) • 3.54 kB
JavaScript
/**** 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';
/**** 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
} = this.props;
let {
ListItemProps = {},
ContainerProps = {}
} = customProps;
let {
customListItem = '',
customTickIcon = ''
} = 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, {
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
}, value ? /*#__PURE__*/React.createElement(Box, {
shrink: true,
adjust: true,
className: needMultiLineText ? style.multiLineValue : style.value
}, value) : null, children ? /*#__PURE__*/React.createElement(Box, {
shrink: true,
adjust: true,
className: style.children
}, children) : 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'
// };
// }