@canlooks/can-ui 0.0.28 → 0.0.30

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.
@@ -12,7 +12,7 @@ const appStyleCallback = (theme) => (0, react_1.css) `
12
12
  color-scheme: ${theme.mode};
13
13
  zoom: ${theme.zoom};
14
14
 
15
- * {
15
+ *, *:before, *:after {
16
16
  box-sizing: border-box;
17
17
  font-family: ${theme.fontFamily};
18
18
  }
@@ -72,7 +72,7 @@ exports.gridItemStyle = (0, utils_1.defineCss)(({ spacing, text }) => (0, react_
72
72
  flex-direction: row-reverse;
73
73
  }
74
74
 
75
- &:not(:last-of-type):not([data-disable-margin=true]) {
75
+ &:not([data-disable-margin=true]) {
76
76
  &[data-label-placement=left], &[data-label-placement=right] {
77
77
  margin-bottom: ${spacing[4]}px;
78
78
 
@@ -32,6 +32,7 @@ interface FormContext<V extends FormValue> extends FormSharedProps {
32
32
  declare const FormContext: React.Context<FormContext<any>>;
33
33
  export declare function useFormContext<V extends FormValue>(): FormContext<V>;
34
34
  export type FormRef<V extends FormValue = FormValue> = {
35
+ /** 存在校验不通过的字段时会得到`null` */
35
36
  submit(): Promise<V | null>;
36
37
  getFieldValue<T = any>(field: FieldPath): T;
37
38
  getFormValue(): V;
@@ -20,7 +20,7 @@ exports.style = (0, utils_1.defineCss)(({ colors, spacing }) => (0, react_1.css)
20
20
  }
21
21
 
22
22
  .${exports.classes.item} {
23
- &:not(:last-of-type):not([data-disable-margin=true]) {
23
+ &:not([data-disable-margin=true]) {
24
24
  &[data-label-placement=left], &[data-label-placement=right] {
25
25
  margin-bottom: ${spacing[6]}px;
26
26
 
@@ -49,7 +49,7 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
49
49
  * --------------------------------------------------------------------
50
50
  * 校验
51
51
  */
52
- const rulesArr = Array.isArray(rules) ? rules : rules && [rules];
52
+ const rulesArr = (0, utils_1.toArray)(rules);
53
53
  const [innerError, setInnerError] = (0, utils_1.useDerivedState)(error);
54
54
  const [innerHelperText, setInnerHelperText] = (0, utils_1.useDerivedState)(helperText);
55
55
  const validate = async () => {
@@ -167,7 +167,7 @@ const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rules, req
167
167
  if (noStyle || variant === 'plain') {
168
168
  return renderedChildren;
169
169
  }
170
- return ((0, jsx_runtime_1.jsxs)(descriptions_1.DescriptionItem, { ...props, ref: wrapperRef, className: (0, utils_1.clsx)(form_style_1.classes.item, props.className), label: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isRequired && !!requiredMark &&
170
+ return ((0, jsx_runtime_1.jsxs)(descriptions_1.DescriptionItem, { flex: void 0, ...props, ref: wrapperRef, className: (0, utils_1.clsx)(form_style_1.classes.item, props.className), label: (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isRequired && !!requiredMark &&
171
171
  (0, jsx_runtime_1.jsx)("span", { className: form_style_1.classes.requiredMark, children: requiredMark }), label] }), children: [renderedChildren, (0, jsx_runtime_1.jsx)(transitionBase_1.Collapse, { in: innerError.current || !!helperText, children: (0, jsx_runtime_1.jsx)("div", { className: form_style_1.classes.helperText, children: innerHelperText.current }) })] }));
172
172
  };
173
173
  exports.FormItem = FormItem;
@@ -1,7 +1,8 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { ColorPropsValue, DivProps } from '../../types';
3
3
  export interface ProgressProps extends DivProps {
4
4
  showInfo?: boolean;
5
+ renderInfo?(value?: number): ReactNode;
5
6
  color?: ColorPropsValue;
6
7
  status?: 'default' | 'processing' | 'success' | 'error';
7
8
  variant?: 'linear' | 'circular' | 'gauge';
@@ -20,4 +21,4 @@ export interface ProgressProps extends DivProps {
20
21
  strokeLinecap?: React.SVGAttributes<SVGCircleElement>['strokeLinecap'];
21
22
  value?: number;
22
23
  }
23
- export declare const Progress: React.MemoExoticComponent<({ showInfo, color, status, variant, gapDegree, size, indeterminate, barWidth, strokeLinecap, value, ...props }: ProgressProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
24
+ export declare const Progress: React.MemoExoticComponent<({ showInfo, renderInfo, color, status, variant, gapDegree, size, indeterminate, barWidth, strokeLinecap, value, ...props }: ProgressProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
@@ -10,10 +10,13 @@ const react_2 = require("@emotion/react");
10
10
  const __1 = require("../..");
11
11
  const faCircleCheck_1 = require("@fortawesome/free-solid-svg-icons/faCircleCheck");
12
12
  const faCircleXmark_1 = require("@fortawesome/free-solid-svg-icons/faCircleXmark");
13
- exports.Progress = (0, react_1.memo)(({ showInfo = true, color = 'primary', status = 'default', variant = 'linear', gapDegree = 90, size = 60, indeterminate = false, barWidth = 4, strokeLinecap = variant === 'gauge' ? 'butt' : 'round', value = 0, ...props }) => {
13
+ exports.Progress = (0, react_1.memo)(({ showInfo = true, renderInfo, color = 'primary', status = 'default', variant = 'linear', gapDegree = 90, size = 60, indeterminate = false, barWidth = 4, strokeLinecap = variant === 'gauge' ? 'butt' : 'round', value = 0, ...props }) => {
14
14
  const { colors: { success, error } } = (0, theme_1.useTheme)();
15
15
  const isSucceed = status === 'success' || (status !== 'error' && value === 100 && variant !== 'gauge');
16
- const renderInfo = () => {
16
+ const renderInfoFn = () => {
17
+ if (renderInfo) {
18
+ return renderInfo(value);
19
+ }
17
20
  if (isSucceed) {
18
21
  return (0, jsx_runtime_1.jsx)(__1.Icon, { icon: faCircleCheck_1.faCircleCheck, className: progress_style_1.classes.icon, style: { color: success.main } });
19
22
  }
@@ -35,19 +38,19 @@ exports.Progress = (0, react_1.memo)(({ showInfo = true, color = 'primary', stat
35
38
  if (variant === 'circular' && indeterminate) {
36
39
  const dasharray = commonCircleProps.r * 10;
37
40
  const anim = (0, react_2.keyframes) `
