vantezzen / auto-form

🌟 A React component that automatically creates a @shadcn/ui form based on a zod schema.
https://vantezzen.github.io/auto-form/
MIT License
2.76k stars 99 forks source link

Add `parent` to `FieldConfigItem` to wrap field with tag #1

Closed josephbona closed 1 year ago

josephbona commented 1 year ago

Great work on this! Here's something I needed right away.

Usage:


<AutoForm
  formSchema={formSchema}
  fieldConfig={{
    firstName: {
      inputProps: {
        placeholder: 'Joseph'
      },
      parent: {
        tag: 'div',
        props: {
          className: 'col-span-1'
        }
      }
    },
  }}
  onSubmit={onSubmit}
>
  <Button type="submit">Submit</Button>
</AutoForm>

// This will be rendered as:
<div className='col-span-1'>
  <input type="text" placeholder="Joseph" /* ... */ />
</div>
vantezzen commented 1 year ago

Thank you for the contribution! I think it's probably best to keep this in JSX-syntax rather than trying to imitate it with parent, startAdornment and endAdornment so I added support for custom parent elements which should cover all these use-cases more intuitively: https://github.com/vantezzen/auto-form#custom-parent-component

josephbona commented 1 year ago

Nice, I like your solution 👍