Skip to content

Commit

Permalink
Add information about AutoForm's goal
Browse files Browse the repository at this point in the history
  • Loading branch information
vantezzen committed Jan 31, 2024
1 parent 6a463a4 commit b4a890e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ A live demo can be found at <https://vantezzen.github.io/auto-form/>.

![AutoForm demo](./demo.png)

## When to use AutoForm?

AutoForm is mostly meant as a drop-in form builder for your internal and low-priority forms with existing zod schemas. For example, if you already have zod schemas for your API and want to create a simple admin panel to edit user profiles, simply pass the schema to AutoForm and you're done.

As forms almost always grow more complex, AutoForm gives you options to customize how forms are rendered (e.g. using the `fieldConfig` options and dependency support) and gives you escape hatches to customize the form even further (e.g. rendering custom parents and adding custom field types).

However, AutoForm does not aim to be a full-featured form builder. It does not aim to support every edge case in your zod schema or allow building complex, multi-page forms. If you need more customization, feel free to customize AutoForm's renderer in your project or use more powerful form builders like [Formik](https://formik.org/) - though those require more specialized configuration instead of simple drop-in support for your zod schema. For an example on how AutoForm can be extended for more powerful, YAML-based, multi-page forms, see [AutoForm YAML](https://github.com/roeyazroel/auto-form).

## Installation

The component depends on the following components from shadcn/ui:
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/auto-form/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function resolveDependencies<
>(
dependencies: Dependency<SchemaType>[],
currentFieldName: keyof SchemaType,
watch: UseFormWatch<FieldValues>
watch: UseFormWatch<FieldValues>,
) {
let isDisabled = false;
let isHidden = false;
Expand All @@ -17,7 +17,7 @@ export default function resolveDependencies<
const currentFieldValue = watch(currentFieldName as string);

const currentFieldDependencies = dependencies.filter(
(dependency) => dependency.targetField === currentFieldName
(dependency) => dependency.targetField === currentFieldName,
);
for (const dependency of currentFieldDependencies) {
const watchedValue = watch(dependency.sourceField as string);
Expand Down
20 changes: 10 additions & 10 deletions src/components/ui/tooltip.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as React from "react"
import * as TooltipPrimitive from "@radix-ui/react-tooltip"
import * as React from "react";
import * as TooltipPrimitive from "@radix-ui/react-tooltip";

import { cn } from "@/lib/utils"
import { cn } from "@/lib/utils";

const TooltipProvider = TooltipPrimitive.Provider
const TooltipProvider = TooltipPrimitive.Provider;

const Tooltip = TooltipPrimitive.Root
const Tooltip = TooltipPrimitive.Root;

const TooltipTrigger = TooltipPrimitive.Trigger
const TooltipTrigger = TooltipPrimitive.Trigger;

const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
Expand All @@ -18,11 +18,11 @@ const TooltipContent = React.forwardRef<
sideOffset={sideOffset}
className={cn(
"z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
className,
)}
{...props}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName
));
TooltipContent.displayName = TooltipPrimitive.Content.displayName;

export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider }
export { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider };

0 comments on commit b4a890e

Please sign in to comment.