@fairys/taro-valtio-form-basic 0.0.12
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/form.d.ts +18 -0
- package/esm/form.item.d.ts +17 -0
- package/esm/form.item.js +81 -0
- package/esm/form.js +25 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.js +1 -0
- package/esm/layout.d.ts +4 -0
- package/esm/layout.js +37 -0
- package/lib/index.js +60 -0
- package/package.json +34 -0
- package/src/form.item.tsx +104 -0
- package/src/form.tsx +38 -0
- package/src/index.tsx +1 -0
- package/src/layout.tsx +39 -0
package/README.md
ADDED
|
File without changes
|
package/esm/form.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FairysTaroValtioFormItem, FairysTaroValtioFormHideItem, FairysTaroValtioFormItemBase } from './form.item';
|
|
2
|
+
import { useFairysValtioFormInstance, useFairysValtioFormInstanceContext, useFairysValtioFormInstanceContextState, useFairysValtioFormInstanceContextHideState } from '@fairys/valtio-form-basic';
|
|
3
|
+
import type { FairysValtioFormAttrsProps, MObject } from '@fairys/valtio-form-basic';
|
|
4
|
+
export * from '@fairys/valtio-form-basic';
|
|
5
|
+
export * from './form.item';
|
|
6
|
+
export * from './layout';
|
|
7
|
+
export interface FairysTaroValtioFormProps<T extends MObject<T> = object> extends FairysValtioFormAttrsProps<T> {
|
|
8
|
+
}
|
|
9
|
+
export declare function FairysTaroValtioForm<T extends MObject<T> = object>(props: FairysTaroValtioFormProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export declare namespace FairysTaroValtioForm {
|
|
11
|
+
var useForm: typeof useFairysValtioFormInstance;
|
|
12
|
+
var useFormState: typeof useFairysValtioFormInstanceContextState;
|
|
13
|
+
var useFormHideState: typeof useFairysValtioFormInstanceContextHideState;
|
|
14
|
+
var useFormInstance: typeof useFairysValtioFormInstanceContext;
|
|
15
|
+
var FormItemBase: typeof FairysTaroValtioFormItemBase;
|
|
16
|
+
var FormItem: typeof FairysTaroValtioFormItem;
|
|
17
|
+
var FormHideItem: typeof FairysTaroValtioFormHideItem;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**表单项*/
|
|
2
|
+
import type { ViewProps } from '@tarojs/components';
|
|
3
|
+
import type { FairysValtioFormItemAttrsProps, MObject } from '@fairys/valtio-form-basic';
|
|
4
|
+
export interface FairysTaroValtioFormItemProps<T extends MObject<T> = object> extends Omit<ViewProps, 'style'>, FairysValtioFormItemAttrsProps {
|
|
5
|
+
/**是否使用控制隐藏的表单项*/
|
|
6
|
+
isHide?: boolean;
|
|
7
|
+
/**是否使用无样式表单项*/
|
|
8
|
+
noStyle?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**普通表单项*/
|
|
11
|
+
export declare function FairysTaroValtioFormItemBase<T extends MObject<T> = object>(props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>): import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
/**控制隐藏的表单项*/
|
|
13
|
+
export declare function FairysTaroValtioFormHideItem<T extends MObject<T> = object>(props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>): import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
/**无样式表单项*/
|
|
15
|
+
export declare function FairysTaroValtioFormItemNoStyle<T extends MObject<T> = object>(props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>): import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
/**表单项基础组件(根据isHide和noStyle判断是否使用控制隐藏的表单项和无样式表单项)*/
|
|
17
|
+
export declare function FairysTaroValtioFormItem<T extends MObject<T> = object>(props: FairysTaroValtioFormItemProps<T>): import("react/jsx-runtime").JSX.Element;
|
package/esm/form.item.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { View } from "@tarojs/components";
|
|
3
|
+
import { Fragment } from "react";
|
|
4
|
+
import { FairysValtioFormParentAttrsContext, useFairysValtioFormInstanceContextHideState, useFairysValtioFormItemAttrs, useFairysValtioFormItemNoStyleAttrs } from "@fairys/valtio-form-basic";
|
|
5
|
+
function FairysTaroValtioFormItemBase(props) {
|
|
6
|
+
const { label, extra, helpText } = props;
|
|
7
|
+
const { itemClassName, itemStyle, containerClassName, itemLabelClassName, itemLabelStyle, itemBodyClassName, itemBodyStyle, itemInputClassName, itemExtraClassName, errorClassName, helpClassName, isInvalid, itemBorderType, children, error, formAttrsNameInstance } = useFairysValtioFormItemAttrs(props);
|
|
8
|
+
return /*#__PURE__*/ jsxs(View, {
|
|
9
|
+
className: itemClassName,
|
|
10
|
+
style: itemStyle,
|
|
11
|
+
children: [
|
|
12
|
+
/*#__PURE__*/ jsxs(View, {
|
|
13
|
+
className: containerClassName,
|
|
14
|
+
children: [
|
|
15
|
+
label ? /*#__PURE__*/ jsx(View, {
|
|
16
|
+
className: itemLabelClassName,
|
|
17
|
+
style: itemLabelStyle,
|
|
18
|
+
children: label
|
|
19
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
20
|
+
/*#__PURE__*/ jsxs(View, {
|
|
21
|
+
className: itemBodyClassName,
|
|
22
|
+
style: itemBodyStyle,
|
|
23
|
+
children: [
|
|
24
|
+
/*#__PURE__*/ jsx(FairysValtioFormParentAttrsContext.Provider, {
|
|
25
|
+
value: formAttrsNameInstance,
|
|
26
|
+
children: /*#__PURE__*/ jsx(View, {
|
|
27
|
+
className: itemInputClassName,
|
|
28
|
+
children: children
|
|
29
|
+
})
|
|
30
|
+
}),
|
|
31
|
+
extra ? /*#__PURE__*/ jsx(View, {
|
|
32
|
+
className: itemExtraClassName,
|
|
33
|
+
children: extra
|
|
34
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
35
|
+
'body' === itemBorderType && isInvalid ? /*#__PURE__*/ jsx(View, {
|
|
36
|
+
className: errorClassName,
|
|
37
|
+
children: error
|
|
38
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
39
|
+
]
|
|
40
|
+
})
|
|
41
|
+
]
|
|
42
|
+
}),
|
|
43
|
+
helpText ? /*#__PURE__*/ jsx(View, {
|
|
44
|
+
className: helpClassName,
|
|
45
|
+
children: helpText
|
|
46
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
47
|
+
isInvalid && 'body' !== itemBorderType ? /*#__PURE__*/ jsx(View, {
|
|
48
|
+
className: errorClassName,
|
|
49
|
+
children: error
|
|
50
|
+
}) : /*#__PURE__*/ jsx(Fragment, {})
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
function FairysTaroValtioFormHideItem(props) {
|
|
55
|
+
const [state] = useFairysValtioFormInstanceContextHideState();
|
|
56
|
+
const isHide = state[props.name];
|
|
57
|
+
if (isHide) return /*#__PURE__*/ jsx(Fragment, {});
|
|
58
|
+
return /*#__PURE__*/ jsx(FairysTaroValtioFormItemBase, {
|
|
59
|
+
...props
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
function FairysTaroValtioFormItemNoStyle(props) {
|
|
63
|
+
const { children, formAttrsNameInstance } = useFairysValtioFormItemNoStyleAttrs(props);
|
|
64
|
+
return /*#__PURE__*/ jsx(FairysValtioFormParentAttrsContext.Provider, {
|
|
65
|
+
value: formAttrsNameInstance,
|
|
66
|
+
children: children
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function FairysTaroValtioFormItem(props) {
|
|
70
|
+
const { isHide, noStyle, ...rest } = props;
|
|
71
|
+
if (isHide) return /*#__PURE__*/ jsx(FairysTaroValtioFormHideItem, {
|
|
72
|
+
...rest
|
|
73
|
+
});
|
|
74
|
+
if (noStyle) return /*#__PURE__*/ jsx(FairysTaroValtioFormItemNoStyle, {
|
|
75
|
+
...rest
|
|
76
|
+
});
|
|
77
|
+
return /*#__PURE__*/ jsx(FairysTaroValtioFormItemBase, {
|
|
78
|
+
...rest
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
export { FairysTaroValtioFormHideItem, FairysTaroValtioFormItem, FairysTaroValtioFormItemBase, FairysTaroValtioFormItemNoStyle };
|
package/esm/form.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { FairysTaroValtioFormLayout } from "./layout.js";
|
|
3
|
+
import { FairysTaroValtioFormHideItem, FairysTaroValtioFormItem, FairysTaroValtioFormItemBase } from "./form.item.js";
|
|
4
|
+
import { FairysValtioFormInstanceContext, useFairysValtioForm, useFairysValtioFormInstance, useFairysValtioFormInstanceContext, useFairysValtioFormInstanceContextHideState, useFairysValtioFormInstanceContextState } from "@fairys/valtio-form-basic";
|
|
5
|
+
export * from "@fairys/valtio-form-basic";
|
|
6
|
+
export * from "./form.item.js";
|
|
7
|
+
export * from "./layout.js";
|
|
8
|
+
function FairysTaroValtioForm(props) {
|
|
9
|
+
const { formInstance, children, ...rest } = useFairysValtioForm(props);
|
|
10
|
+
return /*#__PURE__*/ jsx(FairysValtioFormInstanceContext.Provider, {
|
|
11
|
+
value: formInstance,
|
|
12
|
+
children: /*#__PURE__*/ jsx(FairysTaroValtioFormLayout, {
|
|
13
|
+
...rest,
|
|
14
|
+
children: children
|
|
15
|
+
})
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
FairysTaroValtioForm.useForm = useFairysValtioFormInstance;
|
|
19
|
+
FairysTaroValtioForm.useFormState = useFairysValtioFormInstanceContextState;
|
|
20
|
+
FairysTaroValtioForm.useFormHideState = useFairysValtioFormInstanceContextHideState;
|
|
21
|
+
FairysTaroValtioForm.useFormInstance = useFairysValtioFormInstanceContext;
|
|
22
|
+
FairysTaroValtioForm.FormItemBase = FairysTaroValtioFormItemBase;
|
|
23
|
+
FairysTaroValtioForm.FormItem = FairysTaroValtioFormItem;
|
|
24
|
+
FairysTaroValtioForm.FormHideItem = FairysTaroValtioFormHideItem;
|
|
25
|
+
export { FairysTaroValtioForm };
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './form';
|
package/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./form.js";
|
package/esm/layout.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FairysValtioFormLayoutAttrsProps } from '@fairys/valtio-form-basic';
|
|
2
|
+
export interface FairysTaroValtioFormLayoutProps extends FairysValtioFormLayoutAttrsProps {
|
|
3
|
+
}
|
|
4
|
+
export declare function FairysTaroValtioFormLayout(props: FairysTaroValtioFormLayoutProps): import("react/jsx-runtime").JSX.Element;
|
package/esm/layout.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment } from "react";
|
|
3
|
+
import { View } from "@tarojs/components";
|
|
4
|
+
import { FairysValtioFormLayoutContext, useFairysValtioFormLayoutAttrs } from "@fairys/valtio-form-basic";
|
|
5
|
+
function FairysTaroValtioFormLayout(props) {
|
|
6
|
+
const { children, title, extra } = props;
|
|
7
|
+
const { formLayoutInstance, layoutName, layoutStyle, headerName, headerStyle, headerTitleName, headerExtraName, bodyName, bodyStyle } = useFairysValtioFormLayoutAttrs(props);
|
|
8
|
+
return /*#__PURE__*/ jsx(FairysValtioFormLayoutContext.Provider, {
|
|
9
|
+
value: formLayoutInstance,
|
|
10
|
+
children: /*#__PURE__*/ jsxs(View, {
|
|
11
|
+
className: layoutName,
|
|
12
|
+
style: layoutStyle,
|
|
13
|
+
children: [
|
|
14
|
+
title || extra ? /*#__PURE__*/ jsxs(View, {
|
|
15
|
+
style: headerStyle,
|
|
16
|
+
className: headerName,
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ jsx(View, {
|
|
19
|
+
className: headerTitleName,
|
|
20
|
+
children: title
|
|
21
|
+
}),
|
|
22
|
+
/*#__PURE__*/ jsx(View, {
|
|
23
|
+
className: headerExtraName,
|
|
24
|
+
children: extra
|
|
25
|
+
})
|
|
26
|
+
]
|
|
27
|
+
}) : /*#__PURE__*/ jsx(Fragment, {}),
|
|
28
|
+
/*#__PURE__*/ jsx(View, {
|
|
29
|
+
className: bodyName,
|
|
30
|
+
style: bodyStyle,
|
|
31
|
+
children: children
|
|
32
|
+
})
|
|
33
|
+
]
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export { FairysTaroValtioFormLayout };
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __webpack_modules__ = {
|
|
3
|
+
"./form": function(module) {
|
|
4
|
+
module.exports = require("./form.js");
|
|
5
|
+
}
|
|
6
|
+
};
|
|
7
|
+
var __webpack_module_cache__ = {};
|
|
8
|
+
function __webpack_require__(moduleId) {
|
|
9
|
+
var cachedModule = __webpack_module_cache__[moduleId];
|
|
10
|
+
if (void 0 !== cachedModule) return cachedModule.exports;
|
|
11
|
+
var module = __webpack_module_cache__[moduleId] = {
|
|
12
|
+
exports: {}
|
|
13
|
+
};
|
|
14
|
+
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
15
|
+
return module.exports;
|
|
16
|
+
}
|
|
17
|
+
(()=>{
|
|
18
|
+
__webpack_require__.n = (module)=>{
|
|
19
|
+
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
20
|
+
__webpack_require__.d(getter, {
|
|
21
|
+
a: getter
|
|
22
|
+
});
|
|
23
|
+
return getter;
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
(()=>{
|
|
27
|
+
__webpack_require__.d = (exports1, definition)=>{
|
|
28
|
+
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: definition[key]
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
})();
|
|
34
|
+
(()=>{
|
|
35
|
+
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
36
|
+
})();
|
|
37
|
+
(()=>{
|
|
38
|
+
__webpack_require__.r = (exports1)=>{
|
|
39
|
+
if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
40
|
+
value: 'Module'
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports1, '__esModule', {
|
|
43
|
+
value: true
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
})();
|
|
47
|
+
var __webpack_exports__ = {};
|
|
48
|
+
(()=>{
|
|
49
|
+
__webpack_require__.r(__webpack_exports__);
|
|
50
|
+
var _form__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__("./form");
|
|
51
|
+
var __WEBPACK_REEXPORT_OBJECT__ = {};
|
|
52
|
+
for(var __WEBPACK_IMPORT_KEY__ in _form__WEBPACK_IMPORTED_MODULE_0__)if ("default" !== __WEBPACK_IMPORT_KEY__) __WEBPACK_REEXPORT_OBJECT__[__WEBPACK_IMPORT_KEY__] = (function(key) {
|
|
53
|
+
return _form__WEBPACK_IMPORTED_MODULE_0__[key];
|
|
54
|
+
}).bind(0, __WEBPACK_IMPORT_KEY__);
|
|
55
|
+
__webpack_require__.d(__webpack_exports__, __WEBPACK_REEXPORT_OBJECT__);
|
|
56
|
+
})();
|
|
57
|
+
for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
58
|
+
Object.defineProperty(exports, '__esModule', {
|
|
59
|
+
value: true
|
|
60
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fairys/taro-valtio-form-basic",
|
|
3
|
+
"author": "SunLxy <1011771396@qq.com>",
|
|
4
|
+
"description": "taro表单框架组件",
|
|
5
|
+
"homepage": "https://github.com/autumn-fairy-tales/valtio-form-basic",
|
|
6
|
+
"version": "0.0.12",
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"types": "esm/index.d.ts",
|
|
9
|
+
"module": "esm/index.js",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "carefrees-rslib build ",
|
|
13
|
+
"watch": "carefrees-rslib build --watch"
|
|
14
|
+
},
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/autumn-fairy-tales/valtio-form-basic.git",
|
|
21
|
+
"directory": "packages/taro-valtio-form"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"src",
|
|
25
|
+
"esm"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@fairys/valtio-form-basic": "^0.0.12"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/react": "~18.2.21",
|
|
32
|
+
"react": "^18.0.0"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**表单项*/
|
|
2
|
+
|
|
3
|
+
import { View } from '@tarojs/components';
|
|
4
|
+
import type { ViewProps } from '@tarojs/components';
|
|
5
|
+
import { Fragment } from 'react';
|
|
6
|
+
import type { FairysValtioFormItemAttrsProps, MObject } from '@fairys/valtio-form-basic';
|
|
7
|
+
import {
|
|
8
|
+
useFairysValtioFormItemAttrs,
|
|
9
|
+
useFairysValtioFormInstanceContextHideState,
|
|
10
|
+
useFairysValtioFormItemNoStyleAttrs,
|
|
11
|
+
FairysValtioFormParentAttrsContext,
|
|
12
|
+
} from '@fairys/valtio-form-basic';
|
|
13
|
+
|
|
14
|
+
export interface FairysTaroValtioFormItemProps<T extends MObject<T> = object>
|
|
15
|
+
extends Omit<ViewProps, 'style'>,
|
|
16
|
+
FairysValtioFormItemAttrsProps {
|
|
17
|
+
/**是否使用控制隐藏的表单项*/
|
|
18
|
+
isHide?: boolean;
|
|
19
|
+
/**是否使用无样式表单项*/
|
|
20
|
+
noStyle?: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**普通表单项*/
|
|
24
|
+
export function FairysTaroValtioFormItemBase<T extends MObject<T> = object>(
|
|
25
|
+
props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>,
|
|
26
|
+
) {
|
|
27
|
+
const { label, extra, helpText } = props;
|
|
28
|
+
const {
|
|
29
|
+
itemClassName,
|
|
30
|
+
itemStyle,
|
|
31
|
+
containerClassName,
|
|
32
|
+
itemLabelClassName,
|
|
33
|
+
itemLabelStyle,
|
|
34
|
+
itemBodyClassName,
|
|
35
|
+
itemBodyStyle,
|
|
36
|
+
itemInputClassName,
|
|
37
|
+
itemExtraClassName,
|
|
38
|
+
errorClassName,
|
|
39
|
+
helpClassName,
|
|
40
|
+
isInvalid,
|
|
41
|
+
itemBorderType,
|
|
42
|
+
children,
|
|
43
|
+
error,
|
|
44
|
+
formAttrsNameInstance,
|
|
45
|
+
} = useFairysValtioFormItemAttrs(props);
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<View className={itemClassName} style={itemStyle}>
|
|
49
|
+
<View className={containerClassName}>
|
|
50
|
+
{label ? (
|
|
51
|
+
<View className={itemLabelClassName} style={itemLabelStyle}>
|
|
52
|
+
{label}
|
|
53
|
+
</View>
|
|
54
|
+
) : (
|
|
55
|
+
<Fragment />
|
|
56
|
+
)}
|
|
57
|
+
<View className={itemBodyClassName} style={itemBodyStyle}>
|
|
58
|
+
<FairysValtioFormParentAttrsContext.Provider value={formAttrsNameInstance}>
|
|
59
|
+
<View className={itemInputClassName}>{children}</View>
|
|
60
|
+
</FairysValtioFormParentAttrsContext.Provider>
|
|
61
|
+
{extra ? <View className={itemExtraClassName}>{extra}</View> : <Fragment />}
|
|
62
|
+
{itemBorderType === 'body' && isInvalid ? <View className={errorClassName}>{error}</View> : <Fragment />}
|
|
63
|
+
</View>
|
|
64
|
+
</View>
|
|
65
|
+
{helpText ? <View className={helpClassName}>{helpText}</View> : <Fragment />}
|
|
66
|
+
{isInvalid && itemBorderType !== 'body' ? <View className={errorClassName}>{error}</View> : <Fragment />}
|
|
67
|
+
</View>
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
/**控制隐藏的表单项*/
|
|
71
|
+
export function FairysTaroValtioFormHideItem<T extends MObject<T> = object>(
|
|
72
|
+
props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>,
|
|
73
|
+
) {
|
|
74
|
+
const [state] = useFairysValtioFormInstanceContextHideState();
|
|
75
|
+
const isHide = state[props.name];
|
|
76
|
+
if (isHide) {
|
|
77
|
+
return <Fragment />;
|
|
78
|
+
}
|
|
79
|
+
return <FairysTaroValtioFormItemBase<T> {...props} />;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**无样式表单项*/
|
|
83
|
+
export function FairysTaroValtioFormItemNoStyle<T extends MObject<T> = object>(
|
|
84
|
+
props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>,
|
|
85
|
+
) {
|
|
86
|
+
const { children, formAttrsNameInstance } = useFairysValtioFormItemNoStyleAttrs(props);
|
|
87
|
+
return (
|
|
88
|
+
<FairysValtioFormParentAttrsContext.Provider value={formAttrsNameInstance}>
|
|
89
|
+
{children}
|
|
90
|
+
</FairysValtioFormParentAttrsContext.Provider>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**表单项基础组件(根据isHide和noStyle判断是否使用控制隐藏的表单项和无样式表单项)*/
|
|
95
|
+
export function FairysTaroValtioFormItem<T extends MObject<T> = object>(props: FairysTaroValtioFormItemProps<T>) {
|
|
96
|
+
const { isHide, noStyle, ...rest } = props;
|
|
97
|
+
if (isHide) {
|
|
98
|
+
return <FairysTaroValtioFormHideItem<T> {...rest} />;
|
|
99
|
+
}
|
|
100
|
+
if (noStyle) {
|
|
101
|
+
return <FairysTaroValtioFormItemNoStyle<T> {...rest} />;
|
|
102
|
+
}
|
|
103
|
+
return <FairysTaroValtioFormItemBase<T> {...rest} />;
|
|
104
|
+
}
|
package/src/form.tsx
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { FairysTaroValtioFormLayout } from './layout';
|
|
2
|
+
import { FairysTaroValtioFormItem, FairysTaroValtioFormHideItem, FairysTaroValtioFormItemBase } from './form.item';
|
|
3
|
+
import {
|
|
4
|
+
useFairysValtioForm,
|
|
5
|
+
FairysValtioFormInstanceContext,
|
|
6
|
+
useFairysValtioFormInstance,
|
|
7
|
+
useFairysValtioFormInstanceContext,
|
|
8
|
+
useFairysValtioFormInstanceContextState,
|
|
9
|
+
useFairysValtioFormInstanceContextHideState,
|
|
10
|
+
} from '@fairys/valtio-form-basic';
|
|
11
|
+
import type { FairysValtioFormAttrsProps, MObject } from '@fairys/valtio-form-basic';
|
|
12
|
+
export * from '@fairys/valtio-form-basic';
|
|
13
|
+
export * from './form.item';
|
|
14
|
+
export * from './layout';
|
|
15
|
+
export interface FairysTaroValtioFormProps<T extends MObject<T> = object> extends FairysValtioFormAttrsProps<T> { }
|
|
16
|
+
|
|
17
|
+
export function FairysTaroValtioForm<T extends MObject<T> = object>(props: FairysTaroValtioFormProps<T>) {
|
|
18
|
+
const { formInstance, children, ...rest } = useFairysValtioForm(props);
|
|
19
|
+
return (
|
|
20
|
+
<FairysValtioFormInstanceContext.Provider value={formInstance}>
|
|
21
|
+
<FairysTaroValtioFormLayout {...rest}>{children}</FairysTaroValtioFormLayout>
|
|
22
|
+
</FairysValtioFormInstanceContext.Provider>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
/**初始化实例*/
|
|
26
|
+
FairysTaroValtioForm.useForm = useFairysValtioFormInstance;
|
|
27
|
+
/**获取状态*/
|
|
28
|
+
FairysTaroValtioForm.useFormState = useFairysValtioFormInstanceContextState;
|
|
29
|
+
/**获取隐藏状态*/
|
|
30
|
+
FairysTaroValtioForm.useFormHideState = useFairysValtioFormInstanceContextHideState;
|
|
31
|
+
/**获取上下文实例*/
|
|
32
|
+
FairysTaroValtioForm.useFormInstance = useFairysValtioFormInstanceContext;
|
|
33
|
+
/**表单项基础组件*/
|
|
34
|
+
FairysTaroValtioForm.FormItemBase = FairysTaroValtioFormItemBase;
|
|
35
|
+
/**表单项*/
|
|
36
|
+
FairysTaroValtioForm.FormItem = FairysTaroValtioFormItem;
|
|
37
|
+
/**隐藏表单想*/
|
|
38
|
+
FairysTaroValtioForm.FormHideItem = FairysTaroValtioFormHideItem;
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './form';
|
package/src/layout.tsx
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Fragment } from 'react';
|
|
2
|
+
import { View } from '@tarojs/components';
|
|
3
|
+
import type { FairysValtioFormLayoutAttrsProps } from '@fairys/valtio-form-basic';
|
|
4
|
+
import { FairysValtioFormLayoutContext, useFairysValtioFormLayoutAttrs } from '@fairys/valtio-form-basic';
|
|
5
|
+
export interface FairysTaroValtioFormLayoutProps extends FairysValtioFormLayoutAttrsProps { }
|
|
6
|
+
|
|
7
|
+
export function FairysTaroValtioFormLayout(props: FairysTaroValtioFormLayoutProps) {
|
|
8
|
+
const { children, title, extra } = props;
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
formLayoutInstance,
|
|
12
|
+
layoutName,
|
|
13
|
+
layoutStyle,
|
|
14
|
+
headerName,
|
|
15
|
+
headerStyle,
|
|
16
|
+
headerTitleName,
|
|
17
|
+
headerExtraName,
|
|
18
|
+
bodyName,
|
|
19
|
+
bodyStyle,
|
|
20
|
+
} = useFairysValtioFormLayoutAttrs(props);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<FairysValtioFormLayoutContext.Provider value={formLayoutInstance}>
|
|
24
|
+
<View className={layoutName} style={layoutStyle}>
|
|
25
|
+
{title || extra ? (
|
|
26
|
+
<View style={headerStyle} className={headerName}>
|
|
27
|
+
<View className={headerTitleName}>{title}</View>
|
|
28
|
+
<View className={headerExtraName}>{extra}</View>
|
|
29
|
+
</View>
|
|
30
|
+
) : (
|
|
31
|
+
<Fragment />
|
|
32
|
+
)}
|
|
33
|
+
<View className={bodyName} style={bodyStyle}>
|
|
34
|
+
{children}
|
|
35
|
+
</View>
|
|
36
|
+
</View>
|
|
37
|
+
</FairysValtioFormLayoutContext.Provider>
|
|
38
|
+
);
|
|
39
|
+
}
|