@flatbiz/antd
Version:
40 lines (36 loc) • 1.58 kB
JavaScript
/*! @flatjs/forge MIT @flatbiz/antd */
import { _ as _objectWithoutProperties, b as _objectSpread2 } from './_rollupPluginBabelHelpers-BYm17lo8.js';
import { hooks } from '@wove/react/hooks';
import { Checkbox } from 'antd';
import { isUndefinedOrNull } from '@flatbiz/utils';
import { jsx } from 'react/jsx-runtime';
var _excluded = ["checkedValue", "unCheckedValue", "onChange", "value"];
/**
* 解决 Checkbox 只能接收boolean的限制,与Form.Item结合使用最佳
* ```
* 1. value 为状态值,不局限于boolean,可以为 [string | number | boolean]
* 2. checkedValue 选中值
* 3. unCheckedValue 未选中值
* 4. 与 Form.Item 结合使用,不再需要配置 valuePropName
* <Form.Item name="fieldName">
* <CheckboxWrapper checkedValue={2} unCheckedValue={1} />
* </Form.Item>
* ```
*/
var CheckboxWrapper = function CheckboxWrapper(props) {
var checkedValue = props.checkedValue,
unCheckedValue = props.unCheckedValue,
onChange = props.onChange,
value = props.value,
otherProps = _objectWithoutProperties(props, _excluded);
var onChangeHandle = hooks.useCallbackRef(function (event) {
var checked = event.target.checked;
onChange === null || onChange === void 0 || onChange(checked ? checkedValue : unCheckedValue);
});
return /*#__PURE__*/jsx(Checkbox, _objectSpread2(_objectSpread2({}, otherProps), {}, {
checked: !isUndefinedOrNull(value) && checkedValue === value,
onChange: onChangeHandle
}));
};
export { CheckboxWrapper as C };
//# sourceMappingURL=checkbox-wrapper-vfPLUiSn.js.map