@canlooks/can-ui 0.0.59 → 0.0.61

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,5 +1,5 @@
1
1
  import React, { Dispatch, ReactElement, ReactNode, Ref, RefObject, SetStateAction, ElementType } from 'react';
2
- import { Obj, OverridableProps } from '../../types';
2
+ import { Obj, OverridableProps, Size } from '../../types';
3
3
  import { FieldPath } from '../../utils';
4
4
  import { FieldError, FormItem, FormItemProps, FormItemRef } from './formItem';
5
5
  import { FormRelatable } from './formRelatable';
@@ -11,6 +11,7 @@ export type FormSharedProps = {
11
11
  requiredMark?: ReactNode;
12
12
  /** variant为"grid"或"table"时会渲染Descriptions组件,并传递variant属性,默认为`grid` */
13
13
  variant?: 'plain' | 'grid' | 'table';
14
+ size?: Size;
14
15
  };
15
16
  interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps, DescriptionsSharedProps, GridOwnProps {
16
17
  ref?: Ref<FormRef<V> | null>;
@@ -81,7 +81,6 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
81
81
  for (const [, item] of itemsContainer.current) {
82
82
  item.reset(newValue);
83
83
  }
84
- console.log('after', newValue);
85
84
  setFormValue(newValue);
86
85
  },
87
86
  resetField: field => {
@@ -93,10 +92,10 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
93
92
  };
94
93
  (0, react_1.useImperativeHandle)(ref, () => formRef.current);
95
94
  return ((0, jsx_runtime_1.jsx)(Component, { ...props, ref: wrapperRef, css: form_style_1.style, className: (0, utils_1.clsx)(form_style_1.classes.root, props.className), onSubmit: submitHandler, children: (0, jsx_runtime_1.jsx)(FormContext, { value: (0, react_1.useMemo)(() => ({
96
- requiredMark, variant,
95
+ requiredMark, variant, size,
97
96
  formValue: formValue.current, setFieldValue,
98
97
  itemsContainer: itemsContainer.current, formRef
99
- }), [requiredMark, variant, formValue.current]), children: variant === 'plain'
98
+ }), [requiredMark, variant, size, formValue.current]), children: variant === 'plain'
100
99
  ? props.children
101
100
  : (0, jsx_runtime_1.jsx)(descriptions_1.Descriptions, { ...descriptionsProps, size: size, labelWidth: labelWidth, colon: colon, labelPlacement: labelPlacement, disableMargin: disableMargin, disablePadding: disablePadding, items: items, variant: variant, itemComponent: formItem_1.FormItem, inline: inline, columnCount: columnCount, gap: gap, columnGap: columnGap, rowGap: rowGap, children: props.children }) }) }));
102
101
  });
@@ -8,10 +8,11 @@ const utils_1 = require("../../utils");
8
8
  const descriptions_1 = require("../descriptions");
9
9
  const form_style_1 = require("./form.style");
10
10
  const transitionBase_1 = require("../transitionBase");
11
- const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, ...props }) => {
11
+ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, size, ...props }) => {
12
12
  const { formValue, setFieldValue, itemsContainer, formRef, ...context } = (0, form_1.useFormContext)();
13
13
  requiredMark ??= context.requiredMark ?? '*';
14
14
  variant ??= context.variant ?? 'grid';
15
+ size ??= context.size;
15
16
  /**
16
17
  * --------------------------------------------------------------------
17
18
  * 字段值
@@ -137,7 +138,7 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
137
138
  }
138
139
  }
139
140
  : {}, {
140
- ...props.size && { size: props.size },
141
+ ...size && { size },
141
142
  ...innerError.current ? { color: 'error' } : {}
142
143
  }, randomKey.current);
143
144
  }
@@ -155,12 +156,12 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
155
156
  setFieldValue?.(field, (0, utils_1.getValueOnChange)(e, fieldValue));
156
157
  }
157
158
  },
158
- ...props.size && { size: childProps.size },
159
+ ...size && { size },
159
160
  ...innerError.current && { color: 'error' }
160
161
  });
161
162
  }
162
163
  return children;
163
- }, [children, fieldValue, innerError.current, field, props.size]);
164
+ }, [children, innerError.current, field, size, randomKey.current, fieldValue]);
164
165
  if (noStyle || variant === 'plain') {
165
166
  return renderedChildren;
166
167
  }
@@ -4,9 +4,9 @@ Promise.withResolvers ||= function withResolvers() {
4
4
  if (!this)
5
5
  throw new TypeError('Promise.withResolvers called on non-object');
6
6
  const out = {};
7
- out.promise = new this((resolve_, reject_) => {
8
- out.resolve = resolve_;
9
- out.reject = reject_;
7
+ out.promise = new this((resolve, reject) => {
8
+ out.resolve = resolve;
9
+ out.reject = reject;
10
10
  });
11
11
  return out;
12
12
  };
@@ -1,5 +1,5 @@
1
1
  import React, { Dispatch, ReactElement, ReactNode, Ref, RefObject, SetStateAction, ElementType } from 'react';
2
- import { Obj, OverridableProps } from '../../types';
2
+ import { Obj, OverridableProps, Size } from '../../types';
3
3
  import { FieldPath } from '../../utils';
4
4
  import { FieldError, FormItem, FormItemProps, FormItemRef } from './formItem';
5
5
  import { FormRelatable } from './formRelatable';
@@ -11,6 +11,7 @@ export type FormSharedProps = {
11
11
  requiredMark?: ReactNode;
12
12
  /** variant为"grid"或"table"时会渲染Descriptions组件,并传递variant属性,默认为`grid` */
13
13
  variant?: 'plain' | 'grid' | 'table';
14
+ size?: Size;
14
15
  };
