custom-component.tsx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
  3. * SPDX-License-Identifier: MIT
  4. */
  5. import { Field } from '@flowgram.ai/free-layout-editor';
  6. import { Input, Select } from '@douyinfe/semi-ui';
  7. import { useNodeRenderContext } from '../../../hooks';
  8. import { FormItem } from '../../../form-components';
  9. /**
  10. * 自定义表单组件
  11. */
  12. export function CustomComponent() {
  13. const { readonly } = useNodeRenderContext();
  14. return (
  15. <div>
  16. <FormItem name="配置项名称" required vertical type="string">
  17. <Field<string> name="customConfig.key" defaultValue="">
  18. {({ field }) => (
  19. <Input
  20. value={field.value}
  21. onChange={(value) => field.onChange(value)}
  22. disabled={readonly}
  23. placeholder="请输入..."
  24. />
  25. )}
  26. </Field>
  27. </FormItem>
  28. {/* TODO: 添加更多表单字段 */}
  29. <FormItem name="选择器示例" vertical type="string">
  30. <Field<string> name="customConfig.option" defaultValue="option1">
  31. {({ field }) => (
  32. <Select
  33. value={field.value}
  34. onChange={(value) => field.onChange(value as string)}
  35. disabled={readonly}
  36. style={{ width: '100%' }}
  37. optionList={[
  38. { label: '选项 1', value: 'option1' },
  39. { label: '选项 2', value: 'option2' },
  40. { label: '选项 3', value: 'option3' },
  41. ]}
  42. />
  43. )}
  44. </Field>
  45. </FormItem>
  46. </div>
  47. );
  48. }