For a while I've wanted a React-style framework and workflow for .NET, and today's the day I've finally got something I'm happy with!
I've been working on two components over the past couple of weeks, both tackling different parts of the problem. They've finally come together, so I thought I'd share what I've been up to.
Donkeh UI is the framework side of things. It has a React-style virtual DOM, with familiar patterns like State(), Effect() and so on. There's also a CLI tool to make some of the repetitive stuff quicker, along with a collection of static helpers for creating HTML elements.
There's a CSS engine too. I've tried to cover as much of the CSS specification as I could, although it's a pretty massive spec, so apologies in advance for anything I've missed xox.
Layout is handled internally as well. I've tried to get things like flexbox behaving as close to the browser as possible, although there's only so much I can do. I'm employed after all ;)
Other bits include a built-in UI testing framework for unit tests, an inspector (think Chrome DevTools, but a little more average) and online documentation.
CSS is responsive, and there's support for borderless windows, fullscreen applications, rounded application corners and even the app-region: drag CSS property, which lets you create your own custom window frames.
I've also spent quite a bit of time trying to keep the CSS engine lightweight. Even with fairly complex applications, memory usage generally sits around 30-40 MB, with relatively low CPU and GPU usage.
Under the hood, the CSS engine uses dynamic code generation for both the CSS tokeniser and media query processing. There's also a fair amount of caching and optimisation going on throughout rule resolution, layout and rendering. The aim was to keep things efficient without having to compromise on what the framework can actually do.
It currently compiles for Windows, Linux, macOS, WebAssembly and Android. I don't have access to Apple hardware to test everything, so iOS isn't something I'm planning to support just yet.
CSX
CSX is the other half of this.
It brings JSX-style syntax directly into C#, so you can write your UI components without having to deal with endless nested method calls and object initialisers.
It works by tokenising C# while recognising JSX-style syntax, then transforming it into valid C#. Pretty much the same idea as the JavaScript/JSX transformation pipeline.
There's a bundled language server too, along with VS Code and Rider plugins. Both have a one-command install and provide CSX syntax support, autocomplete, diagnostics and the usual editor features.
And no, I haven't gone and written an entire .NET compiler. I've just piggybacked off Roslyn. Thanks, dotnet team xox.
Anyway...
The whole point was to get something closer to the React development experience into .NET, while keeping the benefits of building applications with C#.
Having both packages working together in an actual application has been really nice to see. There's still plenty I'd like to improve, but I'm pretty happy with where things have ended up.
If anyone fancies giving either of them a go, having a poke around or finding things I've inevitably broken, I'd really appreciate the feedback!
Donkeh UI: https://barely-sentient.github.io/donkeh-ui/index.html
Empty C# JSX Project: https://github.com/barely-sentient/donkeh-csharp-jsx