@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.
- package/es/Form/hooks/useHForm.js +0 -1
- package/es/Select/components/AllSelect.js +18 -4
- package/es/Select/components/CheckBoxOption.d.ts +2 -1
- package/es/Select/components/CheckBoxOption.js +4 -2
- package/es/Select/defaultConfig.js +6 -2
- package/es/Select/hooks/changeHooks.js +5 -1
- package/es/Select/index.js +1 -0
- package/lib/Form/hooks/useHForm.js +0 -1
- package/lib/Select/components/AllSelect.js +18 -4
- package/lib/Select/components/CheckBoxOption.d.ts +2 -1
- package/lib/Select/components/CheckBoxOption.js +4 -2
- package/lib/Select/defaultConfig.js +6 -2
- package/lib/Select/hooks/changeHooks.js +5 -1
- package/lib/Select/index.js +1 -0
- package/package.json +1 -1
- package/src/components/Form/hooks/useHForm.ts +0 -1
- package/src/components/Select/components/AllSelect.tsx +16 -5
- package/src/components/Select/components/CheckBoxOption.tsx +3 -2
- package/src/components/Select/defaultConfig.tsx +3 -2
- package/src/components/Select/hooks/changeHooks.tsx +5 -1
- package/src/components/Select/index.tsx +1 -0
- package/src/pages/Select/index.tsx +2 -3
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
18
|
+
var checked = newVal.indexOf(itemVal) !== -1;
|
|
16
19
|
return jsx(CheckBoxOption, {
|
|
17
|
-
|
|
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"
|
|
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);
|
package/es/Select/index.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
19
|
+
var checked = newVal.indexOf(itemVal) !== -1;
|
|
17
20
|
return jsxRuntime.jsx(CheckBoxOption.default, {
|
|
18
|
-
|
|
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"
|
|
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);
|
package/lib/Select/index.js
CHANGED
package/package.json
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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(
|
|
14
|
-
return <CheckBoxOption label={
|
|
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"
|
|
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);
|
|
@@ -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(
|
|
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}
|