@hw-component/form 1.2.1 → 1.2.3

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.
@@ -1,14 +1,27 @@
1
1
  // welcome to hoo hoo hoo
2
+ import 'core-js/modules/es.object.keys.js';
3
+ import 'core-js/modules/es.symbol.js';
4
+ import 'core-js/modules/es.array.filter.js';
5
+ import 'core-js/modules/es.object.to-string.js';
6
+ import 'core-js/modules/es.object.get-own-property-descriptor.js';
7
+ import 'core-js/modules/web.dom-collections.for-each.js';
8
+ import 'core-js/modules/es.object.get-own-property-descriptors.js';
9
+ import _defineProperty from '@babel/runtime-corejs3/helpers/defineProperty';
10
+ import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/objectWithoutProperties';
2
11
  import { jsx } from 'react/jsx-runtime';
3
12
  import { Checkbox } from 'antd';
4
13
  import { useMemo } from 'react';
5
14
  import { useMatchConfigProps } from '../../hooks/index.js';
6
15
 
16
+ var _excluded = ["value", "onChange", "children", "valueMap"];
17
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
18
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
19
  var Index = function Index(_ref) {
8
20
  var value = _ref.value,
9
21
  onChange = _ref.onChange,
10
22
  children = _ref.children,
11
- propsValueCheckMap = _ref.valueMap;
23
+ propsValueCheckMap = _ref.valueMap,
24
+ props = _objectWithoutProperties(_ref, _excluded);
12
25
  var _useMatchConfigProps = useMatchConfigProps({
13
26
  valueCheckMap: propsValueCheckMap
14
27
  }),
@@ -31,11 +44,12 @@ var Index = function Index(_ref) {
31
44
  }
32
45
  onChange === null || onChange === void 0 || onChange(subVal);
33
46
  };
34
- return jsx(Checkbox, {
47
+ return jsx(Checkbox, _objectSpread(_objectSpread({
35
48
  checked: checkedVal,
36
- onChange: change,
49
+ onChange: change
50
+ }, props), {}, {
37
51
  children: children
38
- });
52
+ }));
39
53
  };
40
54
 
41
55
  export { Index as default };
@@ -15,7 +15,7 @@ import { Col, Form, Space } from 'antd';
15
15
  import React from 'react';
16
16
  import Index$2 from './Helper.js';
17
17
  import { useClassName } from '../../hooks/index.js';
18
- import { usePositionClassName, useHide } from './hooks.js';
18
+ import { usePositionClassName, useHide, useFormItemLabel } from './hooks.js';
19
19
  import { useFormContext } from '../Context/index.js';
20
20
  import { useDefaultRender } from '../hooks/useDefaultRender.js';
21
21
  import { useDefaultComponents } from '../hooks/index.js';
@@ -92,9 +92,11 @@ var Index = function Index(props) {
92
92
  hide: hide,
93
93
  form: form
94
94
  });
95
+ var formItemLabel = useFormItemLabel(form, label);
95
96
  if (hideItem) {
96
97
  return null;
97
98
  }
