@canlooks/can-ui 0.0.26 → 0.0.28
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/dist/cjs/components/actionSheet/actionSheet.js +5 -4
- package/dist/cjs/components/curd/curdFilter.js +10 -9
- package/dist/cjs/components/descriptions/descriptions.d.ts +7 -7
- package/dist/cjs/components/descriptions/descriptions.js +14 -9
- package/dist/cjs/components/descriptions/descriptions.style.js +1 -0
- package/dist/cjs/components/form/form.d.ts +6 -5
- package/dist/cjs/components/form/form.js +5 -5
- package/dist/cjs/components/slider/slider.js +3 -2
- package/dist/esm/components/actionSheet/actionSheet.js +3 -2
- package/dist/esm/components/curd/curdFilter.js +2 -1
- package/dist/esm/components/descriptions/descriptions.d.ts +7 -7
- package/dist/esm/components/descriptions/descriptions.js +8 -3
- package/dist/esm/components/descriptions/descriptions.style.js +1 -0
- package/dist/esm/components/form/form.d.ts +6 -5
- package/dist/esm/components/form/form.js +5 -5
- package/dist/esm/components/slider/slider.js +3 -2
- package/documentation/dist/assets/{index-BViJjOmz.js → index-DGYeA9_D.js} +259 -258
- package/documentation/dist/index.html +1 -1
- package/package.json +1 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ActionSheet = void 0;
|
|
4
|
+
const react_1 = require("@emotion/react");
|
|
4
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const actionSheet_style_1 = require("./actionSheet.style");
|
|
7
8
|
const utils_1 = require("../../utils");
|
|
8
9
|
const overlayBase_1 = require("../overlayBase");
|
|
@@ -12,7 +13,7 @@ const placementToDirection = {
|
|
|
12
13
|
top: 'down',
|
|
13
14
|
bottom: 'up'
|
|
14
15
|
};
|
|
15
|
-
exports.ActionSheet = (0,
|
|
16
|
+
exports.ActionSheet = (0, react_2.memo)(({ ref, title, actions, placement = 'bottom', maskClosable, escapeClosable = true, onAction, onConfirm, onCancel, defaultOpen = false, open, onClose, showConfirm, confirmText = '确 定', confirmProps, showCancel = true, cancelText = '取 消', cancelProps, slideProps, ...props }) => {
|
|
16
17
|
const [innerOpen, setInnerOpen] = (0, utils_1.useControlled)(defaultOpen, open);
|
|
17
18
|
const close = (reason) => {
|
|
18
19
|
onClose?.(reason);
|
|
@@ -34,10 +35,10 @@ exports.ActionSheet = (0, react_1.memo)(({ ref, title, actions, placement = 'bot
|
|
|
34
35
|
confirmProps?.onClick?.(e);
|
|
35
36
|
onConfirm?.(e);
|
|
36
37
|
close('confirmed');
|
|
37
|
-
} }), actions?.map((menuItemProps, i) => (0,
|
|
38
|
+
} }), actions?.map((menuItemProps, i) => (0, react_1.createElement)(menuItem_1.MenuItem, { className: (0, utils_1.clsx)(actionSheet_style_1.classes.action, menuItemProps.className), size: "large", ...menuItemProps, key: menuItemProps.key ?? i, onClick: e => {
|
|
38
39
|
menuItemProps.onClick?.(e);
|
|
39
40
|
onAction?.(menuItemProps);
|
|
40
41
|
close('action');
|
|
41
|
-
} }
|
|
42
|
+
} }))] }), showCancel &&
|
|
42
43
|
(0, jsx_runtime_1.jsx)("div", { className: actionSheet_style_1.classes.card, children: (0, jsx_runtime_1.jsx)(menuItem_1.MenuItem, { color: "error", emphasized: true, size: "large", label: cancelText, ...cancelProps, onClick: cancelHandler }) })] }) }));
|
|
43
44
|
});
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CurdFilter = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
5
|
-
const react_1 = require("react");
|
|
5
|
+
const react_1 = require("@emotion/react");
|
|
6
|
+
const react_2 = require("react");
|
|
6
7
|
const form_1 = require("../form");
|
|
7
8
|
const curd_style_1 = require("./curd.style");
|
|
8
9
|
const utils_1 = require("../../utils");
|
|
@@ -13,25 +14,25 @@ const theme_1 = require("../theme");
|
|
|
13
14
|
const __1 = require("../..");
|
|
14
15
|
const faChevronDown_1 = require("@fortawesome/free-solid-svg-icons/faChevronDown");
|
|
15
16
|
const faFilter_1 = require("@fortawesome/free-solid-svg-icons/faFilter");
|
|
16
|
-
exports.CurdFilter = (0,
|
|
17
|
+
exports.CurdFilter = (0, react_2.memo)(({ ref, columns, expandable, showButton, renderConditions, buttonProps, onFilter, columnCount = 3, ...props }) => {
|
|
17
18
|
const { spacing } = (0, theme_1.useTheme)();
|
|
18
|
-
const items = (0,
|
|
19
|
+
const items = (0, react_2.useMemo)(() => {
|
|
19
20
|
return (0, utils_1.columnsToFilterItem)(columns);
|
|
20
21
|
}, [columns]);
|
|
21
22
|
/**
|
|
22
23
|
* --------------------------------------------------------------
|
|
23
24
|
* 收起与展开
|
|
24
25
|
*/
|
|
25
|
-
const firstItemRef = (0,
|
|
26
|
-
const [expanded, setExpanded] = (0,
|
|
27
|
-
const renderedGrid = ((0, jsx_runtime_1.jsx)(grid_1.Grid, { className: curd_style_1.classes.filterGrid, columnGap: spacing[8], children: items?.map((item, i) => (0,
|
|
26
|
+
const firstItemRef = (0, react_2.useRef)(null);
|
|
27
|
+
const [expanded, setExpanded] = (0, react_2.useState)(false);
|
|
28
|
+
const renderedGrid = ((0, jsx_runtime_1.jsx)(grid_1.Grid, { className: curd_style_1.classes.filterGrid, columnGap: spacing[8], children: items?.map((item, i) => (0, react_2.isValidElement)(item)
|
|
28
29
|
? item
|
|
29
|
-
: (0,
|
|
30
|
+
: (0, react_1.createElement)(form_1.FormItem, { span: { xs: 12, md: 6, lg: 4 }, ...item, key: item.key ?? i, wrapperRef: !i ? firstItemRef : void 0 })) }));
|
|
30
31
|
/**
|
|
31
32
|
* --------------------------------------------------------------
|
|
32
33
|
* 触发筛选
|
|
33
34
|
*/
|
|
34
|
-
const formRef = (0,
|
|
35
|
+
const formRef = (0, react_2.useRef)(null);
|
|
35
36
|
const clickHandler = (e) => {
|
|
36
37
|
buttonProps?.onClick?.(e);
|
|
37
38
|
const filterValue = formRef.current.getFormValue();
|
|
@@ -47,7 +48,7 @@ exports.CurdFilter = (0, react_1.memo)(({ ref, columns, expandable, showButton,
|
|
|
47
48
|
* --------------------------------------------------------------
|
|
48
49
|
* 已生效的筛选条件
|
|
49
50
|
*/
|
|
50
|
-
const [filteredConditions, setFilteredConditions] = (0,
|
|
51
|
+
const [filteredConditions, setFilteredConditions] = (0, react_2.useState)({});
|
|
51
52
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(form_1.Form, { ...props, ref: (0, utils_1.cloneRef)(ref, formRef), className: (0, utils_1.clsx)(curd_style_1.classes.filter, props.className), columnCount: columnCount, variant: "plain", onChange: changeHandler, children: !!items?.length &&
|
|
52
53
|
(0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [expandable
|
|
53
54
|
? (0, jsx_runtime_1.jsx)(transitionBase_1.Collapse, { className: curd_style_1.classes.filterGridContainer, in: expanded, collapsedSize: () => firstItemRef.current?.offsetHeight || 56, appear: false, children: renderedGrid })
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactElement, ReactNode, ElementType } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { ReactElement, ReactNode, ElementType, ComponentPropsWithRef } from 'react';
|
|
2
|
+
import { Obj, ResponsiveProp, Size } from '../../types';
|
|
3
3
|
import { GridProps } from '../grid';
|
|
4
4
|
import { DescriptionItem, DescriptionItemProps } from './descriptionItem';
|
|
5
5
|
export type DescriptionsSharedProps = {
|
|
@@ -14,7 +14,7 @@ export type DescriptionsSharedProps = {
|
|
|
14
14
|
/** 是否禁用padding,{@link DescriptionsProps.variant}为table有效 */
|
|
15
15
|
disablePadding?: boolean;
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
interface DescriptionsBaseProps extends DescriptionsSharedProps {
|
|
18
18
|
items?: (DescriptionItemProps & Obj)[];
|
|
19
19
|
/**
|
|
20
20
|
* @private 用于渲染item的组件,通常为内部使用
|
|
@@ -22,21 +22,21 @@ export interface DescriptionsBaseProps extends DescriptionsSharedProps {
|
|
|
22
22
|
*/
|
|
23
23
|
itemComponent?: ElementType;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
interface DescriptionsGridProps extends DescriptionsBaseProps, GridProps {
|
|
26
26
|
variant?: 'grid';
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
interface DescriptionsTableProps extends DescriptionsBaseProps, ComponentPropsWithRef<'table'> {
|
|
29
29
|
variant: 'table';
|
|
30
30
|
columnCount?: ResponsiveProp;
|
|
31
31
|
}
|
|
32
|
-
export type DescriptionsProps
|
|
32
|
+
export type DescriptionsProps = DescriptionsGridProps | DescriptionsTableProps;
|
|
33
33
|
interface DescriptionsContext extends DescriptionsSharedProps {
|
|
34
34
|
variant?: 'grid' | 'table';
|
|
35
35
|
}
|
|
36
36
|
export declare function useDescriptionsContext(): DescriptionsContext;
|
|
37
37
|
declare const DescriptionsContext: import("react").Context<DescriptionsContext>;
|
|
38
38
|
export declare const Descriptions: {
|
|
39
|
-
|
|
39
|
+
(props: DescriptionsProps): ReactElement;
|
|
40
40
|
Item: typeof DescriptionItem;
|
|
41
41
|
};
|
|
42
42
|
export {};
|
|
@@ -3,36 +3,41 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.Descriptions = void 0;
|
|
4
4
|
exports.useDescriptionsContext = useDescriptionsContext;
|
|
5
5
|
const jsx_runtime_1 = require("@emotion/react/jsx-runtime");
|
|
6
|
-
const react_1 = require("react");
|
|
6
|
+
const react_1 = require("@emotion/react");
|
|
7
|
+
const react_2 = require("react");
|
|
7
8
|
const grid_1 = require("../grid");
|
|
8
9
|
const descriptionItem_1 = require("./descriptionItem");
|
|
9
10
|
const utils_1 = require("../../utils");
|
|
10
11
|
const descriptions_style_1 = require("./descriptions.style");
|
|
11
12
|
const theme_1 = require("../theme");
|
|
12
13
|
function useDescriptionsContext() {
|
|
13
|
-
return (0,
|
|
14
|
+
return (0, react_2.useContext)(DescriptionsContext);
|
|
14
15
|
}
|
|
15
|
-
const DescriptionsContext = (0,
|
|
16
|
-
exports.Descriptions = (0,
|
|
17
|
-
const contextValue = (0,
|
|
16
|
+
const DescriptionsContext = (0, react_2.createContext)({});
|
|
17
|
+
exports.Descriptions = (0, react_2.memo)(({ size, labelWidth, colon = ':', labelPlacement = 'left', disableMargin, disablePadding, items, itemComponent: ItemComponent = descriptionItem_1.DescriptionItem, variant = 'grid', columnCount = 3, ...props }) => {
|
|
18
|
+
const contextValue = (0, react_2.useMemo)(() => ({
|
|
18
19
|
size, labelWidth, colon, labelPlacement, disableMargin, disablePadding, variant
|
|
19
20
|
}), [
|
|
20
21
|
size, labelWidth, colon, labelPlacement, disableMargin, disablePadding, variant
|
|
21
22
|
]);
|
|
22
23
|
const renderGridItems = () => {
|
|
23
|
-
return items?.map((itemProps, i) => (0,
|
|
24
|
+
return items?.map((itemProps, i) => (0, react_1.createElement)(ItemComponent
|
|
25
|
+
// 最后一项沾满剩余行空间
|
|
26
|
+
, {
|
|
24
27
|
// 最后一项沾满剩余行空间
|
|
25
|
-
flex: i === items.length - 1 ? 1 : void 0, ...itemProps
|
|
28
|
+
flex: i === items.length - 1 ? 1 : void 0, ...itemProps, key: itemProps.key ?? i })) || props.children;
|
|
26
29
|
};
|
|
27
30
|
const columnCountNum = (0, utils_1.useResponsiveValue)(columnCount);
|
|
28
31
|
const renderTableItems = () => {
|
|
29
|
-
const actualItems = items ||
|
|
32
|
+
const actualItems = items || react_2.Children.map(props.children, c => (0, react_2.isValidElement)(c) ? c.props : c);
|
|
30
33
|
if (actualItems?.length) {
|
|
31
34
|
const rows = [];
|
|
32
35
|
for (let i = 0, { length } = actualItems; i < length; i++) {
|
|
33
36
|
const cols = rows[Math.floor(i / columnCountNum)] ||= [];
|
|
34
37
|
const itemProps = actualItems[i];
|
|
35
|
-
cols.push((0,
|
|
38
|
+
cols.push((0, react_1.createElement)(ItemComponent
|
|
39
|
+
// 最后一项沾满剩余行空间
|
|
40
|
+
, { ...itemProps, key: itemProps.key ?? i, span: i === actualItems.length - 1 ? columnCountNum - i % columnCountNum : itemProps.span, className: (0, utils_1.clsx)(descriptions_style_1.classes.col, itemProps) }));
|
|
36
41
|
}
|
|
37
42
|
return rows.map((r, i) => (0, jsx_runtime_1.jsx)("tr", { children: r }, i));
|
|
38
43
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import React, { Dispatch, ReactElement, ReactNode, Ref, RefObject, SetStateAction, ElementType } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Obj, OverridableProps } from '../../types';
|
|
3
3
|
import { FieldPath } from '../../utils';
|
|
4
4
|
import { FieldError, FormItem, FormItemProps, FormItemRef } from './formItem';
|
|
5
5
|
import { FormRelatable } from './formRelatable';
|
|
6
|
-
import { DescriptionsProps } from '../descriptions';
|
|
6
|
+
import { DescriptionsProps, DescriptionsSharedProps } from '../descriptions';
|
|
7
|
+
import { GridOwnProps } from '../grid';
|
|
7
8
|
export type FormValue = Obj;
|
|
8
9
|
export type FormSharedProps = {
|
|
10
|
+
/** 必填字段的标记,默认为`*` */
|
|
9
11
|
requiredMark?: ReactNode;
|
|
10
12
|
/** variant为"grid"或"table"时会渲染Descriptions组件,并传递variant属性,默认为`grid` */
|
|
11
13
|
variant?: 'plain' | 'grid' | 'table';
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps, DescriptionsSharedProps, GridOwnProps {
|
|
14
16
|
ref?: Ref<FormRef<V> | null>;
|
|
15
17
|
/** 最外层元素的ref,默认{@link ref}属性已经被{@link FormRef}取代 */
|
|
16
18
|
wrapperRef?: Ref<HTMLFormElement>;
|
|
@@ -20,9 +22,8 @@ export interface FormOwnProps<V extends FormValue = FormValue> extends FormShare
|
|
|
20
22
|
items?: (FormItemProps & Obj)[];
|
|
21
23
|
descriptionsProps?: DescriptionsProps;
|
|
22
24
|
}
|
|
23
|
-
export type FormProps<V extends FormValue = FormValue, C extends ElementType = 'form'> =
|
|
25
|
+
export type FormProps<V extends FormValue = FormValue, C extends ElementType = 'form'> = OverridableProps<FormOwnProps<V>, C>;
|
|
24
26
|
interface FormContext<V extends FormValue> extends FormSharedProps {
|
|
25
|
-
requiredMark?: ReactNode;
|
|
26
27
|
formValue?: V;
|
|
27
28
|
setFieldValue?(field: FieldPath, value: any, silent?: boolean): void;
|
|
28
29
|
itemsContainer?: Map<string, FormItemRef>;
|
|
@@ -13,11 +13,11 @@ const FormContext = (0, react_1.createContext)({});
|
|
|
13
13
|
function useFormContext() {
|
|
14
14
|
return (0, react_1.useContext)(FormContext);
|
|
15
15
|
}
|
|
16
|
-
exports.Form = (({
|
|
17
|
-
// 以下属性从DescriptionsBaseProps继承
|
|
18
|
-
items, variant = 'grid',
|
|
16
|
+
exports.Form = (({ component: Component = 'form', ref, wrapperRef, initialValue, onChange, onFinish, items, descriptionsProps, requiredMark = '*', variant = 'grid',
|
|
19
17
|
// 以下属性从DescriptionsSharedProps继承
|
|
20
|
-
labelWidth, labelPlacement = 'left', colon = ':', size, disableMargin, disablePadding,
|
|
18
|
+
labelWidth, labelPlacement = 'left', colon = ':', size, disableMargin, disablePadding,
|
|
19
|
+
// 以下属性从GridOwnProps继承
|
|
20
|
+
inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
|
|
21
21
|
/**
|
|
22
22
|
* ------------------------------------------------------------------------
|
|
23
23
|
* 表单值
|
|
@@ -97,7 +97,7 @@ labelWidth, labelPlacement = 'left', colon = ':', size, disableMargin, disablePa
|
|
|
97
97
|
itemsContainer: itemsContainer.current, formRef
|
|
98
98
|
}), [requiredMark, variant, formValue.current]), children: variant === 'plain'
|
|
99
99
|
? props.children
|
|
100
|
-
: (0, jsx_runtime_1.jsx)(descriptions_1.Descriptions, { ...descriptionsProps, size: size, labelWidth: labelWidth, colon: colon, labelPlacement: labelPlacement, disableMargin: disableMargin, disablePadding: disablePadding,
|
|
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 }) }) }));
|
|
101
101
|
});
|
|
102
102
|
exports.Form.Item = formItem_1.FormItem;
|
|
103
103
|
exports.Form.Relatable = formRelatable_1.FormRelatable;
|
|
@@ -192,14 +192,15 @@ exports.Slider = (0, react_2.memo)(({ color = 'primary', orientation = 'horizont
|
|
|
192
192
|
};
|
|
193
193
|
return renderHandle
|
|
194
194
|
? renderHandle(value, _handleProps)
|
|
195
|
-
: (0,
|
|
195
|
+
: (0, react_1.createElement)(tooltip_1.Tooltip, { popperRef: r => {
|
|
196
196
|
if (r) {
|
|
197
197
|
tooltipRefs.current[index] = r;
|
|
198
198
|
}
|
|
199
199
|
else {
|
|
200
200
|
delete tooltipRefs.current[index];
|
|
201
201
|
}
|
|
202
|
-
}, title: valueIsArray ? innerValue.current[index] : innerValue.current, trigger: ['hover', 'focus'], placement: orientation === 'horizontal' ? 'top' : 'left', ...tooltipProps,
|
|
202
|
+
}, title: valueIsArray ? innerValue.current[index] : innerValue.current, trigger: ['hover', 'focus'], placement: orientation === 'horizontal' ? 'top' : 'left', ...tooltipProps, key: index },
|
|
203
|
+
(0, react_1.createElement)("button", { ..._handleProps, key: index }));
|
|
203
204
|
};
|
|
204
205
|
return valueIsArray
|
|
205
206
|
? innerValue.current.map(fn)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
1
2
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
3
|
import { memo } from 'react';
|
|
3
4
|
import { classes, style } from './actionSheet.style';
|
|
@@ -31,10 +32,10 @@ export const ActionSheet = memo(({ ref, title, actions, placement = 'bottom', ma
|
|
|
31
32
|
confirmProps?.onClick?.(e);
|
|
32
33
|
onConfirm?.(e);
|
|
33
34
|
close('confirmed');
|
|
34
|
-
} }), actions?.map((menuItemProps, i) =>
|
|
35
|
+
} }), actions?.map((menuItemProps, i) => _createElement(MenuItem, { className: clsx(classes.action, menuItemProps.className), size: "large", ...menuItemProps, key: menuItemProps.key ?? i, onClick: e => {
|
|
35
36
|
menuItemProps.onClick?.(e);
|
|
36
37
|
onAction?.(menuItemProps);
|
|
37
38
|
close('action');
|
|
38
|
-
} }
|
|
39
|
+
} }))] }), showCancel &&
|
|
39
40
|
_jsx("div", { className: classes.card, children: _jsx(MenuItem, { color: "error", emphasized: true, size: "large", label: cancelText, ...cancelProps, onClick: cancelHandler }) })] }) }));
|
|
40
41
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { isValidElement, memo, useMemo, useRef, useState } from 'react';
|
|
3
4
|
import { Form, FormItem } from '../form';
|
|
4
5
|
import { classes } from './curd.style';
|
|
@@ -23,7 +24,7 @@ export const CurdFilter = memo(({ ref, columns, expandable, showButton, renderCo
|
|
|
23
24
|
const [expanded, setExpanded] = useState(false);
|
|
24
25
|
const renderedGrid = (_jsx(Grid, { className: classes.filterGrid, columnGap: spacing[8], children: items?.map((item, i) => isValidElement(item)
|
|
25
26
|
? item
|
|
26
|
-
:
|
|
27
|
+
: _createElement(FormItem, { span: { xs: 12, md: 6, lg: 4 }, ...item, key: item.key ?? i, wrapperRef: !i ? firstItemRef : void 0 })) }));
|
|
27
28
|
/**
|
|
28
29
|
* --------------------------------------------------------------
|
|
29
30
|
* 触发筛选
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactElement, ReactNode, ElementType } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { ReactElement, ReactNode, ElementType, ComponentPropsWithRef } from 'react';
|
|
2
|
+
import { Obj, ResponsiveProp, Size } from '../../types';
|
|
3
3
|
import { GridProps } from '../grid';
|
|
4
4
|
import { DescriptionItem, DescriptionItemProps } from './descriptionItem';
|
|
5
5
|
export type DescriptionsSharedProps = {
|
|
@@ -14,7 +14,7 @@ export type DescriptionsSharedProps = {
|
|
|
14
14
|
/** 是否禁用padding,{@link DescriptionsProps.variant}为table有效 */
|
|
15
15
|
disablePadding?: boolean;
|
|
16
16
|
};
|
|
17
|
-
|
|
17
|
+
interface DescriptionsBaseProps extends DescriptionsSharedProps {
|
|
18
18
|
items?: (DescriptionItemProps & Obj)[];
|
|
19
19
|
/**
|
|
20
20
|
* @private 用于渲染item的组件,通常为内部使用
|
|
@@ -22,21 +22,21 @@ export interface DescriptionsBaseProps extends DescriptionsSharedProps {
|
|
|
22
22
|
*/
|
|
23
23
|
itemComponent?: ElementType;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
interface DescriptionsGridProps extends DescriptionsBaseProps, GridProps {
|
|
26
26
|
variant?: 'grid';
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
interface DescriptionsTableProps extends DescriptionsBaseProps, ComponentPropsWithRef<'table'> {
|
|
29
29
|
variant: 'table';
|
|
30
30
|
columnCount?: ResponsiveProp;
|
|
31
31
|
}
|
|
32
|
-
export type DescriptionsProps
|
|
32
|
+
export type DescriptionsProps = DescriptionsGridProps | DescriptionsTableProps;
|
|
33
33
|
interface DescriptionsContext extends DescriptionsSharedProps {
|
|
34
34
|
variant?: 'grid' | 'table';
|
|
35
35
|
}
|
|
36
36
|
export declare function useDescriptionsContext(): DescriptionsContext;
|
|
37
37
|
declare const DescriptionsContext: import("react").Context<DescriptionsContext>;
|
|
38
38
|
export declare const Descriptions: {
|
|
39
|
-
|
|
39
|
+
(props: DescriptionsProps): ReactElement;
|
|
40
40
|
Item: typeof DescriptionItem;
|
|
41
41
|
};
|
|
42
42
|
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
3
|
import { Children, createContext, isValidElement, memo, useContext, useMemo } from 'react';
|
|
3
4
|
import { Grid } from '../grid';
|
|
4
5
|
import { DescriptionItem } from './descriptionItem';
|
|
@@ -16,9 +17,11 @@ export const Descriptions = memo(({ size, labelWidth, colon = ':', labelPlacemen
|
|
|
16
17
|
size, labelWidth, colon, labelPlacement, disableMargin, disablePadding, variant
|
|
17
18
|
]);
|
|
18
19
|
const renderGridItems = () => {
|
|
19
|
-
return items?.map((itemProps, i) =>
|
|
20
|
+
return items?.map((itemProps, i) => _createElement(ItemComponent
|
|
21
|
+
// 最后一项沾满剩余行空间
|
|
22
|
+
, {
|
|
20
23
|
// 最后一项沾满剩余行空间
|
|
21
|
-
flex: i === items.length - 1 ? 1 : void 0, ...itemProps
|
|
24
|
+
flex: i === items.length - 1 ? 1 : void 0, ...itemProps, key: itemProps.key ?? i })) || props.children;
|
|
22
25
|
};
|
|
23
26
|
const columnCountNum = useResponsiveValue(columnCount);
|
|
24
27
|
const renderTableItems = () => {
|
|
@@ -28,7 +31,9 @@ export const Descriptions = memo(({ size, labelWidth, colon = ':', labelPlacemen
|
|
|
28
31
|
for (let i = 0, { length } = actualItems; i < length; i++) {
|
|
29
32
|
const cols = rows[Math.floor(i / columnCountNum)] ||= [];
|
|
30
33
|
const itemProps = actualItems[i];
|
|
31
|
-
cols.push(
|
|
34
|
+
cols.push(_createElement(ItemComponent
|
|
35
|
+
// 最后一项沾满剩余行空间
|
|
36
|
+
, { ...itemProps, key: itemProps.key ?? i, span: i === actualItems.length - 1 ? columnCountNum - i % columnCountNum : itemProps.span, className: clsx(classes.col, itemProps) }));
|
|
32
37
|
}
|
|
33
38
|
return rows.map((r, i) => _jsx("tr", { children: r }, i));
|
|
34
39
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import React, { Dispatch, ReactElement, ReactNode, Ref, RefObject, SetStateAction, ElementType } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Obj, OverridableProps } from '../../types';
|
|
3
3
|
import { FieldPath } from '../../utils';
|
|
4
4
|
import { FieldError, FormItem, FormItemProps, FormItemRef } from './formItem';
|
|
5
5
|
import { FormRelatable } from './formRelatable';
|
|
6
|
-
import { DescriptionsProps } from '../descriptions';
|
|
6
|
+
import { DescriptionsProps, DescriptionsSharedProps } from '../descriptions';
|
|
7
|
+
import { GridOwnProps } from '../grid';
|
|
7
8
|
export type FormValue = Obj;
|
|
8
9
|
export type FormSharedProps = {
|
|
10
|
+
/** 必填字段的标记,默认为`*` */
|
|
9
11
|
requiredMark?: ReactNode;
|
|
10
12
|
/** variant为"grid"或"table"时会渲染Descriptions组件,并传递variant属性,默认为`grid` */
|
|
11
13
|
variant?: 'plain' | 'grid' | 'table';
|
|
12
14
|
};
|
|
13
|
-
|
|
15
|
+
interface FormOwnProps<V extends FormValue = FormValue> extends FormSharedProps, DescriptionsSharedProps, GridOwnProps {
|
|
14
16
|
ref?: Ref<FormRef<V> | null>;
|
|
15
17
|
/** 最外层元素的ref,默认{@link ref}属性已经被{@link FormRef}取代 */
|
|
16
18
|
wrapperRef?: Ref<HTMLFormElement>;
|
|
@@ -20,9 +22,8 @@ export interface FormOwnProps<V extends FormValue = FormValue> extends FormShare
|
|
|
20
22
|
items?: (FormItemProps & Obj)[];
|
|
21
23
|
descriptionsProps?: DescriptionsProps;
|
|
22
24
|
}
|
|
23
|
-
export type FormProps<V extends FormValue = FormValue, C extends ElementType = 'form'> =
|
|
25
|
+
export type FormProps<V extends FormValue = FormValue, C extends ElementType = 'form'> = OverridableProps<FormOwnProps<V>, C>;
|
|
24
26
|
interface FormContext<V extends FormValue> extends FormSharedProps {
|
|
25
|
-
requiredMark?: ReactNode;
|
|
26
27
|
formValue?: V;
|
|
27
28
|
setFieldValue?(field: FieldPath, value: any, silent?: boolean): void;
|
|
28
29
|
itemsContainer?: Map<string, FormItemRef>;
|
|
@@ -9,11 +9,11 @@ const FormContext = createContext({});
|
|
|
9
9
|
export function useFormContext() {
|
|
10
10
|
return useContext(FormContext);
|
|
11
11
|
}
|
|
12
|
-
export const Form = (({
|
|
13
|
-
// 以下属性从DescriptionsBaseProps继承
|
|
14
|
-
items, variant = 'grid',
|
|
12
|
+
export const Form = (({ component: Component = 'form', ref, wrapperRef, initialValue, onChange, onFinish, items, descriptionsProps, requiredMark = '*', variant = 'grid',
|
|
15
13
|
// 以下属性从DescriptionsSharedProps继承
|
|
16
|
-
labelWidth, labelPlacement = 'left', colon = ':', size, disableMargin, disablePadding,
|
|
14
|
+
labelWidth, labelPlacement = 'left', colon = ':', size, disableMargin, disablePadding,
|
|
15
|
+
// 以下属性从GridOwnProps继承
|
|
16
|
+
inline, columnCount = 1, gap, columnGap, rowGap, ...props }) => {
|
|
17
17
|
/**
|
|
18
18
|
* ------------------------------------------------------------------------
|
|
19
19
|
* 表单值
|
|
@@ -93,7 +93,7 @@ labelWidth, labelPlacement = 'left', colon = ':', size, disableMargin, disablePa
|
|
|
93
93
|
itemsContainer: itemsContainer.current, formRef
|
|
94
94
|
}), [requiredMark, variant, formValue.current]), children: variant === 'plain'
|
|
95
95
|
? props.children
|
|
96
|
-
: _jsx(Descriptions, { ...descriptionsProps, size: size, labelWidth: labelWidth, colon: colon, labelPlacement: labelPlacement, disableMargin: disableMargin, disablePadding: disablePadding,
|
|
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 }) }) }));
|
|
97
97
|
});
|
|
98
98
|
Form.Item = FormItem;
|
|
99
99
|
Form.Relatable = FormRelatable;
|
|
@@ -189,14 +189,15 @@ export const Slider = memo(({ color = 'primary', orientation = 'horizontal', var
|
|
|
189
189
|
};
|
|
190
190
|
return renderHandle
|
|
191
191
|
? renderHandle(value, _handleProps)
|
|
192
|
-
:
|
|
192
|
+
: _createElement(Tooltip, { popperRef: r => {
|
|
193
193
|
if (r) {
|
|
194
194
|
tooltipRefs.current[index] = r;
|
|
195
195
|
}
|
|
196
196
|
else {
|
|
197
197
|
delete tooltipRefs.current[index];
|
|
198
198
|
}
|
|
199
|
-
}, title: valueIsArray ? innerValue.current[index] : innerValue.current, trigger: ['hover', 'focus'], placement: orientation === 'horizontal' ? 'top' : 'left', ...tooltipProps,
|
|
199
|
+
}, title: valueIsArray ? innerValue.current[index] : innerValue.current, trigger: ['hover', 'focus'], placement: orientation === 'horizontal' ? 'top' : 'left', ...tooltipProps, key: index },
|
|
200
|
+
_createElement("button", { ..._handleProps, key: index }));
|
|
200
201
|
};
|
|
201
202
|
return valueIsArray
|
|
202
203
|
? innerValue.current.map(fn)
|