Cool new Sidebar navigation for Blazor Applications


 I have been working with Blazor since 2019.  My first Blazor application did not even use a template.  But the templates were provided shortly after, which were very much welcomed.  When I first starting using the template, I thought it was a good template, nice colors and the nav was good too.  

I have created a lot of Blazor applications,  the current template is starting to look redundant to me.  Plus all other simple Blazor applications have a similar look and feel.  So I figured it was time to generate my own.  This post is the first one I created.

I looked around and found several navigations I like, but none of them had all the feature I was wanted.   This is my version of a navigation bar that has the features I was looking for.  I did struggle with what if any UI kit to use.  More on that in an upcoming blog post.  Spoiler alert, I did not use any.


Key Features

  1. Nice header
  2. Left sided nav bar
  3. Sidebar that slides out
  4. Pin sidebar
  5. Responsive
  6. Cool colors

Building the Nav

Now that I have my features defined, I can get started on building the nav.  The nav is a mixture of HTML, CSS and C#.  Truth be told, the C# code was the easy part.

HTML

The following of the HTML elements used:
  • Header
  • Container ( 2 divs)
  • Nav Items (order list)
  • Icons
  • Href 
  • Div we use to "toggle" the bar to full size of not
The key part if the use of a main sections that holds the @Body tag.

CSS


Most of the CSS is used to set colors and sizing.  You can review the source code for the details.  Media queries were used to handle the responsiveness.  

Some of the cool parts is the "toggle" class.  This class handles the changing of the color and size of the side panel on hover and click,  It provides a nice look and feel once it is widen.  

<div class="toggle @activeClass @navClass" @onclick="ToggleMenu">
</div>



C# Code

We needed to handle the "Pin" event.  For this we used C# instead of JavaScript, because we love Blazor.

One the toggle click, we just add the CSS classes needed to change the UI and to set the flag that the toggle is active.

We had to set the class in the class that handles the position on the right side.  If we did not the right side view would be under the expanded panel.

Icons

I used Font Awesome for my icons.  I already have a link to them and thought I might want to make this available offline.  As it turns out, I no longer really like Font Awesome.  They make it hard to find the "free" fonts and want you to pay for their subscription.

If you are a better recondition, please let me know if the comments.


Summary

This was a fun project.  It took more time they it probably should have.  I am color challenge and the whole mess of what if any UI toolkit to use.  I plan on building several more navs.  I will most likely talk abut all of them in a single post.






Comments

Popular posts from this blog

Yes, Blazor Server can scale!

Blazor new and improved Search Box

Blazor Wizard Step Component