FluentUI React 组件开发
fluentui
VS Code webview 中 FluentUI React v9 组件的模式指南。在使用任意 FluentUI 组件(Toolbar、Overflow、Menu、Button、Dialog、MessageBar 等)、选择 MessageBar 图标或布局、调试 FluentUI 的布局或样式问题、实现工具栏溢出(将项目折叠到「...」菜单),或在 webview 面板中集成 FluentUI 组件时使用。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 33
- Forks
- 22
01 前言 Front Matter
- name
- fluentui
- description
- Patterns for FluentUI React v9 components in VS Code webviews. Use when working with any FluentUI component (Toolbar, Overflow, Menu, Button, Dialog, MessageBar, etc.), choosing MessageBar icons or layout, debugging layout or styling issues with FluentUI, implementing toolbar overflow (collapsing items into a "..." menu), or integrating FluentUI components in webview panels.
02 资源文件 1
- 参考文档references/OVERFLOW_PATTERNS.md9.2 KB
03 SKILL.md 正文
FluentUI React v9 Patterns
Proven patterns and project-specific knowledge for using FluentUI React v9 components in VS Code webviews.
Official Documentation
FluentUI provides LLM-compatible documentation. Use these URLs with fetch_webpage to look up any component:
- Index (all components):
https://storybooks.fluentui.dev/react/llms.txt - Individual component:
https://storybooks.fluentui.dev/react/llms/components-{name}.txt- Examples:
components-overflow.txt,components-toolbar.txt,components-menu-menu.txt,components-button-button.txt
- Examples:
When working with a FluentUI component you're unfamiliar with, fetch its documentation first.
Topic References
This skill covers multiple FluentUI topics. Load the relevant reference when needed:
- Overflow & Toolbar: See references/OVERFLOW_PATTERNS.md — Layout constraints, CSS Grid vs Flexbox, divider handling, priority ordering, debugging checklist
When to Use
- Working with any FluentUI React v9 component in a webview
- Adding or modifying a toolbar with overflow behavior
- Debugging FluentUI layout, styling, or measurement issues
- Items not hiding/showing when the toolbar shrinks/expands
- The "..." overflow menu button renders off-screen or doesn't appear
- Placing an
<Overflow>toolbar alongside other elements in a layout - Integrating FluentUI components that use Griffel (CSS-in-JS) with SCSS stylesheets
MessageBar Multiline Layout
MessageBar has two independent multiline concerns. When a request says “make the MessageBar multiline,” ask which one is intended when the context does not make it clear:
- Responsive actions and icon geometry: Set
layout="multiline". This uses Fluent UI's multiline grid, top-aligns the icon, and movesMessageBarActionsbelow the body when needed. - Title above message:
MessageBarTitleis inline by default, even withlayout="multiline". Add a named body class withdisplay: flex,flexDirection: 'column', and an appropriategapto put the message on the next line.
For the default DocumentDB webview notice with a title and message, use both: layout="multiline" for the Fluent UI geometry and a named title-and-message body class for the vertical title/message layout. Use a separate generic stacked-body class only when the body contains controls, commands, or multiple content blocks rather than a simple title and message.
MessageBar Icons
Fluent's default glyphs (a diamond for errors, a filled triangle for warnings) are not the house style. The product uses:
| Intent | Icon |
|---|---|
error |
ErrorCircleFilled |
warning |
WarningRegular |
success |
Fluent default |
info |
Fluent default |
MessageBlock (src/webviews/components/MessageBlock.tsx) applies these by default, so prefer it for in-flow notices and pass icon only to override. A raw <MessageBar intent="error"> or intent="warning" must set icon explicitly to match.
Critical Rule: Layout Constraints
The <Overflow> component measures its child's clientWidth to decide which items to hide. If the child can grow unconstrained, overflow never triggers.
The child of <Overflow> (usually <Toolbar>) MUST have:
flex-wrap: nowrap;
min-width: 0;
overflow: hidden;
Side-by-Side Layout (Pinned + Overflow)
Use CSS Grid, not Flexbox, when placing an overflow toolbar next to pinned elements:
.toolbarContainer {
display: grid;
grid-template-columns: auto minmax(0, 1fr);
align-items: center;
gap: 10px;
}
- Column 1 (
auto): pinned toolbar — takes its natural width - Column 2 (
minmax(0, 1fr)): overflow toolbar — constrained to remaining space
Why not Flexbox? Flexbox with margin-right: auto on the first child or flex-grow: 1 on the second child fails in practice. The <Overflow> component's clientWidth measurement doesn't shrink correctly in a flex context, even with min-width: 0. CSS Grid's minmax(0, 1fr) provides a hard width constraint that the overflow manager can observe via ResizeObserver.
Right-Alignment
To push overflow items to the right edge of their column:
.toolbarContainer .fui-Overflow {
justify-content: flex-end;
}
Quick Reference: Overflow Priority
Higher priority = overflows later (stays visible longer):
<OverflowItem id="shell" priority={1}> {/* hides first */}
<OverflowItem id="playground" priority={2}>
<OverflowItem id="copy" priority={3}>
<OverflowItem id="import" priority={6}> {/* hides last */}
Quick Reference: Menu Item Visibility
Each menu item must be a separate React component to call useIsOverflowItemVisible (hook rules):
const OverflowMenuItem = ({ id, children }: { id: string; children: JSX.Element | null }) => {
const isVisible = useIsOverflowItemVisible(id);
return isVisible ? null : children;
};
Common Pitfalls
-
Inline
displaystyles on OverflowItem children — The overflow manager setsdisplay: nonevia the[data-overflowing]attribute. If you setdisplay: inline-flexvia an inlinestyle={}prop, React will fight the overflow manager on re-render. Use a CSS class instead, with an explicit&[data-overflowing] { display: none; }override. -
<Overflow>renders no wrapper element — It clones its single child, merging a ref and thefui-Overflowclass. There is no intermediate DOM node. -
<Toolbar>addsdisplay: flex; align-items: centervia Griffel — You don't need to add these yourself. You only need to addflex-wrap: nowrap; min-width: 0; overflow: hiddenfor the overflow behavior.
04 同仓库更多 Skills
扩展发布说明与变更日志编写
writing-release-notes
为 Visual Studio Code 的 DocumentDB 扩展生成发布说明和变更日志条目,并在 GitHub Discussions 上发布版本公告。当需要准备版本发布、编写补丁更新说明、撰写变更日志条目、记录新功能和修复,或向 Discussions 发布正式版或补丁版发布公告时使用。可处理主版本/次版本(新建文件)和补丁更新(追加到现有文件)两种情况。
Webview tRPC 消息通信实现
webview-trpc-messaging
实现 VS Code 扩展宿主与 React webview 之间基于 tRPC 的通信。当需要创建新的 webview 过程(查询、变更、订阅)、添加新的 webview 路由(router)、接入 webview 控制器(controller)、在 React 组件中使用 tRPC 客户端、应用遥测中间件(telemetryMiddlewareBody),或在 webview 操作中支持基于 AbortSignal 的取消时使用。
UX PR 评审准备与执行
ux-pr-review
准备并运行一次由智能体辅助的 UX / 工作流拉取请求(PR)评审。当操作者说“我准备做一个 UX PR 评审,请准备”、“为一个 PR 准备 UX 评审”时使用。
集群树形架构实现
tree-cluster-architecture
vscode-documentdb 中集群节点和树数据提供者的实现模式。当需要添加或更改集群树项、发现提供者(discovery provider)、Connections/Azure/Discovery 树层级结构、树/列表模式、集群标识、treeId/clusterId 查找、Collection View 导入/导出解析、reveal 行为、凭据、shell 操作或复制连接字符串支持时使用。
遥测埋点植入
telemetry-instrumentation
vscode-documentdb 扩展中遥测(telemetry)的埋点模式。适用于为功能添加遥测、用属性或度量值丰富现有遥测、用关联 ID(correlation ID)关联相关事件、为命令或树视图埋点、抑制噪声事件,或决定采集哪些数据点。当被要求为任何功能 “add telemetry” 或 “improve telemetry” 时也使用。
GitHub Copilot 技能创建
skill-creator
在本仓库中创建高效 GitHub Copilot 技能(.github/skills/)的指南。适用于创建新技能、更新现有技能,或被问及 vscode-documentdb 项目的技能结构、格式或最佳实践时。