Skip to content

Commit

Permalink
Merge pull request #707 from alibaba/dev
Browse files Browse the repository at this point in the history
feat(fr):v1.9.7
  • Loading branch information
siyi98 authored Mar 23, 2022
2 parents 09009a7 + 14d9803 commit fe46d31
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/form-render/advanced/display.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const schema = displayType => ({
bind: 'obj',
description: '这是一个对象类型',
type: 'object',
collapsed: false,
properties: {
input1: {
title: '简单输入框',
Expand Down
27 changes: 27 additions & 0 deletions docs/form-render/schema/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,33 @@ readOnly=true 的情况,FormRender 默认使用 html 组件渲染。特殊情
}
```

### collapsed

只在嵌套的对象类型组件中使用,用于控制面板是否折叠

- 类型:boolean
- 默认值:false

```json
{
"type": "object",
"properties": {
"objectName": {
"type": "object",
"description": "这是一个对象类型",
"collapsed": false,
"properties": {
"input1": {
"title": "简单输入框",
"type": "string",
"required": true
}
}
}
}
}
```

### enum & enumNames

只在选择类组件中使用,用于描述枚举值的值和文案
Expand Down
8 changes: 8 additions & 0 deletions packages/form-render/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.9.7

- [+] 对嵌套的`对象类型`组件扩展`schema`,新增`collapsed`属性用于控制面板折叠。

## 1.9.6

- [+] 更新`schema`类型声明

## 1.9.5

- [+] 扩展`watch`的能力
Expand Down
2 changes: 1 addition & 1 deletion packages/form-render/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "form-render",
"version": "1.9.5",
"version": "1.9.7",
"description": "通过 JSON Schema 生成标准 Form,常用于自定义搭建配置界面生成",
"keywords": [
"Form",
Expand Down
15 changes: 13 additions & 2 deletions packages/form-render/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
import { RuleItem } from 'async-validator';
import * as React from 'react';

export type SchemaType =
| 'string'
| 'object'
| 'array'
| 'number'
| 'boolean'
| 'void'
| 'date'
| 'datetime'
| (string & {});

interface SchemaBase {
type: 'string' | 'number' | 'boolean' | 'array' | 'object' | 'range' | 'html';
type: SchemaType;
title: string;
description: string;
descType: 'text' | 'icon';
Expand Down Expand Up @@ -46,7 +57,7 @@ interface SchemaBase {
props: Record<string, any>;
}

type Schema = Partial<SchemaBase>;
export type Schema = Partial<SchemaBase>;

export interface Error {
/** 错误的数据路径 */
Expand Down
13 changes: 9 additions & 4 deletions packages/form-render/src/widgets/antd/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import React, { useEffect, useState } from 'react';
// import { useStore2 } from '../../hooks';
const { Panel } = Collapse;

export default function Map({ children, title, ...rest }) {
export default function Map({ children, title, schema, ...rest }) {
const { theme, displayType, allCollapsed } = {}; // TODO!
const [collapsed, setCollapsed] = useState(false);
const [collapsed, setCollapsed] = useState(schema.collapsed || false);
// useEffect(() => {
// setCollapsed(allCollapsed);
// }, [allCollapsed]);

useEffect(() => {
setCollapsed(allCollapsed);
}, [allCollapsed]);
if (schema.hasOwnProperty('collapsed')) {
setCollapsed(schema.collapsed);
}
}, [schema.collapsed]);

if (!title) {
return <div className="w-100">{children}</div>;
Expand Down

0 comments on commit fe46d31

Please sign in to comment.