material-component-dev
FlowGram 物料组件开发指南 - 用于在 form-materials 包中创建新的物料组件
Best use case
material-component-dev is best used when you need a repeatable AI agent workflow instead of a one-off prompt. It is especially useful for teams working in multi. FlowGram 物料组件开发指南 - 用于在 form-materials 包中创建新的物料组件
FlowGram 物料组件开发指南 - 用于在 form-materials 包中创建新的物料组件
Users should expect a more consistent workflow output, faster repeated execution, and less time spent rewriting prompts from scratch.
Practical example
Example input
Use the "material-component-dev" skill to help with this workflow task. Context: FlowGram 物料组件开发指南 - 用于在 form-materials 包中创建新的物料组件
Example output
A structured workflow result with clearer steps, more consistent formatting, and an output that is easier to reuse in the next run.
When to use this skill
- Use this skill when you want a reusable workflow rather than writing the same prompt again and again.
When not to use this skill
- Do not use this when you only need a one-off answer and do not need a reusable workflow.
- Do not use it if you cannot install or maintain the related files, repository context, or supporting tools.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/material-component-dev/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How material-component-dev Compares
| Feature / Agent | material-component-dev | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
FlowGram 物料组件开发指南 - 用于在 form-materials 包中创建新的物料组件
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# FlowGram Material Component Development
## 概述
本 SKILL 用于指导在 FlowGram 项目的 `@flowgram.ai/form-materials` 包中创建新的物料组件。
## 核心原则
### 1. 组件位置
- ✅ **在现有包中创建**:直接在 `packages/materials/form-materials/src/components/` 下创建组件目录
- ❌ **不要单独拆包**:不创建新的 npm 包,保持简洁
### 2. 代码质量
- ✅ **使用 named export**:所有导出使用 named export 提高 tree shake 性能
- ❌ **不写单元测试**:通过 Storybook 进行手动测试
- ✅ **通过类型检查**:必须通过 `yarn ts-check`
- ✅ **符合代码规范**:遵循项目 ESLint 规则
### 3. 物料设计
- ✅ **保持精简**:只保留必要的 props,不添加非核心功能配置项
- ✅ **功能单一**:一个物料只做一件事
- ✅ **使用内部依赖**:优先使用 FlowGram 内部的组件和类型
### 4. 技术栈
- **UI 组件库**:`@douyinfe/semi-ui`
- **代码编辑器**:`JsonCodeEditor`, `CodeEditor` 等来自 `../code-editor`
- **类型定义**:`IJsonSchema` 来自 `@flowgram.ai/json-schema`(不使用外部的 `json-schema` 包)
- **React**:必须显式 `import React` 避免 UMD 全局引用错误
## 开发流程
### Step 1: 规划组件结构
确定组件的:
- **功能**:组件要解决什么问题
- **Props 接口**:只保留核心必需的 props
- **命名**:使用 PascalCase,清晰描述功能
### Step 2: 创建目录结构
```bash
mkdir -p packages/materials/form-materials/src/components/{组件名}/utils
```
典型结构:
```
packages/materials/form-materials/src/components/{组件名}/
├── index.tsx # 导出文件 (named export)
├── {组件名}.tsx # 主组件
├── {辅助组件}.tsx # 可选的辅助组件
└── utils/ # 可选的工具函数
└── *.ts
```
### Step 3: 实现组件
#### 3.1 工具函数(如需要)
```typescript
// utils/helper.ts
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export function helperFunction(input: string): Output {
// 实现逻辑
}
```
#### 3.2 辅助组件(如需要)
```typescript
// modal.tsx
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import React, { useState } from 'react';
import { Modal, Typography } from '@douyinfe/semi-ui';
interface ModalProps {
visible: boolean;
onClose: () => void;
onConfirm: (data: SomeType) => void;
}
export function MyModal({ visible, onClose, onConfirm }: ModalProps) {
// 实现
}
```
#### 3.3 主组件
```typescript
// my-component.tsx
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import React, { useState } from 'react';
import { Button } from '@douyinfe/semi-ui';
import type { IJsonSchema } from '@flowgram.ai/json-schema';
export interface MyComponentProps {
/** 核心功能的回调 */
onSomething?: (data: SomeType) => void;
}
// 使用 named export,不使用 default export
export function MyComponent({ onSomething }: MyComponentProps) {
const [visible, setVisible] = useState(false);
return (
<>
<Button onClick={() => setVisible(true)}>
操作文本
</Button>
{/* 其他组件 */}
</>
);
}
```
**关键点**:
- ✅ 显式 `import React`
- ✅ 使用 Semi UI 组件
- ✅ 使用 function 声明而非 React.FC
- ✅ Props 精简,只保留核心功能
- ✅ Named export
#### 3.4 导出文件
```typescript
// index.tsx
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
export { MyComponent } from './my-component';
export type { MyComponentProps } from './my-component';
```
### Step 4: 在 form-materials 主入口导出
编辑 `packages/materials/form-materials/src/components/index.ts`:
```typescript
export {
// ... 其他组件按字母序
MyComponent,
// ... 继续其他组件
type MyComponentProps,
// ... 继续其他类型
} from './components';
```
然后编辑 `packages/materials/form-materials/src/index.ts`,确保新组件在主导出列表中:
```typescript
export {
// ... 其他组件按字母序
MyComponent,
// ...
type MyComponentProps,
// ...
} from './components';
```
### Step 5: 创建 Storybook Story
在 `apps/demo-materials/src/stories/components/` 创建 Story:
```typescript
// my-component.stories.tsx
/**
* Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
* SPDX-License-Identifier: MIT
*/
import React, { useState } from 'react';
import type { Meta, StoryObj } from 'storybook-react-rsbuild';
import { MyComponent } from '@flowgram.ai/form-materials';
import type { SomeType } from '@flowgram.ai/json-schema';
const MyComponentDemo: React.FC = () => {
const [result, setResult] = useState<SomeType | null>(null);
return (
<div style={{ padding: '20px' }}>
<h2>My Component Demo</h2>
<MyComponent
onSomething={(data) => {
console.log('Generated data:', data);
setResult(data);
}}
/>
{result && (
<div style={{ marginTop: '20px' }}>
<h3>结果:</h3>
<pre style={{
background: '#f5f5f5',
padding: '16px',
borderRadius: '4px',
overflow: 'auto'
}}>
{JSON.stringify(result, null, 2)}
</pre>
</div>
)}
</div>
);
};
const meta: Meta<typeof MyComponentDemo> = {
title: 'Form Components/MyComponent',
component: MyComponentDemo,
parameters: {
layout: 'centered',
docs: {
description: {
component: '组件功能描述',
},
},
},
tags: ['autodocs'],
};
export default meta;
type Story = StoryObj<typeof meta>;
export const Default: Story = {};
```
### Step 6: 运行类型检查
```bash
cd packages/materials/form-materials
yarn ts-check
```
确保通过所有类型检查。
### Step 7: 启动开发环境测试
开启两个 Terminal:
**Terminal 1 - 监听包编译:**
```bash
rush build:watch
```
**Terminal 2 - 启动 Storybook:**
```bash
cd apps/demo-materials
yarn dev
```
访问 http://localhost:6006/,找到你的组件进行测试。
## 常见问题
### Q1: React 引用错误
**错误信息**:
```
error TS2686: 'React' refers to a UMD global, but the current file is a module.
```
**解决方案**:
在文件顶部添加:
```typescript
import React from 'react';
```
### Q2: 组件未导出
**错误信息**:
```
Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
```
**解决方案**:
检查以下文件的导出:
1. `components/{组件名}/index.tsx`
2. `components/index.ts`
3. `src/index.ts`
### Q3: 类型找不到
**错误信息**:
```
Cannot find module '@flowgram.ai/json-schema' or its corresponding type declarations.
```
**解决方案**:
- 使用 `type IJsonSchema` 而非 `type JSONSchema7`
- 从 `@flowgram.ai/json-schema` 导入而非 `json-schema`
### Q4: CodeEditor 没有 height 属性
**错误信息**:
```
Property 'height' does not exist on type 'CodeEditorPropsType'.
```
**解决方案**:
使用外层 div 设置高度:
```tsx
<div style={{ minHeight: 300 }}>
<JsonCodeEditor value={value} onChange={onChange} />
</div>
```
## 验收标准
- [ ] 组件在 `packages/materials/form-materials/src/components/` 下创建
- [ ] 使用 named export
- [ ] 通过 `yarn ts-check` 类型检查
- [ ] Props 精简,只保留核心功能
- [ ] 在 Storybook 中可以正常显示和使用
- [ ] 功能正常,无明显 bug
- [ ] 代码符合 FlowGram 代码规范
## 最佳实践
### 1. 组件设计
- **单一职责**:一个组件只做一件事
- **Props 精简**:避免过度配置
- **命名清晰**:组件名和 Props 名要清晰易懂
### 2. 代码风格
- **使用 TypeScript**:充分利用类型系统
- **显式导入**:明确导入所需的依赖
- **注释适度**:关键逻辑添加注释
### 3. UI 一致性
- **使用 Semi UI**:保持 UI 风格一致
- **响应式设计**:考虑不同屏幕尺寸
- **错误处理**:友好的错误提示
### 4. 性能优化
- **Named export**:支持 tree shaking
- **按需加载**:避免不必要的依赖
- **合理使用 memo**:必要时使用 React.memo
## 示例参考
完整示例请参考:
- `packages/materials/form-materials/src/components/json-schema-creator/`
- `apps/demo-materials/src/stories/components/json-schema-creator.stories.tsx`Related Skills
web-component-design
Master React, Vue, and Svelte component patterns including CSS-in-JS, composition strategies, and reusable component architecture. Use when building UI component libraries, designing component APIs, or implementing frontend design systems.
next-cache-components
Next.js 16 Cache Components - PPR, use cache directive, cacheLife, cacheTag, updateTag
ui-component-patterns
Build reusable, maintainable UI components following modern design patterns. Use when creating component libraries, implementing design systems, or building scalable frontend architectures. Handles React patterns, composition, prop design, TypeScript, and component best practices.
hig-components-system
Apple HIG guidance for system experience components: widgets, live activities, notifications, complications, home screen quick actions, top shelf, watch faces, app clips, and app shortcuts. Use when asked about: "widget design", "live activity", "notification design", "complication", "home screen quick action", "top shelf", "watch face", "app clip", "app shortcut", "system experience". Also use when the user says "how do I design a widget," "what should my notification look like," "how do Live Activities work," "should I make an App Clip," or asks about surfaces outside the main app. Cross-references: hig-components-status for progress in widgets, hig-inputs for interaction patterns, hig-technologies for Siri and system integration.
hig-components-status
Apple HIG guidance for status and progress UI components including progress indicators, status bars, and activity rings. Use this skill when asked about: "progress indicator", "progress bar", "loading spinner", "status bar", "activity ring", "progress display", determinate vs indeterminate progress, loading states, or fitness tracking rings. Also use when the user says "how do I show loading state," "should I use a spinner or progress bar," "what goes in the status bar," or asks about activity indicators. Cross-references: hig-components-system for widgets and complications, hig-inputs for gesture-driven progress controls, hig-technologies for HealthKit and activity ring data integration.
hig-components-search
Apple HIG guidance for navigation-related components including search fields, page controls, and path controls. Use this skill when the user says "how should search work in my app," "I need a breadcrumb," "how do I paginate content," or asks about search field, search bar, page control, path control, breadcrumb, navigation component, search UX, search suggestions, search scopes, paginated content navigation, or file path hierarchy display. Cross-references: hig-components-menus, hig-components-controls, hig-components-dialogs, hig-patterns.
hig-components-menus
Apple HIG guidance for menu and button components including menus, context menus, dock menus, edit menus, the menu bar, toolbars, action buttons, pop-up buttons, pull-down buttons, disclosure controls, and standard buttons. Use this skill when the user says "how should my buttons look," "what goes in the menu bar," "should I use a context menu or action sheet," "how do I design a toolbar," or asks about button design, menu design, context menu, toolbar, menu bar, action button, pop-up button, pull-down button, disclosure control, dock menu, edit menu, or any menu/button component layout and behavior. Cross-references: hig-components-search, hig-components-controls, hig-components-dialogs.
hig-components-layout
Apple Human Interface Guidelines for layout and navigation components. Use this skill when the user asks about sidebar, split view, tab bar, tab view, scroll view, window design, panel, list view, table view, column view, outline view, navigation structure, app layout, boxes, ornaments, or organizing content hierarchically in Apple apps. Also use when the user says how should I organize my app, what navigation pattern should I use, my layout breaks on iPad, how do I build a sidebar, should I use tabs or a sidebar, or my app doesn't adapt to different screen sizes. Cross-references: hig-foundations for layout/spacing principles, hig-platforms for platform-specific navigation, hig-patterns for multitasking and full-screen, hig-components-content for content display.
hig-components-dialogs
Apple HIG guidance for presentation components including alerts, action sheets, popovers, sheets, and digit entry views. Use this skill when the user says 'should I use an alert or a sheet,' 'how do I show a confirmation dialog,' 'when should I use a popover,' 'my modals are annoying users,' or asks about alert design, action sheet, popover, sheet, modal, dialog, digit entry, confirmation dialog, warning dialog, modal presentation, non-modal content, destructive action confirmation, or overlay UI patterns. Cross-references: hig-components-menus, hig-components-controls, hig-components-search, hig-patterns.
hig-components-controls
Apple HIG guidance for selection and input controls including pickers, toggles, sliders, steppers, segmented controls, combo boxes, text fields, text views, labels, token fields, virtual keyboards, rating indicators, and gauges.
hig-components-content
Apple Human Interface Guidelines for content display components. Use this skill when the user asks about charts component, collection view, image view, web view, color well, image well, activity view, lockup, data visualization, content display, displaying images, rendering web content, color pickers, or presenting collections of items in Apple apps. Also use when the user says how should I display charts, what's the best way to show images, should I use a web view, how do I build a grid of items, what component shows media, or how do I present a share sheet. Cross-references: hig-foundations for color/typography/accessibility, hig-patterns for data visualization patterns, hig-components-layout for structural containers, hig-platforms for platform-specific component behavior.
frontend-mobile-development-component-scaffold
You are a React component architecture expert specializing in scaffolding production-ready, accessible, and performant components. Generate complete component implementations with TypeScript, tests, s