Skip to content

Commit 3fbcd9e

Browse files
committed
* form: add custom component support in form schema and implement rendering logic
1 parent 901d65c commit 3fbcd9e

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/form-builder/dev.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'zui-dev';
22
import type {ComponentType} from 'preact';
33
import yaml from 'js-yaml';
4-
import {$} from '@zui/core';
4+
import {$, jsx} from '@zui/core';
55
import '@zui/button';
66
import '@zui/icons';
77
import '@zui/btn-group';
@@ -37,6 +37,9 @@ onPageUpdate(() => {
3737
defaultData,
3838
widgets: {
3939
progressCircle: ({value}) => [ProgressCircle as unknown as ComponentType, {percent: value || 0}],
40+
customComponent: [(props: Record<string, unknown>) => {
41+
return jsx`<div class="form-static-text">${props.value}</div>`;
42+
}],
4043
},
4144
onSubmit: (event, data) => {
4245
console.log('onSubmit', event, data);

lib/form-builder/dev/form-schema-standard.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,12 @@ export const schema = {
251251
},
252252
extra: {html: '此处为了展示进度环的值的改变会触发表单项 <code>specials.progressCircle</code> 值的改变,使<strong>进度环</strong>显示新的值。'},
253253
},
254+
customComponent: {
255+
title: '自定义组件',
256+
type: 'string',
257+
defaultValue: '这是自定义组件的默认值',
258+
widget: 'customComponent'
259+
}
254260
},
255261
},
256262
},

0 commit comments

Comments
 (0)