@hw-component/form 1.4.3 → 1.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -69,7 +69,6 @@ var useHForm = (function () {
69
69
  if (!format) {
70
70
  return;
71
71
  }
72
- console.log(name, "nnnnnnnn");
73
72
  var inputValue = format.inputValue,
74
73
  outputValue = format.outputValue;
75
74
  formatSourceData[name] = {
@@ -1,9 +1,12 @@
1
1
  // welcome to hoo hoo hoo
2
2
  import 'core-js/modules/es.array.concat.js';
3
+ import 'core-js/modules/es.array.filter.js';
4
+ import 'core-js/modules/es.object.to-string.js';
3
5
  import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
4
6
  import { Space, Checkbox } from 'antd';
5
7
  import { itemOpProvider } from '../utils.js';
6
8
  import { useClassName } from '../../hooks/index.js';
9
+ import { useMemo } from 'react';
7
10
 
8
11
  var useRootClassName = function useRootClassName(checked) {
9
12
  var norClassNames = ["select-item", "select-item-option"];
@@ -19,20 +22,31 @@ var Index = function Index(_ref) {
19
22
  _ref$fieldNames = _ref.fieldNames,
20
23
  fieldNames = _ref$fieldNames === void 0 ? {} : _ref$fieldNames,
21
24
  children = _ref.children;
22
- var opLen = (options === null || options === void 0 ? void 0 : options.length) || 0;
25
+ var notDisOption = useMemo(function () {
26
+ return options === null || options === void 0 ? void 0 : options.filter(function (item) {
27
+ return !item.disabled;
28
+ });
29
+ }, [options]);
30
+ var opLen = (notDisOption === null || notDisOption === void 0 ? void 0 : notDisOption.length) || 0;
23
31
  var checked = (value === null || value === void 0 ? void 0 : value.length) >= opLen;
24
32
  var classNames = useRootClassName(checked);
25
33
  var optionsClassName = useClassName(classNames);
26
34
  var allCheckBox = useClassName("hw-all-check-box");
35
+ var allCheck = function allCheck() {
36
+ var allCheckOption = options === null || options === void 0 ? void 0 : options.filter(function (item) {
37
+ return !item.disabled;
38
+ });
39
+ var subItemOps = itemOpProvider(allCheckOption, fieldNames);
40
+ onChange === null || onChange === void 0 || onChange(allCheckOption, subItemOps);
41
+ };
27
42
  var change = function change() {
28
43
  if (!checked) {
29
- var subItemOps = itemOpProvider(options, fieldNames);
30
- onChange === null || onChange === void 0 || onChange(options, subItemOps);
44
+ allCheck();
31
45
  return;
32
46
  }
33
47
  onChange === null || onChange === void 0 || onChange([], []);
34
48
  };
35
- if (!allSelect || mode !== "multiple" || serviceSearch) {
49
+ if (!allSelect || mode !== "multiple" || serviceSearch || opLen === 0) {
36
50
  return jsx(Fragment, {
37
51
  children: children
38
52
  });
@@ -2,6 +2,7 @@ import React from "react";
2
2
  interface ICheckBoxOptionProps {
3
3
  label?: React.ReactNode;
4
4
  checked: boolean;
5
+ disabled?: boolean;
5
6
  }
6
- declare const _default: ({ label, checked }: ICheckBoxOptionProps) => JSX.Element;
7
+ declare const _default: ({ label, checked, disabled }: ICheckBoxOptionProps) => JSX.Element;
7
8
  export default _default;
@@ -4,10 +4,12 @@ import { Space, Checkbox } from 'antd';
4
4
 
5
5
  var CheckBoxOption = (function (_ref) {
6
6
  var label = _ref.label,
7
- checked = _ref.checked;
7
+ checked = _ref.checked,
8
+ disabled = _ref.disabled;
8
9
  return jsxs(Space, {
9
10
  children: [jsx(Checkbox, {
10
- checked: checked
11
+ checked: checked,
12
+ disabled: disabled
11
13
  }), label]
12
14
  });
13
15
  });
@@ -11,10 +11,14 @@ var defaultModeConfig = {
11
11
  var checkVal = value === null || value === void 0 ? void 0 : value.map(function (itemVal) {
12
12
  return itemVal.value;
13
13
  });
14
+ var label = item.label,
15
+ disabled = item.disabled,
16
+ itemVal = item.value;
14
17
  var newVal = checkVal || [];
15
- var checked = newVal.indexOf(item.value) !== -1;
18
+ var checked = newVal.indexOf(itemVal) !== -1;
16
19
  return jsx(CheckBoxOption, {
17
- label: item.label,
20
+ disabled: disabled,
21
+ label: label,
18
22
  checked: checked
19
23
  });
20
24
  }
@@ -180,10 +180,14 @@ var useValueChange = function useValueChange(params) {
180
180
  onChange(newChangeVal, subItemOps);
181
181
  };
182
182
  useEffect(function () {
183
- if (mode === "tags" || value === null || value === undefined) {
183
+ if (mode === "tags") {
184
184
  setVal(value);
185
185
  return;
186
186
  }
187
+ if (value === null || value === undefined) {
188
+ setVal(undefined);
189
+ return;
190
+ }
187
191
  if (options) {
188
192
  setVal(function (oldVale) {
189
193
  return matchNotFind(params, oldVale);
@@ -119,6 +119,7 @@ var Index = function Index(_ref) {
119
119
  mode: mode,
120
120
  value: val,
121
121
  onChange: change,
122
+ fieldNames: fieldNames,
122
123
  children: node
123
124
  })
124
125
  });
@@ -72,7 +72,6 @@ var useHForm = (function () {
72
72
  if (!format) {
73
73
  return;
74
74
  }
75
- console.log(name, "nnnnnnnn");
76
75
  var inputValue = format.inputValue,
77
76
  outputValue = format.outputValue;
78
77
  formatSourceData[name] = {
@@ -3,10 +3,13 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  require('core-js/modules/es.array.concat.js');
6
+ require('core-js/modules/es.array.filter.js');
7
+ require('core-js/modules/es.object.to-string.js');
6
8
  var jsxRuntime = require('react/jsx-runtime');
7
9
  var antd = require('antd');
8
10
  var utils = require('../utils.js');
9
11
  var index = require('../../hooks/index.js');
12
+ var React = require('react');
10
13
 
11
14
  var useRootClassName = function useRootClassName(checked) {
12
15
  var norClassNames = ["select-item", "select-item-option"];
@@ -22,20 +25,31 @@ var Index = function Index(_ref) {
22
25
  _ref$fieldNames = _ref.fieldNames,
23
26
  fieldNames = _ref$fieldNames === void 0 ? {} : _ref$fieldNames,
24
27
  children = _ref.children;
25
- var opLen = (options === null || options === void 0 ? void 0 : options.length) || 0;
28
+ var notDisOption = React.useMemo(function () {
29
+ return options === null || options === void 0 ? void 0 : options.filter(function (item) {
30
+ return !item.disabled;
31
+ });
32
+ }, [options]);
33
+ var opLen = (notDisOption === null || notDisOption === void 0 ? void 0 : notDisOption.length) || 0;
26
34
  var checked = (value === null || value === void 0 ? void 0 : value.length) >= opLen;
27
35
  var classNames = useRootClassName(checked);
28
36
  var optionsClassName = index.useClassName(classNames);
29
37
  var allCheckBox = index.useClassName("hw-all-check-box");
38
+ var allCheck = function allCheck() {
39
+ var allCheckOption = options === null || options === void 0 ? void 0 : options.filter(function (item) {
40
+ return !item.disabled;
41
+ });
42
+ var subItemOps = utils.itemOpProvider(allCheckOption, fieldNames);
43
+ onChange === null || onChange === void 0 || onChange(allCheckOption, subItemOps);
44
+ };
30
45
  var change = function change() {
31
46
  if (!checked) {
32
- var subItemOps = utils.itemOpProvider(options, fieldNames);
33
- onChange === null || onChange === void 0 || onChange(options, subItemOps);
47
+ allCheck();
34
48
  return;
35
49
  }
36
50
  onChange === null || onChange === void 0 || onChange([], []);
37
51
  };
38
- if (!allSelect || mode !== "multiple" || serviceSearch) {
52
+ if (!allSelect || mode !== "multiple" || serviceSearch || opLen === 0) {
39
53
  return jsxRuntime.jsx(jsxRuntime.Fragment, {
40
54
  children: children
41
55
  });
@@ -2,6 +2,7 @@ import React from "react";
2
2
  interface ICheckBoxOptionProps {
3
3
  label?: React.ReactNode;
4
4
  checked: boolean;
5
+ disabled?: boolean;
5
6
  }
6
- declare const _default: ({ label, checked }: ICheckBoxOptionProps) => JSX.Element;
7
+ declare const _default: ({ label, checked, disabled }: ICheckBoxOptionProps) => JSX.Element;
7
8
  export default _default;
@@ -7,10 +7,12 @@ var antd = require('antd');
7
7
 
8
8
  var CheckBoxOption = (function (_ref) {
9
9
  var label = _ref.label,
10
- checked = _ref.checked;
10
+ checked = _ref.checked,
11
+ disabled = _ref.disabled;
11
12
  return jsxRuntime.jsxs(antd.Space, {
12
13
  children: [jsxRuntime.jsx(antd.Checkbox, {
13
- checked: checked
14
+ checked: checked,
15
+ disabled: disabled
14
16
  }), label]
15
17
  });
16
18
  });
@@ -12,10 +12,14 @@ var defaultModeConfig = {
12
12
  var checkVal = value === null || value === void 0 ? void 0 : value.map(function (itemVal) {
13
13
  return itemVal.value;
14
14
  });
15
+ var label = item.label,
16
+ disabled = item.disabled,
17
+ itemVal = item.value;
15
18
  var newVal = checkVal || [];
16
- var checked = newVal.indexOf(item.value) !== -1;
19
+ var checked = newVal.indexOf(itemVal) !== -1;
17
20
  return jsxRuntime.jsx(CheckBoxOption.default, {
18
- label: item.label,
21
+ disabled: disabled,
22
+ label: label,
19
23
  checked: checked
20
24
  });
21
25
  }
@@ -181,10 +181,14 @@ var useValueChange = function useValueChange(params) {
181
181
  onChange(newChangeVal, subItemOps);
182
182
  };
183
183
  React.useEffect(function () {
184
- if (mode === "tags" || value === null || value === undefined) {
184
+ if (mode === "tags") {
185
185
  setVal(value);
186
186
  return;
187
187
  }
188
+ if (value === null || value === undefined) {
189
+ setVal(undefined);
190
+ return;
191
+ }
188
192
  if (options) {
189
193
  setVal(function (oldVale) {
190
194
  return matchNotFind(params, oldVale);
@@ -122,6 +122,7 @@ var Index = function Index(_ref) {
122
122
  mode: mode,
123
123
  value: val,
124
124
  onChange: change,
125
+ fieldNames: fieldNames,
125
126
  children: node
126
127
  })
127
128
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "1.4.3",
3
+ "version": "1.4.6",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -55,7 +55,6 @@ export default () => {
55
55
  if (!format) {
56
56
  return;
57
57
  }
58
- console.log(name,"nnnnnnnn")
59
58
  const { inputValue, outputValue } = format;
60
59
  formatSourceData[name] = {
61
60
  inputValue,
@@ -2,7 +2,7 @@ import type { HSelectProps } from "@/components/Select/modal";
2
2
  import { Checkbox, Space } from "antd";
3
3
  import { itemOpProvider } from "../utils";
4
4
  import { useClassName } from "../../hooks";
5
- import React from "react";
5
+ import React, {useMemo} from "react";
6
6
 
7
7
  interface IProps extends HSelectProps {
8
8
  checked?: boolean;
@@ -23,20 +23,31 @@ const Index: React.FC<IProps> = ({
23
23
  fieldNames = {},
24
24
  children,
25
25
  }) => {
26
- const opLen = options?.length || 0;
26
+ const notDisOption=useMemo(()=>{
27
+ return options?.filter((item)=>{
28
+ return !item.disabled;
29
+ })
30
+ },[options]);
31
+ const opLen = notDisOption?.length || 0;
27
32
  const checked = (value as any[])?.length >= opLen;
28
33
  const classNames = useRootClassName(checked);
29
34
  const optionsClassName = useClassName(classNames);
30
35
  const allCheckBox = useClassName("hw-all-check-box");
36
+ const allCheck=()=>{
37
+ const allCheckOption=options?.filter((item)=>{
38
+ return !item.disabled;
39
+ });
40
+ const subItemOps=itemOpProvider(allCheckOption,fieldNames);
41
+ onChange?.(allCheckOption, subItemOps);
42
+ }
31
43
  const change = () => {
32
44
  if (!checked) {
33
- const subItemOps = itemOpProvider(options, fieldNames);
34
- onChange?.(options, subItemOps);
45
+ allCheck();
35
46
  return;
36
47
  }
37
48
  onChange?.([], []);
38
49
  };
39
- if (!allSelect || mode !== "multiple" || serviceSearch) {
50
+ if (!allSelect || mode !== "multiple" || serviceSearch||opLen===0) {
40
51
  return <>{children}</>;
41
52
  }
42
53
  return (
@@ -3,11 +3,12 @@ import React from "react";
3
3
  interface ICheckBoxOptionProps {
4
4
  label?: React.ReactNode;
5
5
  checked: boolean;
6
+ disabled?:boolean;
6
7
  }
7
- export default ({ label, checked }: ICheckBoxOptionProps) => {
8
+ export default ({ label, checked ,disabled}: ICheckBoxOptionProps) => {
8
9
  return (
9
10
  <Space>
10
- <Checkbox checked={checked} />
11
+ <Checkbox checked={checked} disabled={disabled}/>
11
12
  {label}
12
13
  </Space>
13
14
  );
@@ -9,9 +9,10 @@ export const defaultModeConfig: HSelectProps["modeConfig"] = {
9
9
  const checkVal = value?.map((itemVal) => {
10
10
  return itemVal.value;
11
11
  });
12
+ const {label,disabled,value:itemVal}=item;
12
13
  const newVal = checkVal || [];
13
- const checked = newVal.indexOf(item.value) !== -1;
14
- return <CheckBoxOption label={item.label} checked={checked} />;
14
+ const checked = newVal.indexOf(itemVal) !== -1;
15
+ return <CheckBoxOption disabled={disabled} label={label} checked={checked} />;
15
16
  },
16
17
  },
17
18
  };
@@ -142,10 +142,14 @@ export const useValueChange = (params: PartialHSelectProps) => {
142
142
  onChange(newChangeVal, subItemOps);
143
143
  };
144
144
  useEffect(() => {
145
- if (mode === "tags" || value === null || value === undefined) {
145
+ if (mode === "tags" ) {
146
146
  setVal(value);
147
147
  return;
148
148
  }
149
+ if (value===null||value===undefined){
150
+ setVal(undefined);
151
+ return;
152
+ }
149
153
  if (options) {
150
154
  setVal((oldVale) => {
151
155
  return matchNotFind(params, oldVale);
@@ -90,6 +90,7 @@ const Index: React.FC<HSelectProps> = ({
90
90
  mode={mode}
91
91
  value={val}
92
92
  onChange={change}
93
+ fieldNames={fieldNames}
93
94
  >
94
95
  {node}
95
96
  </AllSelect>
@@ -2,7 +2,7 @@ import { HSelect } from "../../components";
2
2
  import { Space } from "antd";
3
3
  import { useState } from "react";
4
4
  export default () => {
5
- const [selectVal, setSelectVal] = useState([10]);
5
+ const [selectVal, setSelectVal] = useState(null);
6
6
  return (
7
7
  <Space size={"large"} direction={"vertical"} style={{ width: "100%" }}>
8
8
  <HSelect
@@ -14,13 +14,12 @@ export default () => {
14
14
  <HSelect
15
15
  fieldNames={{ label: "name", value: "value" }}
16
16
  options={[
17
- { name: "测试1", value: 10, userId: 112321 },
17
+ { name: "测试1", value: 10, userId: 112321,disabled:true },
18
18
  { name: "测试2", value: 20, userId: 112321 },
19
19
  ]}
20
20
  placeholder="多选"
21
21
  value={selectVal}
22
22
  onChange={(val, option) => {
23
- console.log(option);
24
23
  setSelectVal(val);
25
24
  }}
26
25
  allSelect={true}