Nav Bar

A navigation bar (nav bar) is a collection of landmarks that each contain a group of links that can be used to navigate through the webpage. This component will provide you with a nav bar where each collection contains a list of anchor tags which can be clicked to navigate to the supplied endpoint.

Installation

Installation

Import the component in the script section of your Svelte file:


import NavBar from 'svve11/NavBar.svelte'
          
Usage

Usage

Creating a Nav Bar

To supply the nav bar with its contents, an options object is passed as a prop to the nav bar. This object can be created in the script section of the .svelte file or imported in from another location. The options object has 6 properties.

    Required Props

  • contentInfo (array): This will set the main content in your nav bar. This array contains a series of objects that should be defined as follows:
    • options (array): The array contains a series of strings, and the order of the strings will determine the order they appear in the nav bar section. This will define the text labeling a given nav landmark.
    • links (array): The array contains a series of strings, and the order of the strings should mimic that of the options array above. These strings will set the href attribute of the anchor tag that enable navigation.
    • subheading (string): This will set the subheading for a section of the nav bar.

    Optional Props

  • id (string): This will be the id attribute you reference for styling inside your navbar component.
  • header (string): This will set the heading for the entire nav bar.
  • imgSrc (string): This will set the file path for an image you want to include at the top of the menu.
  • imgClass (string): This will set the class for the image included with the imgSrc attribute.
  • imgAlt (string): This will set the alternate text for the image included with the imgSrc attribute.

Example Options Object:


const navOptions = {}
  contentInfo: [
	{
	  subheading: '',
	  options: ['Home', 'Github'],
	  links: ['/', 'https://github.com/oslabs-beta/svve11']
	},
	{
	  subheading: 'Components',
	  options: ['Accordion','Button','Checkbox', ...],
	  links: ['/pages/accordion','/pages/button','/pages/checkbox',...]
	},
	{
	  subheading: '',
	  options: ['About the team'],
	  links: ['/about']
	}
  ],
	id: 'nav-bar',
  imgSrc: logo,
  imgClass: 'svvell-logo',
  imgAlt: 'svve11'
};
			

Instantiating a nav bar


<NavBar options={navOptions} />
	

As an example, the nav bar for this webpage is made using this component and the options object above was used to create it.

Styling

Styling the Nav Bar with Classes

The nav bar is made of 5 components that can have styles applied to them using the pre-assigned classes and a globally scoped CSS stylesheet. The classes are:

  • sv-navbar: This applies styling to the nav bar
  • sv-navbar-header: This applies styling to the main heading of the nav bar
  • sv-navbar-subheader: This applies styling to each subheading of the nav bar
  • sv-navbar-section: This applies styling to each section of the nav bar
  • sv-navbar-option: This applies styling to each option of the nav bar
Component API

Component API

This table describes the props that should be passed to the nav bar in the options object
PropTypeRequiredDefault Value
contentInfo array of objects true N/A
id string false N/A
header string false N/A
imgSrc string false N/A
imgClass string false N/A
imgAlt string false N/A