Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add NeutralBaseColor to GlobalState and FDT
  • Loading branch information
vnbaaij committed Mar 16, 2025
commit 42cefdf36d1628979e068695b7960057eab68679
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@namespace Microsoft.FluentUI.AspNetCore.Components
@namespace Microsoft.FluentUI.AspNetCore.Components

<fluent-design-theme id="@Id" mode="@GetMode()" primary-color="@GetColor()" storage-name="@StorageName" />
@ChildContent
<fluent-design-theme id="@Id" mode="@GetMode()" primary-color="@GetColor()" neutral-base-color="@NeutralBaseColor" storage-name="@StorageName" />
@ChildContent
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ public partial class FluentDesignTheme : ComponentBase
[Parameter]
public EventCallback<OfficeColor?> OfficeColorChanged { get; set; }

[Parameter]
public string? NeutralBaseColor { get; set; }

[Parameter]
public EventCallback<string?> NeutralBaseColorChanged { get; set; }

/// <summary>
/// Gets or sets the local storage name to save and retrieve the <see cref="Mode"/> and the <see cref="OfficeColor"/> / <see cref="CustomColor"/>.
/// </summary>
Expand Down Expand Up @@ -175,6 +181,12 @@ public async Task OnChangeRaisedAsync(string name, string value)
}
}

break;
case "neutral-base-color":
if (value.StartsWith('#'))
{
GlobalDesign.SetNeutralColor(value);
}
break;
}
}
Expand Down Expand Up @@ -256,13 +268,24 @@ private async Task ApplyLocalStorageValuesAsync(DataLocalStorage? theme)
await OnChangeRaisedAsync("primary-color", theme.PrimaryColor);
}
}

// Neutral base color
if (!string.IsNullOrEmpty(theme?.NeutralBaseColor))
{
if (theme.NeutralBaseColor.StartsWith('#'))
{
GlobalDesign.SetNeutralColor(theme.NeutralBaseColor);
}
await OnChangeRaisedAsync("neutral-base-color", theme.NeutralBaseColor);
}
}

/// <summary />
private class DataLocalStorage
{
public string? Mode { get; set; }
public string? PrimaryColor { get; set; }
public string? NeutralBaseColor { get; set; }
}

/// <summary />
Expand Down
12 changes: 12 additions & 0 deletions src/Core/GlobalState.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// ------------------------------------------------------------------------
// MIT License - Copyright (c) Microsoft Corporation. All rights reserved.
// ------------------------------------------------------------------------

using Microsoft.AspNetCore.Components;

namespace Microsoft.FluentUI.AspNetCore.Components;
Expand All @@ -16,6 +20,8 @@ public class GlobalState

public string? Color { get; set; }

public string? NeutralColor { get; set; }

public event Action? OnChange;

public void SetDirection(LocalizationDirection dir)
Expand All @@ -42,6 +48,12 @@ public void SetColor(string? color)
NotifyStateHasChanged();
}

public void SetNeutralColor(string? neutralColor)
{
NeutralColor = neutralColor;
NotifyStateHasChanged();
}

private void NotifyStateHasChanged()
{
OnChange?.Invoke();
Expand Down