99
+ console.log(inProps, formItemLabel);
98
100
  return jsx(Col, _objectSpread(_objectSpread({}, itemSpan), {}, {
99
101
  className: "".concat(colClassName, " ").concat(itemClassName),
100
102
  children: jsx(Form.Item, _objectSpread(_objectSpread({
@@ -104,7 +106,7 @@ var Index = function Index(props) {
104
106
  labelWidth: labelWidth,
105
107
  required: required,
106
108
  colon: colon,
107
- children: label
109
+ children: formItemLabel
108
110
  })
109
111
  }, oProps), {}, {
110
112
  style: style || formItemStyle,
@@ -1,5 +1,7 @@
1
+ import React from "react";
1
2
  import type { HFormInstance, HItemProps } from "../modal";
2
3
  import type { LabelAlignModal } from "../modal";
4
+ import { HelperModal } from "../modal";
3
5
  export declare const useFormItemDomControl: ({ shouldUpdate, hide, dependencies, }: HItemProps) => ({ shouldUpdate, dependencies, hide, itemSpan, ...props }: import("../modal").HFormItemProps) => JSX.Element;
4
6
  interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
5
7
  form: HFormInstance;
@@ -7,4 +9,5 @@ interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
7
9
  export declare const useShouldUpdate: ({ hide, shouldUpdate, }: Omit<HItemProps, "name">) => import("rc-field-form/lib/Field").ShouldUpdate<any> | undefined;
8
10
  export declare const useHide: ({ hide, form }: UseHideUpItemModal) => boolean;
9
11
  export declare const usePositionClassName: (position: LabelAlignModal) => string;
12
+ export declare const useFormItemLabel: (form: HFormInstance, label?: React.ReactNode | HelperModal) => any;
10
13
  export {};
@@ -45,6 +45,9 @@ var usePositionClassName = function usePositionClassName(position) {
45
45
  var className = classNameData[position];
46
46
  return useClassName(className);
47
47
  };
48
+ var useFormItemLabel = function useFormItemLabel(form, label) {
49
+ return typeof label === "function" ? label(form) : label;
50
+ };
48
51
 
49
- export { useFormItemDomControl, useHide, usePositionClassName, useShouldUpdate };
52
+ export { useFormItemDomControl, useFormItemLabel, useHide, usePositionClassName, useShouldUpdate };
50
53
  // powered by hdj
@@ -22,7 +22,7 @@ export interface HoverModal {
22
22
  text?: string;
23
23
  icon?: React.ReactNode;
24
24
  }
25
- type HelperModal = (form: HFormInstance) => React.ReactNode | string;
25
+ export type HelperModal = (form: HFormInstance) => React.ReactNode | string;
26
26
  export type HideModal = (form: HFormInstance) => boolean;
27
27
  export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
28
28
  export type DispatchSourceDataModal = Record<string, Record<string, DispatchModal>>;
@@ -33,7 +33,7 @@ export interface DispatchModal<T = string | string[]> {
33
33
  reset?: boolean;
34
34
  }
35
35
  export type LabelAlignModal = "left" | "right" | "topLeft" | "topRight" | "top";
36
- export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
36
+ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign" | "label"> {
37
37
  type?: string;
38
38
  itemProps?: ItemPropsType;
39
39
  render?: RenderFun;
@@ -47,6 +47,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
47
47
  itemSpan?: ColProps;
48
48
  hideLabel?: boolean;
49
49
  labelAlign?: LabelAlignModal;
50
+ label?: React.ReactNode | HelperModal;
50
51
  }
51
52
  export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
52
53
  configData: HItemProps[];
@@ -2,16 +2,29 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ require('core-js/modules/es.object.keys.js');
6
+ require('core-js/modules/es.symbol.js');
7
+ require('core-js/modules/es.array.filter.js');
8
+ require('core-js/modules/es.object.to-string.js');
9
+ require('core-js/modules/es.object.get-own-property-descriptor.js');
10
+ require('core-js/modules/web.dom-collections.for-each.js');
11
+ require('core-js/modules/es.object.get-own-property-descriptors.js');
12
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
13
+ var _objectWithoutProperties = require('@babel/runtime-corejs3/helpers/objectWithoutProperties');
5
14
  var jsxRuntime = require('react/jsx-runtime');
6
15
  var antd = require('antd');
7
16
  var React = require('react');
8
17
  var index = require('../../hooks/index.js');
9
18
 
19
+ var _excluded = ["value", "onChange", "children", "valueMap"];
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
10
22
  var Index = function Index(_ref) {
11
23
  var value = _ref.value,
12
24
  onChange = _ref.onChange,
13
25
  children = _ref.children,
14
- propsValueCheckMap = _ref.valueMap;
26
+ propsValueCheckMap = _ref.valueMap,
27
+ props = _objectWithoutProperties(_ref, _excluded);
15
28
  var _useMatchConfigProps = index.useMatchConfigProps({
16
29
  valueCheckMap: propsValueCheckMap
17
30
  }),
@@ -34,11 +47,12 @@ var Index = function Index(_ref) {
34
47
  }
35
48
  onChange === null || onChange === void 0 || onChange(subVal);
36
49
  };
37
- return jsxRuntime.jsx(antd.Checkbox, {
50
+ return jsxRuntime.jsx(antd.Checkbox, _objectSpread(_objectSpread({
38
51
  checked: checkedVal,
39
- onChange: change,
52
+ onChange: change
53
+ }, props), {}, {
40
54
  children: children
41
- });
55
+ }));
42
56
  };
43
57
 
44
58
  exports.default = Index;
@@ -95,9 +95,11 @@ var Index = function Index(props) {
95
95
  hide: hide,
96
96
  form: form
97
97
  });
98
+ var formItemLabel = hooks.useFormItemLabel(form, label);
98
99
  if (hideItem) {
99
100
  return null;
100
101
  }
102
+ console.log(inProps, formItemLabel);
101
103
  return jsxRuntime.jsx(antd.Col, _objectSpread(_objectSpread({}, itemSpan), {}, {
102
104
  className: "".concat(colClassName, " ").concat(itemClassName),
103
105
  children: jsxRuntime.jsx(antd.Form.Item, _objectSpread(_objectSpread({
@@ -107,7 +109,7 @@ var Index = function Index(props) {
107
109
  labelWidth: labelWidth,
108
110
  required: required,
109
111
  colon: colon,
110
- children: label
112
+ children: formItemLabel
111
113
  })
112
114
  }, oProps), {}, {
113
115
  style: style || formItemStyle,
@@ -1,5 +1,7 @@
1
+ import React from "react";
1
2
  import type { HFormInstance, HItemProps } from "../modal";
2
3
  import type { LabelAlignModal } from "../modal";
4
+ import { HelperModal } from "../modal";
3
5
  export declare const useFormItemDomControl: ({ shouldUpdate, hide, dependencies, }: HItemProps) => ({ shouldUpdate, dependencies, hide, itemSpan, ...props }: import("../modal").HFormItemProps) => JSX.Element;
4
6
  interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
5
7
  form: HFormInstance;
@@ -7,4 +9,5 @@ interface UseHideUpItemModal extends Omit<HItemProps, "name"> {
7
9
  export declare const useShouldUpdate: ({ hide, shouldUpdate, }: Omit<HItemProps, "name">) => import("rc-field-form/lib/Field").ShouldUpdate<any> | undefined;
8
10
  export declare const useHide: ({ hide, form }: UseHideUpItemModal) => boolean;
9
11
  export declare const usePositionClassName: (position: LabelAlignModal) => string;
12
+ export declare const useFormItemLabel: (form: HFormInstance, label?: React.ReactNode | HelperModal) => any;
10
13
  export {};
@@ -46,8 +46,12 @@ var usePositionClassName = function usePositionClassName(position) {
46
46
  var className = classNameData[position];
47
47
  return index.useClassName(className);
48
48
  };
49
+ var useFormItemLabel = function useFormItemLabel(form, label) {
50
+ return typeof label === "function" ? label(form) : label;
51
+ };
49
52
 
50
53
  exports.useFormItemDomControl = useFormItemDomControl;
54
+ exports.useFormItemLabel = useFormItemLabel;
51
55
  exports.useHide = useHide;
52
56
  exports.usePositionClassName = usePositionClassName;
53
57
  exports.useShouldUpdate = useShouldUpdate;
@@ -22,7 +22,7 @@ export interface HoverModal {
22
22
  text?: string;
23
23
  icon?: React.ReactNode;
24
24
  }
25
- type HelperModal = (form: HFormInstance) => React.ReactNode | string;
25
+ export type HelperModal = (form: HFormInstance) => React.ReactNode | string;
26
26
  export type HideModal = (form: HFormInstance) => boolean;
27
27
  export type AddDispatchListenerFn = (action: ActionModal, fn: argsFn) => void;
28
28
  export type DispatchSourceDataModal = Record<string, Record<string, DispatchModal>>;
@@ -33,7 +33,7 @@ export interface DispatchModal<T = string | string[]> {
33
33
  reset?: boolean;
34
34
  }
35
35
  export type LabelAlignModal = "left" | "right" | "topLeft" | "topRight" | "top";
36
- export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
36
+ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign" | "label"> {
37
37
  type?: string;
38
38
  itemProps?: ItemPropsType;
39
39
  render?: RenderFun;
@@ -47,6 +47,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
47
47
  itemSpan?: ColProps;
48
48
  hideLabel?: boolean;
49
49
  labelAlign?: LabelAlignModal;
50
+ label?: React.ReactNode | HelperModal;
50
51
  }
51
52
  export interface HFormProps<T = any, R = any> extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
52
53
  configData: HItemProps[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hw-component/form",
3
- "version": "1.2.1",
3
+ "version": "1.2.3",
4
4
  "description": "基于antd二次开发",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,6 +9,7 @@ const Index: React.FC<HCheckboxProps> = ({
9
9
  onChange,
10
10
  children,
11
11
  valueMap: propsValueCheckMap,
12
+ ...props
12
13
  }) => {
13
14
  const { valueCheckMap = {} } = useMatchConfigProps({
14
15
  valueCheckMap: propsValueCheckMap,
@@ -30,7 +31,7 @@ const Index: React.FC<HCheckboxProps> = ({
30
31
  onChange?.(subVal);
31
32
  };
32
33
  return (
33
- <Checkbox checked={checkedVal} onChange={change}>
34
+ <Checkbox checked={checkedVal} onChange={change} {...props}>
34
35
  {children}
35
36
  </Checkbox>
36
37
  );
@@ -3,7 +3,7 @@ import { Form, Space, Col } from "antd";
3
3
  import React from "react";
4
4
  import Helper from "./Helper";
5
5
  import { useClassName } from "../../hooks";
6
- import { useHide, usePositionClassName } from "./hooks";
6
+ import {useFormItemLabel, useHide, usePositionClassName} from "./hooks";
7
7
  import { useFormContext } from "../Context";
8
8
  import type { HItemProps } from "../modal";
9
9
  import { useDefaultRender } from "../hooks/useDefaultRender";
@@ -67,9 +67,11 @@ const Index: React.FC<HFormItemProps> = (props) => {
67
67
  );
68
68
  const className = usePositionClassName(align);
69
69
  const hideItem = useHide({ hide, form });
70
+ const formItemLabel=useFormItemLabel(form,label);
70
71
  if (hideItem) {
71
72
  return null;
72
73
  }
74
+ console.log(inProps,formItemLabel)
73
75
  return (
74
76
  <Col {...itemSpan} className={`${colClassName} ${itemClassName}`}>
75
77
  <Form.Item
@@ -82,7 +84,7 @@ const Index: React.FC<HFormItemProps> = (props) => {
82
84
  required={required}
83
85
  colon={colon}
84
86
  >
85
- {label}
87
+ {formItemLabel}
86
88
  </Label>
87
89
  )
88
90
  }
@@ -1,9 +1,10 @@
1
1
  import UpFormItem from "./UpFormItem";
2
2
  import RegularFormItem from "./RegularFormItem";
3
- import { useMemo } from "react";
3
+ import React, { useMemo } from "react";
4
4
  import type { HFormInstance, HItemProps } from "../modal";
5
5
  import type { LabelAlignModal } from "../modal";
6
6
  import { useClassName } from "../../hooks";
7
+ import {HelperModal} from "../modal";
7
8
 
8
9
  export const useFormItemDomControl = ({
9
10
  shouldUpdate,
@@ -52,3 +53,7 @@ export const usePositionClassName = (position: LabelAlignModal) => {
52
53
  const className = classNameData[position];
53
54
  return useClassName(className);
54
55
  };
56
+
57
+ export const useFormItemLabel=(form:HFormInstance,label?:React.ReactNode|HelperModal,)=>{
58
+ return typeof label==="function"?label(form):label;
59
+ }
@@ -60,7 +60,7 @@ export interface HoverModal {
60
60
  text?: string;
61
61
  icon?: React.ReactNode;
62
62
  }
63
- type HelperModal = (form: HFormInstance) => React.ReactNode | string;
63
+ export type HelperModal = (form: HFormInstance) => React.ReactNode | string;
64
64
 
65
65
  export type HideModal = (form: HFormInstance) => boolean;
66
66
 
@@ -77,7 +77,7 @@ export interface DispatchModal<T = string | string[]> {
77
77
  }
78
78
  export type LabelAlignModal = "left" | "right" | "topLeft" | "topRight" | "top";
79
79
 
80
- export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
80
+ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"|"label"> {
81
81
  type?: string;
82
82
  itemProps?: ItemPropsType;
83
83
  render?: RenderFun;
@@ -93,6 +93,7 @@ export interface HItemProps extends Omit<FormItemProps, "name" | "labelAlign"> {
93
93
  itemSpan?: ColProps;
94
94
  hideLabel?: boolean;
95
95
  labelAlign?: LabelAlignModal;
96
+ label?:React.ReactNode|HelperModal;
96
97
  }
97
98
  export interface HFormProps<T = any, R = any>
98
99
  extends Omit<FormProps, "form" | "onFinish" | "labelAlign"> {
@@ -35,10 +35,16 @@ const formData = () => {
35
35
  },
36
36
  },
37
37
  {
38
- label: "选择",
38
+ label:(form)=>{
39
+ const nameTest=form.getFieldValue("nameTest")
40
+ return nameTest;
41
+ },
39
42
  name: "checkboxGroup",
40
43
  type: "checkboxGroup",
41
44
  rules: [{ required: true }],
45
+ shouldUpdate:()=>{
46
+ return true;
47
+ },
42
48
  helper: "帮助我",
43
49
  options: [
44
50
  { value: "选择1", key: "check1" },