import React from 'react';
import {
FormItem,
Renderer
} from '../../../src/index';
@FormItem({
type: 'custom'
})
class MyFormItem extends React.Component {
render() {
const {
value,
onChange
} = this.props;
return (
);
}
}
@Renderer({
test: /(^|\/)my\-renderer$/,
})
class CustomRenderer extends React.Component {
render() {
const {tip} = this.props;
return (
{tip || '非 FormItem 类型的渲染器注册, 这种不能修改 form'}
);
}
}
export default {
$schema: "https://houtai.baidu.com/v2/schemas/page.json#",
title: "自定义组件示例",
body: [
{
type: "form",
mode: "horizontal",
api: "/api/mock2/form/saveForm?waitSeconds=2",
actions: [
{
type: "submit",
label: "提交",
primary: true
}
],
controls: [
{
name: 'a',
children: ({value, onChange}) => (
)
},
{
type: 'divider'
},
{
name: 'b',
type: 'custom',
label: '自定义FormItem'
},
{
type: 'divider'
},
{
type: 'my-renderer'
}
]
},
{
type: 'my-renderer',
tip: '他能放 controls 里面,也能放外面。'
}
]
};