@hw-component/form 0.0.1
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/.babelrc +23 -0
- package/.eslintrc.js +8 -0
- package/.husky/pre-commit +4 -0
- package/.stylelintrc.js +5 -0
- package/es/Select/components/AllSelect.d.ts +7 -0
- package/es/Select/components/AllSelect.js +34 -0
- package/es/Select/components/CheckBoxOption.d.ts +7 -0
- package/es/Select/components/CheckBoxOption.js +14 -0
- package/es/Select/components/DropdownComponent.d.ts +9 -0
- package/es/Select/components/DropdownComponent.js +39 -0
- package/es/Select/components/NoFindItem.d.ts +6 -0
- package/es/Select/components/NoFindItem.js +13 -0
- package/es/Select/components/NotFoundContent.d.ts +7 -0
- package/es/Select/components/NotFoundContent.js +40 -0
- package/es/Select/defaultConfig.d.ts +7 -0
- package/es/Select/defaultConfig.js +37 -0
- package/es/Select/hooks/changeHooks.d.ts +5 -0
- package/es/Select/hooks/changeHooks.js +190 -0
- package/es/Select/hooks/norHooks.d.ts +12 -0
- package/es/Select/hooks/norHooks.js +102 -0
- package/es/Select/index.d.ts +4 -0
- package/es/Select/index.js +116 -0
- package/es/Select/index.less.js +5 -0
- package/es/Select/modal.d.ts +30 -0
- package/es/index.css +3 -0
- package/es/index.d.ts +1 -0
- package/es/index.js +3 -0
- package/lib/Select/components/AllSelect.d.ts +7 -0
- package/lib/Select/components/AllSelect.js +37 -0
- package/lib/Select/components/CheckBoxOption.d.ts +7 -0
- package/lib/Select/components/CheckBoxOption.js +17 -0
- package/lib/Select/components/DropdownComponent.d.ts +9 -0
- package/lib/Select/components/DropdownComponent.js +42 -0
- package/lib/Select/components/NoFindItem.d.ts +6 -0
- package/lib/Select/components/NoFindItem.js +16 -0
- package/lib/Select/components/NotFoundContent.d.ts +7 -0
- package/lib/Select/components/NotFoundContent.js +43 -0
- package/lib/Select/defaultConfig.d.ts +7 -0
- package/lib/Select/defaultConfig.js +40 -0
- package/lib/Select/hooks/changeHooks.d.ts +5 -0
- package/lib/Select/hooks/changeHooks.js +191 -0
- package/lib/Select/hooks/norHooks.d.ts +12 -0
- package/lib/Select/hooks/norHooks.js +104 -0
- package/lib/Select/index.d.ts +4 -0
- package/lib/Select/index.js +119 -0
- package/lib/Select/index.less.js +8 -0
- package/lib/Select/modal.d.ts +30 -0
- package/lib/index.css +3 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +8 -0
- package/package.json +80 -0
- package/public/index.html +19 -0
- package/scripts/rollup.config.js +80 -0
- package/scripts/webpack.config.js +72 -0
- package/src/Layout.tsx +61 -0
- package/src/app.tsx +33 -0
- package/src/components/Select/components/AllSelect.tsx +38 -0
- package/src/components/Select/components/CheckBoxOption.tsx +14 -0
- package/src/components/Select/components/DropdownComponent.tsx +35 -0
- package/src/components/Select/components/NoFindItem.tsx +7 -0
- package/src/components/Select/components/NotFoundContent.tsx +25 -0
- package/src/components/Select/defaultConfig.tsx +28 -0
- package/src/components/Select/hooks/changeHooks.tsx +141 -0
- package/src/components/Select/hooks/norHooks.ts +74 -0
- package/src/components/Select/index.less +5 -0
- package/src/components/Select/index.tsx +108 -0
- package/src/components/Select/modal.ts +30 -0
- package/src/components/index.tsx +1 -0
- package/src/components/typings.d.ts +11 -0
- package/src/index.less +20 -0
- package/src/index.tsx +12 -0
- package/src/pages/Select/index.tsx +54 -0
- package/src/routes.tsx +35 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _asyncToGenerator = require('@babel/runtime-corejs3/helpers/asyncToGenerator');
|
|
4
|
+
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
5
|
+
var _regeneratorRuntime = require('@babel/runtime-corejs3/regenerator');
|
|
6
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
7
|
+
var _Promise = require('@babel/runtime-corejs3/core-js/promise');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
var ahooks = require('ahooks');
|
|
10
|
+
|
|
11
|
+
var resultProvider = function resultProvider(data, fieldNames) {
|
|
12
|
+
return data === null || data === void 0 ? void 0 : _mapInstanceProperty(data).call(data, function (item) {
|
|
13
|
+
var _ref = fieldNames || {},
|
|
14
|
+
_ref$label = _ref.label,
|
|
15
|
+
label = _ref$label === void 0 ? "label" : _ref$label,
|
|
16
|
+
_ref$value = _ref.value,
|
|
17
|
+
value = _ref$value === void 0 ? "value" : _ref$value;
|
|
18
|
+
return {
|
|
19
|
+
label: item[label],
|
|
20
|
+
value: item[value]
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
var useOptionReq = function useOptionReq(_ref2) {
|
|
25
|
+
var manual = _ref2.manual,
|
|
26
|
+
fieldNames = _ref2.fieldNames,
|
|
27
|
+
request = _ref2.request,
|
|
28
|
+
options = _ref2.options,
|
|
29
|
+
serviceSearch = _ref2.serviceSearch;
|
|
30
|
+
var _useState = React.useState(),
|
|
31
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
32
|
+
data = _useState2[0],
|
|
33
|
+
setData = _useState2[1];
|
|
34
|
+
var _useRequest = ahooks.useRequest( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
35
|
+
var params,
|
|
36
|
+
type,
|
|
37
|
+
result,
|
|
38
|
+
resultOpt,
|
|
39
|
+
_args = arguments;
|
|
40
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
41
|
+
while (1) switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
params = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
44
|
+
type = _args.length > 1 && _args[1] !== undefined ? _args[1] : "init";
|
|
45
|
+
if (type === "init") {
|
|
46
|
+
setData(undefined);
|
|
47
|
+
}
|
|
48
|
+
if (!request) {
|
|
49
|
+
_context.next = 8;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
_context.next = 6;
|
|
53
|
+
return request(params);
|
|
54
|
+
case 6:
|
|
55
|
+
result = _context.sent;
|
|
56
|
+
return _context.abrupt("return", resultProvider(result, fieldNames));
|
|
57
|
+
case 8:
|
|
58
|
+
resultOpt = resultProvider(options, fieldNames);
|
|
59
|
+
return _context.abrupt("return", _Promise.resolve(resultOpt));
|
|
60
|
+
case 10:
|
|
61
|
+
case "end":
|
|
62
|
+
return _context.stop();
|
|
63
|
+
}
|
|
64
|
+
}, _callee);
|
|
65
|
+
})), {
|
|
66
|
+
manual: manual,
|
|
67
|
+
debounceInterval: 300,
|
|
68
|
+
onSuccess: function onSuccess(resultData) {
|
|
69
|
+
setData(resultData);
|
|
70
|
+
}
|
|
71
|
+
}),
|
|
72
|
+
run = _useRequest.run,
|
|
73
|
+
loading = _useRequest.loading,
|
|
74
|
+
error = _useRequest.error;
|
|
75
|
+
var onSearch = function onSearch(inputValue) {
|
|
76
|
+
if (!serviceSearch) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
run({
|
|
80
|
+
inputValue: inputValue
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
return {
|
|
84
|
+
run: run,
|
|
85
|
+
loading: loading,
|
|
86
|
+
error: error,
|
|
87
|
+
data: data,
|
|
88
|
+
onSearch: onSearch
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
var useFilterOption = function useFilterOption(_ref4) {
|
|
92
|
+
var filterOption = _ref4.filterOption,
|
|
93
|
+
serviceSearch = _ref4.serviceSearch;
|
|
94
|
+
if (serviceSearch) {
|
|
95
|
+
return function () {
|
|
96
|
+
return true;
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
return filterOption;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
exports.useFilterOption = useFilterOption;
|
|
103
|
+
exports.useOptionReq = useOptionReq;
|
|
104
|
+
// powered by h
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { HSelectProps } from "./modal";
|
|
3
|
+
declare const _default: ({ style, mode, options, modeConfig, value, onChange, fieldNames, request, manual, optionLabelProp, filterProvider, optionFilterProp, serviceSearch, onSearch: propsOnSearch, filterOption, showSearch, labelInValue, noMatchItemRender, allSelect, ...props }: HSelectProps) => JSX.Element;
|
|
4
|
+
export default _default;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var _extends = require('@babel/runtime-corejs3/helpers/extends');
|
|
6
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
7
|
+
var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
|
|
8
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js/instance/map');
|
|
9
|
+
var antd = require('antd');
|
|
10
|
+
var React = require('react');
|
|
11
|
+
var norHooks = require('./hooks/norHooks.js');
|
|
12
|
+
var changeHooks = require('./hooks/changeHooks.js');
|
|
13
|
+
var defaultConfig = require('./defaultConfig.js');
|
|
14
|
+
var DropdownComponent = require('./components/DropdownComponent.js');
|
|
15
|
+
var AllSelect = require('./components/AllSelect.js');
|
|
16
|
+
|
|
17
|
+
var _excluded = ["style", "mode", "options", "modeConfig", "value", "onChange", "fieldNames", "request", "manual", "optionLabelProp", "filterProvider", "optionFilterProp", "serviceSearch", "onSearch", "filterOption", "showSearch", "labelInValue", "noMatchItemRender", "allSelect"];
|
|
18
|
+
var Option = antd.Select.Option;
|
|
19
|
+
var index = (function (_ref) {
|
|
20
|
+
var _ref$style = _ref.style,
|
|
21
|
+
style = _ref$style === void 0 ? {
|
|
22
|
+
width: "100%"
|
|
23
|
+
} : _ref$style,
|
|
24
|
+
mode = _ref.mode,
|
|
25
|
+
options = _ref.options,
|
|
26
|
+
_ref$modeConfig = _ref.modeConfig,
|
|
27
|
+
modeConfig = _ref$modeConfig === void 0 ? defaultConfig.defaultModeConfig : _ref$modeConfig,
|
|
28
|
+
value = _ref.value,
|
|
29
|
+
onChange = _ref.onChange,
|
|
30
|
+
_ref$fieldNames = _ref.fieldNames,
|
|
31
|
+
fieldNames = _ref$fieldNames === void 0 ? defaultConfig.defaultFieldNames : _ref$fieldNames,
|
|
32
|
+
request = _ref.request,
|
|
33
|
+
manual = _ref.manual,
|
|
34
|
+
_ref$optionLabelProp = _ref.optionLabelProp,
|
|
35
|
+
optionLabelProp = _ref$optionLabelProp === void 0 ? "label" : _ref$optionLabelProp,
|
|
36
|
+
filterProvider = _ref.filterProvider,
|
|
37
|
+
_ref$optionFilterProp = _ref.optionFilterProp,
|
|
38
|
+
optionFilterProp = _ref$optionFilterProp === void 0 ? "filterlabel" : _ref$optionFilterProp,
|
|
39
|
+
serviceSearch = _ref.serviceSearch,
|
|
40
|
+
propsOnSearch = _ref.onSearch,
|
|
41
|
+
filterOption = _ref.filterOption,
|
|
42
|
+
showSearch = _ref.showSearch,
|
|
43
|
+
labelInValue = _ref.labelInValue,
|
|
44
|
+
_ref$noMatchItemRende = _ref.noMatchItemRender,
|
|
45
|
+
noMatchItemRender = _ref$noMatchItemRende === void 0 ? defaultConfig.defaultSelectConfig.noMatchItemRender : _ref$noMatchItemRende,
|
|
46
|
+
allSelect = _ref.allSelect,
|
|
47
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
48
|
+
var _ref2 = (modeConfig === null || modeConfig === void 0 ? void 0 : modeConfig[mode || ""]) || {},
|
|
49
|
+
icon = _ref2.icon,
|
|
50
|
+
render = _ref2.render;
|
|
51
|
+
var selfFilterOption = norHooks.useFilterOption({
|
|
52
|
+
filterOption: filterOption,
|
|
53
|
+
serviceSearch: serviceSearch
|
|
54
|
+
});
|
|
55
|
+
var _useOptionReq = norHooks.useOptionReq({
|
|
56
|
+
options: options,
|
|
57
|
+
manual: manual,
|
|
58
|
+
fieldNames: fieldNames,
|
|
59
|
+
request: request,
|
|
60
|
+
serviceSearch: serviceSearch
|
|
61
|
+
}),
|
|
62
|
+
run = _useOptionReq.run,
|
|
63
|
+
loading = _useOptionReq.loading,
|
|
64
|
+
data = _useOptionReq.data,
|
|
65
|
+
error = _useOptionReq.error,
|
|
66
|
+
onSearch = _useOptionReq.onSearch;
|
|
67
|
+
var _useValueChange = changeHooks.useValueChange({
|
|
68
|
+
labelInValue: labelInValue,
|
|
69
|
+
onChange: onChange,
|
|
70
|
+
value: value,
|
|
71
|
+
options: data,
|
|
72
|
+
mode: mode,
|
|
73
|
+
noMatchItemRender: noMatchItemRender
|
|
74
|
+
}),
|
|
75
|
+
val = _useValueChange.val,
|
|
76
|
+
change = _useValueChange.change;
|
|
77
|
+
return /*#__PURE__*/React.createElement(antd.Select, _extends({
|
|
78
|
+
style: style,
|
|
79
|
+
mode: mode,
|
|
80
|
+
loading: loading,
|
|
81
|
+
value: val,
|
|
82
|
+
onSearch: propsOnSearch || onSearch,
|
|
83
|
+
onChange: change,
|
|
84
|
+
dropdownRender: function dropdownRender(node) {
|
|
85
|
+
return /*#__PURE__*/React.createElement(DropdownComponent.default, {
|
|
86
|
+
loading: loading,
|
|
87
|
+
reload: run,
|
|
88
|
+
error: error,
|
|
89
|
+
options: data
|
|
90
|
+
}, /*#__PURE__*/React.createElement(AllSelect.default, {
|
|
91
|
+
allSelect: allSelect,
|
|
92
|
+
options: data,
|
|
93
|
+
mode: mode,
|
|
94
|
+
value: val,
|
|
95
|
+
onChange: change
|
|
96
|
+
}), node);
|
|
97
|
+
},
|
|
98
|
+
optionLabelProp: optionLabelProp,
|
|
99
|
+
menuItemSelectedIcon: icon,
|
|
100
|
+
optionFilterProp: optionFilterProp,
|
|
101
|
+
filterOption: selfFilterOption,
|
|
102
|
+
showSearch: showSearch,
|
|
103
|
+
labelInValue: true
|
|
104
|
+
}, props), data === null || data === void 0 ? void 0 : _mapInstanceProperty(data).call(data, function (item) {
|
|
105
|
+
var optionValue = item.value,
|
|
106
|
+
label = item.label;
|
|
107
|
+
var result = (filterProvider === null || filterProvider === void 0 ? void 0 : filterProvider(item)) || label;
|
|
108
|
+
var filer = _defineProperty({}, optionFilterProp, result);
|
|
109
|
+
return /*#__PURE__*/React.createElement(Option, _extends({
|
|
110
|
+
value: optionValue,
|
|
111
|
+
key: optionValue,
|
|
112
|
+
label: label,
|
|
113
|
+
mode: mode
|
|
114
|
+
}, filer), render ? render(item, val) : label);
|
|
115
|
+
}));
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
exports.default = index;
|
|
119
|
+
// powered by h
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { SelectProps } from "antd";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
export type OptionType = Record<string, any>;
|
|
4
|
+
export type PartialHSelectProps = Partial<HSelectProps>;
|
|
5
|
+
export type RenderFn = (data: OptionType) => React.ReactNode;
|
|
6
|
+
interface ModeConfigItem {
|
|
7
|
+
icon?: React.ReactNode | null;
|
|
8
|
+
render?: (item: OptionType, value: any[]) => React.ReactNode;
|
|
9
|
+
}
|
|
10
|
+
export interface ModeConfig {
|
|
11
|
+
multiple?: ModeConfigItem;
|
|
12
|
+
tags?: ModeConfigItem;
|
|
13
|
+
}
|
|
14
|
+
export interface HSelectProps extends Omit<SelectProps, "options"> {
|
|
15
|
+
style?: React.CSSProperties;
|
|
16
|
+
request?: (params: any) => Promise<OptionType[]>;
|
|
17
|
+
manual?: boolean;
|
|
18
|
+
modeConfig?: ModeConfig;
|
|
19
|
+
onChange?: (val: any) => void;
|
|
20
|
+
filterProvider?: (item: any) => string;
|
|
21
|
+
serviceSearch?: boolean;
|
|
22
|
+
options?: OptionType[];
|
|
23
|
+
noMatchItemRender?: RenderFn;
|
|
24
|
+
allSelect?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface FilterDataModal {
|
|
27
|
+
value: any;
|
|
28
|
+
index: number;
|
|
29
|
+
}
|
|
30
|
+
export {};
|
package/lib/index.css
ADDED
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as HSelect } from './Select';
|
package/lib/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hw-component/form",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "基于antd二次开发",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://gitee.com/hdj_wq/hw-components.git"
|
|
8
|
+
},
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"author": "hdj",
|
|
11
|
+
"main": "lib/index.js",
|
|
12
|
+
"module": "es/index.js",
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup --config ./scripts/rollup.config.js",
|
|
15
|
+
"lint:fix": "eslint --fix --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src && npm run lint:style",
|
|
16
|
+
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
|
|
17
|
+
"lint:style": "stylelint --fix \"src/**/*.less\" --syntax less",
|
|
18
|
+
"prepare": "husky install",
|
|
19
|
+
"start": "webpack-dev-server --config ./scripts/webpack.config.js",
|
|
20
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
21
|
+
},
|
|
22
|
+
"lint-staged": {
|
|
23
|
+
"**/*.less": "npm run lint:style",
|
|
24
|
+
"**/*.{js,jsx,ts,tsx}": "npm run lint:fix",
|
|
25
|
+
"**/*.{js,jsx,tsx,ts,less,md,json}": [
|
|
26
|
+
"prettier --write"
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"ahooks": "2.10.9",
|
|
31
|
+
"antd": "4.19.0",
|
|
32
|
+
"react": "16.14.0",
|
|
33
|
+
"react-dom": "17.0.2",
|
|
34
|
+
"react-router-dom": "^6.11.2"
|
|
35
|
+
},
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"@babel/core": "^7.21.8",
|
|
38
|
+
"@babel/plugin-transform-runtime": "^7.21.4",
|
|
39
|
+
"@babel/preset-env": "^7.21.5",
|
|
40
|
+
"@babel/preset-react": "^7.18.6",
|
|
41
|
+
"@babel/preset-typescript": "^7.21.5",
|
|
42
|
+
"@babel/runtime-corejs3": "^7.21.5",
|
|
43
|
+
"@rollup/plugin-babel": "^6.0.3",
|
|
44
|
+
"@rollup/plugin-commonjs": "^25.0.0",
|
|
45
|
+
"@rollup/plugin-inject": "^5.0.3",
|
|
46
|
+
"@rollup/plugin-node-resolve": "^15.0.2",
|
|
47
|
+
"@rollup/plugin-url": "^8.0.1",
|
|
48
|
+
"@types/react": "17.0.14",
|
|
49
|
+
"@types/react-dom": "17.0.9",
|
|
50
|
+
"@typescript-eslint/eslint-plugin": "^5.59.7",
|
|
51
|
+
"@umijs/fabric": "^2.14.1",
|
|
52
|
+
"autoprefixer": "^10.4.14",
|
|
53
|
+
"babel-loader": "^9.1.2",
|
|
54
|
+
"css-loader": "^6.7.4",
|
|
55
|
+
"eslint": "^8.41.0",
|
|
56
|
+
"eslint-plugin-jest": "^27.2.1",
|
|
57
|
+
"eslint-plugin-react": "^7.32.2",
|
|
58
|
+
"eslint-plugin-react-hooks": "^4.6.0",
|
|
59
|
+
"eslint-plugin-unicorn": "^47.0.0",
|
|
60
|
+
"html-webpack-plugin": "^5.5.1",
|
|
61
|
+
"husky": "^8.0.3",
|
|
62
|
+
"less": "^4.1.3",
|
|
63
|
+
"less-loader": "^11.1.0",
|
|
64
|
+
"lint-staged": "10.5.4",
|
|
65
|
+
"postcss": "^8.4.23",
|
|
66
|
+
"postcss-less": "^6.0.0",
|
|
67
|
+
"rollup": "^3.23.0",
|
|
68
|
+
"rollup-plugin-clear": "^2.0.7",
|
|
69
|
+
"rollup-plugin-postcss": "^4.0.2",
|
|
70
|
+
"rollup-plugin-typescript2": "^0.34.1",
|
|
71
|
+
"style-loader": "^3.3.3",
|
|
72
|
+
"stylelint": "13.13.1",
|
|
73
|
+
"typescript": "^5.0.4",
|
|
74
|
+
"webpack": "^5.83.1",
|
|
75
|
+
"webpack-cli": "^5.1.1",
|
|
76
|
+
"webpack-dev-server": "^4.15.0",
|
|
77
|
+
"webpackbar": "^5.0.2"
|
|
78
|
+
},
|
|
79
|
+
"cssPrefix": "hw"
|
|
80
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
7
|
+
<meta name="viewport" content="webpack5">
|
|
8
|
+
<title>hw-components</title>
|
|
9
|
+
<style>
|
|
10
|
+
body{
|
|
11
|
+
margin: 0px;
|
|
12
|
+
padding: 0px;
|
|
13
|
+
}
|
|
14
|
+
</style>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<div id="root"></div>
|
|
18
|
+
</body>
|
|
19
|
+
</html>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const clear = require("rollup-plugin-clear");
|
|
3
|
+
const { nodeResolve } = require("@rollup/plugin-node-resolve");
|
|
4
|
+
const { babel } = require("@rollup/plugin-babel");
|
|
5
|
+
const commonjs = require("@rollup/plugin-commonjs");
|
|
6
|
+
const typescript = require("rollup-plugin-typescript2");
|
|
7
|
+
const postcss = require("rollup-plugin-postcss");
|
|
8
|
+
const autoprefixer = require("autoprefixer");
|
|
9
|
+
const inject = require("@rollup/plugin-inject");
|
|
10
|
+
const url = require("@rollup/plugin-url");
|
|
11
|
+
const pkg = require("../package.json");
|
|
12
|
+
const prefix = pkg.cssPrefix;
|
|
13
|
+
const input = path.resolve(__dirname, "../src/components/index.tsx");
|
|
14
|
+
const outDir = path.resolve(__dirname, "../lib");
|
|
15
|
+
const esOutDir = path.resolve(__dirname, "../es");
|
|
16
|
+
module.exports = {
|
|
17
|
+
input,
|
|
18
|
+
output: [
|
|
19
|
+
{
|
|
20
|
+
dir: outDir,
|
|
21
|
+
format: "cjs",
|
|
22
|
+
footer: "// powered by h",
|
|
23
|
+
entryFileNames: "[name].js",
|
|
24
|
+
exports: "named",
|
|
25
|
+
preserveModules: true,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
dir: esOutDir,
|
|
29
|
+
format: "es",
|
|
30
|
+
banner: "// welcome to ww-building-blocks-tmp",
|
|
31
|
+
footer: "// powered by ww",
|
|
32
|
+
entryFileNames: "[name].js",
|
|
33
|
+
exports: "named",
|
|
34
|
+
preserveModules: true,
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
plugins: [
|
|
38
|
+
clear({
|
|
39
|
+
targets: [outDir, esOutDir],
|
|
40
|
+
}),
|
|
41
|
+
url({
|
|
42
|
+
fileName: "[dirname][hash][extname]",
|
|
43
|
+
}),
|
|
44
|
+
postcss({
|
|
45
|
+
extract: "index.css",
|
|
46
|
+
modules: {
|
|
47
|
+
generateScopedName: `${prefix}_[local]`,
|
|
48
|
+
},
|
|
49
|
+
plugins: [
|
|
50
|
+
autoprefixer({
|
|
51
|
+
overrideBrowserslist: [
|
|
52
|
+
"last 10 Chrome versions",
|
|
53
|
+
"last 5 Firefox versions",
|
|
54
|
+
"Safari >= 6",
|
|
55
|
+
"ie> 8",
|
|
56
|
+
],
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
59
|
+
}),
|
|
60
|
+
typescript({
|
|
61
|
+
tsconfigOverride: {
|
|
62
|
+
include: [`src/components/**/*`],
|
|
63
|
+
},
|
|
64
|
+
}),
|
|
65
|
+
babel({
|
|
66
|
+
exclude: "node_modules/**",
|
|
67
|
+
extensions: [".ts", ".tsx", ".js", ".jsx"],
|
|
68
|
+
babelHelpers: "runtime",
|
|
69
|
+
}),
|
|
70
|
+
inject({
|
|
71
|
+
React: "react",
|
|
72
|
+
}),
|
|
73
|
+
nodeResolve({
|
|
74
|
+
resolveOnly: ["node_modules"], //定义为模块
|
|
75
|
+
}),
|
|
76
|
+
commonjs({
|
|
77
|
+
include: ["node_modules"],
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const path = require("path");
|
|
2
|
+
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
3
|
+
const WebpackBar = require("webpackbar");
|
|
4
|
+
const webpack = require("webpack");
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
mode: "development",
|
|
8
|
+
devtool: "cheap-module-source-map",
|
|
9
|
+
entry: {
|
|
10
|
+
app: path.resolve(__dirname, "../src/index.tsx"),
|
|
11
|
+
},
|
|
12
|
+
output: {
|
|
13
|
+
path: path.resolve("dist"),
|
|
14
|
+
publicPath: "/",
|
|
15
|
+
clean: true, //每次打包前清空目录
|
|
16
|
+
},
|
|
17
|
+
devServer: {
|
|
18
|
+
port: 3000,
|
|
19
|
+
compress: true,
|
|
20
|
+
open: true,
|
|
21
|
+
hot: true,
|
|
22
|
+
historyApiFallback: {
|
|
23
|
+
disableDotRule: true,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
module: {
|
|
27
|
+
rules: [
|
|
28
|
+
{
|
|
29
|
+
test: /\.(tsx?|ts)$/,
|
|
30
|
+
loader: "babel-loader",
|
|
31
|
+
options: { cacheDirectory: true },
|
|
32
|
+
exclude: /node_modules/,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
test: /\.css$/,
|
|
36
|
+
use: ["style-loader", "css-loader"],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
test: /\.less$/,
|
|
40
|
+
exclude: /node_modules/,
|
|
41
|
+
use: [
|
|
42
|
+
"style-loader",
|
|
43
|
+
{
|
|
44
|
+
loader: "css-loader",
|
|
45
|
+
options: {
|
|
46
|
+
modules: true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
"less-loader",
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
resolve: {
|
|
55
|
+
alias: {
|
|
56
|
+
"@": path.resolve(__dirname, "./src/components"),
|
|
57
|
+
},
|
|
58
|
+
extensions: [".tsx", ".ts", ".js", ".json"],
|
|
59
|
+
},
|
|
60
|
+
plugins: [
|
|
61
|
+
new HtmlWebpackPlugin({
|
|
62
|
+
template: path.resolve(__dirname, "../public/index.html"),
|
|
63
|
+
}),
|
|
64
|
+
new WebpackBar({
|
|
65
|
+
name: "hw components",
|
|
66
|
+
color: "#52c41a",
|
|
67
|
+
}),
|
|
68
|
+
new webpack.ProvidePlugin({
|
|
69
|
+
React: "react",
|
|
70
|
+
}),
|
|
71
|
+
],
|
|
72
|
+
};
|
package/src/Layout.tsx
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { Menu } from "antd";
|
|
3
|
+
import styles from "./index.less";
|
|
4
|
+
import type { RouteModal } from "./routes";
|
|
5
|
+
import routes from "./routes";
|
|
6
|
+
import { Outlet, useNavigate, useLocation } from "react-router-dom";
|
|
7
|
+
|
|
8
|
+
const menuItem = (item: RouteModal) => {
|
|
9
|
+
const { name, path, children } = item;
|
|
10
|
+
if (!path) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
if (children) {
|
|
14
|
+
return (
|
|
15
|
+
<Menu.SubMenu title={name} key={path}>
|
|
16
|
+
{children.map((childItem) => {
|
|
17
|
+
return menuItem(childItem);
|
|
18
|
+
})}
|
|
19
|
+
</Menu.SubMenu>
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
return <Menu.Item key={path}>{name}</Menu.Item>;
|
|
23
|
+
};
|
|
24
|
+
export default () => {
|
|
25
|
+
const navigate = useNavigate();
|
|
26
|
+
const { pathname } = useLocation();
|
|
27
|
+
const [keys, setKeys] = useState(["/form/select"]);
|
|
28
|
+
const [openKey, setOpenKey] = useState(["/form"]);
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
setKeys([pathname]);
|
|
31
|
+
const pathOpenKeys = pathname.split("/");
|
|
32
|
+
const openKeys = pathOpenKeys.map((path) => {
|
|
33
|
+
return "/" + path;
|
|
34
|
+
});
|
|
35
|
+
setOpenKey(openKeys);
|
|
36
|
+
}, [pathname]);
|
|
37
|
+
return (
|
|
38
|
+
<div className={styles.layout}>
|
|
39
|
+
<Menu
|
|
40
|
+
className={styles.menu}
|
|
41
|
+
selectedKeys={keys}
|
|
42
|
+
openKeys={openKey}
|
|
43
|
+
onOpenChange={(openKeys) => {
|
|
44
|
+
setOpenKey(openKeys);
|
|
45
|
+
}}
|
|
46
|
+
onSelect={(e) => {
|
|
47
|
+
navigate(e.key);
|
|
48
|
+
}}
|
|
49
|
+
mode={"inline"}
|
|
50
|
+
theme="dark"
|
|
51
|
+
>
|
|
52
|
+
{routes.map((item) => {
|
|
53
|
+
return menuItem(item);
|
|
54
|
+
})}
|
|
55
|
+
</Menu>
|
|
56
|
+
<div className={styles.body}>
|
|
57
|
+
<Outlet />
|
|
58
|
+
</div>
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
};
|
package/src/app.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import routes from "./routes";
|
|
3
|
+
import {
|
|
4
|
+
createBrowserRouter,
|
|
5
|
+
Navigate,
|
|
6
|
+
RouterProvider,
|
|
7
|
+
useRouteError,
|
|
8
|
+
} from "react-router-dom";
|
|
9
|
+
import type { RouteObject } from "react-router";
|
|
10
|
+
import Layout from "./Layout";
|
|
11
|
+
const Error = () => {
|
|
12
|
+
const error = useRouteError();
|
|
13
|
+
if (error.status === 404) {
|
|
14
|
+
return <Navigate to="/form/select" replace />;
|
|
15
|
+
}
|
|
16
|
+
return <div>错误</div>;
|
|
17
|
+
};
|
|
18
|
+
const rootRoute = [
|
|
19
|
+
{
|
|
20
|
+
path: "/",
|
|
21
|
+
element: <Layout />,
|
|
22
|
+
errorElement: <Error />,
|
|
23
|
+
children: routes,
|
|
24
|
+
},
|
|
25
|
+
];
|
|
26
|
+
const router = () => {
|
|
27
|
+
return createBrowserRouter(rootRoute as RouteObject[]);
|
|
28
|
+
};
|
|
29
|
+
export default () => {
|
|
30
|
+
return (
|
|
31
|
+
<RouterProvider router={router()} fallbackElement={<p>Loading...</p>} />
|
|
32
|
+
);
|
|
33
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { HSelectProps } from "@/components/Select/modal";
|
|
2
|
+
import { Checkbox, Space } from "antd";
|
|
3
|
+
import styles from "../index.less";
|
|
4
|
+
interface IProps extends HSelectProps {
|
|
5
|
+
checked?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export default ({
|
|
8
|
+
allSelect,
|
|
9
|
+
mode,
|
|
10
|
+
onChange,
|
|
11
|
+
value,
|
|
12
|
+
serviceSearch,
|
|
13
|
+
options,
|
|
14
|
+
}: IProps) => {
|
|
15
|
+
if (!allSelect || mode !== "multiple" || serviceSearch) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const opLen = options?.length || 0;
|
|
19
|
+
const checked = (value as any[])?.length >= opLen;
|
|
20
|
+
const change = () => {
|
|
21
|
+
if (!checked) {
|
|
22
|
+
onChange?.(options);
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
onChange?.([]);
|
|
26
|
+
};
|
|
27
|
+
return (
|
|
28
|
+
<div
|
|
29
|
+
className={`ant-select-item ant-select-item-option ${styles.option}`}
|
|
30
|
+
onClick={change}
|
|
31
|
+
>
|
|
32
|
+
<Space>
|
|
33
|
+
<Checkbox checked={checked} />
|
|
34
|
+
全部
|
|
35
|
+
</Space>
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
38
|
+
};
|