@fairys/taro-tools-simple-form-ui 0.0.8 → 0.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,8 @@
1
- import { TaroPickerProps, PickerOptions } from '@nutui/nutui-react-taro';
1
+ import { TaroPickerProps, PickerOptions, PickerOption } from '@nutui/nutui-react-taro';
2
2
  export interface FairysTaroPickerProps extends Omit<Partial<TaroPickerProps>, 'value' | 'onChange'> {
3
3
  placeholder?: string;
4
- value?: PickerOptions;
5
- onChange?: (value: PickerOptions) => void;
4
+ value?: PickerOptions | PickerOption;
5
+ onChange?: (value: PickerOptions | PickerOption) => void;
6
6
  bodyClassName?: string;
7
7
  bodyStyle?: React.CSSProperties;
8
8
  }
@@ -4,14 +4,25 @@ import { Picker } from "@nutui/nutui-react-taro";
4
4
  import { useMemo, useState } from "react";
5
5
  import { FairysTaroTextClearBase } from "../clear/index.js";
6
6
  const FairysTaroPickerBase = (props)=>{
7
- const { placeholder = "\u8BF7\u9009\u62E9", bodyClassName, bodyStyle, className, style, value, onChange, ...rest } = props;
7
+ const { placeholder = "\u8BF7\u9009\u62E9", bodyClassName, bodyStyle, className, style, value, onChange, options, ...rest } = props;
8
8
  const [visible, setVisible] = useState(false);
9
+ const isSingle = (options || []).length <= 1;
9
10
  const _renderValue = useMemo(()=>{
11
+ if (isSingle) return value?.label || '';
10
12
  if (Array.isArray(value)) return value.map((item)=>item.label).join(' / ');
11
13
  }, [
12
14
  value
13
15
  ]);
14
16
  const _value = useMemo(()=>{
17
+ if (isSingle) {
18
+ const _value = value?.value || '';
19
+ if ('number' == typeof _value) return [
20
+ _value
21
+ ];
22
+ return [
23
+ _value
24
+ ].filter(Boolean);
25
+ }
15
26
  if (Array.isArray(value)) return value.map((item)=>item.value);
16
27
  }, [
17
28
  value
@@ -29,6 +40,7 @@ const FairysTaroPickerBase = (props)=>{
29
40
  }),
30
41
  /*#__PURE__*/ jsx(Picker, {
31
42
  ...rest,
43
+ options: options,
32
44
  className: `fairys-taro-picker-body fairystaroform__text-left ${bodyClassName || ''}`,
33
45
  style: bodyStyle,
34
46
  value: _value,
@@ -36,7 +48,8 @@ const FairysTaroPickerBase = (props)=>{
36
48
  onClose: ()=>setVisible(false),
37
49
  onConfirm: (selectedOptions)=>{
38
50
  setVisible(false);
39
- onChange?.(selectedOptions);
51
+ if (isSingle) onChange?.(selectedOptions?.[0]);
52
+ else onChange?.(selectedOptions);
40
53
  }
41
54
  })
42
55
  ]
@@ -1,6 +1,6 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { View } from "@tarojs/components";
3
- import { Button, Checkbox, Input } from "@nutui/nutui-react-taro";
3
+ import { Button, Checkbox, ConfigProvider, Input, Loading } from "@nutui/nutui-react-taro";
4
4
  import { Fragment } from "react";
5
5
  import { useFairysTaroPopupSearchBaseInstanceContext } from "./instance.js";
6
6
  import { Del, Search } from "@nutui/icons-react-taro";
@@ -51,6 +51,7 @@ function FairysTaroPopupSearchInputBase() {
51
51
  sync: true
52
52
  });
53
53
  const search = state.search || '';
54
+ const loading = state.loading;
54
55
  return /*#__PURE__*/ jsxs(View, {
55
56
  className: "fairys-taro-popup-search-content-header fairystaroform__flex fairystaroform__flex-row fairystaroform__items-center fairystaroform__flex-nowrap fairystaroform__px-1 fairystaroform__box-border fairystaroform__pr-4 fairystaroform__border-b-1 fairystaroform__border-b-solid fairystaroform__border-b-gray-200",
56
57
  children: [
@@ -59,10 +60,25 @@ function FairysTaroPopupSearchInputBase() {
59
60
  value: search,
60
61
  onChange: instance.onSearch
61
62
  }),
62
- /*#__PURE__*/ jsx(View, {
63
- children: /*#__PURE__*/ jsx(Search, {
64
- className: "fairys-taro-popup-search-content-header-search fairystaroform__text-gray-600 fairystaroform__cursor-pointer"
65
- })
63
+ /*#__PURE__*/ jsxs(View, {
64
+ className: "fairystaroform__flex fairystaroform__flex-row fairystaroform__items-center",
65
+ style: {
66
+ gap: 4
67
+ },
68
+ children: [
69
+ loading ? /*#__PURE__*/ jsx(ConfigProvider, {
70
+ theme: {
71
+ nutuiLoadingIconColor: '#396aca',
72
+ nutuiLoadingIconSize: '24px'
73
+ },
74
+ children: /*#__PURE__*/ jsx(Loading, {
75
+ type: "spinner"
76
+ })
77
+ }) : /*#__PURE__*/ jsx(Fragment, {}),
78
+ /*#__PURE__*/ jsx(Search, {
79
+ className: "fairys-taro-popup-search-content-header-search fairystaroform__text-gray-600 fairystaroform__cursor-pointer"
80
+ })
81
+ ]
66
82
  })
67
83
  ]
68
84
  });
@@ -55,7 +55,7 @@ function FairysTaroPopupSearchBodyBase() {
55
55
  columns
56
56
  ]);
57
57
  useEffect(()=>{
58
- if (visible && 'function' == typeof instance.onLoadData) instance.onSearch('');
58
+ if (visible && 'function' == typeof instance.onLoadData) instance.onSearch('', 0);
59
59
  }, [
60
60
  visible
61
61
  ]);
@@ -75,7 +75,7 @@ function FairysTaroPopupSearchBodyBase() {
75
75
  });
