A component preview and development tool for ASP.NET Core Razor components
Inspired by Storybook, built for .NET developers
Features • Installation • Quick Start • Documentation • Contributing • License
RazorKit brings the component-driven development experience to ASP.NET Core Razor applications. Develop, test, and document your UI components in isolation within your running application using an interactive preview environment—without navigating through the full application flow.
- 🎨 Interactive Component Preview — View and interact with Razor components in isolation
- ⚡ Real-time Property Editor — Dynamically modify component props and see changes instantly
- 📚 Story Support — Define multiple states and variants for each component
- ♿ Accessibility Testing — Built-in axe-core integration for automated a11y validation
- 📱 Responsive Testing — Preview components at different viewport sizes
- 🔍 Component Discovery — Automatically discovers components in your project
- 🏗️ Atomic Design Support — Organize components using Atomic Design methodology
- .NET 9.0 or later
- ASP.NET Core
dotnet add package Manifesto.RazorKitOr add to your .csproj:
<PackageReference Include="Manifesto.RazorKit" Version="0.0.1" />Add RazorKit to your ASP.NET Core application in Program.cs:
using Manifesto.RazorKit.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add Razor Pages (required for RazorKit UI)
builder.Services.AddRazorPages();
// Add RazorKit services
builder.Services.AddRazorKit(options =>
{
options.ComponentLibraryName = "YourProject.Components";
});
var app = builder.Build();
// Map RazorKit routes
app.MapControllers();
app.MapRazorPages();
app.Run();Create a props class for your component:
public class ButtonProps
{
public string Text { get; set; } = "Click me";
public string Variant { get; set; } = "primary";
public bool Disabled { get; set; } = false;
}Keep each component a pure function of its props: render only from the props it's given, and don't look up content, call services or read the request from a component's view. RazorKit renders components with whatever values are entered in its Controls panel.
Define stories to showcase different component states:
using Manifesto.RazorKit.Models;
public class ButtonStories : ComponentStoriesBase<ButtonProps>
{
public override string ComponentName => "Button";
public override List<ComponentStory> GetStories()
{
return new List<ComponentStory>
{
CreateStory("primary", "Primary Button", "Default primary button", new ButtonProps
{
Text = "Primary",
Variant = "primary"
}),
CreateStory("secondary", "Secondary Button", "Secondary variant", new ButtonProps
{
Text = "Secondary",
Variant = "secondary"
}),
CreateStory("disabled", "Disabled State", "Disabled button", new ButtonProps
{
Text = "Disabled",
Disabled = true
})
};
}
}Story values are serialised into the explorer page and its Controls panel, so don't put live services, connections or secrets in stories.
Start your application and navigate to /razorkit to view your components. Live editing in the Controls panel needs the site to be served over HTTPS, or from localhost.
RazorKit supports Atomic Design principles:
Components/
├── Atoms/
│ └── Button/
│ ├── Button.cshtml
│ ├── ButtonProps.cs
│ └── ButtonStories.cs
├── Molecules/
├── Organisms/
└── Templates/
Configure the component library name to specify static asset paths in the preview HTML:
builder.Services.AddRazorKit(options =>
{
options.ComponentLibraryName = "YourProject.Components";
});This generates preview HTML with paths like:
/_content/YourProject.Components/css/main.css/_content/YourProject.Components/js/main.js
If your component library styles itself from a data-theme attribute, list the themes and RazorKit sets the attribute on the preview's <html> element:
builder.Services.AddRazorKit(options =>
{
options.Themes = new List<RazorKitTheme>
{
new() { Name = "Light", DataTheme = "light" },
new() { Name = "Dark", DataTheme = "dark" }
};
});- The first theme is the default. With one theme it is always applied; with two or more, a theme dropdown appears in the toolbar. With none, the preview sets no
data-theme. - The chosen theme travels as
?theme=<Name>on RazorKit's links, so a shared link opens in the same theme. A?theme=that exactly matches a configuredNamealways wins. - The browser remembers the last theme chosen. When the URL's
?theme=is missing, or does not exactly match a configuredName, the remembered theme is used. With no theme remembered, the first configured theme is the default. Namemust be unique (ignoring case).DataThememay only contain letters, digits, hyphens and underscores. An invalid entry stops the application at startup.
The list binds from configuration too, for example builder.Configuration.GetSection("RazorKit:Themes").Bind(options.Themes) with entries of Name and DataTheme.
Implement IComponentDiscovery to customize how components are discovered:
public class CustomComponentDiscovery : IComponentDiscovery
{
public List<ComponentInfo> DiscoverComponents()
{
// Your custom discovery logic
}
}
// Register in Program.cs
builder.Services.AddRazorKit(options =>
{
options.UseCustomDiscovery<CustomComponentDiscovery>();
});For Umbraco CMS projects, see Umbraco Setup Guide for detailed integration instructions.
Quick Umbraco Setup
Create a Composer to register RazorKit services:
using Manifesto.RazorKit.Extensions;
using Umbraco.Cms.Core.Composing;
namespace YourProject.Composers;
public class RazorKitComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
builder.Services.AddRazorKit(options =>
{
options.ComponentLibraryName = "YourProject.UmbracoComponents";
});
}
}We welcome contributions! Please see our Contributing Guide for details on:
- Setting up the development environment
- Submitting pull requests
- Coding standards and guidelines
- Publishing new versions
- 🐛 Bug Reports: Open an issue
- 💡 Feature Requests: Open an issue
- 💬 Questions: Start a discussion
- Visual regression testing integration
- Dark mode support
- Component documentation generation
- Plugin system for custom addons
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Inspired by Storybook
- Built with ❤️ by Manifesto Digital