π Getting Started
System Requirementsβ
.NET SDK ver.8 or later
Example scenarioβ
For the example scenario, you already have a Blazor WebAssembly application project, "MyBlazorWasmApp1", that includes the "Button" component.
Blazing Story supports Blazor Server application projects as well as Blazor WebAssembly application projects.
π (working directory)
+ π MyBlazorWasmApp1.sln
+ π MyBlazorWasmApp1
+ π MyBlazorWasmApp1.csproj
+ ...
+ π Components
+ π Button.razor
+ ...
Preparationβ
Close all Visual Studio IDE instances (if you use Visual Studio IDE), and install the "Blazing Story" project template with the following command. (This installation instruction is enough to execute once in your development environment.)
dotnet new install BlazingStory.ProjectTemplates
Creating a Blazing Story app and storiesβ
Step 1 - Create a new Blazing Story app projectβ
Open the solution file (.sln) with Visual Studio, and add a new "Blazing Story (WebAssembly App)" project from the project templates. (In this example scenario, we named it "MyBlazorWasmApp1.Stories")
If you are working on a Blazor Server application project, you should add a new "Blazing Story (Server App)" project instead of the "Blazing Story (WebAssembly App)" project.
To use the MCP server feature, you need to add a new "Blazing Story (Server App)" project and check the "Enable the MCP server feature" checkbox in the project creation dialog.
Note that the MCP server feature is not available in the Blazing Story app when running on Blazor WebAssembly.
If you are working on dotnet CLI, you can do that with the following commands in a terminal.
Please remind again that this example scenario assumes that there is already a solution file (.sln) in the current directory with an existing Blazor WebAssembly app project.
# Create a new Blazing Story app
dotnet new blazingstorywasm -n MyBlazorWasmApp1.Stories
# Add the Blazing Story app project to the solution
dotnet sln add ./MyBlazorWasmApp1.Stories/
If you are working on a Blazor Server application project, you should run the dotnet new blazingstoryserver
command.
To use the MCP server feature, you need to run the dotnet new blazingstoryserver -mcp
command.
Note that the MCP server feature is not available in the Blazing Story app when running on Blazor WebAssembly.
The file layout will be the following tree.
π (working directory)
+ π MyBlazorWasmApp1.sln
+ π MyBlazorWasmApp1
+ ...
+ π MyBlazorWasmApp1.Stories
+ π MyBlazorWasmApp1.Stories.csprojβ¨ π Add this
Step 2 - Add a project reference of the Blazor Wasm app to the Blazing Story projectβ
Next, add a project reference in the Blazing Story App project "MyBlazorWasmApp1.Stories" that refers to the Blazor WebAssembly app project "MyBlazorWasmApp1".
If you are working on dotnet CLI, you can do that with the following commands in a terminal.
dotnet add ./MyBlazorWasmApp1.Stories reference ./MyBlazorWasmApp1
π (working directory)
+ π MyBlazorWasmApp1.sln
+ π MyBlazorWasmApp1 <--- refers --+
+ ... |
+ π MyBlazorWasmApp1.Stories ------+
+ ...
Step 3 - Add a "stories" fileβ
Add a new "stories" file to the Blazing Story App project "MyBlazorWasmApp1.Stories".
A "stories" file is a normal Razor Component file (.razor), but it is annotated with the [Stories]
attribute and includes a markup of the <Stories>
component. There is no restriction on file layout of "stories" files, but usually, we place it in the "Stories" subfolder.
Currently, The file name of the "stories" files must end with ".stories.razor". This is a requirement of the naming convention for available the "Show code" feature in the "Docs" pages.
In this example scenario, we are going to write a "stories" for the Button
component lived in the "MyBlazorWasmApp1" project, so we would add a new story file named "Button.stories.razor" in the "Stories" subfolder where is under the "MyBlazorWasmApp1.Stories" project.
π (working directory)
+ π MyBlazorWasmApp1.sln
+ π MyBlazorWasmApp1
+ ...
+ π MyBlazorWasmApp1.Stories
+ π MyBlazorWasmApp1.Stories.csproj
+ π Stories
+ π Button.stories.razorβ¨ π Add this
Step 4 - Implement the "stories"β
Implement a stories.
The "Button.stories.razor" would be like the below.
@using MyBlazorWasmApp1.Components
@attribute [Stories("Components/Button")]
<Stories TComponent="Button">
<Story Name="Primary">
<Template>
<Button Label="Button" Primary="true" @attributes="context.Args" />
</Template>
</Story>
</Stories>
Step 5 - Run it!β
If you are working on Visual Studio, right-click the "MyBlazorWasmApp1.Stories" project in the solution explorer to show the context menu, click the "Set as Startup Project" menu item, and hit the Ctrl
+ F5
key.
If you are working on dotnet CLI, you can do that with the following commands in a terminal.
dotnet run --project ./MyBlazorWasmApp1.Stories
Then you will see the clone of the "Storybook" built on Blazor! π