@talend/react-components
Version:
Set of react components.
83 lines (82 loc) • 2.66 kB
JavaScript
import PropTypes from 'prop-types';
import { Component } from 'react';
import classnames from 'classnames';
import theme from './CellCheckbox.module.scss';
import { SELECTION_MODE } from '../utils/constants';
/**
* Cell renderer that displays a checkbox
*/
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
class CellCheckbox extends Component {
shouldComponentUpdate(nextProps) {
return this.props.cellData !== nextProps.cellData || this.props.columnData !== nextProps.columnData || this.props.rowData !== nextProps.rowData || this.props.rowIndex !== nextProps.rowIndex;
}
render() {
const {
cellData,
columnData,
rowData,
rowIndex
} = this.props;
const {
id,
label,
selectionMode,
onChange,
getRowState
} = columnData;
const {
disabled = false
} = getRowState && getRowState(rowData) || {};
const type = selectionMode === SELECTION_MODE.SINGLE ? 'radio' : 'checkbox';
return /*#__PURE__*/_jsx("div", {
className: classnames('tc-list-checkbox', theme['tc-list-checkbox']),
children: /*#__PURE__*/_jsx("div", {
className: classnames('checkbox', {
disabled
}),
children: /*#__PURE__*/_jsxs("label", {
htmlFor: id && `${id}-${rowIndex}-check`,
children: [/*#__PURE__*/_jsx("input", {
id: id && `${id}-${rowIndex}-check`,
type: type,
onChange: e => {
onChange(e, rowData);
},
checked: cellData,
disabled: disabled
}), /*#__PURE__*/_jsx("span", {
className: "tc-cell-checkbox",
children: /*#__PURE__*/_jsx("span", {
className: "sr-only",
children: label
})
})]
})
})
});
}
}
CellCheckbox.displayName = 'VirtualizedList(CellCheckbox)';
CellCheckbox.propTypes = {
// The cell value : props.rowData[props.dataKey]
cellData: PropTypes.bool,
// The custom props passed to <VirtualizedList.Content columnData={}>.
columnData: PropTypes.shape({
selectionMode: PropTypes.string,
getRowState: PropTypes.func,
// The List id. This is used as the checkbox id prefix.
id: PropTypes.string,
// The checkbox label.
label: PropTypes.string,
// The onChange callback triggered on checkbox toggle.
onChange: PropTypes.func.isRequired
}),
// The collection item.
rowData: PropTypes.object,
// eslint-disable-line
// The collection item index.
rowIndex: PropTypes.number
};
export default CellCheckbox;
//# sourceMappingURL=CellCheckbox.component.js.map