@react-fabric/form 1.0.0-beta.32 → 1.0.0-beta.34

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.
Files changed (89) hide show
  1. package/dist/cjs/builder/FileField.js +4 -4
  2. package/dist/cjs/builder/FormField.js +44 -34
  3. package/dist/cjs/builder/SchemaEditor.js +439 -0
  4. package/dist/cjs/form/Controller.js +1 -1
  5. package/dist/cjs/form/Form.js +10 -4
  6. package/dist/cjs/hooks/useFormBuilder.js +27 -15
  7. package/dist/cjs/index.js +8 -2
  8. package/dist/cjs/input/Checkbox.js +4 -3
  9. package/dist/cjs/input/ColorInput.js +1 -1
  10. package/dist/cjs/input/DateInput.js +183 -0
  11. package/dist/cjs/input/Field.js +1 -1
  12. package/dist/cjs/input/File.js +1 -1
  13. package/dist/cjs/input/Hidden.js +1 -1
  14. package/dist/cjs/input/Input.js +1 -1
  15. package/dist/cjs/input/Number.js +1 -1
  16. package/dist/cjs/input/Password.js +1 -1
  17. package/dist/cjs/input/{Range.js → RangeSlider.js} +3 -3
  18. package/dist/cjs/input/Search.js +1 -1
  19. package/dist/cjs/input/Slider.js +1 -1
  20. package/dist/cjs/input/Switch.js +4 -3
  21. package/dist/cjs/input/Textarea.js +1 -1
  22. package/dist/cjs/internal/Field.module.css +1 -1
  23. package/dist/cjs/internal/InputWrapper.js +4 -2
  24. package/dist/cjs/types/schema.js +40 -0
  25. package/dist/esm/builder/FileField.js +4 -4
  26. package/dist/esm/builder/FormField.js +44 -34
  27. package/dist/esm/builder/SchemaEditor.js +439 -0
  28. package/dist/esm/form/Controller.js +1 -1
  29. package/dist/esm/form/Form.js +11 -5
  30. package/dist/esm/hooks/useFormBuilder.js +25 -13
  31. package/dist/esm/index.js +4 -1
  32. package/dist/esm/input/Checkbox.js +4 -3
  33. package/dist/esm/input/ColorInput.js +1 -1
  34. package/dist/esm/input/DateInput.js +183 -0
  35. package/dist/esm/input/Field.js +1 -1
  36. package/dist/esm/input/File.js +1 -1
  37. package/dist/esm/input/Hidden.js +1 -1
  38. package/dist/esm/input/Input.js +1 -1
  39. package/dist/esm/input/Number.js +1 -1
  40. package/dist/esm/input/Password.js +1 -1
  41. package/dist/esm/input/{Range.js → RangeSlider.js} +3 -3
  42. package/dist/esm/input/Search.js +1 -1
  43. package/dist/esm/input/Slider.js +1 -1
  44. package/dist/esm/input/Switch.js +4 -3
  45. package/dist/esm/input/Textarea.js +1 -1
  46. package/dist/esm/internal/Field.module.css +1 -1
  47. package/dist/esm/internal/InputWrapper.js +4 -2
  48. package/dist/esm/types/schema.js +40 -0
  49. package/dist/types/builder/FileField.d.ts +2 -2
  50. package/dist/types/builder/FormField.d.ts +3 -1
  51. package/dist/types/builder/SchemaEditor.d.ts +16 -0
  52. package/dist/types/form/Controller.d.ts +1 -1
  53. package/dist/types/form/Form.d.ts +1 -0
  54. package/dist/types/hooks/useFormBuilder.d.ts +3 -1
  55. package/dist/types/index.d.ts +4 -2
  56. package/dist/types/input/Checkbox.d.ts +4 -3
  57. package/dist/types/input/ColorInput.d.ts +1 -1
  58. package/dist/types/input/DateInput.d.ts +19 -0
  59. package/dist/types/input/{Range.d.ts → RangeSlider.d.ts} +1 -1
  60. package/dist/types/input/Switch.d.ts +1 -1
  61. package/dist/types/internal/InputWrapper.d.ts +1 -1
  62. package/dist/types/types/index.d.ts +7 -3
  63. package/dist/types/types/schema.d.ts +52 -33
  64. package/package.json +5 -4
  65. package/src/builder/FileField.tsx +5 -4
  66. package/src/builder/FormField.tsx +45 -32
  67. package/src/builder/SchemaEditor.tsx +457 -0
  68. package/src/form/Controller.tsx +2 -2
  69. package/src/form/Form.tsx +6 -6
  70. package/src/hooks/useFormBuilder.tsx +29 -15
  71. package/src/index.ts +5 -2
  72. package/src/input/Checkbox.tsx +4 -3
  73. package/src/input/ColorInput.tsx +5 -2
  74. package/src/input/DateInput.tsx +248 -0
  75. package/src/input/Field.tsx +2 -1
  76. package/src/input/File.tsx +1 -1
  77. package/src/input/Hidden.tsx +4 -3
  78. package/src/input/Input.tsx +1 -1
  79. package/src/input/Number.tsx +1 -1
  80. package/src/input/Password.tsx +1 -1
  81. package/src/input/{Range.tsx → RangeSlider.tsx} +2 -2
  82. package/src/input/Search.tsx +1 -1
  83. package/src/input/Slider.tsx +1 -1
  84. package/src/input/Switch.tsx +2 -0
  85. package/src/input/Textarea.tsx +1 -1
  86. package/src/internal/Field.module.css +12 -1
  87. package/src/internal/InputWrapper.tsx +5 -0
  88. package/src/types/index.ts +9 -5
  89. package/src/types/schema.ts +65 -41
