前端UI组件【免费下载链接】fastThe adaptive interface system for modern web experiences.项目地址https://gitcode.com/gh_mirrors/fa/fast点击查看免费下载DisclosureAppearance 是 FAST 组件库microsoft/fast-components中为fast-disclosure折叠面板组件定义的对外观类型别名它通过字面量联合类型将组件的视觉样式收敛为accent与lightweight两种可枚举取值。本文以 fast-components.disclosureappearance.md 为骨架结合仓库中的组件文档、Foundation 层源码 API 说明与设计系统文档系统讲解该类型在 FAST 自适应界面系统中的定位、两种取值的设计语义、在 JSX/模板与自定义设计中的落地方式以及背后的 accessibility无障碍与设计令牌联动机制。类型定义字面量联合类型该文档给出了完整的类型签名export declare type DisclosureAppearance accent | lightweight;这是 TypeScript 中的字符串字面量联合类型string literal union type类型名DisclosureAppearance由microsoft/fast-components包对外导出合法取值仅有两个accent强调/主色外观与lightweight轻量/链接式外观由于是字面量类型而非普通string任何传入组件实例的其他字符串如outline、filled、空字符串都会在编译期直接报错从而在类型层面就锁死了组件外观的合法性。在 fast-components.md 的 Type Aliases 汇总表中DisclosureAppearance与AnchorAppearance、ButtonAppearance、TextFieldAppearance等并列同属 FAST 对外暴露的组件外观类型族。值得注意的是AnchorAppearance的文档描述同样是 Types of anchor appearance这说明 disclosure 在视觉语义上被设计为锚点/链接式的交互控件——它的触发器在默认外观下看起来更像超链接而非实体按钮。与 fast-disclosure 组件的关系DisclosureAppearance是fast-disclosure组件的appearance属性attribute的类型来源。在 fast-disclosure 组件文档 中官方示例直接使用了lightweight取值fast-disclosure appearancelightweight strong slottitleRead about FAST/strong div FAST is a collection of technologies built on Web Components and modern Web Standards, designed to help you efficiently tackle some of the most common challenges in website and application design and development. /div /fast-disclosure组件本身是原生details/summary控件的 Web Component 实现title槽位承载可点击的摘要summary内容默认槽位承载被折叠的附加内容。关于组件的完整注册与 API可参见 fastDisclosure 注册函数 与 Disclosure 基础类。两种外观的设计语义取值设计语义典型使用场景accent使用设计系统中的强调色accent color作为触发器着色视觉更突出、更接近按钮页面中需要引起注意的折叠区块、引导用户主动点击展开的内容lightweight轻量级外观触发器弱化为类似超链接的文本样式融入正文而不喧宾夺主正文中的 FAQ 条目、了解更多式折叠说明、需要弱化存在感的辅助内容在 FAST 的设计令牌design tokens体系下accent会联动强调色令牌lightweight则更多依赖前景文本色。二者共同覆盖了强提示与弱提示两种视觉层级这也是 FAST 自适应界面系统设计哲学的典型体现。如何在模板与自定义组件中使用1. 使用 FAST Design System 注册组件最简单路径import { provideFASTDesignSystem, fastDisclosure } from microsoft/fast-components; provideFASTDesignSystem() .register( fastDisclosure() );注册后即可在 HTML/模板中通过appearance属性切换两种外观!-- 强调色外观 -- fast-disclosure appearanceaccent span slottitle展开详情/span p这里是折叠的附加内容。/p /fast-disclosure !-- 轻量链接式外观 -- fast-disclosure appearancelightweight span slottitle/span p这里是折叠的附加内容。/p /fast-disclosure2. 在 JSX / 模板引擎中传值由于appearance最终是组件的公开属性在支持 TSX 或模板绑定的场景下可以显式赋值以享受类型提示// 在编译期即可获得类型校验 fast-disclosure appearancelightweight strong slottitleRead about FAST/strong divContent here./div /fast-disclosure当appearance属性未显式指定时组件使用样式表内部的默认外观分支详见下文源码分析一般表现为不强调、贴近默认文本的外观。3. 基于 FAST Foundation 打造自有 disclosure 组件如果不想直接使用microsoft/fast-components的成品可以基于microsoft/fast-foundation的Disclosure基类自行组合设计系统外观import { Disclosure, disclosureTemplate as template, } from microsoft/fast-foundation; import { disclosureStyles as styles } from ./my-disclosure.styles; export const myDisclosure Disclosure.compose({ baseName: disclosure, template, styles, });此时appearance的语义由你自己的样式表决定——DisclosureAppearance类型的accent | lightweight联合约束了合法的取值域样式表styles则负责把这两个取值映射为真实的视觉呈现。Fast 组件的样式模板定义可参考 disclosureStyles。源码级实现appearance 如何影响渲染从 Disclosure 基础类 的 API 可以推断其内部实现脉络状态属性expanded: boolean决定是否展示额外内容对应 HTML 中 summary 的aria-expanded语义标题属性title: string作为触发器的可见标题与slottitle内容协同show()/hide()/toggle()公开方法展开、收起、切换折叠状态受保护的setup()在组件挂载时注册事件监听并设定默认折叠模式受保护的onToggle()在每次切换时更新 ARIA 属性并派发toggle事件。appearance属性本身并不参与折叠逻辑它是样式层的开关FAST 的组件样式模板中通过类似:host([appearanceaccent])这样的属性选择器对两种取值分别施加设计令牌。这一点在 high-contrast.md 的设计系统文档中体现得尤为明显——其高对比度样式专门为appearanceaccent分支补充了:hover、:active、:focus及disabled等状态下的强调色控制规则说明accent分支具备完整的交互状态设计而lightweight分支则共享默认的轻量文本外观。从类型设计角度DisclosureAppearance与 AnchorAppearance同样为accent | lightweight语义族保持一致进一步印证了 disclosure 触发器锚点化的视觉定位两种取值都不包含outline、filled等实体按钮形态设计意图是把折叠触发器控制在强调链接与普通链接两档之间。无障碍与交互细节accessibility 联动FAST 的 Disclosure 组件基于 W3C ARIA 实践指南APG中的 disclosure 模式实现其无障碍行为由 Foundation 层保证触发切换时onToggle()同步更新aria-expanded属性让屏幕阅读器获知折叠面板的当前展开/收起状态每次切换派发toggle事件便于外部监听展开/收起行为做统计或联动组件支持start、end两个辅助槽位位于摘要内容前后可在不影响语义的前提下补充图标等装饰内容。appearance的两种取值不会改变上述无障碍契约只会改变视觉层级——在需要强调的场景选accent在需要弱化、融入正文的场景选lightweight二者在键盘操作、ARIA 属性与事件派发上保持一致。快速验证清单类型层面appearance只接受accent | lightweight其余字符串在 TS 编译期报错注册层面使用provideFASTDesignSystem().register(fastDisclosure())注册组件见 fastDisclosure模板层面在fast-disclosure appearance...上直接声明外观title槽位放触发器默认槽位放折叠内容样式层面若自行基于Disclosure.compose()定制请确保样式表对两种外观取值分别提供视觉映射可参考 disclosureStyles 与设计系统的外观分支写法high-contrast.md行为层面验证展开/收起时aria-expanded正确翻转、toggle事件按预期触发对应 Disclosure 基类 的show()/hide()/toggle()契约。参考文档索引DisclosureAppearance 类型定义fast-disclosure 组件指南fastDisclosure 注册函数disclosureStyles 样式模板Disclosure 基础类 APIfast-components 类型别名汇总赞分享前端UI组件【免费下载链接】fastThe adaptive interface system for modern web experiences.项目地址https://gitcode.com/gh_mirrors/fa/fast点击查看免费下载相关推荐FAST 1.x fast-anchor 深度解析Anchor.appearanceChanged() 回调与 appearance 外观属性FAST 1.x fast anchor 深度解析Anchor.appearanceChanged 回调与 appearance 外观属性 本文围绕 FAST前端UI组件FAST fast-colors interpolateRGB() 深度解析RGB 色彩空间线性插值的用法、原理与实战FAST fast colors interpolateRGB 深度解析RGB 色彩空间线性插值的用法、原理与实战 interpolateRGB 是 FAST前端UI组件FAST 组件体系中的 ButtonAppearance 类型五种按钮外观值的定义、用法与样式原理FAST 组件体系中的 ButtonAppearance 类型五种按钮外观值的定义、用法与样式原理 本文围绕 microsoft/fast componen前端UI组件上一篇Atmosphere troposphere组件指南应用层功能与用户界面定制终极教程下一篇如何构建终极跨平台2D游戏引擎OpenBOR架构设计与多平台适配实战解析创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考