38
- 0% {
39
- stroke-dasharray: 1px ${dasharray}px;
40
- stroke-dashoffset: 0;
41
- }
42
- 50% {
43
- stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
44
- stroke-dashoffset: -${dasharray / 2 * .15}px;
45
- }
46
- 100% {
47
- stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
48
- stroke-dashoffset: -${dasharray / 2 * 1.25}px;
49
- }
50
- `;
41
+ 0% {
42
+ stroke-dasharray: 1px ${dasharray}px;
43
+ stroke-dashoffset: 0;
44
+ }
45
+ 50% {
46
+ stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
47
+ stroke-dashoffset: -${dasharray / 2 * .15}px;
48
+ }
49
+ 100% {
50
+ stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
51
+ stroke-dashoffset: -${dasharray / 2 * 1.25}px;
52
+ }
53
+ `;
51
54
  return (0, react_2.css)({ animation: `${anim} 1.4s linear infinite` });
52
55
  }
53
56
  return;
@@ -59,7 +62,7 @@ exports.Progress = (0, react_1.memo)(({ showInfo = true, color = 'primary', stat
59
62
  }, children: (0, jsx_runtime_1.jsx)("div", { className: progress_style_1.classes.bar, style: indeterminate
60
63
  ? void 0
61
64
  : { width: value + '%' } }) }), showInfo && !indeterminate &&
62
- (0, jsx_runtime_1.jsx)("div", { className: progress_style_1.classes.info, children: renderInfo() })] })
65
+ (0, jsx_runtime_1.jsx)("div", { className: progress_style_1.classes.info, children: renderInfoFn() })] })
63
66
  : (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("svg", { className: progress_style_1.classes.svg, width: size, height: size, viewBox: `0 0 ${size} ${size}`, style: {
64
67
  transform: variant === 'gauge'
65
68
  ? `rotate(${90 + gapDegree / 2}deg)`
@@ -67,5 +70,5 @@ exports.Progress = (0, react_1.memo)(({ showInfo = true, color = 'primary', stat
67
70
  }, children: [(0, jsx_runtime_1.jsx)("circle", { ...commonCircleProps, className: progress_style_1.classes.track, strokeDasharray: variant === 'gauge' ? strokeDasharray : void 0, strokeDashoffset: variant === 'gauge' ? strokeDasharray * gapDegree / 360 : void 0 }), (0, jsx_runtime_1.jsx)("circle", { ...commonCircleProps, ref: barRef, css: cssAnimation, className: progress_style_1.classes.bar, strokeDasharray: strokeDasharray, strokeDashoffset: variant === 'circular'
68
71
  ? strokeDasharray * (1 - value / 100)
69
72
  : strokeDasharray * (1 - Math.max(0, Math.min(100, value)) / 100 * (1 - gapDegree / 360)) })] }), showInfo && !indeterminate &&
70
- (0, jsx_runtime_1.jsx)("div", { className: progress_style_1.classes.info, children: renderInfo() })] }) }));
73
+ (0, jsx_runtime_1.jsx)("div", { className: progress_style_1.classes.info, children: renderInfoFn() })] }) }));
71
74
  });
