material.mdx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. import { SourceCode } from '@theme';
  2. import { BasicStory, WithSchemaStory } from 'components/form-materials/components/{物料名称}';
  3. # ComponentName
  4. ComponentName 是一个用于...的组件,它支持...功能。[用 1-2 段文字描述物料的核心功能、使用场景和主要特性]
  5. <br />
  6. <div>
  7. <img loading="lazy" src="/materials/{物料名称}.png" alt="ComponentName 组件" style={{ width: '50%' }} />
  8. </div>
  9. ## 案例演示
  10. ### 基本使用
  11. <BasicStory />
  12. ```tsx pure title="form-meta.tsx"
  13. import { ComponentName } from '@flowgram.ai/form-materials';
  14. const formMeta = {
  15. render: () => (
  16. <>
  17. <FormHeader />
  18. <Field<ValueType> name="field_name">
  19. {({ field }) => (
  20. <ComponentName
  21. value={field.value}
  22. onChange={(value) => field.onChange(value)}
  23. />
  24. )}
  25. </Field>
  26. </>
  27. ),
  28. }
  29. ```
  30. ### 高级用法示例(根据物料特性添加)
  31. <WithSchemaStory />
  32. ```tsx pure title="form-meta.tsx"
  33. import { ComponentName } from '@flowgram.ai/form-materials';
  34. const formMeta = {
  35. render: () => (
  36. <>
  37. <FormHeader />
  38. <Field<ValueType> name="field_name">
  39. {({ field }) => (
  40. <ComponentName
  41. value={field.value}
  42. onChange={(value) => field.onChange(value)}
  43. schema={{ type: 'string' }}
  44. // 其他高级配置...
  45. />
  46. )}
  47. </Field>
  48. </>
  49. ),
  50. }
  51. ```
  52. ## API 参考
  53. ### ComponentName Props
  54. | 属性名 | 类型 | 默认值 | 描述 |
  55. |--------|------|--------|------|
  56. | `value` | `ValueType` | - | 组件的值 |
  57. | `onChange` | `(value: ValueType) => void` | - | 值变化时的回调函数 |
  58. | `readonly` | `boolean` | `false` | 是否为只读模式 |
  59. | `hasError` | `boolean` | `false` | 是否显示错误状态 |
  60. | `style` | `React.CSSProperties` | - | 自定义样式 |
  61. ### RelatedConfigType(如果有相关的配置类型)
  62. | 属性名 | 类型 | 默认值 | 描述 |
  63. |--------|------|--------|------|
  64. | `property1` | `string` | - | 属性说明 |
  65. | `property2` | `boolean` | `false` | 属性说明 |
  66. ### RelatedProviderProps(如果有 Provider 组件)
  67. | 属性名 | 类型 | 默认值 | 描述 |
  68. |--------|------|--------|------|
  69. | `children` | `React.ReactNode` | - | 子组件 |
  70. | `config` | `ConfigType` | - | 配置对象 |
  71. ## 源码导读
  72. <SourceCode
  73. href="https://github.com/bytedance/flowgram.ai/tree/main/packages/materials/form-materials/src/components/{物料路径}"
  74. />
  75. 使用 CLI 命令可以复制源代码到本地:
  76. ```bash
  77. npx @flowgram.ai/cli@latest materials components/{物料路径}
  78. ```
  79. ### 目录结构讲解
  80. ```
  81. {物料名称}/
  82. ├── index.tsx # 主组件实现,包含 ComponentName 核心逻辑
  83. ├── hooks.ts # 自定义 Hooks,处理... [如果有]
  84. ├── context.tsx # Context Provider,提供... [如果有]
  85. ├── utils.ts # 工具函数,用于... [如果有]
  86. └── styles.css # 样式文件
  87. ```
  88. ### 核心实现说明
  89. #### 功能点1
  90. [用简洁的文字描述实现原理]
  91. ```typescript
  92. // 展示关键代码片段
  93. const result = useHookName(props);
  94. ```
  95. #### 功能点2
  96. [描述另一个关键功能的实现方式]
  97. ```typescript
  98. // 展示关键逻辑
  99. if (condition) {
  100. return <ComponentA />;
  101. } else {
  102. return <ComponentB />;
  103. }
  104. ```
  105. ### 整体流程
  106. ```mermaid
  107. graph TD
  108. A[组件初始化] --> B{判断条件}
  109. B -->|条件1| C[执行分支A]
  110. B -->|条件2| D[执行分支B]
  111. C --> E[处理用户交互]
  112. D --> F[处理数据变化]
  113. E --> G[触发 onChange 回调]
  114. F --> G
  115. ```
  116. ### 使用到的 FlowGram API
  117. [**@flowgram.ai/package-name**](https://github.com/bytedance/flowgram.ai/tree/main/packages/path)
  118. - [`ApiName`](https://flowgram.ai/auto-docs/package/type/ApiName): API 的功能说明
  119. - [`HookName`](https://flowgram.ai/auto-docs/package/functions/HookName): Hook 的功能说明
  120. [**@flowgram.ai/another-package**](https://github.com/bytedance/flowgram.ai/tree/main/packages/another-path)
  121. - [`TypeName`](https://flowgram.ai/auto-docs/package/interfaces/TypeName): 类型定义说明
  122. ### 依赖的其他物料
  123. [**DependentMaterial**](./dependent-material) 物料的简要说明
  124. - `ExportedComponent`: 导出组件的用途
  125. - `ExportedHook`: 导出 Hook 的用途
  126. [**AnotherMaterial**](./another-material) 物料的简要说明
  127. ### 使用的第三方库
  128. [**library-name**](https://library-url.com) 库的说明
  129. - `ImportedComponent`: 组件的用途
  130. - `importedFunction`: 函数的用途