安装

只需三步,即可将 SurfaceOne 添加到 Angular 22 应用中。

1. 安装包

bash
npm install @surface-one/angular @surface-one/tokens

Markdown 入口点还需要其可选的对等依赖(marked、dompurify 以及 @codemirror/* 包)。只有在导入 @surface-one/angular/markdown 时才需要安装它们。

2. 加载样式

将令牌和组件样式表添加到构建目标的 styles 数组中,令牌放在最前面:

json
"styles": [
  "@surface-one/tokens",
  "@surface-one/angular/styles.css",
  "src/styles.css"
]

组件样式特意设为全局:大多数部件通过内容投影或传送门渲染,模拟封装无法作用到这些位置。

3. 启用本地化

组件使用 $localize 标记其内置字符串(例如“关闭”),因此请添加该 polyfill:

bash
ng add @angular/localize

使用组件

ts
import { Component } from "@angular/core";
import { SoneButtonDirective } from "@surface-one/angular/button";
import { SoneSwitchComponent } from "@surface-one/angular/switch";

@Component({
  selector: "app-root",
  imports: [SoneButtonDirective, SoneSwitchComponent],
  template: `
    <sone-switch [(checked)]="enabled" ariaLabel="Notifications" />
    <button soneBtn variant="outline" type="button">Save</button>
  `,
})
export class App {
  enabled = true;
}

接下来,在主题页面中选择皮肤和颜色模式。