npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gimme-react-form

v0.0.3

Published

Wrapper around simple Radix UI/Tailwind input components and react hook form, generate your form component from config, with type assistence

Downloads

9

Readme

gimme-react-form logo

gimme-react-form

gimme-react-form is a React component library that generates forms based on a TypeScript type and a simple configuration object.

Using amazing components from https://github.com/shadcn/ui !

Installation

To install the package, run:

npm install gimme-react-form

Usage

To use the library, import the GimmeForm component and pass it the following props:

  • schema: a object configuration that defines the shape of the form data. Use the GimmeFormSchema type to convert your data type to a configuration object type.
  • onSubmit: a callback function that receives the form data when the form is submitted.
  • defaultValues (optional): an object that provides default values for the form fields.
  • resolver (optional): a Yup or Zod validation schema or custom resolver that validates the form data.

Example usage:

import { GimmeFormSchema, GimmeForm } from "gimme-react-form";

type FormData = {
  name: string;
  //better to use "|undefined" then "property?:"
  age: number | undefined;
  isMarried: boolean;
  hobbies: {
    name: string;
    years: number;
  }[];
};

const formType: GimmeFormSchema<FormData> = {
  name: "string",
  age: "number?",
  isMarried: ["boolean", "Are you married?"], //or ['Married', 'Single'] to use switch instead of checkbox
  hobbies: { name: "string", years: "number" },
};

const handleSubmit = (data: FormData) => {
  console.log(data);
};

function App() {
  return <GimmeForm type={formType} onSubmit={handleSubmit}/>;
}

API

function GimmeForm<T>

The GimmeForm<T> is React component that renders the form.

export function GimmeForm<T extends FieldValues>({ schema, onSubmit, defaultValues, resolver }: GimmeFormProps<T>) {
  const formMethods = useForm<T>({ defaultValues, resolver });
  const { handleSubmit, formState } = formMethods
  return (
    <FormProvider methods={formMethods} onSubmit={handleSubmit(onSubmit)}>
      <GimmeFormInputs schema={schema} />
      <LoadingButton type="submit" activeBtnText="Submit" loading={formState.isSubmitting} />
    </FormProvider>
  )
}

function GimmeFormInputs<T>

The GimmeFormInputs creates only inputs. Those are expected to be on the form connected with react-hook-forms as in GimmeForm function, but it's possible to initialize that separately.

type GimmeFormSchema<T>

The GimmeFormSchema<T> type is used to convert a TypeScript type to a configuration object type that defines the shape of the form fields.

Contributing

Contributions are welcome! If you'd like to contribute to this project, please follow these steps:

  1. Fork this repository
  2. Clone your forked repository to your local machine
  3. Create a new branch: git checkout -b my-new-feature
  4. Make your changes and commit them: git commit -m 'Add some feature'
  5. Push to the branch: git push origin my-new-feature
  6. Create a new pull request

Please ensure that your code follows the existing coding style and includes examples and documentation for any new functionality.