FAST is a toolkit for building reusable web components with native browser standards. Its core library, @microsoft/fast-element, defines custom elements without requiring a full application framework. It also supports the broader work of making components fit a design system, including theming and accessibility patterns. section 7.0 section 7.1
A greeting component
After defining a <hello-world> component, use <hello-world></hello-world> for its default greeting or <hello-world name="Mark"></hello-world> to supply a name. Its class extends FASTElement; @customElement registers its name, template, and styles, while @attr exposes the name attribute. The html template binds the greeting to the component’s name property through ${x => x.name}. section 7.2
Listing 7.1 hello-world.ts
import {
attr,
css,
customElement,
FASTElement,
html,
} from "@microsoft/fast-element";
const template = html<HelloWorld>`<p>Hello, ${x => x.name}!</p>`;
@customElement({
name: "hello-world",
template,
styles: css`
:host {
color: blue;
}
`,
})
export class HelloWorld extends FASTElement {
@attr name: string = "World";
}
The complete greeting component shows the FASTElement class, decorators, typed html template, binding, and scoped styles together. section 7.2
FAST templates use template literals rather than JSX. A binding function receives the component instance, letting the template read its properties; a TypeScript type argument can check those references. This makes a simple substitution more verbose than in some other libraries, but keeps its dependency explicit. Templates can also repeat items, render conditionally, and attach event handlers. section 7.2 section 7.1 section 7.12
For a more interactive component, choose the feature that matches the job:
- Use observable properties and template bindings to update a sortable table; split complex rendering into helper templates. FAST needs much of this reactive logic in the template, which can become harder to read. section 7.12
- Use event bindings such as @change or @click for interactions. A radio group uses repeat to render options and updates its selected value when an input changes. section 7.9
- Use a state object when separate components need the same value. Changes update consumers automatically, avoiding the need to pass the value through their component hierarchy. section 7.11
To start a TypeScript project, install @microsoft/fast-element. Vite is recommended for its development server and hot updates, and TypeScript must be configured for the decorators used in these examples. FAST can reduce boilerplate compared with equivalent vanilla web components; weigh that benefit against the extra binding code and the readability of larger templates. section 7.2 section 7.13 section 7.12
