@douyinfe/semi-ui
Version:
A modern, comprehensive, flexible design system and UI library. Connect DesignOps & DevOps. Quickly build beautiful React apps. Maintained by Douyin-fe team.
71 lines • 2.17 kB
JavaScript
import _noop from "lodash/noop";
import React from 'react';
import BaseComponent from '../_base/baseComponent';
import classnames from 'classnames';
import PropTypes from 'prop-types';
import { cssClasses } from '@douyinfe/semi-foundation/lib/es/table/constants';
import TableSelectionCellFoundation from '@douyinfe/semi-foundation/lib/es/table/tableSelectionCellFoundation';
import { Checkbox } from '../checkbox';
/**
* render selection cell
*/
export default class TableSelectionCell extends BaseComponent {
get adapter() {
var _this = this;
return Object.assign(Object.assign({}, super.adapter), {
notifyChange: function () {
return _this.props.onChange(...arguments);
}
});
}
constructor(props) {
super(props);
this.handleChange = e => this.foundation.handleChange(e);
this.foundation = new TableSelectionCellFoundation(this.adapter);
}
render() {
const {
selected,
getCheckboxProps,
indeterminate,
disabled,
prefixCls,
className
} = this.props;
const ariaLabel = this.props['aria-label'];
let checkboxProps = {
onChange: this.handleChange,
disabled,
indeterminate,
checked: selected
};
if (typeof getCheckboxProps === 'function') {
checkboxProps = Object.assign(Object.assign({}, checkboxProps), getCheckboxProps());
}
const wrapCls = classnames(`${prefixCls}-selection-wrap`, {
[`${prefixCls}-selection-disabled`]: disabled
}, className);
return /*#__PURE__*/React.createElement("span", {
className: wrapCls
}, /*#__PURE__*/React.createElement(Checkbox, Object.assign({
"aria-label": ariaLabel
}, checkboxProps)));
}
}
TableSelectionCell.propTypes = {
columnTitle: PropTypes.string,
getCheckboxProps: PropTypes.func,
type: PropTypes.string,
onChange: PropTypes.func,
selected: PropTypes.bool,
disabled: PropTypes.bool,
indeterminate: PropTypes.bool,
prefixCls: PropTypes.string,
className: PropTypes.string,
'aria-label': PropTypes.string
};
TableSelectionCell.defaultProps = {
disabled: false,
onChange: _noop,
prefixCls: cssClasses.PREFIX
};