DEV Community

Cover image for How to Add a Sign In Button to your React Navbar
Hrushi M
Hrushi M

Posted on • Edited on • Originally published at blog.superflows.dev

How to Add a Sign In Button to your React Navbar

Introduction

This article shows you how to implement the sign in button in the react navigation bar. It shows you how to configure the sign in button input, show / hide it, set its caption, listen to the callback and then how to style it.

Prerequisites

This article assumes that you have read the previous navbar tutorials. In case you haven't you will find a consolidated list in the reference links section. This article assumes that you have installed the Superflows library, have the default navigation bar up and running, have added your brand information, have also customised your menu and have also added the search input. This tutorial takes it forward from there.

Step 1 - Show / Hide the Sign In Button

The navigation bar comes with an in-built sign in button, which is visible by default. To explicitly show it, set the showSignIn prop to true, as shown:

return (
        <div>
                <SfNav showSignIn={true}/>
        </div>
);
Enter fullscreen mode Exit fullscreen mode

It renders as follows:

Signin visible

Signin visible mobile

To hide it, set the showSignIn prop to false, as shown:

return (
        <div>
                <SfNav showSignIn={false}/>
        </div>
);
Enter fullscreen mode Exit fullscreen mode

It renders as follows:

Signin hidden

Signin hidden mobile

Step 2 - Set the Sign In Button Caption

To change the sign in button caption, set the signInCaption prop to the appropriate string value, as shown:

return (
        <div>
                <SfNav signInCaption="Log In" />
        </div>
);
Enter fullscreen mode Exit fullscreen mode

It renders as follows:

Sign In Caption

Sign In Caption Mobile

Step 3 - Handle the Callback

The navigation bar returns a callback if the user presses the sign in button. You can subscribe to this callback by subscribing to the onSignInPressed prop, as shown:

return (
        <div>
              <SfNav onSignInPressed={() => {alert('Sign In Pressed!')}}/>
        </div>
);
Enter fullscreen mode Exit fullscreen mode

Step 4 - Styling

You can then customise the look and feel, by using inline css or by class names. The Superflows navigation bar exposes props that facilitate customisation. An example is shown below:

return (
        <div>
              <SfNav 
                  stylesSignIn={{backgroundColor: 'black', color: 'white', border: 'solid 1px gray'}}
              />
        </div>
);
Enter fullscreen mode Exit fullscreen mode

It renders as follows:

Signin Styling

Signin Styling Mobile

Reference Links

Documentation

This link

Example Project For This Tutorial

This link

Previous Tutorials of Navbar

YouTube Channel

This link

Discord Community

This link

Example Projects Collection

This link

Video Tutorial

Further Reading

You have already seen how to get started with the navigation bar, how to insert brand information into it, how to customise the menu and now, how to configure the search input and how to use the sign in button. The next tutorial will discuss user profiles in the navigation bar.

Conclusion

This article shows you how to configure the search input. How to show / hide it, how to change the caption, how to add an icon, how to handle callback and how to customise and style it.

Top comments (0)