@fairys/taro-tools-simple-form-ui 0.0.5
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/README.md +0 -0
- package/esm/components/calendar/index.d.ts +10 -0
- package/esm/components/calendar/index.js +35 -0
- package/esm/components/cascader/index.d.ts +10 -0
- package/esm/components/cascader/index.js +85 -0
- package/esm/components/checkbox.group/index.d.ts +5 -0
- package/esm/components/checkbox.group/index.js +14 -0
- package/esm/components/clear/index.d.ts +21 -0
- package/esm/components/clear/index.js +31 -0
- package/esm/components/date.picker/index.d.ts +18 -0
- package/esm/components/date.picker/index.js +122 -0
- package/esm/components/index.d.ts +8 -0
- package/esm/components/index.js +8 -0
- package/esm/components/picker/index.d.ts +9 -0
- package/esm/components/picker/index.js +45 -0
- package/esm/components/popup.search/base.d.ts +2 -0
- package/esm/components/popup.search/base.js +70 -0
- package/esm/components/popup.search/index.d.ts +9 -0
- package/esm/components/popup.search/index.js +157 -0
- package/esm/components/popup.search/instance.d.ts +127 -0
- package/esm/components/popup.search/instance.js +319 -0
- package/esm/components/popup.search/list.table.d.ts +1 -0
- package/esm/components/popup.search/list.table.js +91 -0
- package/esm/components/popup.search/list.virtual.d.ts +1 -0
- package/esm/components/popup.search/list.virtual.js +71 -0
- package/esm/components/radio.group/index.d.ts +5 -0
- package/esm/components/radio.group/index.js +13 -0
- package/esm/form/form.d.ts +30 -0
- package/esm/form/form.item.d.ts +54 -0
- package/esm/form/form.item.js +172 -0
- package/esm/form/form.js +31 -0
- package/esm/form/instance/index.d.ts +63 -0
- package/esm/form/instance/index.js +141 -0
- package/esm/form/item.config.d.ts +87 -0
- package/esm/form/item.config.js +105 -0
- package/esm/form/layout.d.ts +1784 -0
- package/esm/form/layout.js +134 -0
- package/esm/index.d.ts +5 -0
- package/esm/index.js +5 -0
- package/esm/interface.d.ts +4 -0
- package/esm/interface.js +0 -0
- package/esm/item.config.d.ts +0 -0
- package/esm/item.config.js +0 -0
- package/esm/styles/index.css +352 -0
- package/lib/index.js +96 -0
- package/package.json +38 -0
- package/src/components/calendar/index.tsx +45 -0
- package/src/components/cascader/index.tsx +127 -0
- package/src/components/checkbox.group/index.tsx +16 -0
- package/src/components/clear/index.tsx +49 -0
- package/src/components/date.picker/index.tsx +167 -0
- package/src/components/index.ts +8 -0
- package/src/components/picker/index.tsx +57 -0
- package/src/components/popup.search/base.tsx +51 -0
- package/src/components/popup.search/index.tsx +198 -0
- package/src/components/popup.search/instance.ts +440 -0
- package/src/components/popup.search/list.table.tsx +92 -0
- package/src/components/popup.search/list.virtual.tsx +84 -0
- package/src/components/radio.group/index.tsx +16 -0
- package/src/form/form.item.tsx +280 -0
- package/src/form/form.tsx +54 -0
- package/src/form/instance/index.ts +222 -0
- package/src/form/item.config.tsx +189 -0
- package/src/form/layout.tsx +232 -0
- package/src/index.tsx +5 -0
- package/src/interface.ts +4 -0
- package/src/item.config.tsx +202 -0
- package/src/styles/index.css +39 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Checkbox, Table } from "@nutui/nutui-react-taro";
|
|
3
|
+
import { Del } from "@nutui/icons-react-taro";
|
|
4
|
+
import { useFairysTaroPopupSearchBaseInstanceContext } from "./instance.js";
|
|
5
|
+
import { useMemo } from "react";
|
|
6
|
+
function TableItemCheckBox(props) {
|
|
7
|
+
const { rowData } = props;
|
|
8
|
+
const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext();
|
|
9
|
+
const _tempValue = state._tempValue;
|
|
10
|
+
const operationStatus = state.operationStatus;
|
|
11
|
+
const manageSelectedDataList = state.manageSelectedDataList;
|
|
12
|
+
const checked = useMemo(()=>instance.isCheckedData(rowData), [
|
|
13
|
+
rowData,
|
|
14
|
+
_tempValue,
|
|
15
|
+
operationStatus,
|
|
16
|
+
manageSelectedDataList
|
|
17
|
+
]);
|
|
18
|
+
return /*#__PURE__*/ jsx(Checkbox, {
|
|
19
|
+
className: "fairys-taro-popup-search-list-virtual-checkbox fairystaroform__flex-1",
|
|
20
|
+
checked: checked,
|
|
21
|
+
onChange: ()=>instance.onCheckedData(rowData, checked)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
function TableItemDelete(props) {
|
|
25
|
+
const { rowData } = props;
|
|
26
|
+
const [, instance] = useFairysTaroPopupSearchBaseInstanceContext();
|
|
27
|
+
return /*#__PURE__*/ jsx(Button, {
|
|
28
|
+
size: "mini",
|
|
29
|
+
fill: "none",
|
|
30
|
+
className: "fairys-taro-popup-search-list-virtual-delete-button",
|
|
31
|
+
onClick: ()=>instance.onDeleteData(rowData),
|
|
32
|
+
icon: /*#__PURE__*/ jsx(Del, {
|
|
33
|
+
color: "red"
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function FairysTaroPopupSearchListTable() {
|
|
38
|
+
const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext();
|
|
39
|
+
const popupHeight = instance.popupHeight;
|
|
40
|
+
const data = state._tempFilterDataList || [];
|
|
41
|
+
const operationStatus = state.operationStatus;
|
|
42
|
+
const columns = state.columns || [];
|
|
43
|
+
const tableProps = instance.useTableProps?.(instance.tableProps || {}, instance) || instance.tableProps || {};
|
|
44
|
+
const showRowDeleteButton = instance.showRowDeleteButton;
|
|
45
|
+
const _newColumns = useMemo(()=>{
|
|
46
|
+
const list = [
|
|
47
|
+
{
|
|
48
|
+
key: '__checkbox',
|
|
49
|
+
width: 40,
|
|
50
|
+
align: 'center',
|
|
51
|
+
title: '',
|
|
52
|
+
fixed: 'left',
|
|
53
|
+
render: (rowData)=>/*#__PURE__*/ jsx(TableItemCheckBox, {
|
|
54
|
+
rowData: rowData
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
].concat([
|
|
58
|
+
...columns
|
|
59
|
+
]);
|
|
60
|
+
if ('manage' === operationStatus && 'multiple' === instance.mode && showRowDeleteButton) return [
|
|
61
|
+
...list,
|
|
62
|
+
{
|
|
63
|
+
key: '__delete',
|
|
64
|
+
width: 50,
|
|
65
|
+
align: 'center',
|
|
66
|
+
title: '',
|
|
67
|
+
fixed: 'right',
|
|
68
|
+
render: (rowData)=>/*#__PURE__*/ jsx(TableItemDelete, {
|
|
69
|
+
rowData: rowData
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
];
|
|
73
|
+
return list;
|
|
74
|
+
}, [
|
|
75
|
+
columns,
|
|
76
|
+
operationStatus,
|
|
77
|
+
showRowDeleteButton
|
|
78
|
+
]);
|
|
79
|
+
return /*#__PURE__*/ jsx(Table, {
|
|
80
|
+
bordered: true,
|
|
81
|
+
...tableProps,
|
|
82
|
+
className: `fairys-taro-popup-search-list-table ${tableProps?.className || ''}`,
|
|
83
|
+
style: {
|
|
84
|
+
height: popupHeight,
|
|
85
|
+
...tableProps?.style || {}
|
|
86
|
+
},
|
|
87
|
+
columns: _newColumns,
|
|
88
|
+
data: data
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
export { FairysTaroPopupSearchListTable };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function FairysTaroPopupSearchListVirtual<T = any>(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Button, Cell, Checkbox } from "@nutui/nutui-react-taro";
|
|
3
|
+
import { Del } from "@nutui/icons-react-taro";
|
|
4
|
+
import { ScrollView } from "@tarojs/components";
|
|
5
|
+
import { useFairysTaroPopupSearchBaseInstanceContext } from "./instance.js";
|
|
6
|
+
import { Fragment, useMemo } from "react";
|
|
7
|
+
function VirtualListItem(props) {
|
|
8
|
+
const { rowData } = props;
|
|
9
|
+
const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext();
|
|
10
|
+
const renderListItemText = instance.renderListItemText;
|
|
11
|
+
const _tempValue = state._tempValue;
|
|
12
|
+
const operationStatus = state.operationStatus;
|
|
13
|
+
const manageSelectedDataList = state.manageSelectedDataList;
|
|
14
|
+
const showRowDeleteButton = instance.showRowDeleteButton;
|
|
15
|
+
const renderText = useMemo(()=>renderListItemText?.(rowData, instance) || rowData[instance.displayField], [
|
|
16
|
+
rowData,
|
|
17
|
+
instance.displayField,
|
|
18
|
+
renderListItemText
|
|
19
|
+
]);
|
|
20
|
+
const checked = useMemo(()=>instance.isCheckedData(rowData), [
|
|
21
|
+
rowData,
|
|
22
|
+
_tempValue,
|
|
23
|
+
operationStatus,
|
|
24
|
+
manageSelectedDataList
|
|
25
|
+
]);
|
|
26
|
+
return /*#__PURE__*/ jsx(Cell, {
|
|
27
|
+
className: "fairys-taro-popup-search-list-virtual-cell fairystaroform__px-_zkh1_0_dl_75rem_zhk2__gqh_ fairystaroform__py-_zkh1_0_dl_5rem_zhk2__gqh_ fairystaroform__mx-0 fairystaroform__my-_zkh1_0_dl_1rem_zhk2__gqh_",
|
|
28
|
+
onClick: (event)=>{
|
|
29
|
+
event?.stopPropagation?.();
|
|
30
|
+
event?.preventDefault?.();
|
|
31
|
+
instance.onCheckedData(rowData, checked);
|
|
32
|
+
},
|
|
33
|
+
title: /*#__PURE__*/ jsx(Checkbox, {
|
|
34
|
+
className: "fairys-taro-popup-search-list-virtual-checkbox fairystaroform__flex-1",
|
|
35
|
+
checked: checked,
|
|
36
|
+
children: renderText
|
|
37
|
+
}),
|
|
38
|
+
extra: 'manage' === operationStatus && showRowDeleteButton ? /*#__PURE__*/ jsx(Button, {
|
|
39
|
+
size: "mini",
|
|
40
|
+
fill: "none",
|
|
41
|
+
className: "fairys-taro-popup-search-list-virtual-delete-button",
|
|
42
|
+
onClick: (event)=>{
|
|
43
|
+
event?.stopPropagation?.();
|
|
44
|
+
event?.preventDefault?.();
|
|
45
|
+
instance.onDeleteData(rowData);
|
|
46
|
+
},
|
|
47
|
+
icon: /*#__PURE__*/ jsx(Del, {
|
|
48
|
+
color: "red"
|
|
49
|
+
})
|
|
50
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
function FairysTaroPopupSearchListVirtual() {
|
|
54
|
+
const [state, instance] = useFairysTaroPopupSearchBaseInstanceContext();
|
|
55
|
+
const popupHeight = instance.popupHeight;
|
|
56
|
+
const _tempFilterDataList = state._tempFilterDataList;
|
|
57
|
+
const rowKey = instance.rowKey;
|
|
58
|
+
return /*#__PURE__*/ jsx(ScrollView, {
|
|
59
|
+
scrollY: true,
|
|
60
|
+
style: {
|
|
61
|
+
height: popupHeight,
|
|
62
|
+
overflow: 'auto'
|
|
63
|
+
},
|
|
64
|
+
children: _tempFilterDataList.map((item, index)=>/*#__PURE__*/ jsx(VirtualListItem, {
|
|
65
|
+
rowData: item,
|
|
66
|
+
dataIndex: index,
|
|
67
|
+
index: index
|
|
68
|
+
}, `${item[rowKey]}_${index}`))
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
export { FairysTaroPopupSearchListVirtual };
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RadioGroupProps, RadioProps } from '@nutui/nutui-react-taro';
|
|
2
|
+
export interface FairysTaroRadioGroupProps extends Partial<RadioGroupProps> {
|
|
3
|
+
items?: RadioProps[];
|
|
4
|
+
}
|
|
5
|
+
export declare const FairysTaroRadioGroupBase: (props: FairysTaroRadioGroupProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Radio, RadioGroup } from "@nutui/nutui-react-taro";
|
|
3
|
+
const FairysTaroRadioGroupBase = (props)=>{
|
|
4
|
+
const { items, className, ...rest } = props;
|
|
5
|
+
return /*#__PURE__*/ jsx(RadioGroup, {
|
|
6
|
+
className: `fairys-taro-radio-group ${className || ''}`,
|
|
7
|
+
...rest,
|
|
8
|
+
children: items?.map((item)=>/*#__PURE__*/ jsx(Radio, {
|
|
9
|
+
...item
|
|
10
|
+
}, item.value))
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export { FairysTaroRadioGroupBase };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MObject } from '../interface';
|
|
2
|
+
import { FairysTaroValtioFormInstance, useFairysTaroValtioFormInstance, useFairysTaroValtioFormInstanceContext, useFairysTaroValtioFormInstanceContextState } from './instance';
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
import { FairysTaroValtioFormLayoutProps } from './layout';
|
|
5
|
+
import { FairysTaroValtioFormItem, FairysTaroValtioFormHideItem } from './form.item';
|
|
6
|
+
export * from './item.config';
|
|
7
|
+
export interface FairysTaroValtioFormProps<T extends MObject<T> = object> extends FairysTaroValtioFormLayoutProps {
|
|
8
|
+
/**表单实例*/
|
|
9
|
+
form?: FairysTaroValtioFormInstance<T>;
|
|
10
|
+
/**子元素*/
|
|
11
|
+
children: ReactNode;
|
|
12
|
+
/**表单项规则*/
|
|
13
|
+
rules?: FairysTaroValtioFormInstance<T>['rules'];
|
|
14
|
+
/**表单初始值*/
|
|
15
|
+
formData?: FairysTaroValtioFormInstance<T>['state'];
|
|
16
|
+
/**表单隐藏状态*/
|
|
17
|
+
hideState?: FairysTaroValtioFormInstance<T>['hideState'];
|
|
18
|
+
}
|
|
19
|
+
export declare function FairysTaroValtioForm<T extends MObject<T> = object>(props: FairysTaroValtioFormProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
20
|
+
export declare namespace FairysTaroValtioForm {
|
|
21
|
+
var useForm: typeof useFairysTaroValtioFormInstance;
|
|
22
|
+
var useFormState: typeof useFairysTaroValtioFormInstanceContextState;
|
|
23
|
+
var useFormInstance: typeof useFairysTaroValtioFormInstanceContext;
|
|
24
|
+
var FormItemListItem: (props: {
|
|
25
|
+
items: import("./item.config").FairysTaroValtioInputConfigType[];
|
|
26
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
27
|
+
var FormItemConfig: (config: import("./item.config").FairysTaroValtioInputConfigType) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
+
var FormItem: typeof FairysTaroValtioFormItem;
|
|
29
|
+
var FormHideItem: typeof FairysTaroValtioFormHideItem;
|
|
30
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**表单项*/
|
|
2
|
+
import { MObject } from '../interface';
|
|
3
|
+
import type { ViewProps } from '@tarojs/components';
|
|
4
|
+
import React from 'react';
|
|
5
|
+
import { FairysTaroValtioFormInstance } from './instance';
|
|
6
|
+
export interface FairysTaroValtioFormItemProps<T extends MObject<T> = object> extends ViewProps {
|
|
7
|
+
/**表单项名称*/
|
|
8
|
+
name: string;
|
|
9
|
+
/**表单项标签*/
|
|
10
|
+
label?: string;
|
|
11
|
+
/**是否使用样式*/
|
|
12
|
+
noStyle?: boolean;
|
|
13
|
+
/**传递组件字段*/
|
|
14
|
+
valuePropName?: string;
|
|
15
|
+
/**自定义获取值*/
|
|
16
|
+
getValueFromEvent?: (event: any, form: FairysTaroValtioFormInstance<T>) => any;
|
|
17
|
+
/**值格式化*/
|
|
18
|
+
formatValue?: (value: any, form: FairysTaroValtioFormInstance<T>, event: any) => any;
|
|
19
|
+
/**触发数据更新之后触发(用于数据联动之类的)*/
|
|
20
|
+
onAfterUpdate?: (value: any, form: FairysTaroValtioFormInstance<T>, event: any) => void;
|
|
21
|
+
/**事件名称*/
|
|
22
|
+
trigger?: string;
|
|
23
|
+
style?: React.CSSProperties;
|
|
24
|
+
labelClassName?: string;
|
|
25
|
+
labelStyle?: React.CSSProperties;
|
|
26
|
+
bodyClassName?: string;
|
|
27
|
+
bodyStyle?: React.CSSProperties;
|
|
28
|
+
/**规则校验失败错误提示位置*/
|
|
29
|
+
errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
|
|
30
|
+
/**label显示模式*/
|
|
31
|
+
labelMode?: 'left' | 'top' | 'between';
|
|
32
|
+
/**额外内容*/
|
|
33
|
+
extra?: React.ReactNode;
|
|
34
|
+
/**底部提示内容*/
|
|
35
|
+
helpText?: React.ReactNode;
|
|
36
|
+
/**
|
|
37
|
+
* 表单项占据列数
|
|
38
|
+
* @default 1
|
|
39
|
+
*/
|
|
40
|
+
colSpan?: number;
|
|
41
|
+
/**
|
|
42
|
+
* 表单项占据行数
|
|
43
|
+
* @default 1
|
|
44
|
+
*/
|
|
45
|
+
rowSpan?: number;
|
|
46
|
+
/**是否必填*/
|
|
47
|
+
isRequired?: boolean;
|
|
48
|
+
/**底部显示边框*/
|
|
49
|
+
bottomBordered?: boolean;
|
|
50
|
+
/**输入框属性*/
|
|
51
|
+
attrs?: any;
|
|
52
|
+
}
|
|
53
|
+
export declare function FairysTaroValtioFormItem<T extends MObject<T> = object>(props: FairysTaroValtioFormItemProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
54
|
+
export declare function FairysTaroValtioFormHideItem<T extends MObject<T> = object>(props: FairysTaroValtioFormItemProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View } from "@tarojs/components";
|
|
3
|
+
import react, { Fragment, useMemo } from "react";
|
|
4
|
+
import clsx from "clsx";
|
|
5
|
+
import { useFairysTaroValtioFormInstanceContextHideState, useFairysTaroValtioFormInstanceContextState } from "./instance/index.js";
|
|
6
|
+
import { useFairysTaroValtioFormLayoutContext } from "./layout.js";
|
|
7
|
+
function FairysTaroValtioFormItem(props) {
|
|
8
|
+
const [layoutAttrs] = useFairysTaroValtioFormLayoutContext();
|
|
9
|
+
const colCount = layoutAttrs.colCount || 1;
|
|
10
|
+
const parent_bottomBordered = layoutAttrs.bottomBordered || true;
|
|
11
|
+
const parent_errorLayout = layoutAttrs.errorLayout || 'right-bottom';
|
|
12
|
+
const parent_formItemClassName = layoutAttrs.formItemClassName;
|
|
13
|
+
const parent_formItemLabelClassName = layoutAttrs.formItemLabelClassName;
|
|
14
|
+
const parent_formItemLabelStyle = layoutAttrs.formItemLabelStyle;
|
|
15
|
+
const parent_formItemStyle = layoutAttrs.formItemStyle;
|
|
16
|
+
const parent_labelMode = layoutAttrs.labelMode || 'between';
|
|
17
|
+
const { name, label, noStyle, valuePropName = 'value', getValueFromEvent, formatValue, onAfterUpdate, trigger = 'onChange', className, style, labelClassName, labelStyle, bodyClassName, bodyStyle, children, labelMode = parent_labelMode, errorLayout = parent_errorLayout, extra, helpText, colSpan = 1, rowSpan = 1, isRequired: _isRequired, bottomBordered = parent_bottomBordered, attrs = {}, ...rest } = props;
|
|
18
|
+
const [state, errorState, formInstance] = useFairysTaroValtioFormInstanceContextState();
|
|
19
|
+
const rules = formInstance.rules?.[name];
|
|
20
|
+
const value = state[name];
|
|
21
|
+
const error = errorState[name];
|
|
22
|
+
const onValueChange = (event)=>{
|
|
23
|
+
let value = event;
|
|
24
|
+
const target = event?.detail || event?.target;
|
|
25
|
+
if ('function' == typeof getValueFromEvent) value = getValueFromEvent(event, formInstance);
|
|
26
|
+
else if (event && target && 'object' == typeof target && valuePropName in target) value = target.valuePropName;
|
|
27
|
+
if ('function' == typeof formatValue) value = formatValue(value, formInstance, event);
|
|
28
|
+
formInstance.updated({
|
|
29
|
+
[name]: value
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
const baseControl = {
|
|
33
|
+
...attrs,
|
|
34
|
+
name,
|
|
35
|
+
[valuePropName]: value,
|
|
36
|
+
[trigger]: onValueChange
|
|
37
|
+
};
|
|
38
|
+
const isRequired = useMemo(()=>{
|
|
39
|
+
if (_isRequired) return _isRequired;
|
|
40
|
+
if (Array.isArray(rules) && rules.length) return rules.some((rule)=>rule.required);
|
|
41
|
+
return false;
|
|
42
|
+
}, [
|
|
43
|
+
rules,
|
|
44
|
+
formInstance
|
|
45
|
+
]);
|
|
46
|
+
const isInvalid = useMemo(()=>{
|
|
47
|
+
if (Array.isArray(error) && error.length) return true;
|
|
48
|
+
return false;
|
|
49
|
+
}, [
|
|
50
|
+
error
|
|
51
|
+
]);
|
|
52
|
+
const item_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item fairystaroform__p-_zkh1_0_dl_2rem_zhk2_ fairystaroform__text-_zkh1_0_dl_6rem_zhk2_ fairystaroform__relative fairystaroform__flex fairystaroform__flex-col fairystaroform__box-border fairystaroform__break-all', {
|
|
53
|
+
'fairystaroform__border-b fairystaroform__border-b-solid fairystaroform__border-b-gray-100 ': bottomBordered
|
|
54
|
+
}, className, parent_formItemClassName), [
|
|
55
|
+
className,
|
|
56
|
+
parent_formItemClassName,
|
|
57
|
+
labelMode,
|
|
58
|
+
bottomBordered
|
|
59
|
+
]);
|
|
60
|
+
const itemContainer_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-container fairystaroform__flex-1 fairystaroform__h-full fairystaroform__flex fairystaroform__box-border', {
|
|
61
|
+
'fairystaroform__flex-row fairystaroform__items-center fairystaroform__justify-between fairystaroform__gap-_zkh1_0_dl_4rem_zhk2_': 'between' === labelMode,
|
|
62
|
+
'fairystaroform__flex-col fairystaroform__gap-_zkh1_0_dl_2rem_zhk2_': 'top' === labelMode,
|
|
63
|
+
'fairystaroform__flex-row fairystaroform__gap-_zkh1_0_dl_4rem_zhk2_': 'left' === labelMode
|
|
64
|
+
}, labelClassName), [
|
|
65
|
+
labelClassName,
|
|
66
|
+
labelMode
|
|
67
|
+
]);
|
|
68
|
+
const itemLabel_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-label fairystaroform__text-gray-800 fairystaroform__text-_zkh1_0_dl_75rem_zhk2_ fairystaroform__min-h-_zkh1_1_dl_4rem_zhk2_ fairystaroform__flex fairystaroform__items-center fairystaroform__relative fairystaroform__box-border', {
|
|
69
|
+
'fairystaroform__justify-start': 'left' !== labelMode,
|
|
70
|
+
'fairystaroform__justify-end': 'left' === labelMode,
|
|
71
|
+
required: isRequired
|
|
72
|
+
}, labelClassName, parent_formItemLabelClassName), [
|
|
73
|
+
labelClassName,
|
|
74
|
+
parent_formItemLabelClassName,
|
|
75
|
+
labelMode,
|
|
76
|
+
isRequired
|
|
77
|
+
]);
|
|
78
|
+
const itemBody_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body fairystaroform__flex fairystaroform__box-border', {
|
|
79
|
+
'fairystaroform__flex-row fairystaroform__justify-start': 'left' === labelMode,
|
|
80
|
+
'fairystaroform__flex-row fairystaroform__justify-end': 'between' === labelMode || 'top' === labelMode,
|
|
81
|
+
'fairystaroform__flex-row': 'top' === labelMode
|
|
82
|
+
}, bodyClassName), [
|
|
83
|
+
bodyClassName,
|
|
84
|
+
labelMode
|
|
85
|
+
]);
|
|
86
|
+
const itemInput_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body fairystaroform__flex fairystaroform__flex-row fairystaroform__flex-1 fairystaroform__box-border', {
|
|
87
|
+
'fairystaroform__justify-end fairystaroform__text-right': 'between' === labelMode,
|
|
88
|
+
'fairystaroform__justify-start fairystaroform__text-left fairystaroform__items-center': 'between' !== labelMode
|
|
89
|
+
}), [
|
|
90
|
+
labelMode
|
|
91
|
+
]);
|
|
92
|
+
const itemExtra_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body-extra fairystaroform__box-border fairystaroform__flex fairystaroform__items-center fairystaroform__justify-center'), []);
|
|
93
|
+
const itemHelp_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body-help fairystaroform__text-_zkh1_0_dl_5rem_zhk2_ fairystaroform__w-full fairystaroform__box-border'), []);
|
|
94
|
+
const itemError_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body-error fairystaroform__px-_zkh1_0_dl_2rem_zhk2_ fairystaroform__w-full fairystaroform__flex fairystaroform__flex-row fairystaroform__box-border fairystaroform__text-red fairystaroform__absolute fairystaroform__text-_zkh1_0_dl_5rem_zhk2_ fairystaroform__z-10', {
|
|
95
|
+
'fairystaroform__bottom-_zkh1_-0_dl_7rem_zhk2_ fairystaroform__left-0 fairystaroform__justify-start': 'left-bottom' === errorLayout,
|
|
96
|
+
'fairystaroform__bottom-_zkh1_-0_dl_7rem_zhk2_ fairystaroform__right-0 fairystaroform__justify-end': 'right-bottom' === errorLayout,
|
|
97
|
+
'fairystaroform__top-_zkh1_-0_dl_7rem_zhk2_ fairystaroform__right-0 fairystaroform__justify-end': 'top-right' === errorLayout,
|
|
98
|
+
'fairystaroform__top-_zkh1_-0_dl_7rem_zhk2_ fairystaroform__left-0 fairystaroform__justify-start': 'top-left' === errorLayout
|
|
99
|
+
}), [
|
|
100
|
+
errorLayout
|
|
101
|
+
]);
|
|
102
|
+
const styleBase = useMemo(()=>{
|
|
103
|
+
const css = {};
|
|
104
|
+
if (colSpan) {
|
|
105
|
+
const end = colCount > colSpan ? colSpan : colCount;
|
|
106
|
+
css.gridColumnEnd = `span ${end}`;
|
|
107
|
+
}
|
|
108
|
+
if (rowSpan) css.gridRowEnd = `span ${rowSpan}`;
|
|
109
|
+
return css;
|
|
110
|
+
}, [
|
|
111
|
+
colSpan,
|
|
112
|
+
rowSpan,
|
|
113
|
+
colCount
|
|
114
|
+
]);
|
|
115
|
+
return /*#__PURE__*/ jsxs(View, {
|
|
116
|
+
...rest,
|
|
117
|
+
className: item_cls,
|
|
118
|
+
style: {
|
|
119
|
+
...parent_formItemStyle || {},
|
|
120
|
+
...styleBase,
|
|
121
|
+
...style || {}
|
|
122
|
+
},
|
|
123
|
+
children: [
|
|
124
|
+
/*#__PURE__*/ jsxs(View, {
|
|
125
|
+
className: itemContainer_cls,
|
|
126
|
+
children: [
|
|
127
|
+
/*#__PURE__*/ jsx(View, {
|
|
128
|
+
className: itemLabel_cls,
|
|
129
|
+
style: {
|
|
130
|
+
...parent_formItemLabelStyle || {},
|
|
131
|
+
...labelStyle || {}
|
|
132
|
+
},
|
|
133
|
+
children: label
|
|
134
|
+
}),
|
|
135
|
+
/*#__PURE__*/ jsxs(View, {
|
|
136
|
+
className: itemBody_cls,
|
|
137
|
+
style: bodyStyle,
|
|
138
|
+
children: [
|
|
139
|
+
/*#__PURE__*/ jsx(View, {
|
|
140
|
+
className: itemInput_cls,
|
|
141
|
+
children: /*#__PURE__*/ react.isValidElement(children) ? /*#__PURE__*/ react.cloneElement(children, {
|
|
142
|
+
...baseControl
|
|
143
|
+
}) : children
|
|
144
|
+
}),
|
|
145
|
+
extra ? /*#__PURE__*/ jsx(View, {
|
|
146
|
+
className: itemExtra_cls,
|
|
147
|
+
children: extra
|
|
148
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
149
|
+
]
|
|
150
|
+
})
|
|
151
|
+
]
|
|
152
|
+
}),
|
|
153
|
+
helpText ? /*#__PURE__*/ jsx(View, {
|
|
154
|
+
className: itemHelp_cls,
|
|
155
|
+
children: helpText
|
|
156
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
157
|
+
isInvalid ? /*#__PURE__*/ jsx(View, {
|
|
158
|
+
className: itemError_cls,
|
|
159
|
+
children: error
|
|
160
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
161
|
+
]
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
function FairysTaroValtioFormHideItem(props) {
|
|
165
|
+
const [state] = useFairysTaroValtioFormInstanceContextHideState();
|
|
166
|
+
const isHide = state[props.name];
|
|
167
|
+
if (isHide) return /*#__PURE__*/ jsx(Fragment, {});
|
|
168
|
+
return /*#__PURE__*/ jsx(FairysTaroValtioFormItem, {
|
|
169
|
+
...props
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
export { FairysTaroValtioFormHideItem, FairysTaroValtioFormItem };
|
package/esm/form/form.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FairysTaroValtioFormInstanceContext, useFairysTaroValtioFormInstance, useFairysTaroValtioFormInstanceContext, useFairysTaroValtioFormInstanceContextState } from "./instance/index.js";
|
|
3
|
+
import { useMemo } from "react";
|
|
4
|
+
import { FairysTaroValtioFormLayout } from "./layout.js";
|
|
5
|
+
import { FairysTaroValtioFormHideItem, FairysTaroValtioFormItem } from "./form.item.js";
|
|
6
|
+
import { FairysTaroValtioFormConfigItem, FairysTaroValtioFormConfigListItem } from "./item.config.js";
|
|
7
|
+
export * from "./item.config.js";
|
|
8
|
+
function FairysTaroValtioForm(props) {
|
|
9
|
+
const { form, children, rules, formData, hideState, ...rest } = props;
|
|
10
|
+
const formInstance = useFairysTaroValtioFormInstance(form);
|
|
11
|
+
formInstance.rules = rules;
|
|
12
|
+
useMemo(()=>formInstance.ctor({
|
|
13
|
+
formData,
|
|
14
|
+
hideState
|
|
15
|
+
}), []);
|
|
16
|
+
return /*#__PURE__*/ jsx(FairysTaroValtioFormInstanceContext.Provider, {
|
|
17
|
+
value: formInstance,
|
|
18
|
+
children: /*#__PURE__*/ jsx(FairysTaroValtioFormLayout, {
|
|
19
|
+
...rest,
|
|
20
|
+
children: children
|
|
21
|
+
})
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
FairysTaroValtioForm.useForm = useFairysTaroValtioFormInstance;
|
|
25
|
+
FairysTaroValtioForm.useFormState = useFairysTaroValtioFormInstanceContextState;
|
|
26
|
+
FairysTaroValtioForm.useFormInstance = useFairysTaroValtioFormInstanceContext;
|
|
27
|
+
FairysTaroValtioForm.FormItemListItem = FairysTaroValtioFormConfigListItem;
|
|
28
|
+
FairysTaroValtioForm.FormItemConfig = FairysTaroValtioFormConfigItem;
|
|
29
|
+
FairysTaroValtioForm.FormItem = FairysTaroValtioFormItem;
|
|
30
|
+
FairysTaroValtioForm.FormHideItem = FairysTaroValtioFormHideItem;
|
|
31
|
+
export { FairysTaroValtioForm };
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { MObject } from '../../interface';
|
|
2
|
+
import { RuleItem, ValidateFieldsError, Values } from 'async-validator';
|
|
3
|
+
/**表单实例*/
|
|
4
|
+
export declare class FairysTaroValtioFormInstance<T extends MObject<T> = Record<string, any>> {
|
|
5
|
+
/**状态*/
|
|
6
|
+
state: T;
|
|
7
|
+
/**
|
|
8
|
+
* 错误信息
|
|
9
|
+
*/
|
|
10
|
+
errorState: Record<PropertyKey, string[]>;
|
|
11
|
+
/**隐藏状态*/
|
|
12
|
+
hideState: Record<PropertyKey, boolean>;
|
|
13
|
+
/**初始化表单值*/
|
|
14
|
+
ctor: (options?: {
|
|
15
|
+
formData?: Partial<T>;
|
|
16
|
+
hideState?: Partial<Record<PropertyKey, boolean>>;
|
|
17
|
+
}) => void;
|
|
18
|
+
/**
|
|
19
|
+
* 更新数据
|
|
20
|
+
* @param state 更新数据对象
|
|
21
|
+
* @param isValidate 是否验证(可选)
|
|
22
|
+
*/
|
|
23
|
+
updated: <M = T>(state: Partial<M>, isValidate?: boolean) => void;
|
|
24
|
+
/**
|
|
25
|
+
* 更新行数据的隐藏信息
|
|
26
|
+
* @param objectHideInfo 行数据隐藏信息对象
|
|
27
|
+
*/
|
|
28
|
+
updatedHideInfo: (objectHideInfo: Record<PropertyKey, boolean>) => this;
|
|
29
|
+
/**
|
|
30
|
+
* 清理隐藏信息
|
|
31
|
+
*/
|
|
32
|
+
clearHideInfo: (fields?: PropertyKey[]) => this;
|
|
33
|
+
/**
|
|
34
|
+
* 更新行数据的错误信息
|
|
35
|
+
* @param objectErrorInfo 行数据错误信息对象
|
|
36
|
+
*/
|
|
37
|
+
updatedErrorInfo: (objectErrorInfo: Record<PropertyKey, string[]>) => this;
|
|
38
|
+
/**
|
|
39
|
+
* 清理错误信息
|
|
40
|
+
*/
|
|
41
|
+
clearErrorInfo: (fields?: PropertyKey[]) => this;
|
|
42
|
+
/**
|
|
43
|
+
* 清理所有数据
|
|
44
|
+
*/
|
|
45
|
+
clear: () => void;
|
|
46
|
+
/**列规则 */
|
|
47
|
+
rules: Record<PropertyKey, ((formData: T, instance: FairysTaroValtioFormInstance<T>) => RuleItem[] | Promise<RuleItem[]>) | RuleItem[]>;
|
|
48
|
+
/**规则验证
|
|
49
|
+
* @param fields 列字段数组(可选)
|
|
50
|
+
* @param isReturn 是否返回验证结果(可选)
|
|
51
|
+
*/
|
|
52
|
+
validate: (fields?: PropertyKey[], isReturn?: boolean) => Promise<ValidateFieldsError | Values>;
|
|
53
|
+
}
|
|
54
|
+
/**声明实例*/
|
|
55
|
+
export declare function useFairysTaroValtioFormInstance<T extends MObject<T> = object>(instance?: FairysTaroValtioFormInstance<T>): FairysTaroValtioFormInstance<T>;
|
|
56
|
+
/**表单实例上下文*/
|
|
57
|
+
export declare const FairysTaroValtioFormInstanceContext: import("react").Context<FairysTaroValtioFormInstance<any>>;
|
|
58
|
+
/**表单实例上下文*/
|
|
59
|
+
export declare function useFairysTaroValtioFormInstanceContext<T extends MObject<T> = object>(): FairysTaroValtioFormInstance<T>;
|
|
60
|
+
/**状态取值*/
|
|
61
|
+
export declare function useFairysTaroValtioFormInstanceContextState<T extends MObject<T> = object>(): [T, Record<PropertyKey, string[]>, FairysTaroValtioFormInstance<T>, any, any];
|
|
62
|
+
/**隐藏组件状态取值*/
|
|
63
|
+
export declare function useFairysTaroValtioFormInstanceContextHideState<T extends MObject<T> = object>(): [Record<PropertyKey, boolean>, FairysTaroValtioFormInstance<T>, any];
|