Skip to content

Commit

Permalink
fix(antd/next): fix arrayCollapse will throw error in accordion mode
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Jun 12, 2021
1 parent 3ef2bab commit 4c88ca7
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 2 deletions.
8 changes: 8 additions & 0 deletions designable/antd/src/locales/zh-CN.ts
Expand Up @@ -292,6 +292,13 @@ const FormTabLocale = {
],
}

const FormCollapseLocale = {
accordion: '手风琴模式',
collapsible: { title: '可折叠区域', dataSource: ['头部', '禁用'] },
ghost: '幽灵模式',
header: '头部内容',
}

const ComponentLocale = {
...FormLayoutLocale,
...InputLocale,
Expand All @@ -311,6 +318,7 @@ const ComponentLocale = {
...FormGridLocale,
...SpaceLocale,
...FormTabLocale,
...FormCollapseLocale,
}

const FieldLocale = {
Expand Down
61 changes: 61 additions & 0 deletions designable/antd/src/schemas/FormCollapse.ts
@@ -0,0 +1,61 @@
import { ISchema } from '@formily/react'

export const FormCollapse: ISchema = {
type: 'object',
properties: {
accordion: {
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Switch',
},
collapsible: {
type: 'string',
enum: ['header', 'disabled'],
'x-decorator': 'FormItem',
'x-component': 'Radio.Group',
'x-component-props': {
defaultValue: 'header',
optionType: 'button',
},
},
ghost: {
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Switch',
},
bordered: {
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Switch',
'x-component-props': {
defaultChecked: true,
},
},
},
}

export const FormCollapse_o_CollapsePanel: ISchema = {
type: 'object',
properties: {
collapsible: {
type: 'string',
enum: ['header', 'disabled'],
'x-decorator': 'FormItem',
'x-component': 'Radio.Group',
'x-component-props': {
defaultValue: 'header',
optionType: 'button',
},
},
header: {
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Input',
},
extra: {
type: 'boolean',
'x-decorator': 'FormItem',
'x-component': 'Input',
},
},
}
1 change: 1 addition & 0 deletions designable/antd/src/schemas/index.ts
Expand Up @@ -21,3 +21,4 @@ export * from './Switch'
export * from './FormGrid'
export * from './Space'
export * from './FormTab'
export * from './FormCollapse'
1 change: 1 addition & 0 deletions packages/antd/docs/components/ArrayCollapse.md
Expand Up @@ -39,6 +39,7 @@ export default () => {
x-decorator="FormItem"
x-component="ArrayCollapse"
x-component-props={{
accordion: true,
defaultOpenPanelCount: 3,
}}
>
Expand Down
3 changes: 2 additions & 1 deletion packages/antd/src/array-collapse/index.tsx
Expand Up @@ -14,6 +14,7 @@ import {
observer,
ISchema,
} from '@formily/react'
import { toArr } from '@formily/shared'
import cls from 'classnames'
import ArrayBase, { ArrayBaseMixins } from '../array-base'
import { usePrefixCls } from '../__builtins__'
Expand Down Expand Up @@ -114,7 +115,7 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
<Collapse
{...props}
activeKey={activeKeys}
onChange={(keys: string[]) => setActiveKeys(keys.map(Number))}
onChange={(keys: string[]) => setActiveKeys(toArr(keys).map(Number))}
className={cls(`${prefixCls}-item`, props.className)}
>
{dataSource.map((item, index) => {
Expand Down
1 change: 1 addition & 0 deletions packages/next/docs/components/ArrayCollapse.md
Expand Up @@ -39,6 +39,7 @@ export default () => {
x-decorator="FormItem"
x-component="ArrayCollapse"
x-component-props={{
accordion: true,
defaultOpenPanelCount: 3,
}}
>
Expand Down
3 changes: 2 additions & 1 deletion packages/next/src/array-collapse/index.tsx
Expand Up @@ -7,6 +7,7 @@ import {
observer,
ISchema,
} from '@formily/react'
import { toArr } from '@formily/shared'
import cls from 'classnames'
import ArrayBase, { ArrayBaseMixins } from '../array-base'
import { usePrefixCls, Empty } from '../__builtins__'
Expand Down Expand Up @@ -109,7 +110,7 @@ export const ArrayCollapse: ComposedArrayCollapse = observer(
<Collapse
{...props}
expandedKeys={expandKeys.map(String)}
onExpand={(keys: string[]) => setExpandKeys(keys.map(Number))}
onExpand={(keys: string[]) => setExpandKeys(toArr(keys).map(Number))}
className={cls(`${prefixCls}-item`, props.className)}
>
{dataSource.map((item, index) => {
Expand Down

0 comments on commit 4c88ca7

Please sign in to comment.