蚂蚁设计渲染器 jsonforms
json形式 是“高效构建基于形式网络用户界面的申报框架” jsonforms 拥有多个用于不同框架和组件库的渲染软件包,这是其中的一个软件包.
您可以通过故事本预览渲染器 这里。 。 。 .
开始
npm install @great-expectations/jsonforms-antd-renderers
使用 AntD 渲染器
为了使用此软件包, 您需要从此软件包中导入渲染器注册项并提供给 @jsonforms/react JsonForms 组件 :
import { JsonForms } from "@jsonforms/react"
import {
rendererRegistryEntries,
cellRegistryEntries,
} from "@great-expectations/jsonforms-antd-renderers"
function MyForm({ data }: { data: Record<string, unknown> }) {
return (
<JsonForms
data={data}
schema={schema}
renderers={rendererRegistryEntries}
cells={cellRegistryEntries}
/>
)
}
写入 UISchemas
此软件包扩展了类型和配置 jsonforms UISchemas 化学式写UISchema的时候,你会想 提供你的Jsonschema的类型给我们 UISchema 类型,以利用高级类型检查 & UI 配置。 参见我们的故事书(运行故事书的指示) Contributing),用于更多实例.
import { useState } from "react"
import { Form, Button } from "antd"
import { JsonForms } from "@jsonforms/react"
import {
rendererRegistryEntries,
UISchema,
} from "@great-expectations/jsonforms-antd-renderers"
const schema = {
type: "object",
properties: { password: { type: "string" } },
} as const
// Be sure to use an `as const` assertion so that UISchema
// can see the specific types of `type` fields within a schema.
// i.e. without `as const`, the value "object" is interpreted
// as a string type, and not the string literal type "object"
const uischema: UISchema<typeof schema> = {
type: "VerticalLayout",
elements: [
{
type: "Control",
scope: "#/properties/password",
// Properties like type: "password" here are unique to this renderer package.
// This allows you more declarative control over how your forms render.
// In this case, the password field will be rendered with AntD's password input component.
options: { type: "password" },
},
],
}
function MyForm() {
const [data, setData] = useState<Record<string, unknown>>({})
return (
<Form onFinish={() => myApiCall(data)}>
<JsonForms
data={data}
onChange={(result) => setData(result.data as Record<string, unknown>)}
schema={schema}
uischema={uischema}
renderers={rendererRegistryEntries}
/>
<Form.Item>
<Button htmlType="submit">Submit</Button>
</Form.Item>
</Form>
)
}
捐款
第一次设置
- 安装节点.js( 目前只支持节点 v20)
- 安装版本 小时 定义
packageManager输入package.json - 克隆此寄存器
- 安装依赖性 :
pnpm i --frozen-lockfile - 运行测试 :
pnpm test - 运行测试和视图覆盖 :
pnpm test:covnpx vite preview --outDir html- 在终端,类型
o+ 键enter在浏览器中打开结果
- 运行故事本 :
pnpm storybook
作出改变
- 更改代码
- 运行测试 :
pnpm test - 运行故事本 :
pnpm storybook - 运行格式 :
pnpm format:write - 运行林特 :
pnpm lint - 提交更改
常规承诺
- 我们用 语义释放 来发布我们的软件包,所以确保您的承诺遵守 常规承诺格式
- 特别是承诺信息的形式
fix(<scope>): <short summary>, (中文(简体) ),feat(<scope>): <short summary>,或BREAKING CHANGE: <short summary>将引发释放.short summary需要时间.scope是可选的.
本地测试软件包
- 从此目录创建可安装的 tarball 文件 :
pnpm pack - 如果您先前安装了软件包, 您可能需要先删除:
npm uninstall @great-expectations/jsonforms-antd-renderers并可能清除您的软件包管理器缓存 - 在您的工程中安装软件包 :
npm install /path/to/jsonforms-antd-renderers-0.0.0-semantic-release.tgz