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

kp-form

v2.0.4

Published

render forms with json

Downloads

6

Readme

kp-form

介绍

kp-form 是基于 rc-field-form (by Antd)的表单组件。在性能优先的前提下,可以与多个 ui 框架(Tea/Taro/Antd...)快速集成。并拥有根据 JSON Schema 来生成表单的能力 🥳

为什么使用?

-> 除了 Antd 以外,Tea / Taro 等 ui 组件表单能力十分有限,通常需要搭配三方表单库来使用;

-> 出于易用性、流行度、一致性等方面考虑。团队需要一致的表单能力。React Antd 属于行业使用率与认可度最高的一款;

-> 其他 UI 库很难与 Antd Form 集成,本组件可以做到无需安装 Antd,在全局定义一次 renderProps,即可在原有 UI 库 api 的基础上,使用 Antd Form 的 api 与 FormInstance 能力。

-> 需要通过 json 数据驱动表单渲染?还在自己写 case map 么?来试试 kp-form 吧

JSON Schema 结构

[
  {                                      // 表单项的 props,通常会透传给对应 UI Form.Item
    type: string                         // 字段类型
    name: string                         // 字段 id
    label?: string                       // 字段标签
    fieldProps?: Record<string, any>     // 字段组件属性,会透传给 <Select> <Input> 等组件的 props
    innerProps?: Record<string, any>     // 字段与渲染无关的其他属性
    value?: any                          // 默认值,与 initialValue 作用相同。区分在于 value 会经过值转换,initialValue 会原封不动传递
    // ... 其他属性参照对应 UI Form.Item props
  }
]

整体为数组结构 ItemProps[],便于排序。对象内主要有两个关键层级点:

ItemProps 表单项的 props,除了 JSON 表单扩展的一些属性外,其他与 Form.Item props 一致。属性会透传

fieldProps` 字段的 props,会直接透传给字段,type 不同 props 不同,如 `type='select'` 时,通常会有 `fieldProps: { options: [] }

快速开始

安装

npm i kp-form

目前使用 babel cjs 与 esm 两种格式构建打包,组件已默认值支持 webpack 的 tree-shaking

使用

<KpForm
  onFinish={(values) => {
    console.log('submit: ', values);
  }}
>
  <KpForm.Item name="title" label="title">
    <Input />
  </KpForm.Item>

  <KpForm.Item name="content" label="content">
    <Input />
  </KpForm.Item>
</KpForm>

源码开发

安装

npm i --registry https://mirrors.tencent.com/npm/

运行

npm start

构建文档网站

npm run docs:build

本地打包

npm run build