‹ 首页

component-development

@fritzandfriends · 收录于 昨天 · 上游提交 1 个月前

Provides a step-by-step workflow for creating Blazor components that emulate ASP.NET Web Forms controls in the BlazorWebFormsComponents library. Covers base class selection (BaseWebFormsComponent, BaseStyledComponent, DataBoundComponent, BaseValidator), Web Forms property and event naming conventions, Playwright integration testing setup, and the complete checklist from component creation through documentation and navigation updates. Use when implementing a new BWFC component, choosing the correct base class for a control type, adding unit or integration tests, or extending an existing component with new Web Forms property support.

适合你,如果需要在 Blazor 中复刻 ASP.NET Web Forms 控件

/ 通过 npx 安装 校验哈希
npx oh-my-skill add fritzandfriends/blazorwebformscomponents/component-development
/ 通过 bash 安装
curl -fsSL https://oh-my-skill.com/install.sh | bash -s -- fritzandfriends/blazorwebformscomponents/component-development
/ 已经装过?验证本机副本,不用重装
npx oh-my-skill verify fritzandfriends/blazorwebformscomponents/component-development
安装目标可用 --agent / --scope 或 --to 明确指定;省略时只会在唯一已存在的 agent 目录上自动选择,零命中或多命中会停止并提示。content_hash 缺失或不一致均拒装。
449GitHub stars
~769最小装载
~2.4K含声明引用
~2.4K文本包总量
索引托管

怎么用

技能原文 SKILL.md作者撰写 · MIT · 3154758

Component Development Skill

This skill covers creating new Blazor components that emulate ASP.NET Web Forms controls.

Related Guides
  • [HTML Output Matching Guide](HTML_OUTPUT_MATCHING.md) - How to ensure Blazor components render identical HTML to Web Forms controls
Quick Reference
Creating a New Component
  1. Identify the Web Forms control from System.Web.UI.WebControls
  2. Research the HTML output using the [HTML Output Matching Guide](HTML_OUTPUT_MATCHING.md)
  3. Create component files:
  4. src/BlazorWebFormsComponents/{ComponentName}.razor
  5. src/BlazorWebFormsComponents/{ComponentName}.razor.cs
  6. Inherit from appropriate base class:
  7. BaseWebFormsComponent - Basic components
  8. BaseStyledComponent - Components with styling
  9. DataBoundComponent<T> - Data-bound components
  10. Add unit tests in src/BlazorWebFormsComponents.Test/{ComponentName}/
  11. Add sample page in samples/AfterBlazorServerSide/Components/Pages/ControlSamples/{ComponentName}/
  12. Add integration tests using Playwright in samples/AfterBlazorServerSide.Tests/
  13. Create documentation in docs/{Category}/{ComponentName}.md
  14. Update navigation:
  15. Add to samples/AfterBlazorServerSide/Components/Layout/NavMenu.razor (TreeView)
  16. Add to samples/AfterBlazorServerSide/Components/Pages/ComponentList.razor (home page catalog)
  17. Update mkdocs.yml and README.md
Base Class Selection

| Base Class | Use When | |------------|----------| | BaseWebFormsComponent | Simple components without styling (Literal, PlaceHolder) | | BaseStyledComponent | Components with visual styling (Label, Panel, Button) | | ButtonBaseComponent | Button-like components (Button, LinkButton, ImageButton) | | DataBoundComponent<T> | Components binding to collections (Repeater, GridView) | | BaseValidator | Validation controls |

Property Naming Convention

Match Web Forms property names exactly:

  • Text not Label or Content
  • CssClass not Class or ClassName
  • NavigateUrl not Href or Url
  • ImageUrl not Src or Source
Event Naming Convention

Prefix with On:

  • OnClick for click events
  • OnCommand for command events
  • OnSelectedIndexChanged for selection changes
  • OnDataBinding for data binding events
Integration Testing Requirements

Every component must have integration tests in samples/AfterBlazorServerSide.Tests/ using Playwright:

  1. Page load test in ControlSampleTests.cs:
  2. Add route to the appropriate [Theory] test (EditorControl, DataControl, etc.)
  3. Verifies page loads without console errors or page errors
  1. Interactive test in InteractiveComponentTests.cs (for interactive components):
  2. Test user interactions (clicks, input, selection changes)
  3. Verify component responds correctly to user actions
  4. Assert no console errors during interaction

Example page load test entry:

[Theory]
[InlineData("/ControlSamples/YourComponent")]
public async Task EditorControl_Loads_WithoutErrors(string path)

Example interactive test:

[Fact]
public async Task YourComponent_Interaction_Works()
{
    var page = await _fixture.NewPageAsync();
    try
    {
        await page.GotoAsync($"{_fixture.BaseUrl}/ControlSamples/YourComponent");
        // Test interactions...
        // Assert expected behavior...
    }
    finally
    {
        await page.CloseAsync();
    }
}

Run integration tests with:

dotnet test samples/AfterBlazorServerSide.Tests
按 MIT 许可原样转载,未经改动 · 在 GitHub 查看 →

评论

登录即可评论;带「已验证安装」的,是发布者名下有本店的安装或持有记录。