UNPKG

@zohodesk/components

Version:

In this Package, we Provide Some Basic Components to Build Web App

137 lines (132 loc) 3.64 kB
import React from 'react'; import Radio from "../Radio/Radio"; import { Box, Container } from "../Layout"; import ListContainer from "./ListContainer"; import { ListItemWithRadioDefaultProps } from "./props/defaultProps"; import { ListItemWithRadio_Props } from "./props/propTypes"; import style from "./ListItem.module.css"; export default class ListItemWithRadio extends React.Component { constructor(props) { super(props); this.onClick = this.onClick.bind(this); this.getRef = this.getRef.bind(this); this.onHover = this.onHover.bind(this); } getRef(ele) { this.ele = ele; let { index, getRef } = this.props; getRef && getRef(ele, index); } onClick(e) { let { onClick, id, value, index } = this.props; onClick && onClick(id, value, index, e); } onHover(e) { let { onHover, id, value, index } = this.props; onHover && onHover(id, value, index, e); } render() { let { size, active, highlight, value, checked, autoHover, palette, id, dataId, dataSelectorId, title, isDisabled, disableTitle, a11y, customClass, customProps, needMultiLineText, secondaryValue, lhsAlignContent, lhsJustifyContent } = this.props; let { ListItemProps = {}, ContainerProps = {} } = customProps; const listA11y = { role: 'option', ...a11y }; let { customListItem = '', customRadio = '', customRadioWrap = '' } = customClass; return /*#__PURE__*/React.createElement(ListContainer, { 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.createElement(Box, { align: lhsAlignContent, className: `${style.iconBox} ${style.lhsBox} ${style[`lhsJustifyContent_${lhsJustifyContent}`]}`, dataId: `${dataId}_radio` }, /*#__PURE__*/React.createElement(Box, { align: lhsAlignContent, className: lhsAlignContent !== 'center' ? style[`lhsBox_${size}`] : '' }, /*#__PURE__*/React.createElement(Radio, { checked: checked, id: id, a11y: { ariaHidden: true }, customClass: { customRadio: customRadio, customRadioWrap: customRadioWrap } }))), /*#__PURE__*/React.createElement(Box, { flexible: true, shrink: true }, /*#__PURE__*/React.createElement(Container, { alignBox: "column" }, value ? /*#__PURE__*/React.createElement(Box, { "data-title": disableTitle ? null : title, className: needMultiLineText ? style.multiLineValue : style.value }, value) : null, secondaryValue ? /*#__PURE__*/React.createElement(Box, { "data-title": isDisabled ? null : secondaryValue, className: `${style.secondaryField} ${needMultiLineText ? style.multiLine : style.secondaryValue}` }, secondaryValue) : null))); } } ListItemWithRadio.defaultProps = ListItemWithRadioDefaultProps; ListItemWithRadio.propTypes = ListItemWithRadio_Props; // if (__DOCS__) { // ListItemWithRadio.docs = { // componentGroup: 'Molecule', // folderName: 'Style Guide' // }; // }