index.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. import { __rest } from "tslib";
  2. import { jsx as _jsx } from "react/jsx-runtime";
  3. import { Checkbox } from "antd";
  4. import { isNumber, isObject, merge } from "lodash";
  5. import { useEffect, useState } from "react";
  6. export const DageCheckboxGroup = (_a) => {
  7. var { options, max } = _a, rest = __rest(_a, ["options", "max"]);
  8. const [_options, _setOptions] = useState([]);
  9. useEffect(() => {
  10. _setOptions(merge([], options === null || options === void 0 ? void 0 : options.map((i) => {
  11. if (isObject(i))
  12. return i;
  13. return {
  14. label: i,
  15. value: i,
  16. };
  17. }), _options));
  18. }, [options]);
  19. useEffect(() => {
  20. const { value } = rest;
  21. if (!value || !isNumber(max))
  22. return;
  23. _setOptions((val) => {
  24. return val.map((i) => (Object.assign(Object.assign({}, i), { disabled: value.length >= max ? !value.includes(i.value) : false })));
  25. });
  26. }, [rest.value, max]);
  27. return _jsx(Checkbox.Group, Object.assign({ options: _options }, rest));
  28. };