@talend/react-components
Version:
Set of react components.
88 lines (87 loc) • 3.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = require("react");
var _classnames = _interopRequireDefault(require("classnames"));
var _CellCheckboxModule = _interopRequireDefault(require("./CellCheckbox.module.scss"));
var _constants = require("../utils/constants");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
/**
* Cell renderer that displays a checkbox
*/class CellCheckbox extends _react.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 === _constants.SELECTION_MODE.SINGLE ? 'radio' : 'checkbox';
return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _classnames.default)('tc-list-checkbox', _CellCheckboxModule.default['tc-list-checkbox']),
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
className: (0, _classnames.default)('checkbox', {
disabled
}),
children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("label", {
htmlFor: id && `${id}-${rowIndex}-check`,
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("input", {
id: id && `${id}-${rowIndex}-check`,
type: type,
onChange: e => {
onChange(e, rowData);
},
checked: cellData,
disabled: disabled
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
className: "tc-cell-checkbox",
children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
className: "sr-only",
children: label
})
})]
})
})
});
}
}
CellCheckbox.displayName = 'VirtualizedList(CellCheckbox)';
CellCheckbox.propTypes = {
// The cell value : props.rowData[props.dataKey]
cellData: _propTypes.default.bool,
// The custom props passed to <VirtualizedList.Content columnData={}>.
columnData: _propTypes.default.shape({
selectionMode: _propTypes.default.string,
getRowState: _propTypes.default.func,
// The List id. This is used as the checkbox id prefix.
id: _propTypes.default.string,
// The checkbox label.
label: _propTypes.default.string,
// The onChange callback triggered on checkbox toggle.
onChange: _propTypes.default.func.isRequired
}),
// The collection item.
rowData: _propTypes.default.object,
// eslint-disable-line
// The collection item index.
rowIndex: _propTypes.default.number
};
var _default = exports.default = CellCheckbox;
//# sourceMappingURL=CellCheckbox.component.js.map