@@ -1,13 +1,15 @@
1
1
  import "./i18n";
2
2
  export { Controller } from "./form/Controller";
3
3
  export { Form, type FormRef } from "./form/Form";
4
+ export { SchemaEditor } from "./builder/SchemaEditor";
4
5
  export { useFileUploader } from "./hooks/useFileUploader";
5
6
  export { useFormBuilder } from "./hooks/useFormBuilder";
6
- export { type FormSchema } from "./types/schema";
7
+ export { DATA_TYPES, type FormSchema, type SchemaDef } from "./types/schema";
7
8
  export { ArrayInput } from "./input/ArrayInput";
8
9
  export { Checkbox } from "./input/Checkbox";
9
10
  export { ColorInput } from "./input/ColorInput";
10
11
  export { ColorPicker } from "./input/ColorPicker";
12
+ export { DateInput } from "./input/DateInput";
11
13
  export { Field } from "./input/Field";
12
14
  export { FileInput } from "./input/File";
13
15
  export { HiddenInput } from "./input/Hidden";
@@ -16,7 +18,7 @@ export { Number } from "./input/Number";
16
18
  export { Password } from "./input/Password";
17
19
  export { Radio } from "./input/Radio";
18
20
  export { RadioGroup } from "./input/RadioGroup";
19
- export { Range } from "./input/Range";
21
+ export { RangeSlider } from "./input/RangeSlider";
20
22
  export { Search } from "./input/Search";
21
23
  export { Slider } from "./input/Slider";
