Added drawer state management
This commit is contained in:
Родитель
720434c952
Коммит
b18a71d89e
|
@ -3,10 +3,13 @@
|
|||
|
||||
@inherits LayoutComponentBase
|
||||
@inject ITelerikStringLocalizer L
|
||||
|
||||
@inject ILocalStorageService LocalStorage
|
||||
|
||||
<TelerikRootComponent>
|
||||
<TelerikDrawer @bind-Expanded="@Expanded" Width="280px" Data="Data" Mode="DrawerMode.Push" Position="DrawerPosition.Left" MiniMode="true">
|
||||
<TelerikDrawer @ref="MenuDrawer"
|
||||
Expanded="@Expanded"
|
||||
ExpandedChanged="((bool newValue) => ExpandedChangedHandler(newValue))"
|
||||
Width="280px" Data="Data" Mode="DrawerMode.Push" Position="DrawerPosition.Left" MiniMode="true">
|
||||
<Template>
|
||||
<DrawTemplate Data="context"></DrawTemplate>
|
||||
</Template>
|
||||
|
@ -14,7 +17,7 @@
|
|||
<header class="header">
|
||||
<div class="nav-container">
|
||||
<div class="menu-button">
|
||||
<TelerikButton Icon="@IconName.Menu" OnClick="@(() => Expanded = !Expanded)" />
|
||||
<TelerikButton Icon="@IconName.Menu" OnClick="ToggleMenuDrawer" />
|
||||
</div>
|
||||
|
||||
<div class="title">
|
||||
|
@ -59,7 +62,10 @@
|
|||
</TelerikRootComponent>
|
||||
|
||||
@code {
|
||||
bool Expanded { get; set; } = true;
|
||||
|
||||
TelerikDrawer<DrawerItem> MenuDrawer { get; set; }
|
||||
|
||||
bool Expanded { get; set; }
|
||||
bool SettingsExpanded { get; set; }
|
||||
|
||||
IEnumerable<DrawerItem> Data =>
|
||||
|
@ -73,6 +79,38 @@
|
|||
new DrawerItem{ Text = "Telerik", Icon = IconName.HyperlinkGlobe, Url="https://telerik.com", Group = "ext"},
|
||||
new DrawerItem{ Text = L["Documentation"], Icon = IconName.Html, Url="https://docs.telerik.com/blazor-ui/introduction", Group = "ext"},
|
||||
new DrawerItem{ Text = L["Support"], Icon = IconName.Question, Url="https://www.telerik.com/account/support-tickets", Group = "ext"}
|
||||
};
|
||||
};
|
||||
|
||||
async Task ToggleMenuDrawer()
|
||||
{
|
||||
if (Expanded)
|
||||
{
|
||||
await MenuDrawer.CollapseAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
await MenuDrawer.ExpandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
async Task ExpandedChangedHandler(bool value)
|
||||
{
|
||||
Expanded = value;
|
||||
|
||||
await LocalStorage.SetItemAsync<bool>("drawerState", value);
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var hasKey = await LocalStorage.ContainKeyAsync("drawerState");
|
||||
if (hasKey)
|
||||
{
|
||||
Expanded = await LocalStorage.GetItemAsync<bool>("drawerState");
|
||||
}
|
||||
else
|
||||
{
|
||||
Expanded = true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Загрузка…
Ссылка в новой задаче