Skip to content

Commit

Permalink
refactor: rename InputOrGroup to AutoField
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed May 13, 2024
1 parent 46aa8ff commit ab8df61
Show file tree
Hide file tree
Showing 19 changed files with 19 additions and 17 deletions.
2 changes: 1 addition & 1 deletion apps/docs/components/Preview/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { CSSProperties } from "react";

export { InputOrGroup } from "@/core/components/InputOrGroup";
export { AutoField } from "@/core/components/AutoField";

import { ReactNode } from "react";
import "@/core/styles.css";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: <FieldLabel>
---

import { ConfigPreview } from "../../../../components/Preview";
import { FieldLabel } from "@/core/components/InputOrGroup";
import { FieldLabel } from "@/core/components/AutoField";
import { Globe } from "lucide-react";

# \<FieldLabel\>
Expand Down
2 changes: 1 addition & 1 deletion apps/docs/pages/docs/extending-puck/custom-fields.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ConfigPreview } from "@/docs/components/Preview";
import { FieldLabel } from "@/core/components/InputOrGroup";
import { FieldLabel } from "@/core/components/AutoField";

# Custom Fields

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import getClassNameFactory from "../../../../lib/get-class-name-factory";
import styles from "./styles.module.css";
import { List, Plus, Trash } from "lucide-react";
import { FieldLabelInternal, InputOrGroup, type InputProps } from "../..";
import { FieldLabelInternal, AutoField, type InputProps } from "../..";
import { IconButton } from "../../../IconButton";
import { reorder, replace } from "../../../../lib";
import { Droppable } from "../../../Droppable";
Expand Down Expand Up @@ -263,7 +263,7 @@ export const ArrayField = ({
const wildcardFieldName = `${name}[*].${fieldName}`;

return (
<InputOrGroup
<AutoField
key={subFieldName}
name={subFieldName}
label={subField.label || fieldName}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import getClassNameFactory from "../../../../lib/get-class-name-factory";
import styles from "./styles.module.css";
import { MoreVertical } from "lucide-react";
import { FieldLabelInternal, InputOrGroup, type InputProps } from "../..";
import { FieldLabelInternal, AutoField, type InputProps } from "../..";

const getClassName = getClassNameFactory("ObjectField", styles);
const getClassNameItem = getClassNameFactory("ObjectFieldItem", styles);

export const ObjectField = ({
field,
Expand Down Expand Up @@ -38,7 +37,7 @@ export const ObjectField = ({
const wildcardFieldName = `${name}.${fieldName}`;

return (
<InputOrGroup
<AutoField
key={subFieldName}
name={subFieldName}
label={subField.label || fieldName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ export type InputProps<F = Field<any>> = {
readOnlyFields?: Record<string, boolean | undefined>;
};

export const InputOrGroup = ({ onChange, ...props }: InputProps) => {
export function AutoField<FieldType extends Field>({
onChange,
...props
}: InputProps<FieldType>) {
const { overrides } = useAppContext();

const { name, field, value, readOnly } = props;
Expand Down Expand Up @@ -178,4 +181,4 @@ export const InputOrGroup = ({ onChange, ...props }: InputProps) => {
const Render = render[field.type] as (props: InputProps) => ReactElement;

return <Render {...mergedProps}>{children}</Render>;
};
}
4 changes: 2 additions & 2 deletions packages/core/components/ExternalInput/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Modal } from "../Modal";
import { Heading } from "../Heading";
import { ClipLoader } from "react-spinners";
import { Button } from "../Button";
import { InputOrGroup } from "../InputOrGroup";
import { AutoField } from "../AutoField";
import { IconButton } from "../IconButton";

const getClassName = getClassNameFactory("ExternalInput", styles);
Expand Down Expand Up @@ -195,7 +195,7 @@ export const ExternalInput = ({
Object.keys(filterFields).map((fieldName) => {
const filterField = filterFields[fieldName];
return (
<InputOrGroup
<AutoField
key={fieldName}
field={filterField}
name={fieldName}
Expand Down
6 changes: 3 additions & 3 deletions packages/core/components/Puck/components/Fields/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
RootData,
UiState,
} from "../../../../types/Config";
import { InputOrGroup } from "../../../InputOrGroup";
import { AutoField } from "../../../AutoField";
import { useAppContext } from "../../context";

import styles from "./styles.module.css";
Expand Down Expand Up @@ -264,7 +264,7 @@ export const Fields = () => {
const { readOnly = {} } = selectedItem;

return (
<InputOrGroup
<AutoField
key={`${selectedItem.props.id}_${fieldName}`}
field={field}
name={fieldName}
Expand All @@ -280,7 +280,7 @@ export const Fields = () => {
const { readOnly = {} } = data.root;

return (
<InputOrGroup
<AutoField
key={`page_${fieldName}`}
field={field}
name={fieldName}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export * from "./lib/transform-props";
export * from "./lib/resolve-all-data";
export { usePuck } from "./lib/use-puck";

export { FieldLabel } from "./components/InputOrGroup";
export { FieldLabel } from "./components/AutoField";
2 changes: 1 addition & 1 deletion packages/core/types/Overrides.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactElement, ReactNode } from "react";
import { InputProps } from "../components/InputOrGroup";
import { InputProps } from "../components/AutoField";
import { Field } from "./Config";
import { ItemSelector } from "../lib/get-item";

Expand Down

0 comments on commit ab8df61

Please sign in to comment.