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

@mui-ext/hookform

v0.0.9

Published

react-hook-form @ Material UI (mui)

Downloads

4

Readme

@mui-ext/hookform

gitee-repo version dt

react-hook-form@mui

该版本仅作为早期预览版本,并用于某项目中使用,所以测试代码未完善。

组件索引

  • HookForm - 将 react-hook-form 表单声明包装成组件,支持泛型(但 hookform 的泛型其实意义不大)。
    • 生成的表单不使用 form 结构(为了和 RN 的使用保持一致的可替换性结构)。
    • setupHookForm - 全局表单配置
    • SubmitRow - 表单的提交按钮行(可选添加 reset、cancel 等,还可添加其他内容)。
    • FormField - react-hook-form Control 的实现,
    • FormFieldError - react-hook-form 的表单字段验证错误提示(目前仅支持 hook form rules 的验证)
    • Label - 针对表单的 Label 预留 I18n 扩展
    • useHookForm - 引用表单上下文,主要用于自行扩展表单组件使用
    • FormGenerator - 配置化表单生成器,上述的一切都没有绑定固定的标签结构,仅包含组件自身的基础内容,FormGenerator 负责将所有组件整合。
  • InputRegistry - 全局输入控件管理(该实例默认不对外直接访问,请通过下面的方面)
    • isRegInput, regInput, getRegInput

最基础的用法

import { HookForm, SubmitRow } from '@mui-ext/hookform';

<HookForm>
  {({ register }) => {
    return (
      <>
        <div>
          <input type="text" {...register('username')} />
        </div>
        <div>
          <input type="password" {...register('password')} />
        </div>
        <SubmitRow/>
      </>
    )
  }}
</HookForm>

结合 FormField 组件

import { HookForm, SubmitRow, FormField } from '@mui-ext/hookform';

<HookForm>
  <FormField name={'username'} label={'username'} input={'text'} rules={{ required: true }}/>
  <FormField name={'password'} label={'password'} input={'password'} rules={{ required: true }}/>
  <SubmitRow/>
</HookForm>

useHookForm

export type HookFormContext<T extends FieldValues = FieldValues> = {
  autoId: string,
  config: HookFormConfig,
  customErrors: HookFormCustomErrors<T>,
  setCustomError: (field: keyof T | string, err: HookFormCustomError | null) => void,
  setCustomErrors: (errs: HookFormCustomErrors<T>) => void,
  loading: boolean,
  setLoading: Dispatch<SetStateAction<boolean>>,
  gap: number | string,
  generalErrorKey: string,
  formSubmit: () => (e: BaseSyntheticEvent) => Promise<void>,
  validateReturn: typeof validateReturn
} & UseFormReturn<T>;

FormGenerator

仅使用 fields

import { FormGenerator } from '@mui-ext/hookform';

// 已包含 SubmitRow
<FormGenerator
  fields={[
    { name: 'username', label: 'username', input: 'text' },
    { name: 'password', label: 'password', input: 'password' },
  ]}
/>

结合 layout

import { FormGenerator } from '@mui-ext/hookform';

<FormGenerator
  fields={[
    { name: 'username', label: 'username', input: 'text' },
    { name: 'password', label: 'password', input: 'password' },
  ]}
  layout={[
    ['username', 'password'],
  ]}
/>