diff --git a/packages/core/components/InputOrGroup/fields/ArrayField/index.tsx b/packages/core/components/InputOrGroup/fields/ArrayField/index.tsx
new file mode 100644
index 0000000000..7c713496a6
--- /dev/null
+++ b/packages/core/components/InputOrGroup/fields/ArrayField/index.tsx
@@ -0,0 +1,90 @@
+import getClassNameFactory from "../../../../lib/get-class-name-factory";
+import styles from "../../styles.module.css";
+import { List, Trash } from "react-feather";
+import { InputOrGroup, type InputProps } from "../..";
+import { IconButton } from "../../../IconButton";
+import { replace } from "../../../../lib";
+
+const getClassName = getClassNameFactory("Input", styles);
+
+export const ArrayField = ({
+ field,
+ onChange,
+ value,
+ name,
+ label,
+}: InputProps) => {
+ if (!field.arrayFields) {
+ return null;
+ }
+
+ return (
+
+
+
+
+
+ {label || name}
+
+
+ {Array.isArray(value) ? (
+ value.map((item, i) => (
+
+
+ {field.getItemSummary
+ ? field.getItemSummary(item, i)
+ : `Item #${i}`}
+
+
+ {
+ const existingValue = value || [];
+
+ existingValue.splice(i, 1);
+ onChange(existingValue);
+ }}
+ title="Delete"
+ >
+
+
+
+
+
+
+ ))
+ ) : (
+
+ )}
+
+
+
+
+ );
+};
diff --git a/packages/core/components/InputOrGroup/fields/DefaultField/index.tsx b/packages/core/components/InputOrGroup/fields/DefaultField/index.tsx
new file mode 100644
index 0000000000..dfb9f2c90b
--- /dev/null
+++ b/packages/core/components/InputOrGroup/fields/DefaultField/index.tsx
@@ -0,0 +1,42 @@
+import getClassNameFactory from "../../../../lib/get-class-name-factory";
+import styles from "../../styles.module.css";
+import { Hash, Type } from "react-feather";
+import type { InputProps } from "../..";
+
+const getClassName = getClassNameFactory("Input", styles);
+
+export const DefaultField = ({
+ field,
+ onChange,
+ readOnly,
+ value,
+ name,
+ label,
+}: InputProps) => {
+ return (
+
+ );
+};
diff --git a/packages/core/components/InputOrGroup/fields/ExternalField/index.tsx b/packages/core/components/InputOrGroup/fields/ExternalField/index.tsx
new file mode 100644
index 0000000000..672d6e63e3
--- /dev/null
+++ b/packages/core/components/InputOrGroup/fields/ExternalField/index.tsx
@@ -0,0 +1,28 @@
+import getClassNameFactory from "../../../../lib/get-class-name-factory";
+import styles from "../../styles.module.css";
+import type { InputProps } from "../..";
+import { ExternalInput } from "../../../ExternalInput";
+
+const getClassName = getClassNameFactory("Input", styles);
+
+export const ExternalField = ({
+ field,
+ onChange,
+ readOnly,
+ value,
+ name,
+ label,
+}: InputProps) => {
+ if (!field.adaptor) {
+ return null;
+ }
+
+ return (
+
+
+ {name === "_data" ? "External content" : label || name}
+
+
+
+ );
+};
diff --git a/packages/core/components/InputOrGroup/fields/RadioField/index.tsx b/packages/core/components/InputOrGroup/fields/RadioField/index.tsx
new file mode 100644
index 0000000000..3dc630b56f
--- /dev/null
+++ b/packages/core/components/InputOrGroup/fields/RadioField/index.tsx
@@ -0,0 +1,63 @@
+import getClassNameFactory from "../../../../lib/get-class-name-factory";
+import styles from "../../styles.module.css";
+import { CheckCircle } from "react-feather";
+import type { InputProps } from "../..";
+
+const getClassName = getClassNameFactory("Input", styles);
+
+export const RadioField = ({
+ field,
+ onChange,
+ readOnly,
+ value,
+ name,
+}: InputProps) => {
+ if (!field.options) {
+ return null;
+ }
+
+ return (
+
+
+
+
+
+
+ {field.label || name}
+
+
+
+ {field.options.map((option) => (
+
+ ))}
+
+
+
+ );
+};
diff --git a/packages/core/components/InputOrGroup/fields/SelectField/index.tsx b/packages/core/components/InputOrGroup/fields/SelectField/index.tsx
new file mode 100644
index 0000000000..f98ef53ca7
--- /dev/null
+++ b/packages/core/components/InputOrGroup/fields/SelectField/index.tsx
@@ -0,0 +1,52 @@
+import getClassNameFactory from "../../../../lib/get-class-name-factory";
+import styles from "../../styles.module.css";
+import { ChevronDown } from "react-feather";
+import type { InputProps } from "../..";
+
+const getClassName = getClassNameFactory("Input", styles);
+
+export const SelectField = ({
+ field,
+ onChange,
+ label,
+ value,
+ name,
+}: InputProps) => {
+ if (!field.options) {
+ return null;
+ }
+
+ return (
+
+ );
+};
diff --git a/packages/core/components/InputOrGroup/fields/TextareaField/index.tsx b/packages/core/components/InputOrGroup/fields/TextareaField/index.tsx
new file mode 100644
index 0000000000..8fae006c7d
--- /dev/null
+++ b/packages/core/components/InputOrGroup/fields/TextareaField/index.tsx
@@ -0,0 +1,34 @@
+import getClassNameFactory from "../../../../lib/get-class-name-factory";
+import styles from "../../styles.module.css";
+import { Type } from "react-feather";
+import type { InputProps } from "../..";
+
+const getClassName = getClassNameFactory("Input", styles);
+
+export const TextareaField = ({
+ onChange,
+ readOnly,
+ value,
+ name,
+ label,
+}: InputProps) => {
+ return (
+
+ );
+};
diff --git a/packages/core/components/InputOrGroup/fields/index.tsx b/packages/core/components/InputOrGroup/fields/index.tsx
new file mode 100644
index 0000000000..8eef387521
--- /dev/null
+++ b/packages/core/components/InputOrGroup/fields/index.tsx
@@ -0,0 +1,6 @@
+export * from "./ArrayField";
+export * from "./DefaultField";
+export * from "./ExternalField";
+export * from "./RadioField";
+export * from "./SelectField";
+export * from "./TextareaField";
diff --git a/packages/core/components/InputOrGroup/index.tsx b/packages/core/components/InputOrGroup/index.tsx
index 57f57906f7..2ec4ec16ed 100644
--- a/packages/core/components/InputOrGroup/index.tsx
+++ b/packages/core/components/InputOrGroup/index.tsx
@@ -1,19 +1,16 @@
import getClassNameFactory from "../../lib/get-class-name-factory";
import { Field } from "../../types/Config";
-import { ExternalInput } from "../ExternalInput";
import styles from "./styles.module.css";
-import { replace } from "../../lib";
-import {
- Trash,
- Type,
- List,
- ChevronDown,
- CheckCircle,
- Hash,
-} from "react-feather";
-import { IconButton } from "../IconButton";
import { ReactNode } from "react";
+import {
+ RadioField,
+ SelectField,
+ ExternalField,
+ ArrayField,
+ DefaultField,
+ TextareaField,
+} from "./fields";
const getClassName = getClassNameFactory("Input", styles);
@@ -37,226 +34,36 @@ export const FieldLabel = ({
);
};
-export const InputOrGroup = ({
- name,
- field,
- value,
- label,
- onChange,
- readOnly,
-}: {
+export type InputProps = {
name: string;
field: Field;
value: any;
label?: string;
onChange: (value: any) => void;
readOnly?: boolean;
-}) => {
- if (field.type === "array") {
- if (!field.arrayFields) {
- return null;
- }
-
- return (
-
-
-
-
-
- {label || name}
-
-
- {Array.isArray(value) ? (
- value.map((item, i) => (
-
-
- {field.getItemSummary
- ? field.getItemSummary(item, i)
- : `Item #${i}`}
-
-
- {
- const existingValue = value || [];
-
- existingValue.splice(i, 1);
- onChange(existingValue);
- }}
- title="Delete"
- >
-
-
-
-
-
-
- ))
- ) : (
-
- )}
+export const InputOrGroup = (props: InputProps) => {
+ const { name, field, value, onChange, readOnly } = props;
-
-
-
- );
+ if (field.type === "array") {
+ return ;
}
if (field.type === "external") {
- if (!field.adaptor) {
- return null;
- }
-
- return (
-
-
- {name === "_data" ? "External content" : label || name}
-
-
-
- );
+ return ;
}
if (field.type === "select") {
- if (!field.options) {
- return null;
- }
-
- return (
-
- );
+ return ;
}
if (field.type === "textarea") {
- return (
-
- );
+ return ;
}
if (field.type === "radio") {
- if (!field.options) {
- return null;
- }
-
- return (
-
-
-
-
-
-
- {field.label || name}
-
-
-
- {field.options.map((option) => (
-
- ))}
-
-
-
- );
+ return ;
}
if (field.type === "custom") {
@@ -277,30 +84,5 @@ export const InputOrGroup = ({
);
}
- return (
-
- );
+ return ;
};