@@ -9,7 +9,7 @@ export const appStyleCallback = (theme) => css `
9
9
  color-scheme: ${theme.mode};
10
10
  zoom: ${theme.zoom};
11
11
 
12
- * {
12
+ *, *:before, *:after {
13
13
  box-sizing: border-box;
14
14
  font-family: ${theme.fontFamily};
15
15
  }
@@ -69,7 +69,7 @@ export const gridItemStyle = defineCss(({ spacing, text }) => css `
69
69
  flex-direction: row-reverse;
70
70
  }
71
71
 
72
- &:not(:last-of-type):not([data-disable-margin=true]) {
72
+ &:not([data-disable-margin=true]) {
73
73
  &[data-label-placement=left], &[data-label-placement=right] {
74
74
  margin-bottom: ${spacing[4]}px;
75
75
 
@@ -32,6 +32,7 @@ interface FormContext<V extends FormValue> extends FormSharedProps {
32
32
  declare const FormContext: React.Context<FormContext<any>>;
33
33
  export declare function useFormContext<V extends FormValue>(): FormContext<V>;
34
34
  export type FormRef<V extends FormValue = FormValue> = {
35
+ /** 存在校验不通过的字段时会得到`null` */
35
36
  submit(): Promise<V | null>;
36
37
  getFieldValue<T = any>(field: FieldPath): T;
37
38
  getFormValue(): V;
@@ -17,7 +17,7 @@ export const style = defineCss(({ colors, spacing }) => css `
17
17
  }
18
18
 
19
19
  .${classes.item} {
20
- &:not(:last-of-type):not([data-disable-margin=true]) {
20
+ &:not([data-disable-margin=true]) {
21
21
  &[data-label-placement=left], &[data-label-placement=right] {
22
22
  margin-bottom: ${spacing[6]}px;
23
23
 
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  import { cloneElement, isValidElement, useDeferredValue, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
3
3
  import { useFormContext } from './form';
4
- import { clsx, getValueOnChange, queryDeep, stringifyField, useDerivedState } from '../../utils';
4
+ import { clsx, getValueOnChange, queryDeep, stringifyField, useDerivedState, toArray } from '../../utils';
5
5
  import { DescriptionItem } from '../descriptions';
6
6
  import { classes } from './form.style';
7
7
  import { Collapse } from '../transitionBase';
@@ -46,7 +46,7 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
46
46
  * --------------------------------------------------------------------
47
47
  * 校验
48
48
  */
49
- const rulesArr = Array.isArray(rules) ? rules : rules && [rules];
49
+ const rulesArr = toArray(rules);
50
50
  const [innerError, setInnerError] = useDerivedState(error);
51
51
  const [innerHelperText, setInnerHelperText] = useDerivedState(helperText);
52
52
  const validate = async () => {
@@ -164,6 +164,6 @@ export const FormItem = ({ ref, wrapperRef, field, initialValue, label = '', rul
164
164
  if (noStyle || variant === 'plain') {
165
165
  return renderedChildren;
166
166
  }
167
- return (_jsxs(DescriptionItem, { ...props, ref: wrapperRef, className: clsx(classes.item, props.className), label: _jsxs(_Fragment, { children: [isRequired && !!requiredMark &&
167
+ return (_jsxs(DescriptionItem, { flex: void 0, ...props, ref: wrapperRef, className: clsx(classes.item, props.className), label: _jsxs(_Fragment, { children: [isRequired && !!requiredMark &&
168
168
  _jsx("span", { className: classes.requiredMark, children: requiredMark }), label] }), children: [renderedChildren, _jsx(Collapse, { in: innerError.current || !!helperText, children: _jsx("div", { className: classes.helperText, children: innerHelperText.current }) })] }));
169
169
  };
@@ -1,7 +1,8 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { ColorPropsValue, DivProps } from '../../types';
3
3
  export interface ProgressProps extends DivProps {
4
4
  showInfo?: boolean;
5
+ renderInfo?(value?: number): ReactNode;
5
6
  color?: ColorPropsValue;
6
7
  status?: 'default' | 'processing' | 'success' | 'error';
7
8
  variant?: 'linear' | 'circular' | 'gauge';
@@ -20,4 +21,4 @@ export interface ProgressProps extends DivProps {
20
21
  strokeLinecap?: React.SVGAttributes<SVGCircleElement>['strokeLinecap'];
21
22
  value?: number;
22
23
  }
23
- export declare const Progress: React.MemoExoticComponent<({ showInfo, color, status, variant, gapDegree, size, indeterminate, barWidth, strokeLinecap, value, ...props }: ProgressProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
24
+ export declare const Progress: React.MemoExoticComponent<({ showInfo, renderInfo, color, status, variant, gapDegree, size, indeterminate, barWidth, strokeLinecap, value, ...props }: ProgressProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
@@ -7,10 +7,13 @@ import { css, keyframes } from '@emotion/react';
7
7
  import { Icon } from '../..';
8
8
  import { faCircleCheck } from '@fortawesome/free-solid-svg-icons/faCircleCheck';
9
9
  import { faCircleXmark } from '@fortawesome/free-solid-svg-icons/faCircleXmark';
10
- export const Progress = memo(({ showInfo = true, color = 'primary', status = 'default', variant = 'linear', gapDegree = 90, size = 60, indeterminate = false, barWidth = 4, strokeLinecap = variant === 'gauge' ? 'butt' : 'round', value = 0, ...props }) => {
10
+ export const Progress = memo(({ showInfo = true, renderInfo, color = 'primary', status = 'default', variant = 'linear', gapDegree = 90, size = 60, indeterminate = false, barWidth = 4, strokeLinecap = variant === 'gauge' ? 'butt' : 'round', value = 0, ...props }) => {
11
11
  const { colors: { success, error } } = useTheme();
12
12
  const isSucceed = status === 'success' || (status !== 'error' && value === 100 && variant !== 'gauge');
13
- const renderInfo = () => {
13
+ const renderInfoFn = () => {
14
+ if (renderInfo) {
15
+ return renderInfo(value);
16
+ }
14
17
  if (isSucceed) {
15
18
  return _jsx(Icon, { icon: faCircleCheck, className: classes.icon, style: { color: success.main } });
16
19
  }
@@ -32,19 +35,19 @@ export const Progress = memo(({ showInfo = true, color = 'primary', status = 'de
32
35
  if (variant === 'circular' && indeterminate) {
33
36
  const dasharray = commonCircleProps.r * 10;
34
37
  const anim = keyframes `
35
- 0% {
36
- stroke-dasharray: 1px ${dasharray}px;
37
- stroke-dashoffset: 0;
38
- }
39
- 50% {
40
- stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
41
- stroke-dashoffset: -${dasharray / 2 * .15}px;
42
- }
43
- 100% {
44
- stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
45
- stroke-dashoffset: -${dasharray / 2 * 1.25}px;
46
- }
47
- `;
38
+ 0% {
39
+ stroke-dasharray: 1px ${dasharray}px;
40
+ stroke-dashoffset: 0;
41
+ }
42
+ 50% {
43
+ stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
44
+ stroke-dashoffset: -${dasharray / 2 * .15}px;
45
+ }
46
+ 100% {
47
+ stroke-dasharray: ${dasharray / 2}px ${dasharray}px;
48
+ stroke-dashoffset: -${dasharray / 2 * 1.25}px;
49
+ }
50
+ `;
48
51
  return css({ animation: `${anim} 1.4s linear infinite` });
49
52
  }
50
53
  return;
@@ -56,7 +59,7 @@ export const Progress = memo(({ showInfo = true, color = 'primary', status = 'de
56
59
  }, children: _jsx("div", { className: classes.bar, style: indeterminate
57
60
  ? void 0
58
61
  : { width: value + '%' } }) }), showInfo && !indeterminate &&
59
- _jsx("div", { className: classes.info, children: renderInfo() })] })
62
+ _jsx("div", { className: classes.info, children: renderInfoFn() })] })
60
63
  : _jsxs(_Fragment, { children: [_jsxs("svg", { className: classes.svg, width: size, height: size, viewBox: `0 0 ${size} ${size}`, style: {
61
64
  transform: variant === 'gauge'
62
65
  ? `rotate(${90 + gapDegree / 2}deg)`
@@ -64,5 +67,5 @@ export const Progress = memo(({ showInfo = true, color = 'primary', status = 'de
64
67
  }, children: [_jsx("circle", { ...commonCircleProps, className: classes.track, strokeDasharray: variant === 'gauge' ? strokeDasharray : void 0, strokeDashoffset: variant === 'gauge' ? strokeDasharray * gapDegree / 360 : void 0 }), _jsx("circle", { ...commonCircleProps, ref: barRef, css: cssAnimation, className: classes.bar, strokeDasharray: strokeDasharray, strokeDashoffset: variant === 'circular'
65
68
  ? strokeDasharray * (1 - value / 100)
66
69
  : strokeDasharray * (1 - Math.max(0, Math.min(100, value)) / 100 * (1 - gapDegree / 360)) })] }), showInfo && !indeterminate &&
67
- _jsx("div", { className: classes.info, children: renderInfo() })] }) }));
70
+ _jsx("div", { className: classes.info, children: renderInfoFn() })] }) }));
68
71
  });