Open In App

Angular PrimeNG Slide Menu Styling

Improve
Improve
Like Article
Like
Save
Share
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG Slide Menu Styling.

The Slide Menu component allows the creation of the menu in the form of a tier. It displays submenus in nested overlays. The Slide Menu Styling classes allow changing the design of the component from the default design by implementing the list of structural style classes provided by Angular PrimeNG.

Angular PrimeNG Slide Menu Styling Classes:

  • p-slidemenu: It is a container element.
  • p-slidemenu-wrapper: It is a wrapper of content.
  • p-slidemenu-content: It is a content element.
  • p-slidemenu-backward: It is an element to navigate to the previous menu on click.
  • p-menu-list: It is a list element.
  • p-menuitem: It is a menu item element.
  • p-menuitem-text: It is a label of a menu item.
  • p-menuitem-icon: It is an icon of a menu item.
  • p-submenu-icon: It is the arrow icon of a submenu.

 

Syntax:

// app.component.html
<p-slideMenu [model]="..."></p-slideMenu>

// app.component.css
:host ::ng-deep .p-slidemenu {
  border: 2px green;
  border-style: dashed;
  padding: 2px;
}

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new geeks_angular

Step 2: After creating your project folder i.e. geeks_angular, move to it using the following command.

cd geeks_angular

Step 3: Install PrimeNG and CDK in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: The project structure will look like the following:

 

Example 1: In the following example, we have a SlideMenu with a border around the list.

  • app.component.html

HTML




<h1 style="color: green;
           text-align:center;">
  GeeksforGeeks
</h1>
  
<h3>Angular PrimeNG SlideMenu Styling</h3>
<p-slideMenu [model]="items" 
             [viewportHeight]="300">
</p-slideMenu>


  • app.component.css

CSS




:host ::ng-deep .p-slidemenu {
  border: 4px green;
  border-style: dashed;
  padding: 8px;
}


  • app.component.ts

Javascript




import { Component, OnInit, ViewEncapsulation } 
    from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
export class AppComponent {
    items: MenuItem[];
  
    ngOnInit() {
        this.items = [
            {
                label: 'Data Structures',
                items: [
                    {
                        label: 'Linked List',
                        items: [
                            {
                                label: 'Singly Linked List',
                            },
                            {
                                label: 'Doubly Linked List',
                            },
                        ],
                    },
                    {
                        label: 'Trie',
                    },
                    {
                        label: 'Array',
                    },
                ],
            },
            {
                label: 'Algorithms',
                items: [
                    {
                        label: 'Sorting',
                    },
                    {
                        label: 'Searching',
                    },
                ],
            },
            {
                label: 'Development',
  
                items: [
                    {
                        label: 'Android',
                    },
                    {
                        label: 'Web development',
                    },
                ],
            },
        ];
    }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { SlideMenuModule } from 'primeng/slidemenu';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        SlideMenuModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

Example 2: In the following example, we have added a shadow and border around the back button.

  • app.component.html

HTML




<h1 style="color: green;
           text-align:center;">
  GeeksforGeeks
</h1>
  
<h3>Angular PrimeNG SlideMenu Styling</h3>
<p-slideMenu [model]="items" 
             [viewportHeight]="300">
</p-slideMenu>


  • app.component.css

CSS




:host ::ng-deep .p-slidemenu-backward {
  border: 2px gray;
  border-style: solid;
  border-radius: 25px;
  margin-bottom: 20px;
  box-shadow: 5px 10px 12px #888888;
}


  • app.component.ts

Javascript




import { Component, OnInit, ViewEncapsulation } 
    from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css'],
})
export class AppComponent {
    items: MenuItem[];
  
    ngOnInit() {
        this.items = [
            {
                label: 'Data Structures',
                items: [
                    {
                        label: 'Linked List',
                        items: [
                            {
                                label: 'Singly Linked List',
                            },
                            {
                                label: 'Doubly Linked List',
                            },
                        ],
                    },
                    {
                        label: 'Trie',
                    },
                    {
                        label: 'Array',
                    },
                ],
            },
            {
                label: 'Algorithms',
                items: [
                    {
                        label: 'Sorting',
                    },
                    {
                        label: 'Searching',
                    },
                ],
            },
            {
                label: 'Development',
  
                items: [
                    {
                        label: 'Android',
                    },
                    {
                        label: 'Web development',
                    },
                ],
            },
        ];
    }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { SlideMenuModule } from 'primeng/slidemenu';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        SlideMenuModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

Reference: http://primefaces.org/primeng/slidemenu



Last Updated : 15 Dec, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads