Blazor FAST Web Components

Interfaces built with FAST adapt to your design system

Interfaces built with FAST adapt to your design system and can be used with any modern UI Framework by leveraging industry standard Web Components.

Let’s put this to the test using Blazor.

In this article you’ll find answers to the following questions:

  1. What is fast in a nutshell

What is fast?

FAST tries to solve the -redundant- problem I have in every new project… creating web components. However FAST does it in a framework agnostic way. The components should behave the same whether you’re creating an Angular, React, Vue or any other framework. In this case I’m wondering how FAST can be integrated with Blazor Projects. There are already quite some components implemented as you can see using the component explorer:

Using these components is quite trivial for example the fast-button with a framework-agnostic setup.

<fast-button>Button</fast-button>

Configuration

You can easily configure the primary colors, border-radius, density, etc.… The dark or light mode is built-in and very easy to use, it’s really just a switch away.

On the website of Fast you can configure your theme as you’d like. For example I believe border-radius is overrated so I turned it to 0 but hey, that’s subjective….

Themes

Currently there are 2 themes, the FAST default theme and the Microsoft’s Fluent Design theme, the latter is quite know in the community for their React implementation and looks really nice, however it’s quite unfortunate that the styling is tightly coupled to React and JavaScript so it’s not so easy to wrap in a Blazor Component library.

Integration with Blazor

It’s quite easy to integrate the basic components like fast-button, fast-anchor and some others. But it gets tricky when you try to use the form components like InputDate, InputNumber , etc-and let’s be honest- an application or website without a descent EditForm is really basic… We’ve been spoiled by the Blazor team with our Input* components for example:<InputText/>,<InputNumber/>,<InputDate/> and some others which automagically binds datatypes and their values, so I guess we have to wrap these components to be able to use them?

Transition to BlazorFAST instead of Blazor + Fast.

First, I was quite hesitant to wrap the FAST web components because it’s against the design principles of the library (being framework agnostic). But what if we could do it in a way that:

  1. Keeps the same API, without introducing a bunch of custom parameters and redundant work.

It turns out… that it can be done, that’s why we created Blazor.Fast a very tiny wrapper around Fast. You can see some examples below, the API is almost the same and very familiar for Blazor developers and FAST or Fluent library users. The only difference is that there is no prefix of fast- or fluent- since we abstracted away the theme.

FAST Button

<fast-button>Button</fast-button>

Blazor.Fast Button

<Button></Button>

FAST Menu

<fast-menu>
<fast-menu-item>Menu item 1</fast-menu-item>
<fast-menu-item>Menu item 2</fast-menu-item>
<fast-menu-item>Menu item 3</fast-menu-item>
<fast-divider></fast-divider>
<fast-menu-item>Menu item 4</fast-menu-item>
</fast-menu>

Blazor.Fast Menu

<Menu>
<MenuItem>Menu item 1</MenuItem>
<MenuItem>Menu item 2</MenuItem>
<MenuItem>Menu item 3</MenuItem>
<Divider></Divider>
<MenuItem>Menu item 4</MenuItem>
<MenuItem>Menu item 5</MenuItem>
</Menu>

Fast TextField

<fast-text-field appearance="filled"></fast-text-field>

Blazor.Fast TextField inside a Form

The EditModel

public class MyFormModel
{
public string Text { get; set; }
}

The Form

<EditForm Model="model" OnValidSubmit="HandleValidSubmit">
<TextField @bind-Value="model.Text"> </TextField>
</EditForm>

Or a more realistic example with validation of multiple datatypes:

How is this possible?

Actually it’s pretty simple due to the flexibility of both the Blazor framework and the FAST library, it took about 2 days to wrap almost all the components from the FAST library and create some examples and documentation around it. Basically we created a ThemeProvider which serves as a CascandingParameter to all the components and use it as the highest-level component which takes care of the “Theme agnostic side of things”.

For the EditFormcomponents or <Input*/> components we inherit from the <InputBase<T>> and override the BuilderRenderTree(RenderTreeBuilder b) to have some more control, but the heavy lifting is still done in the core framework and the FAST or Fluent API didn’t change.

Getting Started

  1. Create a new Blazor application
dotnet new blazorwasm -o WebApplication

2. Install the Nuget package

Install-Package Append.Blazor.Fast

3. Add the Javascript file to the _host.cshtml(server-side) or index.html(client-side) page below the Blazor framework script.

// Provided by default
<script src="_framework/blazor.webassembly.js"></script>
// FAST
<script type="module" src="https://unpkg.com/@microsoft/fast-components"></script>
// Fluent (optional)
<script type="module" src="https://unpkg.com/@fluentui/web-components"></script>

4. Add the required namespaces in the _imports.razor file

@using Append.Blazor.Fast.Components
@using Append.Blazor.Fast.Core

5. Adjust the App.razorfile to the following, to provide a highest level ThemeProvider.

6. Use a component on the index.razor page

<Button appearance="accent">Click Me</Button>

To see all the components in action you can visit the documentation site

We ❤ open source so the source code can be found on Github

Turning coffee into code.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store