Angular PrimeNG Toolbar Styling
Last Updated :
14 Feb, 2023
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. In this article, we will learn how to use the Toolbar Styling in Angular PrimeNG.
The Toolbar Component is used to group buttons and other components. The Styling classes are used to add some CSS styles on the Toolbar components.
Angular PrimeNG Toolbar Styling:
- p-toolbar: It is the main container element.
- p-toolbar-group-start: It is the start container element.
- p-toolbar-group-center: It is the center container element.
- p-toolbar-group-end: It is the end container element.
Creating Angular application & module installation:
Step 1: Create an Angular application using the following command.
ng new appname
Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
Step 3: Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save
Project Structure: It will look like the following:
Steps to run the application: To run the above file, run the below command:
ng serve --save
Example 1: Below is the example code that illustrates the use of Angular PrimeNG Toolbar Styling.
HTML
< h1 style = "color: green;" >GeeksforGeeks</ h1 >
< h5 >Angular PrimeNG Toolbar Styling</ h5 >
< p-toolbar >
< div class = "p-toolbar-group-left" >
< p-button
label = "GfG Tutorials"
icon = "pi pi-book"
styleClass = "p-button-success" >
</ p-button >
< i class = "p-toolbar-separator pi pi-code mr-2" ></ i >
< p-splitButton
label = "GfG Courses"
[model]="gfg"
styleClass = "p-button-warning" >
</ p-splitButton >
</ div >
</ p-toolbar >
|
Javascript
import { Component } from "@angular/core" ;
import { MenuItem } from "primeng/api" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
styleUrls: [ "./app.component.css" ],
})
export class AppComponent {
gfg: MenuItem[];
ngOnInit() {
this .gfg = [
{
label: "Data Structure" ,
styleClass: "myClass"
},
{
label: "System Design"
},
{
label: "SDE Test Series"
},
{
label: "C++ STL"
}
];
}
}
|
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 { ToolbarModule } from "primeng/toolbar" ;
import { ButtonModule } from "primeng/button" ;
import { SplitButtonModule } from "primeng/splitbutton" ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
ToolbarModule,
ButtonModule,
SplitButtonModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
|
CSS
:host ::ng-deep .p-toolbar {
border : 5px solid green ;
}
|
Output:
Example 2: Below is another example code that illustrates the use of Angular PrimeNG Toolbar Styling.
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h5 >Angular PrimeNG Toolbar Styling</ h5 >
< p-toolbar >
< div class = "p-toolbar-group-left" >
< p-button label = "GfG Tutorials" icon = "pi pi-book"
styleClass = "p-button-success myClass" >
</ p-button >
< i class = "p-toolbar-separator pi pi-code mr-2" ></ i >
< p-splitButton label = "GfG Courses" [model]="gfg"
styleClass = "p-button-warning myClass" >
</ p-splitButton >
</ div >
< div class = "p-toolbar-group-right" >
< p-button label = "Sign In" icon = "pi pi-sign-in"
styleClass = "myClass" style = "margin-right: 5px" >
</ p-button >
< p-button label = "Sign Out"
styleClass = "myClass" icon = "pi pi-sign-out" >
</ p-button >
</ div >
</ p-toolbar >
|
Javascript
import { Component } from "@angular/core" ;
import { MenuItem } from "primeng/api" ;
@Component({
selector: "app-root" ,
templateUrl: "./app.component.html" ,
styleUrls: [ "./app.component.css" ],
})
export class AppComponent {
gfg: MenuItem[];
ngOnInit() {
this .gfg = [
{
label: "Data Structure" ,
styleClass: "myClass"
},
{
label: "System Design" ,
styleClass: "myClass"
},
{
label: "SDE Test Series" ,
styleClass: "myClass"
},
{
label: "C++ STL" ,
styleClass: "myClass"
}
];
}
}
|
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 { ToolbarModule } from "primeng/toolbar" ;
import { ButtonModule } from "primeng/button" ;
import { SplitButtonModule } from "primeng/splitbutton" ;
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
ToolbarModule,
ButtonModule,
SplitButtonModule
],
declarations: [AppComponent],
bootstrap: [AppComponent]
})
export class AppModule {}
|
CSS
:host ::ng-deep .p-toolbar {
box-shadow: 2px 12px #888888 ;
}
:host ::ng-deep .myClass{
border : 2px solid red ;
box-shadow: 6px 8px #888888 ;
}
|
Output:
Reference: https://primefaces.org/primeng/toolbar
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...