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

@hbtv/pro-form

v1.4.24

Published

ant-design 4.x 自定义Form套件

Downloads

16

Readme

@hbtv/pro-form 组件

ant-design 4.x 自定义Form套件

  • 支持数据分组
  • 支持图形化生成表单
  • 支持根据数据生成表单

安装方法

npm install @hbtv/pro-form --save

更新记录

查看更新记录

使用方法

ProForm 共有 5 个组件

  • ProForm, 根据配置的json, 生成表单
  • ProFormEditor 编辑器,图形化生成表单对应的json数据
  • ProFormRender 渲染器, 根据表单配置json和表单数据data,渲染表单数据
  • TemplateRender 渲染器, 根据表单配置json,表单数据data及模板来渲染页面
  • ProFormCodeView 查看表单配置json代码

ProForm

ProForm使用方法

import React from 'react';
import { ProForm } from '@hbtv/pro-form';
import { Button } from 'antd';

const ProFromTest = () => {
  const [form] = ProForm.useForm();
  const fields = [
      { dataIndex: 'userName', title: '用户名', componentType: 'text' },
      { dataIndex: 'user.trueName', title: '真实姓名', componentType: 'text' },
      { dataIndex: 'user.nickname', title: '昵称', componentType: 'text' },
      { dataIndex: 'startTime', title: '时间', componentType: 'time', displayRule: 'date(HH:mm)' },
  ];
  const handleFinish = (values:any) => {
    console.log('values',values)
  };

  return (
    <>
      <ProForm form={form} fields={fields} onFinish={handleFinish} />
      <Button onClick={()=>form.submit()}>提交表单</Button>
    </>
  );
}
export interface ProFormProps {
  uploadServices?: ServicesType; // MediaUploadProps 的 services
  form: FormInstance; // 通过 ProForm.useForm() 创建, 等同 antd Form.useForm()
  labelCol?: any; // 等同 antd labelCol
  wrapperCol?: any; // 等同 antd wrapperCol
  menuWidth?: number; // 如果是分组表单,分类菜单的宽度
  fields: ProFormFieldType[];  // 详见下方的 字段声明
  activeGroup?: string; // 当前分组的dataIndex
  initialValue?:any; // 1.1.23 新增 表单初始值
  onGroupChange?: (
    newGroupName: string,
    oldGroupName: string,
    oldValues?: any,
    isValidate?: boolean | any,
  ) => void; // 1.1.22 修改了参数
  onFinish?: (values: any, groupName?: string) => void; // form.submit() 后校验成功后触发
  valueEnum?: {  // 可供select作为枚举值使用的枚举
    [k: string]: ProFormEnumType[];
  };
}

字段配置文件的声明

import { ListColumnType, ValueEnumType, TreeDataType } from '@hbtv/list-input';

export interface ProFormFieldType extends ListColumnType {
  dependOn?: DependOnType[];
}

ProFormEditor

辅助工具,可以生成ProFormFieldType对应的字段,详见src/ProFormTest.tsx

ProFormEditor使用方法

import React,{ useState } from 'react';
import { ProFormFieldType } from '@hbtv/pro-form';
import { ProFormEditor } from '@hbtv/pro-form/dist/ProFormEditor';

const ProFormEditorTest = () => {
  const [fields , setFields] = useState<ProFormFieldType[]>([]);

  return <ProFormEditor value={fields} onChange={setFields} />
}
export interface ProFormEditorProps {
  value?: ProFormFieldType[];
  onChange?: (values: ProFormFieldType[]) => void;
  createGroupBtn?: boolean;
  previewBtn?: boolean;
  actions?: React.ReactNode[];
}

ProFormRender

import React,{ useState } from 'react';
import { ProFormFieldType } from '@hbtv/pro-form';
import { ProFormRender } from '@hbtv/pro-form/dist/ProFormRender';

const ProFormRenderTest = () => {
  const fields = [
      { dataIndex: 'userName', title: '用户名', componentType: 'text' },
      { dataIndex: 'detail.trueName', title: '真实姓名', componentType: 'text' },
      { dataIndex: 'detail.nickname', title: '昵称', componentType: 'text' },
      { dataIndex: 'startTime', title: '时间', componentType: 'time', displayRule: 'date(HH:mm)' },
  ];

  const data = {
    userName:'your name',
    detail:{
      trueName:'your trueName',
      nickname:'your nickname',
    },
    startTime:'2020-06-20 09:10:30',  // ProForm中所有的时间都保存为完整时间字符串,仅通过显示规则来显示不同
  }

  return <ProFormRender fields={fields} data={data} />
}
export interface ProFormRenderProps {
  fields: ProFormFieldType[];
  data?: any;
  valueEnum?: {
    [k: string]: ValueEnumType[] | TreeDataType[];
  };
}

TemplateRender

import React,{ useState } from 'react';
import { ProFormFieldType } from '@hbtv/pro-form';
import { TemplateRender } from '@hbtv/pro-form/dist/TemplateRender';

const TemplateRenderTest = () => {
  const fields = [
      { dataIndex: 'userName', title: '用户名', componentType: 'text' },
      { dataIndex: 'detail.trueName', title: '真实姓名', componentType: 'text' },
      { dataIndex: 'detail.nickname', title: '昵称', componentType: 'text' },
      { dataIndex: 'startTime', title: '时间', componentType: 'time', displayRule: 'date(HH:mm)' },
  ];

  const data = {
    userName:'your name',
    detail:{
      trueName:'your trueName',
      nickname:'your nickname',
    },
    startTime:'2020-06-20 09:10:30',  // ProForm中所有的时间都保存为完整时间字符串,仅通过显示规则来显示不同
  }

  const template = `<p>{{userName}}</p>
  <p>{{user.trueName}}</p>
  <p>{{user.nickname}}</p>
  <p>{{allowLogin}}</p>
  `;

  return <TemplateRender fields={fields} data={data} template={template} />
}
export interface TemplateRenderProps {
  fields: ProFormFieldType[];
  data: { [k: string]: any };
  template: string;
  valueEnum?: {
    [k: string]: ValueEnumType[] | TreeDataType[];
  };
}

显示规则配置displayRule

  • date 显示时间及日期,例如 date(YYYY-MM) date(HH:mm), 通moment.format使用的字符串
  • image 显示图片,image(宽,高), 缺省为auto,例如 image(128,128)图片尺寸为 128*128, image(,64)指定宽度auto,高度为64
  • video 显示视频,参数同image
  • audio 显示音频,无参数
  • bool 显示布尔值
  • url 显示为链接,url(显示的文本), 默认为当前值