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

create-hook-form

v0.1.4

Published

Reusable Facade components for creating [react-hook-form](https://github.com/react-hook-form/react-hook-form) Forms very fast, featuring:

Downloads

3

Readme

Create-Hook-Form

Reusable Facade components for creating react-hook-form Forms very fast, featuring:

  • Create React forms in just a few lines of code, easily

  • Seamless integration with your favorite component libraries

  • Maintainable Forms in React

  • Stop coding forms from scratch.

# install create-hook-form
npm i create-hook-form
# requires react-hook-form
npm i react-hook-form

optionally to use schema validation: (like zod, yup)

npm i @hookform/resolvers

Features

<SimpleForm />
<OperationForm />
  • MultiStepForm (WIP)

How To Use

//the main props is fields {id: string, label: string}[]
const fields = [
    { id: 'user', label: 'User' },
    { id: 'password', label: 'Password', type: 'password' },
];

function onSubmit(data) {
    console.log('logging in', data);
}

<SimpleForm fields={fields} onSubmit={onSubmit} />;

Simple Form

For more simple forms like: contact form, sign/log in

import { SimpleForm } from 'create-hook-form';

Operation Form

Crud operations like Create and Update

Example:

import { OperationForm } from 'create-hook-form';

const [operationState, setOperationState] = useState<'create' | 'update'>(
    'create'
);

<OperationForm
    fields={[
        {
            id: 'project-name',
            label: 'Project Name',

            helperText: 'select a great and memorable name',
            hideOnEditMode: true,
        },
        {
            id: 'project-desc',
            label: 'Project description',
        },
        {
            id: 'project-length',
            label: 'Project length',
            helperText: 'current left',
            components: {
                helper: ({ children }) => <Tag mt="4">{children}</Tag>,
            },
        },
    ]}
    onSubmit={[console.log, console.log]}
    onError={[console.log, console.log]}
    components={{
        wrapper: ({ children, errors, name }) => (
            <FormControl isInvalid={!!errors?.[name]}>{children}</FormControl>
        ),
        input: Input,
        helper: FormHelperText,
        error: FormErrorMessage,
        label: FormLabel,
    }}
    header={({ operation }) => (
        <Heading as={'h2'}>
            {operation === 'create' ? 'Create' : 'Edit'} Project
        </Heading>
    )}
    submit={() => (
        <Button type="submit" mt={4} float="right">
            Submit
        </Button>
    )}
    setValuesToUpdate={{ 'project-length': '999' }}
    footer={({ reset }) => (
        <Button colorScheme={'messenger'} mt={4} onClick={reset}>
            Reset
        </Button>
    )}
    operation={operationState}
    schema={[CreateProjectSchema, EditProjectSchema]}
/>;

Examples

all examples are in the same project link you can analyze src/examples to get inspired

Core Features

UI Libraries

Props API

options marked as ? are optional

    //SimpleForm
    fields: ControlledFormInputProps[];
    onSubmit: SubmitHandler<V>;
    onError: SubmitErrorHandler<V>;
    schema?: Resolver<V>;
    components?: FormComponents; //base components


    //OperationForm
    schema?: [Resolver<V>,Resolver<V>]; //tuple
    operation: Operation;
    onSubmit: [SubmitHandler<V>,SubmitHandler<V>]; //tuple
    onError: [SubmitErrorHandler<V>,SubmitErrorHandler<V>]; //tuple

    fields: ControlledFormInputProps[];
    setValuesToUpdate?: { [id: string]: any };
    components?: FormComponents; //base components

fields

type ControlledFormInputProps = {
    id: string;
    label?: string;
    defaultValue?: any;
    isOptional?: boolean;
    helperText?: string;
    components?: FormComponents;
};

components

type FormComponents = {
    input?: InputWithFields; // render the input (here you may put imported Input from libraries like Material, Chakra, etc....)
    label?: ComponentWithChildrenAndProps;
    helper?: ComponentWithChildrenAndProps; //display HelperText
    error?: ComponentWithChildrenAndProps; //display the error
    wrapper?: ComponentWithChildrenAndProps; // surrounds every Other
};