From 1530de764aced4dd8bbbdbe8eeec40461f6329f0 Mon Sep 17 00:00:00 2001 From: Chris Villa Date: Thu, 26 Oct 2023 22:36:33 +0100 Subject: [PATCH] refactor: share common label code between fields --- .../InputOrGroup/fields/ArrayField/index.tsx | 17 ++-- .../fields/DefaultField/index.tsx | 18 +++-- .../fields/ExternalField/index.tsx | 17 ++-- .../InputOrGroup/fields/RadioField/index.tsx | 78 +++++++++---------- .../InputOrGroup/fields/SelectField/index.tsx | 16 ++-- .../fields/TextareaField/index.tsx | 16 ++-- .../core/components/InputOrGroup/index.tsx | 38 ++++++++- .../components/InputOrGroup/styles.module.css | 4 +- 8 files changed, 114 insertions(+), 90 deletions(-) diff --git a/packages/core/components/InputOrGroup/fields/ArrayField/index.tsx b/packages/core/components/InputOrGroup/fields/ArrayField/index.tsx index 06f25131db..97d0ef2bf1 100644 --- a/packages/core/components/InputOrGroup/fields/ArrayField/index.tsx +++ b/packages/core/components/InputOrGroup/fields/ArrayField/index.tsx @@ -2,7 +2,7 @@ import getClassNameFactory from "../../../../lib/get-class-name-factory"; import inputStyles from "../../styles.module.css"; import styles from "./styles.module.css"; import { List, Plus, Trash } from "react-feather"; -import { InputOrGroup, type InputProps } from "../.."; +import { FieldLabelInternal, InputOrGroup, type InputProps } from "../.."; import { IconButton } from "../../../IconButton"; import { reorder, replace } from "../../../../lib"; import DroppableStrictMode from "../../../DroppableStrictMode"; @@ -69,13 +69,12 @@ export const ArrayField = ({ } return ( -
- -
- -
- {label || name} -
+ } + el="div" + readOnly={readOnly} + > { if (event.destination) { @@ -221,6 +220,6 @@ export const ArrayField = ({ }} -
+ ); }; diff --git a/packages/core/components/InputOrGroup/fields/DefaultField/index.tsx b/packages/core/components/InputOrGroup/fields/DefaultField/index.tsx index dfb9f2c90b..010fc6739e 100644 --- a/packages/core/components/InputOrGroup/fields/DefaultField/index.tsx +++ b/packages/core/components/InputOrGroup/fields/DefaultField/index.tsx @@ -1,7 +1,7 @@ import getClassNameFactory from "../../../../lib/get-class-name-factory"; import styles from "../../styles.module.css"; import { Hash, Type } from "react-feather"; -import type { InputProps } from "../.."; +import { FieldLabelInternal, type InputProps } from "../.."; const getClassName = getClassNameFactory("Input", styles); @@ -14,14 +14,16 @@ export const DefaultField = ({ label, }: InputProps) => { return ( - + ); }; diff --git a/packages/core/components/InputOrGroup/fields/ExternalField/index.tsx b/packages/core/components/InputOrGroup/fields/ExternalField/index.tsx index 773c1bc5d4..80cc59ab89 100644 --- a/packages/core/components/InputOrGroup/fields/ExternalField/index.tsx +++ b/packages/core/components/InputOrGroup/fields/ExternalField/index.tsx @@ -1,6 +1,6 @@ import getClassNameFactory from "../../../../lib/get-class-name-factory"; import styles from "../../styles.module.css"; -import type { InputProps } from "../.."; +import { FieldLabelInternal, type InputProps } from "../.."; import { ExternalInput } from "../../../ExternalInput"; import { Link } from "react-feather"; @@ -18,15 +18,12 @@ export const ExternalField = ({ } return ( -
-
-
- -
- - {label || name} -
+ } + el="div" + > -
+ ); }; diff --git a/packages/core/components/InputOrGroup/fields/RadioField/index.tsx b/packages/core/components/InputOrGroup/fields/RadioField/index.tsx index 091bb4e6ea..57749e47e1 100644 --- a/packages/core/components/InputOrGroup/fields/RadioField/index.tsx +++ b/packages/core/components/InputOrGroup/fields/RadioField/index.tsx @@ -1,7 +1,7 @@ import getClassNameFactory from "../../../../lib/get-class-name-factory"; import styles from "../../styles.module.css"; import { CheckCircle } from "react-feather"; -import type { InputProps } from "../.."; +import { FieldLabelInternal, type InputProps } from "../.."; const getClassName = getClassNameFactory("Input", styles); @@ -17,47 +17,43 @@ export const RadioField = ({ } return ( -
-
-
-
- -
- {field.label || name} -
+ } + label={field.label || name} + readOnly={readOnly} + el="div" + > +
+ {field.options.map((option) => ( + + ))}
-
+ ); }; diff --git a/packages/core/components/InputOrGroup/fields/SelectField/index.tsx b/packages/core/components/InputOrGroup/fields/SelectField/index.tsx index d4a0c52c4f..6010453121 100644 --- a/packages/core/components/InputOrGroup/fields/SelectField/index.tsx +++ b/packages/core/components/InputOrGroup/fields/SelectField/index.tsx @@ -1,7 +1,7 @@ import getClassNameFactory from "../../../../lib/get-class-name-factory"; import styles from "../../styles.module.css"; import { ChevronDown } from "react-feather"; -import type { InputProps } from "../.."; +import { FieldLabelInternal, type InputProps } from "../.."; const getClassName = getClassNameFactory("Input", styles); @@ -18,13 +18,11 @@ export const SelectField = ({ } return ( - + ); }; diff --git a/packages/core/components/InputOrGroup/fields/TextareaField/index.tsx b/packages/core/components/InputOrGroup/fields/TextareaField/index.tsx index 8fae006c7d..94d2193b30 100644 --- a/packages/core/components/InputOrGroup/fields/TextareaField/index.tsx +++ b/packages/core/components/InputOrGroup/fields/TextareaField/index.tsx @@ -1,7 +1,7 @@ import getClassNameFactory from "../../../../lib/get-class-name-factory"; import styles from "../../styles.module.css"; import { Type } from "react-feather"; -import type { InputProps } from "../.."; +import { FieldLabelInternal, type InputProps } from "../.."; const getClassName = getClassNameFactory("Input", styles); @@ -13,13 +13,11 @@ export const TextareaField = ({ label, }: InputProps) => { return ( -