22
24
  export { Switch } from "./input/Switch";
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  import { type RefProp } from "@react-fabric/core/dist/types/types";
3
- export interface CheckboxProps extends RefProp<HTMLInputElement> {
3
+ interface CheckboxProps extends RefProp<HTMLInputElement> {
4
4
  /**
5
5
  * checkbox label
6
6
  */
@@ -16,7 +16,7 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
16
16
  /**
17
17
  * on checked change
18
18
  */
19
- onChange?: (checked: boolean | string | number) => void;
19
+ onChange?: (checked: boolean) => void;
20
20
  /**
21
21
  * disabled input
22
22
  */
@@ -43,4 +43,5 @@ export interface CheckboxProps extends RefProp<HTMLInputElement> {
43
43
  iconChecked?: string;
44
44
  name?: string;
45
45
  }
46
- export declare const Checkbox: ({ ref, label, value, name, checked, invalid, disabled, error, width, icon, iconChecked, onChange, ...rest }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
46
+ export declare const Checkbox: ({ ref, label, value, name, checked, invalid, disabled, error, width, icon, iconChecked, required, onChange, ...rest }: CheckboxProps) => import("react/jsx-runtime").JSX.Element;
47
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { type RefProp } from "@react-fabric/core/dist/types/types";
2
2
  import { type InputProps } from "../types";
3
3
  import { type ColorProps } from "./ColorPicker";
4
- export interface ColorInputProps extends InputProps, ColorProps, RefProp {
4
+ export interface ColorInputProps extends InputProps, Omit<ColorProps, "onChange">, RefProp {
5
5
  /**
6
6
  * show eydrop picker
7
7
  */
@@ -0,0 +1,19 @@
1
+ import { type RefProp } from "@react-fabric/core/dist/types/types";
2
+ import { type DateLike } from "@react-fabric/date";
3
+ import { type InputProps } from "../types";
4
+ export interface DateProps extends InputProps<string>, RefProp<HTMLInputElement> {
5
+ type?: "date" | "datetime";
6
+ /**
7
+ * date format
8
+ */
9
+ format?: string;
10
+ /**
11
+ * minimum value
12
+ */
13
+ min?: DateLike;
14
+ /**
15
+ * maximum value
16
+ */
17
+ max?: DateLike;
18
+ }
19
+ export declare const DateInput: ({ ref, name, value, invalid, readOnly, disabled, required, placeholder, autoFocus, error, type, onChange, onEnterPressed, format, min, max, ...rest }: DateProps) => import("react/jsx-runtime").JSX.Element;
@@ -56,4 +56,4 @@ export interface RangeProps extends Omit<InputProps<[number, number]>, "placehol
56
56
  /**
57
57
  * Number Range input
58
58
  */
59
- export declare const Range: ({ error, name, value, step, min, max, height, color, vertical, showLabels, showValue, minLabel, maxLabel, ranges, format, autoFocus, disabled, readOnly, onBlur, onChange, onEnterPressed, onFocus, onSlide, invalid, ...rest }: RangeProps) => import("react/jsx-runtime").JSX.Element;
59
+ export declare const RangeSlider: ({ error, name, value, step, min, max, height, color, vertical, showLabels, showValue, minLabel, maxLabel, ranges, format, autoFocus, disabled, readOnly, onBlur, onChange, onEnterPressed, onFocus, onSlide, invalid, ...rest }: RangeProps) => import("react/jsx-runtime").JSX.Element;
@@ -43,4 +43,4 @@ export interface SwitchProps extends RefProp<HTMLInputElement> {
43
43
  offLabel?: string;
44
44
  offLabelColor?: string | ColorType;
45
45
  }
46
- export declare const Switch: ({ ref, label, checked, invalid, disabled, error, width, color, name, onLabel, offLabel, onLabelColor, offLabelColor, defaultColor, onChange, ...rest }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
46
+ export declare const Switch: ({ ref, label, checked, invalid, disabled, error, width, color, name, onLabel, offLabel, onLabelColor, offLabelColor, defaultColor, required, onChange, ...rest }: SwitchProps) => import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- export declare const InputWrapper: ({ invalid, error, allowClear, showClear, decorateStart, decorateEnd, children, onClear, noOutline, noBorder, textarea, textareaExpandable, "data-inner": isInner, "data-open": isOpen, floatingExpand, wrapperRef, width, ...rest }: KeyValue) => import("react/jsx-runtime").JSX.Element;
1
+ export declare const InputWrapper: ({ invalid, error, allowClear, showClear, decorateStart, decorateEnd, decorateEndShowWhenEmpty, decorateEndHideWhenEmpty, children, onClear, noOutline, noBorder, textarea, textareaExpandable, "data-inner": isInner, "data-open": isOpen, floatingExpand, wrapperRef, width, ...rest }: KeyValue) => import("react/jsx-runtime").JSX.Element;
@@ -8,7 +8,7 @@ export interface InputProps<V = string> extends TestProps {
8
8
  /**
9
9
  * change handler
10
10
  */
11
- onChange?: (value?: V) => void;
11
+ onChange?: (value?: V | null) => void;
12
12
  /**
13
13
  * on focus event handler
14
14
  */
@@ -45,6 +45,8 @@ export interface InputProps<V = string> extends TestProps {
45
45
  *
46
46
  */
47
47
  decorateEnd?: JSX.Element | string | number | boolean;
48
+ decorateEndShowWhenEmpty?: boolean;
49
+ decorateEndHideWhenEmpty?: boolean;
48
50
  /**
49
51
  * info label at bottom
50
52
  */
@@ -90,7 +92,7 @@ export interface InputProps<V = string> extends TestProps {
90
92
  */
91
93
  labelWidth?: string;
92
94
  }
93
- export interface BaseSelectProps<T> extends RefProp<HTMLInputElement>, Omit<InputProps, "value" | "onChange"> {
95
+ export interface BaseSelectProps<T extends AnyObject = string> {
94
96
  /**
95
97
  * list options
96
98
  */
@@ -132,7 +134,8 @@ export interface BaseSelectProps<T> extends RefProp<HTMLInputElement>, Omit<Inpu
132
134
  */
133
135
  matcher?: (option: T, query: string) => boolean;
134
136
  }
135
- export type SelectProps<T> = BaseSelectProps<T> & ({
137
+ type BaseSelectType<T> = BaseSelectProps<T> & RefProp<HTMLInputElement> & Omit<InputProps, "value" | "onChange">;
138
+ export type SelectProps<T> = BaseSelectType<T> & ({
136
139
  /**
137
140
  * is multiple selection
138
141
  */
@@ -167,3 +170,4 @@ export type SelectProps<T> = BaseSelectProps<T> & ({
167
170
  */
168
171
  onChange?: (value?: string[]) => void;
169
172
  });
173
+ export {};
@@ -1,59 +1,78 @@
1
- interface BaseSchemaDef {
1
+ import { type DateLike } from "@react-fabric/date";
2
+ export declare enum DATA_TYPES {
3
+ TEXT = "text",
4
+ COLOR = "color",
5
+ BOOL = "bool",
6
+ DATE = "date",
7
+ STRING = "string",
8
+ NUMBER = "number",
9
+ RANGE = "range",
10
+ FILE = "file",
11
+ AVATAR = "avatar",
12
+ SCHEMA = "schema"
13
+ }
14
+ interface SingleValue {
15
+ multiple?: false;
16
+ minItems?: never;
17
+ maxItems?: never;
18
+ }
19
+ interface MultipleValue {
20
+ multiple: true;
21
+ minItems?: number;
22
+ maxItems?: number;
23
+ }
24
+ export type ValueType = SingleValue | MultipleValue;
25
+ interface BaseSchema {
2
26
  id: string;
3
27
  label: string;
4
28
  datatype: string;
5
29
  required?: boolean;
6
- multiple?: boolean;
7
- defaultValue?: AnyObject;
8
30
  }
9
- interface SchemaDef extends BaseSchemaDef {
10
- datatype: "text" | "color";
31
+ export interface DefaultSchema extends BaseSchema {
32
+ datatype: DATA_TYPES.TEXT | DATA_TYPES.COLOR;
11
33
  }
12
- interface BooleanSchema extends BaseSchemaDef {
13
- datatype: "boolean";
14
- defaultValue?: boolean;
34
+ export interface BooleanSchema extends BaseSchema {
35
+ datatype: DATA_TYPES.BOOL;
15
36
  }
16
- interface StringSchema extends BaseSchemaDef {
17
- datatype: "string";
18
- options?: string[];
37
+ export interface StringSchema extends BaseSchema {
38
+ datatype: DATA_TYPES.STRING;
19
39
  regex?: string;
20
- identifierType?: string;
40
+ options?: string[];
41
+ optionList?: string;
42
+ allowCustom?: boolean;
21
43
  }
22
- interface RangeSchema extends BaseSchemaDef {
23
- datatype: "range";
44
+ export interface RangeSchema extends BaseSchema {
45
+ datatype: DATA_TYPES.RANGE;
24
46
  min?: number;
25
47
  max?: number;
26
48
  step?: number;
27
- defaultValue?: [number, number];
28
49
  }
29
- interface NumberSchema extends BaseSchemaDef {
30
- datatype: "number";
31
- min?: number;
32
- max?: number;
33
- step?: number;
34
- defaultValue?: number;
50
+ export interface DateSchema extends BaseSchema {
51
+ datatype: DATA_TYPES.DATE;
52
+ type?: "date" | "datetime";
53
+ min?: DateLike;
54
+ max?: DateLike;
35
55
  }
36
- interface DecimalSchema extends BaseSchemaDef {
37
- datatype: "decimal";
56
+ export interface NumberSchema extends BaseSchema {
57
+ datatype: DATA_TYPES.NUMBER;
38
58
  min?: number;
39
59
  max?: number;
40
60
  step?: number;
41
- defaultValue?: number;
42
61
  }
43
- export interface FileSchema extends BaseSchemaDef {
44
- datatype: "file";
62
+ export interface FileSchema extends BaseSchema {
63
+ datatype: DATA_TYPES.FILE;
45
64
  accept?: string;
46
65
  }
47
- export interface AvatarSchema extends BaseSchemaDef {
48
- datatype: "avatar";
66
+ export interface AvatarSchema extends BaseSchema {
67
+ datatype: DATA_TYPES.AVATAR;
49
68
  multiple?: false;
50
69
  }
51
- export type SchemaType = SchemaDef | BooleanSchema | StringSchema | RangeSchema | NumberSchema | DecimalSchema | FileSchema | AvatarSchema;
52
- export interface ChildSchema extends BaseSchemaDef {
53
- datatype: "schema";
70
+ export type SchemaType = (DefaultSchema & ValueType) | (BooleanSchema & ValueType) | (StringSchema & ValueType) | (RangeSchema & ValueType) | (DateSchema & ValueType) | (NumberSchema & ValueType) | (FileSchema & ValueType) | (AvatarSchema & ValueType);
71
+ export interface ChildSchema extends BaseSchema {
72
+ datatype: DATA_TYPES.SCHEMA;
54
73
  inline?: boolean;
55
74
  schema: SchemaType[];
56
- defaultValue?: never;
57
75
  }
58
- export type FormSchema = SchemaType | ChildSchema;
76
+ export type SchemaDef = SchemaType | (ChildSchema & ValueType);
77
+ export type FormSchema = SchemaDef[];
59
78
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/form",
3
- "version": "1.0.0-beta.32",
3
+ "version": "1.0.0-beta.34",
4
4
  "description": "RUF: Form package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -39,8 +39,9 @@
39
39
  "@dnd-kit/utilities": "^3.2.2",
40
40
  "@floating-ui/react": "^0.26.24",
41
41
  "@hookform/resolvers": "^3.9.0",
42
- "@react-fabric/core": "^1.0.0-beta.32",
43
- "@react-fabric/utilities": "^1.0.0-beta.32",
42
+ "@react-fabric/core": "^1.0.0-beta.34",
43
+ "@react-fabric/date": "^1.0.0-beta.34",
44
+ "@react-fabric/utilities": "^1.0.0-beta.34",
44
45
  "classnames": "^2.5.1",
45
46
  "color": "^4.2.3",
46
47
  "react-color": "^2.19.3",
@@ -60,5 +61,5 @@
60
61
  "node": ">=18.12.0",
61
62
  "npm": ">=8.19.0"
62
63
  },
63
- "gitHead": "e8ba7088116f5ae253ed989854d6fdaef2ad7507"
64
+ "gitHead": "dcd1c1b247b6597b168a0649d2b3a53463b9c37e"
64
65
  }
@@ -24,20 +24,21 @@
24
24
  import { Button, Icon, ProgressBar } from "@react-fabric/core";
25
25
  import { FileUtil, Format } from "@react-fabric/utilities";
26
26
  import { Fragment } from "react";
27
- import { type UploadHandler, useFileUploader } from "../hooks/useFileUploader";
27
+ import { useFileUploader, type UploadHandler } from "../hooks/useFileUploader";
28
28
  import { Field } from "../input/Field";
29
29
  import { HiddenInput } from "../input/Hidden";
30
- import { type FileSchema } from "../types/schema";
30
+ import { type FileSchema, type ValueType } from "../types/schema";
31
31
 
32
32
  export const FileField = ({
33
33
  uploadHandler,
34
34
  inline,
35
35
  label,
36
36
  accept,
37
- multiple = false,
38
37
  value,
38
+ fileUrl,
39
+ multiple,
39
40
  ...rest
40
- }: Partial<FileSchema> & {
41
+ }: Partial<FileSchema & ValueType> & {
41
42
  value?: AnyObject;
42
43
  inline?: boolean;
43
44
  fileUrl?: (path: string) => string;
@@ -21,6 +21,7 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
+ import { isEmpty } from "@react-fabric/utilities";
24
25
  import { useMemo } from "react";
25
26
  import { useTranslation } from "react-i18next";
26
27
  import { Controller } from "../form/Controller";
@@ -28,13 +29,15 @@ import { type UploadHandler } from "../hooks/useFileUploader";
28
29
  import { ArrayInput } from "../input/ArrayInput";
29
30
  import { AvatarInput } from "../input/AvatarInput";
30
31
  import { ColorInput } from "../input/ColorInput";
32
+ import { DateInput } from "../input/DateInput";
31
33
  import { Input } from "../input/Input";
32
34
  import { Number } from "../input/Number";
33
- import { Range } from "../input/Range";
35
+ import { RangeSlider } from "../input/RangeSlider";
34
36
  import { Switch } from "../input/Switch";
35
37
  import { Textarea } from "../input/Textarea";
36
38
  import { Select } from "../select/Select";
37
- import { type SchemaType } from "../types/schema";
39
+ import { type BaseSelectProps } from "../types";
40
+ import { DATA_TYPES, type SchemaType } from "../types/schema";
38
41
  import { FileField } from "./FileField";
39
42
 
40
43
  export const FormField = ({
@@ -44,7 +47,7 @@ export const FormField = ({
44
47
  inline,
45
48
  prefix,
46
49
  autoFocus,
47
- defaultValue,
50
+ optionLists,
48
51
  fileUrl,
49
52
  uploadHandler,
50
53
  ...rest
@@ -52,6 +55,7 @@ export const FormField = ({
52
55
  inline?: boolean;
53
56
  prefix?: string;
54
57
  autoFocus?: boolean;
58
+ optionLists?: KeyValue<BaseSelectProps<any>>;
55
59
  fileUrl?: (path: string) => string;
56
60
  uploadHandler?: UploadHandler;
57
61
  }) => {
@@ -61,32 +65,34 @@ export const FormField = ({
61
65
  [id, prefix],
62
66
  );
63
67
 
64
- const E = useMemo(() => {
65
- if (rest.datatype === "number" || rest.datatype === "decimal")
66
- return Number;
67
- if (rest.datatype === "range") return Range;
68
- if (rest.datatype === "boolean") return Switch;
69
- if (rest.datatype === "text") return Textarea;
70
- if (rest.datatype === "color") return ColorInput;
71
- if (rest.datatype === "string" && rest.options) return Select;
68
+ const hasOptions = useMemo(
69
+ () =>
70
+ rest.datatype === DATA_TYPES.STRING &&
71
+ ((rest.optionList === "--CUSTOM--" && !isEmpty(rest.options)) ||
72
+ !isEmpty(optionLists?.[rest.optionList ?? ""])),
73
+ [rest],
74
+ );
75
+
76
+ const E = useMemo<AnyObject>(() => {
77
+ if (rest.datatype === DATA_TYPES.NUMBER) return Number;
78
+ if (rest.datatype === DATA_TYPES.RANGE) return RangeSlider;
79
+ if (rest.datatype === DATA_TYPES.BOOL) return Switch;
80
+ if (rest.datatype === DATA_TYPES.TEXT) return Textarea;
81
+ if (rest.datatype === DATA_TYPES.DATE) return DateInput;
82
+ if (rest.datatype === DATA_TYPES.COLOR) return ColorInput;
83
+ if (hasOptions) return Select;
72
84
 
73
85
  return Input;
74
- }, [rest.datatype]);
86
+ }, [rest.datatype, hasOptions]);
75
87
 
76
88
  const props = useMemo(() => {
77
- if (rest.datatype === "number")
89
+ if (rest.datatype === DATA_TYPES.NUMBER)
78
90
  return {
79
91
  min: rest.min,
80
92
  max: rest.max,
81
93
  step: rest.step ?? 1,
82
94
  };
83
- if (rest.datatype === "decimal")
84
- return {
85
- min: rest.min,
86
- max: rest.max,
87
- step: rest.step ?? 0.1,
88
- };
89
- if (rest.datatype === "range")
95
+ if (rest.datatype === DATA_TYPES.RANGE)
90
96
  return {
91
97
  min: rest.min ?? 1,
92
98
  max: rest.max ?? 99,
@@ -94,20 +100,27 @@ export const FormField = ({
94
100
  showValue: true,
95
101
  showLabels: true,
96
102
  };
97
- if (rest.datatype === "text") return { rows: 3 };
98
- if (rest.datatype === "color") return { showPicker: true };
103
+ if (rest.datatype === DATA_TYPES.DATE)
104
+ return {
105
+ min: rest.min,
106
+ max: rest.max,
107
+ type: rest.type,
108
+ };
109
+ if (rest.datatype === DATA_TYPES.TEXT) return { rows: 3 };
110
+ if (rest.datatype === DATA_TYPES.COLOR) return { showPicker: true };
99
111
 
100
- if (rest.datatype === "string" && rest.options)
112
+ if (rest.datatype === DATA_TYPES.STRING && hasOptions)
101
113
  return {
102
- options: rest.options,
103
114
  multiple: rest.multiple,
115
+ allowCreate: rest.allowCustom,
104
116
  searchable: true,
117
+ ...(optionLists?.[rest.optionList ?? ""] ?? { options: rest.options }),
105
118
  };
106
119
 
107
120
  return {};
108
- }, [rest]);
121
+ }, [rest, hasOptions, optionLists]);
109
122
 
110
- if (rest.datatype === "avatar")
123
+ if (rest.datatype === DATA_TYPES.AVATAR)
111
124
  return (
112
125
  uploadHandler && (
113
126
  <Controller name={fieldName}>
@@ -120,7 +133,7 @@ export const FormField = ({
120
133
  )
121
134
  );
122
135
 
123
- if (rest.datatype === "file")
136
+ if (rest.datatype === DATA_TYPES.FILE)
124
137
  return (
125
138
  uploadHandler && (
126
139
  <Controller name={fieldName}>
@@ -135,12 +148,12 @@ export const FormField = ({
135
148
  )
136
149
  );
137
150
 
138
- return rest.multiple && !("options" in rest) ? (
151
+ return rest.multiple && !hasOptions ? (
139
152
  <ArrayInput
140
153
  name={fieldName}
141
- label={t(label, label)}
154
+ label={t(`fb.${id}`, label || id)}
142
155
  required={required}
143
- onAdd={() => ""}
156
+ onAdd={() => String("")}
144
157
  >
145
158
  <Controller>
146
159
  <E {...props} />
@@ -151,8 +164,8 @@ export const FormField = ({
151
164
  <E
152
165
  {...props}
153
166
  autoFocus={autoFocus}
154
- label={t(label, label)}
155
- placeholder={t(label, label)}
167
+ label={t(`fb.${id}`, label || id)}
168
+ placeholder={t(`fb.${id}`, label || id)}
156
169
  required={required}
157
170
  inline={inline}
158
171
  />