Skip to content

0use-TE/Blazor.GoldenLayout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

39 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

  • 🌟 Welcome to Blazor.GoldenLayout

    Hello, I'm Ouse, and welcome to this library!

    This is a Blazor wrapper for GoldenLayout.js, enabling you to easily implement draggable, IDE-like split-panel layouts in your Blazor projects.
    Special thanks to the GoldenLayout development team for their amazing work! πŸ‘

    image


    ✨ Quick Start

    1️⃣ Install the NuGet Package

Install-Package Blazor.GoldenLayout

2️⃣ Add Theme Styles

Simply add your preferred theme stylesheet, and the JS file will be dynamically loaded at runtime.
For Blazor WASM projects, add the following to wwwroot/index.html:

<link type="text/css" rel="stylesheet" href="_content/Blazor.GoldenLayout/goldenlayout-dark-theme.css" />

For Blazor Server projects (.NET 8 Blazor Web App), add the same link to the <head> section in App.razor:

<head>
    <link type="text/css" rel="stylesheet" href="_content/Blazor.GoldenLayout/goldenlayout-dark-theme.css" />
</head>

3️⃣ Register Component Services

In Program.cs, register your component types and their names (used in GoldenLayout configuration):

βœ… Blazor WebAssembly:

builder.Services.RegisterGoldenLayoutService(new Dictionary<Type, string>
{
    { typeof(Counter), "Counter"},
    { typeof(HelloWorld), "HelloWorld"},
});
builder.RootComponents.RegisterGoldenLayoutComponent();

βœ… Blazor Server:

builder.Services.RegisterGoldenLayoutService(new Dictionary<Type, string>
{
    { typeof(Counter), "Counter"},
    { typeof(HelloWorld), "HelloWorld"},
});

builder.Services.AddServerSideBlazor(options =>
{
    options.RootComponents.RegisterGoldenLayoutComponent();
});

4️⃣ Disable Prerendering (If Enabled)

If prerendering is enabled, you need to disable it, as it may cause components to be registered multiple times. Prerendering support is currently under development. You can disable it globally or for specific pages:

βœ… Globally Disable Prerendering (Blazor Web App):

<body>
    <Routes @rendermode="@(new InteractiveServerRenderMode(prerender: false))" />
    <script src="_framework/blazor.web.js"></script>
</body>

5️⃣ Usage

Two approaches are supported:

  • 🧩 Razor Component Approach (Declarative Configuration)
  • πŸ”§ Code-Based Approach (Pure C# Configuration)

🧩 Razor Declarative Configuration Example:

<GoldenLayoutSpawner>
    <div style="width:1000px;display: flex; gap: 12px; padding: 8px 12px; justify-content: center; background-color: #f9f9f9; border-radius: 8px; align-items: center;">
        <GoldenLayoutSpawnerItem ContentItem="_counter">ByDrag</GoldenLayoutSpawnerItem>
        <GoldenLayoutSpawnerItem ContentItem="_hello" SpawnerType="GoldenLayoutSpawnerType.BySelection">BySelection</GoldenLayoutSpawnerItem>
    </div>
</GoldenLayoutSpawner>

<GoldenLayout Style="width:1000px;height:800px" GoldenLayoutConfiguration="_configuration" SelectionChangedCallback="SelectionChangedCallback">
    <GoldenLayoutRow Title="Row">
        <GoldenLayoutStack>
            <GoldenLayoutComponent ComponentName="Counter" Title="Counter" />
            <GoldenLayoutComponent ComponentName="HelloWorld" Title="Hello" />
            <GoldenLayoutComponent ComponentName="Counter" Title="Counter" />
        </GoldenLayoutStack>
        <GoldenLayoutComponent ComponentName="HelloWorld" Title="Hello" />
        <GoldenLayoutComponent ComponentName="HelloWorld" Title="Hello" />
    </GoldenLayoutRow>
</GoldenLayout>

πŸ”§ Code-Based Configuration Example:

@page "/SimpleExample"
@using Blazor.GoldenLayout
<PageTitle>SimpleExample</PageTitle>

<GoldenLayout Style="width:600px;height:400px" GoldenLayoutConfiguration="layoutConfig" />

@code {
    private GoldenLayoutConfiguration layoutConfig = new()
    {
        Content = new List<ContentItem>
        {
            new ContentItem
            {
                ContentType = ContentType.Row,
                Content = new List<ContentItem>
                {
                    new ContentItem
                    {
                        ContentType = ContentType.Component,
                        ComponentName = "Counter",
                        Title = "Counter",
                        ComponentState = new Dictionary<string, object> { { "Cnt", 123 } }
                    },
                    new ContentItem
                    {
                        ContentType = ContentType.Component,
                        ComponentName = "Counter",
                        ComponentState = new Dictionary<string, object> { { "Cnt", 100 } }
                    },
                    new ContentItem
                    {
                        ContentType = ContentType.Component,
                        ComponentName = "Counter",
                        ComponentState = new Dictionary<string, object> { { "Cnt", 10 } }
                    }
                }
            }
        }
    };
}

🧠 How It Works

This project wraps JavaScript operations with Blazor, while supporting declarative layout configuration, making the component more aligned with the Blazor style.

To be continued...


πŸ“š API Documentation

Documentation is under development. Stay tuned!


🌈 Future Plans

  • βœ… Add more GoldenLayout API wrappers
  • βœ… Provide sample projects and GitHub Pages previews
  • πŸ”„ Support automatic adaptation for prerendering
  • βœ… Support lazy loading and dynamic component registration
  • πŸš€ Contributions via PRs or issues are welcome!

About

Blazor wrapper for GoldenLayout.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published