zent
Version:
一套前端设计语言和基于React的实现
62 lines (61 loc) • 2.54 kB
JavaScript
import { __assign, __extends } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
import { PureComponent } from 'react';
import Radio from '../radio';
import Pop from '../pop';
var getRowCheckedState = function (rowInfo) {
var _a;
var store = rowInfo.store, rowIndex = rowInfo.rowIndex;
return ((_a = store.getState('selectedRowKeys')) !== null && _a !== void 0 ? _a : []).indexOf(rowIndex) !== -1;
};
var SelectionCheckbox = (function (_super) {
__extends(SelectionCheckbox, _super);
function SelectionCheckbox(props) {
var _this = _super.call(this, props) || this;
_this.subscribe = function () {
var _a = _this.props, store = _a.store, rowIndex = _a.rowIndex;
_this.unsubscribe = store.subscribe('selectedRowKeys', function () {
var checked = getRowCheckedState({
store: store,
rowIndex: rowIndex,
});
if (_this.state.checked !== checked) {
_this.setState({ checked: checked });
}
});
};
_this.state = {
checked: getRowCheckedState({
store: props.store,
rowIndex: props.rowIndex,
}),
};
return _this;
}
SelectionCheckbox.getDerivedStateFromProps = function (props, state) {
var checked = getRowCheckedState({
store: props.store,
rowIndex: props.rowIndex,
});
if (checked === state.checked) {
return null;
}
return {
checked: checked,
};
};
SelectionCheckbox.prototype.componentDidMount = function () {
this.subscribe();
};
SelectionCheckbox.prototype.componentWillUnmount = function () {
var _a;
(_a = this.unsubscribe) === null || _a === void 0 ? void 0 : _a.call(this);
};
SelectionCheckbox.prototype.render = function () {
var _a = this.props, onChange = _a.onChange, disabled = _a.disabled, reason = _a.reason;
var checked = this.state.checked;
return reason && disabled ? (_jsx(Pop, __assign({ content: reason, trigger: "hover", position: "top-left", centerArrow: true }, { children: _jsx(Radio, { onChange: onChange, checked: checked, disabled: disabled }, void 0) }), void 0)) : (_jsx(Radio, { onChange: onChange, checked: checked, disabled: disabled }, void 0));
};
return SelectionCheckbox;
}(PureComponent));
export default SelectionCheckbox;