76
76
  }
77
77
  function FairysTaroPopupSearchBase(props) {
78
- const { placeholder = "\u8BF7\u9009\u62E9", className, style, value, onChange, onLoadData, otherRequestParams, maxWidth, maxHeight, renderText, renderListItemText, showRowDeleteButton = true, showSearch = true, renderList, options, columns, mode = 'single', rowKey = 'value', displayField = 'label', renderType = 'list', maxTagCount = 9, tableProps = {}, useTableProps, isNeedManage = false, isUseOptionsChecked = true, ...rest } = props;
78
+ const { placeholder = "\u8BF7\u9009\u62E9", className, style, value, onChange, onLoadData, otherRequestParams, maxWidth, maxHeight, renderText, renderListItemText, showRowDeleteButton = true, showSearch = true, renderList, options, columns, mode = 'single', rowKey = 'value', displayField = 'label', renderType = 'list', maxTagCount = 9, tableProps = {}, useTableProps, isNeedManage = false, isUseOptionsChecked = true, isFirstLoadAfterOptions = false, ...rest } = props;
79
79
  const [state, instance] = useFairysTaroPopupSearchBaseInstance();
80
80
  instance.maxWidth = maxWidth;
81
81
  instance.maxHeight = maxHeight;
@@ -89,6 +89,7 @@ function FairysTaroPopupSearchBase(props) {
89
89
  instance.useTableProps = useTableProps;
90
90
  instance.isNeedManage = isNeedManage;
91
91
  instance.isUseOptionsChecked = isUseOptionsChecked;
92
+ instance.isFirstLoadAfterOptions = isFirstLoadAfterOptions;
92
93
  instance.rowKey = rowKey;
93
94
  instance.displayField = displayField;
94
95
  instance.mode = mode;
@@ -11,6 +11,8 @@ export declare class FairysTaroPopupSearchBaseInstanceMount<T = any> {
11
11
  renderListItemText?: (data: T, instance: FairysTaroPopupSearchBaseInstanceMount<T>) => React.ReactNode;
12
12
  /**自定义渲染列表数据*/
13
13
  renderList?: (dataList: T[], type: 'select' | 'manage', instance: FairysTaroPopupSearchBaseInstanceMount<T>) => React.ReactNode;
14
+ /**onLoadData仅第一次成功加载,之后按照传递 options 处理*/
15
+ isFirstLoadAfterOptions?: boolean;
14
16
  /**选择模式*/
15
17
  mode?: 'multiple' | 'single';
16
18
  /**列表项的唯一键值*/
@@ -77,6 +79,8 @@ export interface FairysTaroPopupSearchBaseInstanceState<T = any> {
77
79
  operationStatus: 'manage' | 'select';
78
80
  /**选中列表数据*/
79
81
  manageSelectedDataList: T[];
82
+ /**是否第一次成功加载并存在数据*/
83
+ isFirstLoadSuccess?: boolean;
80
84
  /**全选按钮是否选中状态*/
81
85
  allChecked: boolean;
82
86
  /**选择模式
@@ -85,6 +89,8 @@ export interface FairysTaroPopupSearchBaseInstanceState<T = any> {
85
89
  mode?: 'multiple' | 'single';
86
90
  /**列表列配置*/
87
91
  columns?: TableColumnProps[];
92
+ /**是否正在加载数据*/
93
+ loading?: boolean;
88
94
  }
89
95
  export declare class FairysTaroPopupSearchBaseInstance<T = any> extends FairysTaroPopupSearchBaseInstanceMount<T> {
90
96
  /**窗口高度*/
@@ -102,7 +108,10 @@ export declare class FairysTaroPopupSearchBaseInstance<T = any> extends FairysTa
102
108
  /**判断是否使用 options 参数,并且不是管理模式*/
103
109
  isUseOptions: () => boolean;
104
110
  /**搜索*/
105
- onSearch: (keyword: string) => Promise<void>;
111
+ private _onSearch;
112
+ timer: NodeJS.Timeout;
113
+ /**搜索*/
114
+ onSearch: (keyword: string, count?: number) => Promise<void>;
106
115
  /**保存数据*/
107
116
  onSave: () => void;
108
117
  /**清空数据*/
@@ -8,6 +8,7 @@ class FairysTaroPopupSearchBaseInstanceMount {
8
8
  renderText;
9
9
  renderListItemText;
10
10
  renderList;
11
+ isFirstLoadAfterOptions;
11
12
  mode = 'single';
12
13
  rowKey = 'value';
13
14
  displayField = 'label';
@@ -42,7 +43,9 @@ class FairysTaroPopupSearchBaseInstance extends FairysTaroPopupSearchBaseInstanc
42
43
  _tempValue: void 0,
43
44
  operationStatus: 'select',
44
45
  manageSelectedDataList: [],
45
- allChecked: false
46
+ allChecked: false,
47
+ isFirstLoadSuccess: false,
48
+ loading: false
46
49
  });
47
50
  ctor() {
48
51
  const isWeb = taro.getEnv() === taro.ENV_TYPE.WEB;
@@ -70,22 +73,27 @@ class FairysTaroPopupSearchBaseInstance extends FairysTaroPopupSearchBaseInstanc
70
73
  if (Array.isArray(this.options) && !this.onLoadData && !this.isNeedManage) return this.isUseOptionsChecked;
71
74
  return false;
72
75
  };
73
- onSearch = async (keyword)=>{
74
- this.state.search = keyword;
76
+ _onSearch = async (keyword)=>{
75
77
  const _keyword = `${keyword || ''}`.trim();
76
78
  try {
77
- if (this.onLoadData && 'select' === this.state.operationStatus) {
78
- await new Promise((resolve)=>setTimeout(resolve, 500));
79
+ let isRequest = this.onLoadData && 'select' === this.state.operationStatus;
80
+ if (isRequest && this.state.isFirstLoadSuccess && this.isFirstLoadAfterOptions) isRequest = false;
81
+ if (isRequest) {
82
+ this.state.loading = true;
79
83
  const search = {
80
84
  keyword: _keyword
81
85
  };
82
86
  const dataList = await this.onLoadData(this.otherRequestParams?.(search, this) || search, this);
83
- if (Array.isArray(dataList)) this.updateState({
84
- _tempFilterDataList: dataList || [],
85
- dataList: dataList || []
86
- });
87
- else this.updateState({
88
- _tempFilterDataList: []
87
+ if (Array.isArray(dataList)) {
88
+ const isFirstLoadSuccess = !!dataList.length && !_keyword;
89
+ this.updateState({
90
+ _tempFilterDataList: dataList || [],
91
+ dataList: dataList || [],
92
+ isFirstLoadSuccess
93
+ });
94
+ } else this.updateState({
95
+ _tempFilterDataList: [],
96
+ isFirstLoadSuccess: false
89
97
  });
90
98
  } else if ('select' === this.state.operationStatus) {
91
99
  if (!_keyword) return void this.updateState({
@@ -117,8 +125,22 @@ class FairysTaroPopupSearchBaseInstance extends FairysTaroPopupSearchBaseInstanc
117
125
  }
118
126
  } catch (error) {
119
127
  console.error(error);
128
+ } finally{
129
+ this.state.loading = false;
120
130
  }
121
131
  };
132
+ timer;
133
+ onSearch = async (keyword, count)=>{
134
+ this.state.search = keyword;
135
+ if (this.onLoadData && 'select' === this.state.operationStatus) if (0 === count) this._onSearch(keyword);
136
+ else {
137
+ clearTimeout(this.timer);
138
+ this.timer = setTimeout(()=>{
139
+ this._onSearch(this.state.search || '');
140
+ }, 800);
141
+ }
142
+ else this._onSearch(this.state.search || '');
143
+ };
122
144
  onSave = ()=>{
123
145
  if ('multiple' === this.mode) {
124
146
  const dataList = this.state._tempValue || [];
@@ -248,7 +270,8 @@ class FairysTaroPopupSearchBaseInstance extends FairysTaroPopupSearchBaseInstanc
248
270
  search: '',
249
271
  _tempValue: this.state.value,
250
272
  operationStatus: 'select',
251
- _tempFilterDataList: this.state.dataList || []
273
+ _tempFilterDataList: this.state.dataList || [],
274
+ isFirstLoadSuccess: false
252
275
  });
253
276
  };
254
277
  updateOperationStatus = ()=>{
@@ -1,33 +1,24 @@
1
1
  import { MObject } from '../interface';
2
- import { FairysTaroValtioFormInstance, useFairysTaroValtioFormInstance, useFairysTaroValtioFormInstanceContext, useFairysTaroValtioFormInstanceContextState, useFairysTaroValtioFormInstanceContextHideState } from './instance';
3
- import { type ReactNode } from 'react';
4
- import { FairysTaroValtioFormLayoutProps } from './layout';
5
- import { FairysTaroValtioFormItem, FairysTaroValtioFormHideItem } from './form.item';
2
+ import { FairysTaroValtioFormItem, FairysTaroValtioFormHideItem, FairysTaroValtioFormItemBase } from './form.item';
3
+ import { useFairysValtioFormInstance, useFairysValtioFormInstanceContext, useFairysValtioFormInstanceContextState, useFairysValtioFormInstanceContextHideState } from '@fairys/valtio-form-basic';
4
+ import type { FairysValtioFormAttrsProps } from '@fairys/valtio-form-basic';
5
+ export * from '@fairys/valtio-form-basic';
6
+ export * from './form.item';
7
+ export * from './layout';
6
8
  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
- /**formData 是否进行深度拷贝,如果不是则直接把 formData 赋值到 state ,否则使用 copy 方法深度拷贝后赋值 */
19
- isDeepCopy?: boolean;
9
+ export interface FairysTaroValtioFormProps<T extends MObject<T> = object> extends FairysValtioFormAttrsProps<T> {
20
10
  }
21
11
  export declare function FairysTaroValtioForm<T extends MObject<T> = object>(props: FairysTaroValtioFormProps<T>): import("react/jsx-runtime").JSX.Element;
22
12
  export declare namespace FairysTaroValtioForm {
23
- var useForm: typeof useFairysTaroValtioFormInstance;
24
- var useFormState: typeof useFairysTaroValtioFormInstanceContextState;
25
- var useFormHideState: typeof useFairysTaroValtioFormInstanceContextHideState;
26
- var useFormInstance: typeof useFairysTaroValtioFormInstanceContext;
13
+ var useForm: typeof useFairysValtioFormInstance;
14
+ var useFormState: typeof useFairysValtioFormInstanceContextState;
15
+ var useFormHideState: typeof useFairysValtioFormInstanceContextHideState;
16
+ var useFormInstance: typeof useFairysValtioFormInstanceContext;
27
17
  var FormItemListItem: (props: {
28
18
  items: import("./item.config").FairysTaroValtioInputConfigType[];
29
19
  }) => import("react/jsx-runtime").JSX.Element;
30
20
  var FormItemConfig: (config: import("./item.config").FairysTaroValtioInputConfigType) => import("react/jsx-runtime").JSX.Element;
21
+ var FormItemBase: typeof FairysTaroValtioFormItemBase;
31
22
  var FormItem: typeof FairysTaroValtioFormItem;
32
23
  var FormHideItem: typeof FairysTaroValtioFormHideItem;
33
24
  }
@@ -1,57 +1,18 @@
1
1
  /**表单项*/
2
2
  import { MObject } from '../interface';
3
3
  import type { ViewProps } from '@tarojs/components';
4
- import React from 'react';
5
- import { FairysTaroValtioFormInstance } from './instance';
6
- import { FairysTaroValtioFormLayoutContextOptions } from './layout';
7
- export interface FairysTaroValtioFormItemProps<T extends MObject<T> = object> extends ViewProps {
8
- /**表单项名称*/
9
- name: string;
10
- /**表单项标签*/
11
- label?: string;
12
- /**是否使用样式*/
4
+ import type { FairysValtioFormItemAttrsProps } from '@fairys/valtio-form-basic';
5
+ export interface FairysTaroValtioFormItemProps<T extends MObject<T> = object> extends Omit<ViewProps, 'style'>, FairysValtioFormItemAttrsProps {
6
+ /**是否使用控制隐藏的表单项*/
7
+ isHide?: boolean;
8
+ /**是否使用无样式表单项*/
13
9
  noStyle?: boolean;
14
- /**传递组件字段*/
15
- valuePropName?: string;
16
- /**自定义获取值*/
17
- getValueFromEvent?: (event: any, form: FairysTaroValtioFormInstance<T>) => any;
18
- /**值格式化*/
19
- formatValue?: (value: any, form: FairysTaroValtioFormInstance<T>, event: any) => any;
20
- /**触发数据更新之后触发(用于数据联动之类的)*/
21
- onAfterUpdate?: (value: any, form: FairysTaroValtioFormInstance<T>, event: any) => void;
22
- /**事件名称*/
23
- trigger?: string;
24
- style?: React.CSSProperties;
25
- labelClassName?: string;
26
- labelStyle?: React.CSSProperties;
27
- bodyClassName?: string;
28
- bodyStyle?: React.CSSProperties;
29
- /**规则校验失败错误提示位置*/
30
- errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
31
- /**label显示模式*/
32
- labelMode?: 'left' | 'top' | 'between';
33
- /**额外内容*/
34
- extra?: React.ReactNode;
35
- /**底部提示内容*/
36
- helpText?: React.ReactNode;
37
- /**
38
- * 表单项占据列数
39
- * @default 1
40
- */
41
- colSpan?: number;
42
- /**
43
- * 表单项占据行数
44
- * @default 1
45
- */
46
- rowSpan?: number;
47
- /**是否必填*/
48
- isRequired?: boolean;
49
- /**是否显示冒号*/
50
- showColon?: boolean;
51
- /**底部显示边框*/
52
- borderedType?: FairysTaroValtioFormLayoutContextOptions['borderedType'];
53
- /**输入框属性*/
54
- attrs?: any;
55
10
  }
56
- export declare function FairysTaroValtioFormItem<T extends MObject<T> = object>(props: FairysTaroValtioFormItemProps<T>): import("react/jsx-runtime").JSX.Element;
57
- export declare function FairysTaroValtioFormHideItem<T extends MObject<T> = object>(props: FairysTaroValtioFormItemProps<T>): import("react/jsx-runtime").JSX.Element;
11
+ /**普通表单项*/
12
+ export declare function FairysTaroValtioFormItem<T extends MObject<T> = object>(props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>): import("react/jsx-runtime").JSX.Element;
13
+ /**控制隐藏的表单项*/
14
+ export declare function FairysTaroValtioFormHideItem<T extends MObject<T> = object>(props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>): import("react/jsx-runtime").JSX.Element;
15
+ /**无样式表单项*/
16
+ export declare function FairysTaroValtioFormItemNoStyle<T extends MObject<T> = object>(props: Omit<FairysTaroValtioFormItemProps<T>, 'isHide' | 'noStyle'>): import("react/jsx-runtime").JSX.Element;
17
+ /**表单项基础组件(根据isHide和noStyle判断是否使用控制隐藏的表单项和无样式表单项)*/
18
+ export declare function FairysTaroValtioFormItemBase<T extends MObject<T> = object>(props: FairysTaroValtioFormItemProps<T>): import("react/jsx-runtime").JSX.Element;
@@ -1,164 +1,39 @@
1
1
  import { jsx, jsxs } from "react/jsx-runtime";
2
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";
3
+ import { Fragment } from "react";
4
+ import { FairysValtioFormParentAttrsContext, useFairysValtioFormInstanceContextHideState, useFairysValtioFormItemAttrs, useFairysValtioFormItemNoStyleAttrs } from "@fairys/valtio-form-basic";
7
5
  function FairysTaroValtioFormItem(props) {
8
- const [layoutAttrs] = useFairysTaroValtioFormLayoutContext();
9
- const colCount = layoutAttrs.colCount || 1;
10
- const parent_borderedType = layoutAttrs.borderedType || 'bottom';
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_formItemBodyClassName = layoutAttrs.formItemBodyClassName;
17
- const parent_formItemBodyStyle = layoutAttrs.formItemBodyStyle;
18
- const parent_labelMode = layoutAttrs.labelMode || 'between';
19
- 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, borderedType = parent_borderedType, attrs = {}, showColon = false, ...rest } = props;
20
- const [state, errorState, formInstance] = useFairysTaroValtioFormInstanceContextState();
21
- const rules = formInstance.rules?.[name];
22
- const value = state[name];
23
- const error = errorState[name];
24
- const onValueChange = (event)=>{
25
- let value = event;
26
- const target = event?.detail || event?.target;
27
- if ('function' == typeof getValueFromEvent) value = getValueFromEvent(event, formInstance);
28
- else if (event && target && 'object' == typeof target && valuePropName in target) value = target.valuePropName;
29
- if ('function' == typeof formatValue) value = formatValue(value, formInstance, event);
30
- formInstance.updated({
31
- [name]: value
32
- });
33
- };
34
- const baseControl = {
35
- ...attrs,
36
- name,
37
- [valuePropName]: value,
38
- [trigger]: onValueChange
39
- };
40
- const isRequired = useMemo(()=>{
41
- if (_isRequired) return _isRequired;
42
- if (Array.isArray(rules) && rules.length) return rules.some((rule)=>rule.required);
43
- return false;
44
- }, [
45
- rules,
46
- formInstance
47
- ]);
48
- const isInvalid = useMemo(()=>{
49
- if (Array.isArray(error) && error.length) return true;
50
- return false;
51
- }, [
52
- error
53
- ]);
54
- const item_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item fairystaroform__p-_zkh1_4px_zhk2_ fairystaroform__text-_zkh1_12px_zhk2_ fairystaroform__relative fairystaroform__flex fairystaroform__flex-col fairystaroform__box-border fairystaroform__break-all', {
55
- 'fairystaroform__border-b fairystaroform__border-b-solid fairystaroform__border-b-gray-200': 'bottom' === borderedType,
56
- [labelMode]: labelMode
57
- }, className, parent_formItemClassName), [
58
- className,
59
- parent_formItemClassName,
60
- labelMode,
61
- borderedType
62
- ]);
63
- const itemContainer_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-container fairystaroform__flex-1 fairystaroform__h-full fairystaroform__flex fairystaroform__box-border', {
64
- 'fairystaroform__flex-row fairystaroform__items-center fairystaroform__justify-between fairystaroform__gap-_zkh1_8px_zhk2_': 'between' === labelMode,
65
- 'fairystaroform__flex-col fairystaroform__gap-_zkh1_4px_zhk2_': 'top' === labelMode,
66
- 'fairystaroform__flex-row fairystaroform__gap-_zkh1_8px_zhk2_': 'left' === labelMode
67
- }, labelClassName), [
68
- labelClassName,
69
- labelMode
70
- ]);
71
- const itemLabel_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-label fairystaroform__text-gray-800 fairystaroform__flex fairystaroform__items-center fairystaroform__relative fairystaroform__box-border', {
72
- 'fairystaroform__justify-start': 'left' !== labelMode,
73
- 'fairystaroform__justify-end': 'left' === labelMode,
74
- required: isRequired,
75
- 'show-colon': showColon
76
- }, labelClassName, parent_formItemLabelClassName), [
77
- labelClassName,
78
- parent_formItemLabelClassName,
79
- labelMode,
80
- isRequired,
81
- showColon
82
- ]);
83
- const itemBody_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body fairystaroform__relative fairystaroform__flex-1 fairystaroform__flex fairystaroform__box-border', {
84
- 'fairystaroform__flex-row fairystaroform__justify-start': 'left' === labelMode,
85
- 'fairystaroform__flex-row fairystaroform__justify-end': 'between' === labelMode || 'top' === labelMode,
86
- 'fairystaroform__flex-row': 'top' === labelMode,
87
- 'fairystaroform__border-b fairystaroform__border-b-solid fairystaroform__border-b-gray-200 ': 'body' === borderedType
88
- }, bodyClassName, parent_formItemBodyClassName), [
89
- bodyClassName,
90
- labelMode,
91
- borderedType,
92
- parent_formItemBodyClassName
93
- ]);
94
- const itemInput_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body fairystaroform__flex fairystaroform__flex-row fairystaroform__flex-1 fairystaroform__box-border', {
95
- 'fairystaroform__justify-end fairystaroform__text-right': 'between' === labelMode,
96
- 'fairystaroform__justify-start fairystaroform__text-left fairystaroform__items-center': 'between' !== labelMode
97
- }), [
98
- labelMode
99
- ]);
100
- const itemExtra_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body-extra fairystaroform__box-border fairystaroform__flex fairystaroform__items-center fairystaroform__justify-center'), []);
101
- const itemHelp_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body-help fairystaroform__text-_zkh1_10px_zhk2_ fairystaroform__w-full fairystaroform__box-border'), []);
102
- const itemError_cls = useMemo(()=>clsx('fairys-taro-valtio-form-item-body-error fairystaroform__px-_zkh1_4px_zhk2_ fairystaroform__w-full fairystaroform__flex fairystaroform__flex-row fairystaroform__box-border fairystaroform__text-red fairystaroform__absolute fairystaroform__text-_zkh1_10px_zhk2_ fairystaroform__z-10', {
103
- 'fairystaroform__bottom-_zkh1_-14px_zhk2_ fairystaroform__left-0 fairystaroform__justify-start': 'left-bottom' === errorLayout,
104
- 'fairystaroform__bottom-_zkh1_-14px_zhk2_ fairystaroform__right-0 fairystaroform__justify-end': 'right-bottom' === errorLayout,
105
- 'fairystaroform__top-_zkh1_-14px_zhk2_ fairystaroform__right-0 fairystaroform__justify-end': 'top-right' === errorLayout,
106
- 'fairystaroform__top-_zkh1_-14px_zhk2_ fairystaroform__left-0 fairystaroform__justify-start': 'top-left' === errorLayout
107
- }), [
108
- errorLayout
109
- ]);
110
- const styleBase = useMemo(()=>{
111
- const css = {};
112
- if (colSpan) {
113
- const end = colCount > colSpan ? colSpan : colCount;
114
- css.gridColumnEnd = `span ${end}`;
115
- }
116
- if (rowSpan) css.gridRowEnd = `span ${rowSpan}`;
117
- return css;
118
- }, [
119
- colSpan,
120
- rowSpan,
121
- colCount
122
- ]);
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);
123
8
  return /*#__PURE__*/ jsxs(View, {
124
- ...rest,
125
- className: item_cls,
126
- style: {
127
- ...parent_formItemStyle || {},
128
- ...styleBase,
129
- ...style || {}
130
- },
9
+ className: itemClassName,
10
+ style: itemStyle,
131
11
  children: [
132
12
  /*#__PURE__*/ jsxs(View, {
133
- className: itemContainer_cls,
13
+ className: containerClassName,
134
14
  children: [
135
- /*#__PURE__*/ jsx(View, {
136
- className: itemLabel_cls,
137
- style: {
138
- ...parent_formItemLabelStyle || {},
139
- ...labelStyle || {}
140
- },
15
+ label ? /*#__PURE__*/ jsx(View, {
16
+ className: itemLabelClassName,
17
+ style: itemLabelStyle,
141
18
  children: label
142
- }),
19
+ }) : /*#__PURE__*/ jsx(Fragment, {}),
143
20
  /*#__PURE__*/ jsxs(View, {
144
- className: itemBody_cls,
145
- style: {
146
- ...parent_formItemBodyStyle || {},
147
- ...bodyStyle || {}
148
- },
21
+ className: itemBodyClassName,
22
+ style: itemBodyStyle,
149
23
  children: [
150
- /*#__PURE__*/ jsx(View, {
151
- className: itemInput_cls,
152
- children: /*#__PURE__*/ react.isValidElement(children) ? /*#__PURE__*/ react.cloneElement(children, {
153
- ...baseControl
154
- }) : children
24
+ /*#__PURE__*/ jsx(FairysValtioFormParentAttrsContext.Provider, {
25
+ value: formAttrsNameInstance,
26
+ children: /*#__PURE__*/ jsx(View, {
27
+ className: itemInputClassName,
28
+ children: children
29
+ })
155
30
  }),
156
31
  extra ? /*#__PURE__*/ jsx(View, {
157
- className: itemExtra_cls,
32
+ className: itemExtraClassName,
158
33
  children: extra
159
34
  }) : /*#__PURE__*/ jsx(Fragment, {}),
160
- 'body' === borderedType && isInvalid ? /*#__PURE__*/ jsx(View, {
161
- className: itemError_cls,
35
+ 'body' === itemBorderType && isInvalid ? /*#__PURE__*/ jsx(View, {
36
+ className: errorClassName,
162
37
  children: error
163
38
  }) : /*#__PURE__*/ jsx(Fragment, {})
164
39
  ]
@@ -166,22 +41,41 @@ function FairysTaroValtioFormItem(props) {
166
41
  ]
167
42
  }),
168
43
  helpText ? /*#__PURE__*/ jsx(View, {
169
- className: itemHelp_cls,
44
+ className: helpClassName,
170
45
  children: helpText
171
46
  }) : /*#__PURE__*/ jsx(Fragment, {}),
172
- isInvalid && 'body' !== borderedType ? /*#__PURE__*/ jsx(View, {
173
- className: itemError_cls,
47
+ isInvalid && 'body' !== itemBorderType ? /*#__PURE__*/ jsx(View, {
48
+ className: errorClassName,
174
49
  children: error
175
50
  }) : /*#__PURE__*/ jsx(Fragment, {})
176
51
  ]
177
52
  });
178
53
  }
179
54
  function FairysTaroValtioFormHideItem(props) {
180
- const [state] = useFairysTaroValtioFormInstanceContextHideState();
55
+ const [state] = useFairysValtioFormInstanceContextHideState();
181
56
  const isHide = state[props.name];
182
57
  if (isHide) return /*#__PURE__*/ jsx(Fragment, {});
183
58
  return /*#__PURE__*/ jsx(FairysTaroValtioFormItem, {
184
59
  ...props
185
60
  });
186
61
  }
187
- export { FairysTaroValtioFormHideItem, FairysTaroValtioFormItem };
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 FairysTaroValtioFormItemBase(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(FairysTaroValtioFormItem, {
78
+ ...rest
79
+ });
80
+ }
81
+ export { FairysTaroValtioFormHideItem, FairysTaroValtioFormItem, FairysTaroValtioFormItemBase, FairysTaroValtioFormItemNoStyle };