1.0.0 • Published 3 years ago

@psyora/psy-sidenav-icon v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

Introduction

Psy-SideNav-Icon library is created to easily render sidenav cards that can be used to navigate to the main content inside an Angular application. This library was generated with Angular CLI version 10.0.14.

This library is recommened to be used with a layout generated via CSS-Grid.

Installation Instructions

Step 1: Install the library from npm

To install, run the following command in your angular project

npm i @psyora/psy-sidenav-Icon

Step 2: Import the library to Angular

To use the library in your application, import it to your angular application in your app or shared module.

import { PsySidenavIconModule } from 'psy-sidenav-icon';

@NgModule({
    imports: [
        ...,
        PsySidenavIconModule,
        ...
    ]
})

export class AppModule { }

Step 3: Use the library in the application using the selector

selector: psy-sidenav-icon

<div>
  <div>
    This is the content of the website
  </div>
  <div>
    <psy-sidenav-icon></psy-sidenav-icon>   
  </div>
</div>

The icons will not be rendered after this. Refer to the instructions from Quick Setup setup to see the preview of icons.

Usage instructions

The component psy-sidenav-icon can be used to create a single icon-card with 1. Icon 1. Title 1. Text

By default, only Icon and Title are visible.

default-card

When a user hovers over the card, the card expands and the card becomes visible.

expanded-card

On clicking a card, the user can be redirected to a url path. More details.

In order to generate more than one icons using the library, either have 2 selectors in the component or use *ngFor to create a loop.

API Reference

To generate a sidenav icon easily, the library exposes a ISideNavLink interface.

The definition of the interface is as follows:

export interface ISideNavLink {
  'matIcon': string,
  'title': string,
  'text': string,
  'path': string,
}
#PropertyDescriptionRequired
1.Mat IconThe code of the material icon that needs to be renderedY
2.TitleTitle of the CardY
3.TextAdditional information about card. Visible only when user hovers over the cardY
4.PathA relative or absoute path, that the app should navigate to on clicking on cardY

Quick Setup

Use the following boiler-plate code in the application for a quick simulation of a working application:


Prerequisites:

  • Angular Material Module needs to be installed and imported inside the app.

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { PsySidenavIconModule } from 'psy-sidenav-icon';
import { MatIconModule } from '@angular/material/icon';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    PsySidenavIconModule,

    MatIconModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

app.component.ts

import { Component } from '@angular/core';
import { ISideNavLink } from 'psy-sidenav-icon';

@Component({
  selector: 'psy-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})

export class AppComponent {

  sideNavLinks: ISideNavLink[] = [{
    'matIcon': 'home',
    'title': 'Home',
    'text': 'Return to home',
    'path': '/test'
  }, {
    'matIcon': 'edit',
    'title': 'Update',
    'text': 'Update object',
    'path': '/test'
  }, {
    'matIcon': 'schedule',
    'title': 'History',
    'text': 'Check logs',
    'path': '/test'
  }]
};

app.component.scss

@import "https://fonts.googleapis.com/icon?family=Material+Icons";

.grid {
    display: grid;
    margin: 1em;
    height: 90vh;

    grid-template-columns: 70% 30%;
    grid-column-gap: 1em;

    &__sidenav {
        display: grid;
        grid-template-columns: repeat(2, minmax(50%, max-content));
        align-content: flex-start;
    }
}

app.component.html

<div class="grid">
  <div class="grid__content">
    This is the content of the website
  </div>
  <div class="grid__sidenav">
    <psy-sidenav-icon *ngFor="let sideNavLink of sideNavLinks" [sideNavLink]="sideNavLink"></psy-sidenav-icon>   
  </div>
</div>

On Success, you should see the SideNav's as follows: 01.app-preview