ant-design-blazor/site/AntDesign.Docs/Shared/HeaderMenu.razor.cs
James Yeung d2e9c4b247 feat(module: config-provider): support RTL (#1238)
* feat(module: config-provider): support RTL

* add rtl for each component

* fix rtl for pagination

* add rtl for overlay
2021-03-31 19:23:26 +08:00

46 lines
1.5 KiB
C#

using System.Threading.Tasks;
using AntDesign.Docs.Localization;
using AntDesign.Docs.Services;
using Microsoft.AspNetCore.Components;
namespace AntDesign.Docs.Shared
{
public partial class HeaderMenu : ComponentBase
{
[Parameter] public bool IsMobile { get; set; }
[Inject] private DemoService DemoService { get; set; }
[Inject] private ILanguageService LanguageService { get; set; }
[Inject] private NavigationManager NavigationManager { get; set; }
[CascadingParameter] public ConfigProvider ConfigProvider { get; set; }
string CurrentLanguage => LanguageService.CurrentCulture.Name;
string Direction => ConfigProvider?.Direction;
private DemoMenuItem[] _menuItems = { };
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
_menuItems = await DemoService.GetMenuAsync();
LanguageService.LanguageChanged += async (sender, args) =>
{
_menuItems = await DemoService.GetMenuAsync();
await InvokeAsync(StateHasChanged);
};
}
private void ChangeLanguage(string language)
{
var currentUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
var newUrl = currentUrl.IndexOf('/') > 0 ? currentUrl.Substring(currentUrl.IndexOf('/') + 1) : currentUrl;
NavigationManager.NavigateTo($"{language}/{newUrl}");
}
}
}