UNPKG

@talend/react-components

Version:
54 lines (53 loc) 1.47 kB
import { Component } from 'react'; import PropTypes from 'prop-types'; import { getRowData } from '../VirtualizedList/utils/gridrow'; import Badge from '../Badge'; import { jsx as _jsx } from "react/jsx-runtime"; class ItemViewRow extends Component { static getDerivedStateFromProps(props) { return { item: getRowData(props.parent, props.index) }; } constructor(props) { super(props); this.state = {}; } shouldComponentUpdate(nextProps, nextState) { const oldData = this.state.item; const newData = nextState.item; return oldData !== newData && ['selected', 'value', 'name'].some(attr => oldData[attr] !== newData[attr]); } render() { const item = this.state.item; return /*#__PURE__*/_jsx("div", { style: this.props.style, children: /*#__PURE__*/_jsx(Badge, { label: item.name, selected: true, onDelete: event => this.props.parent.props.onRowClick({ event, rowData: item.value }) }) }); } } ItemViewRow.propTypes = { style: PropTypes.object, index: PropTypes.number, parent: PropTypes.shape({ props: PropTypes.shape({ collection: PropTypes.array, onRowClick: PropTypes.func }) }) }; // eslint-disable-next-line import/prefer-default-export export function ItemView(props) { return /*#__PURE__*/_jsx(ItemViewRow, { ...props }); } ItemView.rowHeight = 35; //# sourceMappingURL=ItemView.component.js.map