15
16
  interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps, DescriptionsSharedProps, GridOwnProps {
16
17
  ref?: Ref<FormRef<V> | null>;
@@ -77,7 +77,6 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
77
77
  for (const [, item] of itemsContainer.current) {
78
78
  item.reset(newValue);
79
79
  }
80
- console.log('after', newValue);
81
80
  setFormValue(newValue);
82
81
  },
83
82
  resetField: field => {
@@ -89,10 +88,10 @@ inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
89
88
  };
90
89
  useImperativeHandle(ref, () => formRef.current);
91
90
  return (_jsx(Component, { ...props, ref: wrapperRef, css: style, className: clsx(classes.root, props.className), onSubmit: submitHandler, children: _jsx(FormContext, { value: useMemo(() => ({
92
- requiredMark, variant,
91
+ requiredMark, variant, size,
93
92
  formValue: formValue.current, setFieldValue,
94
93
  itemsContainer: itemsContainer.current, formRef
95
- }), [requiredMark, variant, formValue.current]), children: variant === 'plain'
94
+ }), [requiredMark, variant, size, formValue.current]), children: variant === 'plain'
96
95
  ? props.children
97
96
  : _jsx(Descriptions, { ...descriptionsProps, size: size, labelWidth: labelWidth, colon: colon, labelPlacement: labelPlacement, disableMargin: disableMargin, disablePadding: disablePadding, items: items, variant: variant, itemComponent: FormItem, inline: inline, columnCount: columnCount, gap: gap, columnGap: columnGap, rowGap: rowGap, children: props.children }) }) }));
98
97
  });
@@ -5,10 +5,11 @@ import { clsx, getValueOnChange, queryDeep, stringifyField, useDerivedState, toA
5
5
  import { DescriptionItem } from '../descriptions';
6
6
  import { classes } from './form.style';
7
7
  import { Collapse } from '../transitionBase';
8
- export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, ...props }) => {
8
+ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, required, error, helperText, dependencies, children, noStyle, requiredMark, variant, size, ...props }) => {
9
9
  const { formValue, setFieldValue, itemsContainer, formRef, ...context } = useFormContext();
10
10
  requiredMark ??= context.requiredMark ?? '*';
11
11
  variant ??= context.variant ?? 'grid';
12
+ size ??= context.size;
12
13
  /**
13
14
  * --------------------------------------------------------------------
14
15
  * 字段值
@@ -134,7 +135,7 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
134
135
  }
135
136
  }
136
137
  : {}, {
137
- ...props.size && { size: props.size },
138
+ ...size && { size },
138
139
  ...innerError.current ? { color: 'error' } : {}
139
140
  }, randomKey.current);
140
141
  }
@@ -152,12 +153,12 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
152
153
  setFieldValue?.(field, getValueOnChange(e, fieldValue));
153
154
  }
154
155
  },
155
- ...props.size && { size: childProps.size },
156
+ ...size && { size },
156
157
  ...innerError.current && { color: 'error' }
157
158
  });
158
159
  }
159
160
  return children;
160
- }, [children, fieldValue, innerError.current, field, props.size]);
161
+ }, [children, innerError.current, field, size, randomKey.current, fieldValue]);
161
162
  if (noStyle || variant === 'plain') {
162
163
  return renderedChildren;
163
164
  }
@@ -2,9 +2,9 @@ Promise.withResolvers ||= function withResolvers() {
2
2
  if (!this)
3
3
  throw new TypeError('Promise.withResolvers called on non-object');
4
4
  const out = {};
5
- out.promise = new this((resolve_, reject_) => {
6
- out.resolve = resolve_;
7
- out.reject = reject_;
5
+ out.promise = new this((resolve, reject) => {
6
+ out.resolve = resolve;
7
+ out.reject = reject;
8
8
  });
9
9
  return out;
10
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canlooks/can-ui",
3
- "version": "0.0.59",
3
+ "version": "0.0.61",
4
4
  "author": "C.CanLiang <canlooks@gmail.com>",
5
5
  "description": "My ui framework",
6
6
  "license": "MIT",